Skip to content

Commit

Permalink
ld.bfd: omit DF_1_PIE when targeting Android
Browse files Browse the repository at this point in the history
Some versions of the Android dynamic linker (e.g. N) print a warning:

    WARNING: linker: /data/local/tmp/a.out: unsupported flags DT_FLAGS_1=0x8000000

${target} will be something like:

 - arm-unknown-linux-androideabi
 - aarch64-unknown-linux-android
 - i686-pc-linux-android

Bug: android/ndk#602
Test: manual:
  1. create a standalone ARM64 toolchain with NDK r16b
  2. echo 'int main() {}' > justmain.c
  3. ~/stand-arm64-21-libc++-r16b/bin/clang justmain.c -pie -fPIE \
         -fuse-ld=bfd && \
         readelf -d a.out | grep FLAG
     -- OUTPUT: 0x000000006ffffffb (FLAGS_1)            Flags: 8000000
  4. ~/stand-arm64-21-libc++-r16b/bin/clang justmain.c -pie -fPIE \
         -fuse-ld=bfd \
         -B ~/android/ndk/out/binutils/linux/arm64/install/binutils-arm64-linux/aarch64-linux-android/bin && \
         readelf -d a.out | grep FLAG
     -- OUTPUT: nothing
Change-Id: I040b6edbd8d7943b790db0ef19b76cfdffc1ccdf
  • Loading branch information
rprichard committed Dec 19, 2017
1 parent 08f5b70 commit b6e5526
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions binutils-2.27/ld/emultempl/elf32.em
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,21 @@ fragment <<EOF
static void
gld${EMULATION_NAME}_after_parse (void)
{
EOF
case ${target} in
*-*-linux-android*)
# Some versions of the Android dynamic linker (e.g. N) warn on binaries
# with the DF_1_PIE flag, so don't set it.
# https://github.com/android-ndk/ndk/issues/602
;;
*)
fragment <<EOF
if (bfd_link_pie (&link_info))
link_info.flags_1 |= (bfd_vma) DF_1_PIE;
EOF
;;
esac
fragment <<EOF

after_parse_default ();
}
Expand Down

0 comments on commit b6e5526

Please sign in to comment.