Skip to content

Commit f3be202

Browse files
committed
[Clang][AArch64] Add support for SHF_AARCH64_PURECODE ELF section flag (2/3)
Add support for the new SHF_AARCH64_PURECODE ELF section flag: ARM-software/abi-aa#304 The general implementation follows the existing one for ARM targets. Simlarly to ARM targets, generating object files with the `SHF_AARCH64_PURECODE` flag set is enabled by the `-mexecute-only`/`-mpure-code` driver flag.
1 parent 05589ee commit f3be202

File tree

5 files changed

+51
-5
lines changed

5 files changed

+51
-5
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4725,9 +4725,9 @@ def mno_long_calls : Flag<["-"], "mno-long-calls">, Group<m_Group>,
47254725
HelpText<"Restore the default behaviour of not generating long calls">;
47264726
} // let Flags = [TargetSpecific]
47274727
def mexecute_only : Flag<["-"], "mexecute-only">, Group<m_arm_Features_Group>,
4728-
HelpText<"Disallow generation of data access to code sections (ARM only)">;
4728+
HelpText<"Disallow generation of data access to code sections (AArch64/ARM only)">;
47294729
def mno_execute_only : Flag<["-"], "mno-execute-only">, Group<m_arm_Features_Group>,
4730-
HelpText<"Allow generation of data access to code sections (ARM only)">;
4730+
HelpText<"Allow generation of data access to code sections (AArch64/ARM only)">;
47314731
let Flags = [TargetSpecific] in {
47324732
def mtp_mode_EQ : Joined<["-"], "mtp=">, Group<m_arm_Features_Group>, Values<"soft,cp15,tpidrurw,tpidruro,tpidrprw,el0,el1,el2,el3,tpidr_el0,tpidr_el1,tpidr_el2,tpidr_el3,tpidrro_el0">,
47334733
HelpText<"Thread pointer access method. "

clang/lib/Driver/ToolChains/Arch/AArch64.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,17 @@ void aarch64::getAArch64TargetFeatures(const Driver &D,
332332
} else if (Triple.isOSOpenBSD())
333333
Features.push_back("+strict-align");
334334

335+
// Generate execute-only output (no data access to code sections).
336+
// This only makes sense for the compiler, not for the assembler.
337+
if (!ForAS) {
338+
if (Arg *A = Args.getLastArg(options::OPT_mexecute_only,
339+
options::OPT_mno_execute_only)) {
340+
if (A->getOption().matches(options::OPT_mexecute_only)) {
341+
Features.push_back("+execute-only");
342+
}
343+
}
344+
}
345+
335346
if (Args.hasArg(options::OPT_ffixed_x1))
336347
Features.push_back("+reserve-x1");
337348

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// RUN: %clang -target aarch64 -### %s 2>&1 \
2+
// RUN: | FileCheck %s -check-prefix CHECK-NO-EXECUTE-ONLY
3+
4+
// RUN: %clang -target aarch64 -### -mexecute-only %s 2>&1 \
5+
// RUN: | FileCheck %s -check-prefix CHECK-EXECUTE-ONLY
6+
7+
// RUN: %clang -target aarch64 -### -mexecute-only -mno-execute-only %s 2>&1 \
8+
// RUN: | FileCheck %s -check-prefix CHECK-NO-EXECUTE-ONLY
9+
10+
11+
// -mpure-code flag for GCC compatibility
12+
// RUN: %clang -target aarch64 -### %s 2>&1 \
13+
// RUN: | FileCheck %s -check-prefix CHECK-NO-EXECUTE-ONLY
14+
15+
// RUN: %clang -target aarch64 -### -mpure-code %s 2>&1 \
16+
// RUN: | FileCheck %s -check-prefix CHECK-EXECUTE-ONLY
17+
18+
// RUN: %clang -target aarch64 -### -mpure-code -mno-pure-code %s 2>&1 \
19+
// RUN: | FileCheck %s -check-prefix CHECK-NO-EXECUTE-ONLY
20+
21+
// CHECK-NO-EXECUTE-ONLY-NOT: "+execute-only"
22+
// CHECK-EXECUTE-ONLY: "+execute-only"
23+
24+
void a() {}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// RUN: %clang --sysroot=%S/Inputs -c -fdriver-only -Werror --target=aarch64-unknown-linux-gnu \
2+
// RUN: -mexecute-only %s 2>&1 | count 0
3+
4+
// RUN: %clang -### --target=aarch64-unknown-linux-gnu -x assembler -mexecute-only %s -c -### 2>&1 \
5+
// RUN: | FileCheck %s --check-prefix=CHECK-NO-EXECUTE-ONLY-ASM
6+
// CHECK-NO-EXECUTE-ONLY-ASM: warning: argument unused during compilation: '-mexecute-only'

clang/test/Driver/fsanitize.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,21 +1053,26 @@
10531053
// RUN: not %clang --target=x86_64-sie-ps5 -fsanitize=kcfi %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-KCFI-TARGET
10541054
// RUN: not %clang --target=x86_64-sie-ps5 -fsanitize=function -fsanitize=kcfi %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-KCFI-TARGET --check-prefix=CHECK-UBSAN-FUNCTION-TARGET
10551055
// RUN: %clang --target=x86_64-sie-ps5 -fsanitize=undefined %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-UNDEFINED
1056-
// CHECK-UBSAN-UNDEFINED: "-fsanitize={{((alignment|array-bounds|bool|builtin|enum|float-cast-overflow|integer-divide-by-zero|nonnull-attribute|null|pointer-overflow|return|returns-nonnull-attribute|shift-base|shift-exponent|signed-integer-overflow|unreachable|vla-bound),?){17}"}}
10571056

10581057
// RUN: not %clang --target=armv6t2-eabi -mexecute-only -fsanitize=function %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-FUNCTION-MEXECUTE-ONLY
10591058
// RUN: not %clang --target=armv6t2-eabi -mpure-code -fsanitize=function %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-FUNCTION-MPURE-CODE
10601059
// RUN: not %clang --target=armv6t2-eabi -mexecute-only -fsanitize=kcfi %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-KCFI-MEXECUTE-ONLY
10611060
// RUN: not %clang --target=armv6t2-eabi -mpure-code -fsanitize=kcfi %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-KCFI-MPURE-CODE
1062-
// RUN: %clang --target=armv6t2-eabi -mexecute-only -fsanitize=undefined %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-UNDEFINED-VPTR
1061+
// RUN: %clang --target=armv6t2-eabi -mexecute-only -fsanitize=undefined %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-UNDEFINED
1062+
1063+
// RUN: not %clang --target=aarch64 -mexecute-only -fsanitize=function %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-FUNCTION-MEXECUTE-ONLY
1064+
// RUN: not %clang --target=aarch64 -mpure-code -fsanitize=function %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-FUNCTION-MPURE-CODE
1065+
// RUN: not %clang --target=aarch64 -mexecute-only -fsanitize=kcfi %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-KCFI-MEXECUTE-ONLY
1066+
// RUN: not %clang --target=aarch64 -mpure-code -fsanitize=kcfi %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-KCFI-MPURE-CODE
1067+
// RUN: %clang --target=aarch64 -mexecute-only -fsanitize=undefined %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-UNDEFINED
10631068

10641069
// CHECK-UBSAN-KCFI-TARGET-DAG: error: unsupported option '-fsanitize=kcfi' for target 'x86_64-sie-ps5'
10651070
// CHECK-UBSAN-KCFI-MEXECUTE-ONLY-DAG: error: invalid argument '-fsanitize=kcfi' not allowed with '-mexecute-only'
10661071
// CHECK-UBSAN-KCFI-MPURE-CODE-DAG: error: invalid argument '-fsanitize=kcfi' not allowed with '-mpure-code'
10671072
// CHECK-UBSAN-FUNCTION-TARGET-DAG: error: unsupported option '-fsanitize=function' for target 'x86_64-sie-ps5'
10681073
// CHECK-UBSAN-FUNCTION-MEXECUTE-ONLY-DAG: error: invalid argument '-fsanitize=function' not allowed with '-mexecute-only'
10691074
// CHECK-UBSAN-FUNCTION-MPURE-CODE-DAG: error: invalid argument '-fsanitize=function' not allowed with '-mpure-code'
1070-
// CHECK-UBSAN-UNDEFINED-VPTR: "-fsanitize={{((alignment|array-bounds|bool|builtin|enum|float-cast-overflow|integer-divide-by-zero|nonnull-attribute|null|pointer-overflow|return|returns-nonnull-attribute|shift-base|shift-exponent|signed-integer-overflow|unreachable|vla-bound),?){17}"}}
1075+
// CHECK-UBSAN-UNDEFINED: "-fsanitize={{((alignment|array-bounds|bool|builtin|enum|float-cast-overflow|integer-divide-by-zero|nonnull-attribute|null|pointer-overflow|return|returns-nonnull-attribute|shift-base|shift-exponent|signed-integer-overflow|unreachable|vla-bound),?){17}"}}
10711076

10721077
// * Test BareMetal toolchain sanitizer support *
10731078

0 commit comments

Comments
 (0)