SSong
SSong

Reputation: 35

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).

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). Somehow the symbol of the dummy function still exists and we can see it by using "nm" against the generated .so.

We are using NDK r8d on Linux 11.10.

Is there any specific compiler/linker flags that we need to apply to Android.mk in order to get the dead code removed?

Thank you!

Upvotes: 3

Views: 1101

Answers (1)

Yasir Malik
Yasir Malik

Reputation: 439

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.

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. http://gcc.gnu.org/wiki/Visibility

Upvotes: 2

Related Questions