Skip to content

Commit 5133a8f

Browse files
authored
[Driver] Add -fandroid-pad-segment/-fno-android-pad-segment (#77244)
-fandroid-pad-segment is an Android-specific opt-in option that links in crt_pad_segment.o (beside other crt*.o relocatable files). crt_pad_segment.o contains a note section, which will be included in the linker-created PT_NOTE segment. This PT_NOTE tell Bionic that: when create a map for a PT_LOAD segment, extend the end to cover the gap so that we will have fewer kernel 'struct vm_area_struct' objects when page_size < MAXPAGESIZE. See also https://sourceware.org/bugzilla/show_bug.cgi?id=31076 Link: https://r.android.com/2902180
1 parent 4fffb04 commit 5133a8f

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6298,6 +6298,11 @@ def fno_sycl : Flag<["-"], "fno-sycl">,
62986298
Visibility<[ClangOption, CLOption]>,
62996299
Group<sycl_Group>, HelpText<"Disables SYCL kernels compilation for device">;
63006300

6301+
// OS-specific options
6302+
let Flags = [TargetSpecific] in {
6303+
defm android_pad_segment : BooleanFFlag<"android-pad-segment">, Group<f_Group>;
6304+
} // let Flags = [TargetSpecific]
6305+
63016306
//===----------------------------------------------------------------------===//
63026307
// FLangOption + NoXarchOption
63036308
//===----------------------------------------------------------------------===//

clang/lib/Driver/ToolChains/Gnu.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,11 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA,
508508

509509
// Add crtfastmath.o if available and fast math is enabled.
510510
ToolChain.addFastMathRuntimeIfAvailable(Args, CmdArgs);
511+
512+
if (isAndroid && Args.hasFlag(options::OPT_fandroid_pad_segment,
513+
options::OPT_fno_android_pad_segment, false))
514+
CmdArgs.push_back(
515+
Args.MakeArgString(ToolChain.GetFilePath("crt_pad_segment.o")));
511516
}
512517

513518
Args.addAllArgs(CmdArgs, {options::OPT_L, options::OPT_u});

clang/test/Driver/Inputs/basic_android_tree/sysroot/usr/lib/crt_pad_segment.o

Whitespace-only changes.

clang/test/Driver/linux-ld.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1347,7 +1347,24 @@
13471347
// RUN: --sysroot=%S/Inputs/basic_android_tree/sysroot \
13481348
// RUN: | FileCheck --check-prefix=CHECK-ANDROID-PTHREAD-LINK %s
13491349
// CHECK-ANDROID-PTHREAD-LINK-NOT: argument unused during compilation: '-pthread'
1350-
//
1350+
1351+
/// Check -fandroid-pad-segment.
1352+
// RUN: %clang -### %s --target=aarch64-linux-android -rtlib=platform --unwindlib=platform \
1353+
// RUN: --gcc-toolchain="" --sysroot=%S/Inputs/basic_android_tree/sysroot \
1354+
// RUN: -fandroid-pad-segment 2>&1 | FileCheck --check-prefix=CHECK-ANDROID-PAD-PHDR %s
1355+
// CHECK-ANDROID-PAD-PHDR: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]"
1356+
// CHECK-ANDROID-PAD-PHDR: "[[SYSROOT]]/usr/lib/crtbegin_dynamic.o" "[[SYSROOT]]/usr/lib/crt_pad_segment.o"
1357+
1358+
// RUN: %clang -### %s --target=aarch64-linux-android -rtlib=platform --unwindlib=platform \
1359+
// RUN: --gcc-toolchain="" --sysroot=%S/Inputs/basic_android_tree/sysroot \
1360+
// RUN: -fandroid-pad-segment -fno-android-pad-segment 2>&1 | FileCheck --check-prefix=CHECK-NO-ANDROID-PAD-PHDR %s
1361+
// CHECK-NO-ANDROID-PAD-PHDR: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]"
1362+
// CHECK-NO-ANDROID-PAD-PHDR: "[[SYSROOT]]/usr/lib/crtbegin_dynamic.o"
1363+
// CHECK-NO-ANDROID-PAD-PHDR-NOT: crt_pad_segment.o"
1364+
1365+
// RUN: not %clang -### %s --target=aarch64-linux -fandroid-pad-segment 2>&1 | FileCheck --check-prefix=ERR-ANDROID-PAD-EHDR %s
1366+
// ERR-ANDROID-PAD-EHDR: error: unsupported option '-fandroid-pad-segment' for target 'aarch64-linux'
1367+
13511368
// Check linker invocation on a Debian LoongArch sysroot.
13521369
// RUN: %clang -### %s -no-pie 2>&1 \
13531370
// RUN: --target=loongarch64-linux-gnu -rtlib=platform --unwindlib=platform \

0 commit comments

Comments
 (0)