Is it possible to remove symbols from a shared library built with Android NDK?

て烟熏妆下的殇ゞ 提交于 2019-12-04 22:14:22

问题


I'm building a shared library for use in a Java app using the Android NDK. Using readelf to inspect the lib/armeabi-v7a/libXXXlib.so file generated by a release build, it appears to contain all the symbols (function, variable names) of my native C/C++ code.

Indeed, the shared object file appears to be identical for the debug and release builds. (The only difference in the output in the libs folder being whether or not the gsb.setup and gdbserver files are created.) I'm overriding the optimisation set by the NDK with an APP_CFLAGS += -O3 in my Application.mk, but I wouldn't expect the release build to generate debug symbols by including the -g flag, which it does.

I found a comment on SO stating 'In both cases, debug and release, it leaves the -g flag in because, to quote the comment, "we generate symbol versions of the binaries that are later stripped when they are copied to the final project's libs/ directory"', and another stating: 'JNI cannot find the functions for java if they don't have names.'

ndk-build is certainly stripping something from the obj/armeabi-v7a/libXXXlib.so file, as that is much larger than the one eventually created in libs, but it still seems to be leaving all my functions' and variables' names intact in the file.

Are all my functions' names required by JNI (rather than just the entry-points into the native code)?

If not, how can I remove the symbols which are not required?


回答1:


Feel free to set default visibility=hidden, and set attribute visibility=default for the few functions you need to export (similar to DLLEXPORT) in Windows



来源:https://stackoverflow.com/questions/17022983/is-it-possible-to-remove-symbols-from-a-shared-library-built-with-android-ndk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!