简体   繁体   中英

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

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?

您可以随意设置默认的visibility = hidden,并为Windows中需要导出的少数函数设置属性visibility = default(类似于DLLEXPORT)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM