Skip to content

Commit 90e21e8

Browse files
committed
Add no-rosegment by default for API < 29.
Details in: android/ndk#1196 Fixes: android/ndk#1294
1 parent 867a1d6 commit 90e21e8

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

clang/lib/Driver/ToolChains/Linux.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,14 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
256256
ExtraOpts.push_back("-z");
257257
ExtraOpts.push_back("max-page-size=16384");
258258
}
259+
if (Triple.isAndroidVersionLT(29)) {
260+
// https://github.com/android/ndk/issues/1196
261+
// The unwinder used by the crash handler on versions of Android prior to
262+
// API 29 did not correctly handle binaries built with rosegment, which is
263+
// enabled by default for LLD. Android only supports LLD, so it's not an
264+
// issue that this flag is not accepted by other linkers.
265+
ExtraOpts.push_back("--no-rosegment");
266+
}
259267
}
260268

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

clang/test/Driver/linux-ld.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,20 @@
940940
// CHECK-ANDROID-HASH-STYLE-M: "{{.*}}ld{{(.exe)?}}"
941941
// CHECK-ANDROID-HASH-STYLE-M: "--hash-style=gnu"
942942

943+
// Check that we pass --no-rosegment for pre-29 Android versions and do not for
944+
// 29+.
945+
// RUN: %clang %s -### -o %t.o 2>&1 \
946+
// RUN: --target=armv7-linux-android28 \
947+
// RUN: | FileCheck --check-prefix=CHECK-ANDROID-ROSEGMENT-28 %s
948+
// CHECK-ANDROID-ROSEGMENT-28: "{{.*}}ld{{(.exe)?}}"
949+
// CHECK-ANDROID-ROSEGMENT-28: "--no-rosegment"
950+
//
951+
// RUN: %clang %s -### -o %t.o 2>&1 \
952+
// RUN: --target=armv7-linux-android29 \
953+
// RUN: | FileCheck --check-prefix=CHECK-ANDROID-ROSEGMENT-29 %s
954+
// CHECK-ANDROID-ROSEGMENT-29: "{{.*}}ld{{(.exe)?}}"
955+
// CHECK-ANDROID-ROSEGMENT-29-NOT: "--no-rosegment"
956+
943957
// RUN: %clang -### %s -no-pie 2>&1 --target=mips64-linux-gnuabin32 \
944958
// RUN: | FileCheck --check-prefix=CHECK-MIPS64EL-GNUABIN32 %s
945959
// CHECK-MIPS64EL-GNUABIN32: "{{.*}}ld{{(.exe)?}}"

0 commit comments

Comments
 (0)