Skip to content

lld + objcopy/strip breaks relro #843

@ngg

Description

@ngg

NDK version: r18b
Architecture: tested on aarch64 (probably others as well)
Host OS: tested on Linux (probably others as well)

This bug is most probably caused by https://sourceware.org/bugzilla/show_bug.cgi?id=22829

To reproduce, compile an executable (or shared library) with lld and relro enabled then strip or objcopy it. This last step will disable relro by deleting the GNU_RELRO segment.

Possible solutions:

Example file and command to reproduce:

// hello.c
#include <stdio.h>
int main(void)
{
    puts("Hello world!");
    return 0;
}
nggpc% $NDK/toolchains/llvm/prebuilt/linux-x86_64/bin/clang -target aarch64-none-linux-android --sysroot $NDK/platforms/android-21/arch-arm64 -L$NDK/sources/cxx-stl/llvm-libc++/libs/arm64-v8a -isystem $NDK/sysroot/usr/include -isystem $NDK/sysroot/usr/include/aarch64-linux-android -gcc-toolchain $NDK/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64 -fuse-ld=lld -o original hello.c                                                                                                                                    
nggpc% $NDK/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/aarch64-linux-android/bin/objcopy original copied
nggpc% cp original stripped
nggpc% $NDK/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/aarch64-linux-android/bin/strip stripped
nggpc% readelf -We original |grep RELRO
  GNU_RELRO      0x030000 0x0000000000030000 0x0000000000030000 0x000200 0x001000 R   0x1
nggpc% readelf -We copied |grep RELRO
[1]    15327 done       readelf -We copied | 
       15328 exit 1     grep --color=auto RELRO
nggpc% readelf -We stripped |grep RELRO
[1]    15406 done       readelf -We stripped | 
       15407 exit 1     grep --color=auto RELRO

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions