Skip to content

Commit fbb376b

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 6ff1cc4 commit fbb376b

File tree

5 files changed

+50
-3
lines changed

5 files changed

+50
-3
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4677,9 +4677,9 @@ def mno_long_calls : Flag<["-"], "mno-long-calls">, Group<m_Group>,
46774677
HelpText<"Restore the default behaviour of not generating long calls">;
46784678
} // let Flags = [TargetSpecific]
46794679
def mexecute_only : Flag<["-"], "mexecute-only">, Group<m_arm_Features_Group>,
4680-
HelpText<"Disallow generation of data access to code sections (ARM only)">;
4680+
HelpText<"Disallow generation of data access to code sections (AArch64/ARM only)">;
46814681
def mno_execute_only : Flag<["-"], "mno-execute-only">, Group<m_arm_Features_Group>,
4682-
HelpText<"Allow generation of data access to code sections (ARM only)">;
4682+
HelpText<"Allow generation of data access to code sections (AArch64/ARM only)">;
46834683
let Flags = [TargetSpecific] in {
46844684
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">,
46854685
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: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1052,20 +1052,26 @@
10521052
// RUN: not %clang --target=x86_64-sie-ps5 -fsanitize=kcfi %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-KCFI-TARGET
10531053
// 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
10541054
// RUN: %clang --target=x86_64-sie-ps5 -fsanitize=undefined %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-UNDEFINED
1055-
// 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}"}}
10561055

10571056
// RUN: not %clang --target=armv6t2-eabi -mexecute-only -fsanitize=function %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-FUNCTION-MEXECUTE-ONLY
10581057
// RUN: not %clang --target=armv6t2-eabi -mpure-code -fsanitize=function %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-FUNCTION-MPURE-CODE
10591058
// RUN: not %clang --target=armv6t2-eabi -mexecute-only -fsanitize=kcfi %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-KCFI-MEXECUTE-ONLY
10601059
// RUN: not %clang --target=armv6t2-eabi -mpure-code -fsanitize=kcfi %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-KCFI-MPURE-CODE
10611060
// RUN: %clang --target=armv6t2-eabi -mexecute-only -fsanitize=undefined %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-UNDEFINED-VPTR
10621061

1062+
// RUN: not %clang --target=aarch64 -mexecute-only -fsanitize=function %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-FUNCTION-MEXECUTE-ONLY
1063+
// RUN: not %clang --target=aarch64 -mpure-code -fsanitize=function %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-FUNCTION-MPURE-CODE
1064+
// RUN: not %clang --target=aarch64 -mexecute-only -fsanitize=kcfi %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-KCFI-MEXECUTE-ONLY
1065+
// RUN: not %clang --target=aarch64 -mpure-code -fsanitize=kcfi %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-KCFI-MPURE-CODE
1066+
// RUN: %clang --target=aarch64 -mexecute-only -fsanitize=undefined %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-UNDEFINED
1067+
10631068
// CHECK-UBSAN-KCFI-TARGET-DAG: error: unsupported option '-fsanitize=kcfi' for target 'x86_64-sie-ps5'
10641069
// CHECK-UBSAN-KCFI-MEXECUTE-ONLY-DAG: error: invalid argument '-fsanitize=kcfi' not allowed with '-mexecute-only'
10651070
// CHECK-UBSAN-KCFI-MPURE-CODE-DAG: error: invalid argument '-fsanitize=kcfi' not allowed with '-mpure-code'
10661071
// CHECK-UBSAN-FUNCTION-TARGET-DAG: error: unsupported option '-fsanitize=function' for target 'x86_64-sie-ps5'
10671072
// CHECK-UBSAN-FUNCTION-MEXECUTE-ONLY-DAG: error: invalid argument '-fsanitize=function' not allowed with '-mexecute-only'
10681073
// CHECK-UBSAN-FUNCTION-MPURE-CODE-DAG: error: invalid argument '-fsanitize=function' not allowed with '-mpure-code'
1074+
// 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}"}}
10691075
// 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|vptr),?){18}"}}
10701076

10711077
// * Test BareMetal toolchain sanitizer support *

0 commit comments

Comments
 (0)