Skip to content

Commit df367ed

Browse files
committed
Pack relocations for Android API >= 28
Patch copied from: android/ndk#909 (comment) Fixes: android/ndk#909
1 parent 90e21e8 commit df367ed

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

clang/lib/Driver/ToolChains/Linux.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,16 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
264264
// issue that this flag is not accepted by other linkers.
265265
ExtraOpts.push_back("--no-rosegment");
266266
}
267+
if (!Triple.isAndroidVersionLT(28)) {
268+
// Android supports relr packing starting with API 28 and had its own
269+
// flavor (--pack-dyn-relocs=android) starting in API 23.
270+
// TODO: It's possible to use both with --pack-dyn-relocs=android+relr,
271+
// but we need to gather some data on the impact of that form before we
272+
// can know if it's a good default.
273+
// On the other hand, relr should always be an improvement.
274+
ExtraOpts.push_back("--use-android-relr-tags");
275+
ExtraOpts.push_back("--pack-dyn-relocs=relr");
276+
}
267277
}
268278

269279
if (GCCInstallation.getParentLibPath().contains("opt/rh/"))

clang/test/Driver/linux-ld.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -954,6 +954,22 @@
954954
// CHECK-ANDROID-ROSEGMENT-29: "{{.*}}ld{{(.exe)?}}"
955955
// CHECK-ANDROID-ROSEGMENT-29-NOT: "--no-rosegment"
956956

957+
// Check that we pass --pack-dyn-relocs=relr for API 28+ and not before.
958+
// RUN: %clang %s -### -o %t.o 2>&1 \
959+
// RUN: --target=armv7-linux-android27 \
960+
// RUN: | FileCheck --check-prefix=CHECK-ANDROID-RELR-27 %s
961+
// CHECK-ANDROID-RELR-27: "{{.*}}ld{{(.exe)?}}"
962+
// CHECK-ANDROID-RELR-27-NOT: "--pack-dyn-relocs=relr"
963+
// CHECK-ANDROID-RELR-27-NOT: "--pack-dyn-relocs=android+relr"
964+
//
965+
// RUN: %clang %s -### -o %t.o 2>&1 \
966+
// RUN: --target=armv7-linux-android28 \
967+
// RUN: | FileCheck --check-prefix=CHECK-ANDROID-RELR-28 %s
968+
// CHECK-ANDROID-RELR-28: "{{.*}}ld{{(.exe)?}}"
969+
// CHECK-ANDROID-RELR-28: "--use-android-relr-tags"
970+
// CHECK-ANDROID-RELR-28: "--pack-dyn-relocs=relr"
971+
// CHECK-ANDROID-RELR-28-NOT: "--pack-dyn-relocs=android+relr"
972+
957973
// RUN: %clang -### %s -no-pie 2>&1 --target=mips64-linux-gnuabin32 \
958974
// RUN: | FileCheck --check-prefix=CHECK-MIPS64EL-GNUABIN32 %s
959975
// CHECK-MIPS64EL-GNUABIN32: "{{.*}}ld{{(.exe)?}}"

0 commit comments

Comments
 (0)