Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
biasmv opened this issue Mar 20, 2020 · 14 comments
Closed

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

biasmv opened this issue Mar 20, 2020 · 14 comments
Assignees
Labels
Milestone

Comments

@biasmv
Copy link

biasmv commented Mar 20, 2020

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

@DanAlbert
Copy link
Member

objdump the library and see where it's being referenced, I suppose.

@rprichard
Copy link
Collaborator

It looks like llvm-objcopy --strip-debug leaves FILE symbols around, whereas binutils' objcopy --strip-debug removes them.

$ $TOOLCHAIN/bin/llvm-objcopy --strip-debug libfoo.so  libfoo-stripped.so && readelf -s libfoo-stripped.so  | grep FILE
    20: 0000000000000000     0 FILE    LOCAL  DEFAULT   ABS /buildbot/tmp/crtbrand-440a44.o
    28: 0000000000000000     0 FILE    LOCAL  DEFAULT   ABS crtbegin_so.c
    37: 0000000000000000     0 FILE    LOCAL  DEFAULT   ABS foo.cpp
    41: 0000000000000000     0 FILE    LOCAL  DEFAULT   ABS 
$ $TOOLCHAIN/bin/aarch64-linux-android-objcopy --strip-debug libfoo.so  libfoo-stripped.so && readelf -s libfoo-stripped.so  | grep FILE
<nothing>

@biasmv
Copy link
Author

biasmv commented Mar 23, 2020

Thanks aarch64-linux-android-objcopy indeed removes the FILE symbols. Is this an expected difference between the two objcopy implementations? Or is it worth submitting a bug to llvm-objcopy?

@enh-google
Copy link
Collaborator

yeah, given that the manual mentions a --keep-file-symbols option, i'm assuming that this is indeed a bug :-)

@pirama-arumuga-nainar might know more because i think he was involved in some of the objcopy issues we had switching the OS itself over to llvm-objcopy... maybe this is already fixed?

@pirama-arumuga-nainar
Copy link
Collaborator

@kongy has the most background on this. We did fix some llvm-objcopy in later AOSP clang versions.

@enh-google
Copy link
Collaborator

@kongy uploaded https://reviews.llvm.org/D76675 to fix this upstream...

@DanAlbert DanAlbert added this to the r22 milestone Mar 24, 2020
@DanAlbert
Copy link
Member

It seems this affects only objcopy and not strip. Since we don't use llvm-objcopy in ndk-build or our CMake toolchain and using the LLVM flavors of the tools is only a recommendation in r21, I'm leaning toward saying this can wait until r22.

That said, if @stephenhines and co think this is trivial to fix in r21 we might as well since it's the LTS people will be on for a while and we're already working on a release of that. WDYT?

@stephenhines
Copy link
Collaborator

I think this is fine for r22. We haven't switched to the LLVM binutils in r21 LTS (and there would be a workaround for this), so this doesn't really belong there.

@biasmv
Copy link
Author

biasmv commented Mar 27, 2020

Thanks for getting this fixed so quickly! What's the procedure here, do you want to keep the ticket open as long as the change to LLVM is still pending?

@DanAlbert
Copy link
Member

Yeah, we'll keep this open until we've merged it into the NDK. Once the fix is available in our master branch we'll close it.

@stephenhines
Copy link
Collaborator

Yi, can you follow up on that upstream patch to ensure it makes it in? I'd like to be able to get this for R22. We can cherry-pick as necessary after Yabin's update too.

kongy added a commit to llvm/llvm-project that referenced this issue Apr 21, 2020
GNU objcopy removes STT_FILE symbols for strip-debug operations, and
keeps them for --discard-all operation. Match their behaviour for
llvm-objcopy.

Bug: android/ndk#1212

Differential Revision: https://reviews.llvm.org/D76675
MaskRay added a commit to llvm/llvm-project that referenced this issue Apr 21, 2020
Don't error on Config.KeepFileSymbols for COFF and Mach-O.

Original description:

GNU objcopy removes STT_FILE symbols for strip-debug operations, and
keeps them for --discard-all operation. Match their behaviour for
llvm-objcopy.

Bug: android/ndk#1212

Differential Revision: https://reviews.llvm.org/D76675
@kongy
Copy link
Collaborator

kongy commented Apr 21, 2020

@kongy kongy closed this as completed Apr 21, 2020
@DanAlbert
Copy link
Member

DanAlbert commented Apr 21, 2020

Reopening so we don't forget to take the update into the NDK itself. Reassigning to myself to do that. Thanks for the fix 👍

@DanAlbert DanAlbert reopened this Apr 21, 2020
@DanAlbert DanAlbert assigned DanAlbert and unassigned kongy and stephenhines Apr 21, 2020
@DanAlbert
Copy link
Member

We have updated now.

arichardson pushed a commit to arichardson/llvm-project that referenced this issue Jul 2, 2020
GNU objcopy removes STT_FILE symbols for strip-debug operations, and
keeps them for --discard-all operation. Match their behaviour for
llvm-objcopy.

Bug: android/ndk#1212

Differential Revision: https://reviews.llvm.org/D76675
arichardson pushed a commit to arichardson/llvm-project that referenced this issue Jul 2, 2020
Don't error on Config.KeepFileSymbols for COFF and Mach-O.

Original description:

GNU objcopy removes STT_FILE symbols for strip-debug operations, and
keeps them for --discard-all operation. Match their behaviour for
llvm-objcopy.

Bug: android/ndk#1212

Differential Revision: https://reviews.llvm.org/D76675
wantguns pushed a commit to wantguns/toolchain_llvm_android that referenced this issue Jul 17, 2020
…g file symbols"

... and r385798 for avoid merge conflicts.

Bug: android/ndk#1212
Change-Id: Ia614630a02c654ea17e5ed5d86494de36d7c89d9
mem-frob pushed a commit to draperlaboratory/hope-llvm-project that referenced this issue Oct 7, 2022
GNU objcopy removes STT_FILE symbols for strip-debug operations, and
keeps them for --discard-all operation. Match their behaviour for
llvm-objcopy.

Bug: android/ndk#1212

Differential Revision: https://reviews.llvm.org/D76675
mem-frob pushed a commit to draperlaboratory/hope-llvm-project that referenced this issue Oct 7, 2022
Don't error on Config.KeepFileSymbols for COFF and Mach-O.

Original description:

GNU objcopy removes STT_FILE symbols for strip-debug operations, and
keeps them for --discard-all operation. Match their behaviour for
llvm-objcopy.

Bug: android/ndk#1212

Differential Revision: https://reviews.llvm.org/D76675
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants