Skip to content

[question] NDK 21: how to get rid of source filenames in .so? #1212

@biasmv

Description

@biasmv

We are currently trying to switch to NDK 21 from r18b. In NDK 21, when building a shared object file, it appears that the source file names are included in the resulting .so file. What's the best way to get rid of those filenames from the .so file?

This behaviour can be reproduced with the following setup:

> cat foo.cpp
extern "C" void foo_function() {}
> cat CMakeLists.txt
project(AndroidStripTest CXX)
add_library(
    foo SHARED
    foo.cpp
)
> mkdir build
> cd build
> cmake -DCMAKE_TOOLCHAIN_FILE=$NDK_ROOT/build/cmake/android.toolchain.cmake \
             -DANDROID_ABI=arm64-v8a \
             -DCMAKE_BUILD_TYPE=Release \
             -DANDROID_STL=none
> make
> export TOOLCHAIN=$NDK_ROOT/toolchains/llvm/prebuilt/darwin-x86_64
> $TOOLCHAIN/bin/llvm-objcopy --strip-debug \
        --discard-all libfoo.so libfoo-stripped.so
> strings libfoo-stripped.so | grep foo.cpp
foo.cpp

Tested with NDK Version: 21.0.6113669

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions