简体   繁体   English

不会从Android NDK构建的共享对象中删除死函数

[英]Dead function is not removed from the shared object built from Android NDK

We noticed that some dead functions are not removed from the generated shared object file (.so) that is built as release (via "ndk-build" without any parameter). 我们注意到,生成的共享对象文件(.so)中没有删除一些死函数,这些文件是作为发布版本构建的(通过“ndk-build”而没有任何参数)。

To prove that we introduced a dummy function that is definitely not called anywhere (and is also not exported since the default visibility is already set to "hidden" for the whole .so). 为了证明我们引入了一个绝对不会在任何地方调用的虚函数(并且也没有导出,因为默认可见性已经被设置为整个.so的“隐藏”)。 Somehow the symbol of the dummy function still exists and we can see it by using "nm" against the generated .so. 不知何故,虚函数的符号仍然存在,我们可以通过对生成的.so使用“nm”来看到它。

We are using NDK r8d on Linux 11.10. 我们在Linux 11.10上使用NDK r8d。

Is there any specific compiler/linker flags that we need to apply to Android.mk in order to get the dead code removed? 是否有任何特定的编译器/链接器标志需要应用于Android.mk才能删除死代码?

Thank you! 谢谢!

Removing dead functions can greatly reduce the binary size too. 删除死函数也可以大大减少二进制大小。 For this, change C and C++ compilation flags and the linker flags in Android.mk . 为此,请更改Android.mk C和C ++编译标志以及链接器标志。

LOCAL_CPPFLAGS += -ffunction-sections -fdata-sections
LOCAL_CFLAGS += -ffunction-sections -fdata-sections 
LOCAL_LDFLAGS += -Wl,--gc-sections

Also, the visibility features in GCC can be of help. 此外,GCC中的visibility功能可能会有所帮助。 http://gcc.gnu.org/wiki/Visibility http://gcc.gnu.org/wiki/Visibility

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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