Skip to content

Commit fae16fc

Browse files
committed
Disable rosegment for old Android versions.
The unwinder used by the crash handler on versions of Android prior to API 29 did not correctly handle binaries built with rosegment, which is enabled by default for LLD. Android only supports LLD, so it's not an issue that this flag is not accepted by other linkers. Reviewed By: srhines Differential Revision: https://reviews.llvm.org/D95166
1 parent f3c9687 commit fae16fc

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

clang/lib/Driver/ToolChains/Linux.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,15 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
236236
ExtraOpts.push_back("relro");
237237
}
238238

239+
if (Triple.isAndroid() && Triple.isAndroidVersionLT(29)) {
240+
// https://github.com/android/ndk/issues/1196
241+
// The unwinder used by the crash handler on versions of Android prior to
242+
// API 29 did not correctly handle binaries built with rosegment, which is
243+
// enabled by default for LLD. Android only supports LLD, so it's not an
244+
// issue that this flag is not accepted by other linkers.
245+
ExtraOpts.push_back("--no-rosegment");
246+
}
247+
239248
// Android ARM/AArch64 use max-page-size=4096 to reduce VMA usage. Note, lld
240249
// from 11 onwards default max-page-size to 65536 for both ARM and AArch64.
241250
if ((Triple.isARM() || Triple.isAArch64()) && Triple.isAndroid()) {

clang/test/Driver/linux-ld.c

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

1092+
// Check that we pass --no-rosegment for pre-29 Android versions and do not for
1093+
// 29+.
1094+
// RUN: %clang %s -### -o %t.o 2>&1 \
1095+
// RUN: --target=armv7-linux-android28 \
1096+
// RUN: | FileCheck --check-prefix=CHECK-ANDROID-ROSEGMENT-28 %s
1097+
// CHECK-ANDROID-ROSEGMENT-28: "{{.*}}ld{{(.exe)?}}"
1098+
// CHECK-ANDROID-ROSEGMENT-28: "--no-rosegment"
1099+
//
1100+
// RUN: %clang %s -### -o %t.o 2>&1 \
1101+
// RUN: --target=armv7-linux-android29 \
1102+
// RUN: | FileCheck --check-prefix=CHECK-ANDROID-ROSEGMENT-29 %s
1103+
// CHECK-ANDROID-ROSEGMENT-29: "{{.*}}ld{{(.exe)?}}"
1104+
// CHECK-ANDROID-ROSEGMENT-29-NOT: "--no-rosegment"
1105+
10921106
// RUN: %clang %s -### -o %t.o 2>&1 \
10931107
// RUN: --target=armv7-linux-android21 \
10941108
// RUN: | FileCheck --check-prefix=CHECK-ANDROID-NOEXECSTACK %s

0 commit comments

Comments
 (0)