[clang] [Clang] Improve error for `-fsanitize=function/kcfi -mexecute-only` incompatibility (PR #118816)
https://github.com/Il-Capitano updated https://github.com/llvm/llvm-project/pull/118816 From 94c933e0e7b7497e76c541f3ea7ed210349d2044 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Csan=C3=A1d=20Hajd=C3=BA?= Date: Thu, 5 Dec 2024 14:46:08 +0100 Subject: [PATCH] [Clang] Improve error for `-fsanitize=function/kcfi -mexecute-only` incompatibility The current error message when using the `-fsanitize=function -mexecute-only` flags together points to the target triple as the reason that `-fsanitize=function` is not allowed to be used, even when the function sanitizer is otherwise supported on the target when not using `-mexecute-only`. The error message is improved to give `-mexecute-only` as the reason for disallowing `-fsanitize=function` if it was passed to the driver. --- clang/lib/Driver/SanitizerArgs.cpp | 10 -- clang/test/Driver/fsanitize.c | 4 ++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/clang/lib/Driver/SanitizerArgs.cpp b/clang/lib/Driver/SanitizerArgs.cpp index 1abfe8fd92807e..6a2d376e93d05b 100644 --- a/clang/lib/Driver/SanitizerArgs.cpp +++ b/clang/lib/Driver/SanitizerArgs.cpp @@ -418,8 +418,14 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC, Add & NotAllowedWithExecuteOnly & ~DiagnosedKinds) { if (DiagnoseErrors) { std::string Desc = describeSanitizeArg(Arg, KindsToDiagnose); -D.Diag(diag::err_drv_argument_not_allowed_with) -<< Desc << Triple.str(); +llvm::opt::Arg *A = Args.getLastArgNoClaim( +options::OPT_mexecute_only, options::OPT_mno_execute_only); +if (A && A->getOption().matches(options::OPT_mexecute_only)) + D.Diag(diag::err_drv_argument_not_allowed_with) + << Desc << A->getAsString(Args); +else + D.Diag(diag::err_drv_argument_not_allowed_with) + << Desc << Triple.str(); } DiagnosedKinds |= KindsToDiagnose; } diff --git a/clang/test/Driver/fsanitize.c b/clang/test/Driver/fsanitize.c index 15f190165a7d73..a99bfb3e82ac95 100644 --- a/clang/test/Driver/fsanitize.c +++ b/clang/test/Driver/fsanitize.c @@ -1000,8 +1000,8 @@ // RUN: not %clang --target=armv6t2-eabi -mexecute-only -fsanitize=kcfi %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-KCFI // RUN: %clang --target=armv6t2-eabi -mexecute-only -fsanitize=undefined %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-UNDEFINED-VPTR -// CHECK-UBSAN-KCFI-DAG: error: invalid argument '-fsanitize=kcfi' not allowed with {{('x86_64-sie-ps5'|'armv6t2-unknown-unknown-eabi')}} -// CHECK-UBSAN-FUNCTION-DAG: error: invalid argument '-fsanitize=function' not allowed with {{('x86_64-sie-ps5'|'armv6t2-unknown-unknown-eabi')}} +// CHECK-UBSAN-KCFI-DAG: error: invalid argument '-fsanitize=kcfi' not allowed with {{('x86_64-sie-ps5'|'-mexecute-only')}} +// CHECK-UBSAN-FUNCTION-DAG: error: invalid argument '-fsanitize=function' not allowed with {{('x86_64-sie-ps5'|'-mexecute-only')}} // 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}"}} // * Test BareMetal toolchain sanitizer support * ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Improve error for `-fsanitize=function/kcfi -mexecute-only` incompatibility (PR #118816)
https://github.com/Il-Capitano created https://github.com/llvm/llvm-project/pull/118816 The current error message when using the `-fsanitize=function -mexecute-only` flags together points to the target triple as the reason that `-fsanitize=function` is not allowed to be used, even when the function sanitizer is otherwise supported on the target when not using `-mexecute-only`. The error message is improved to give `-mexecute-only` as the reason for disallowing `-fsanitize=function` if it was passed to the driver. From 691a26b6602a4f7c9f2ea5eaf27bb8d1a0be11a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Csan=C3=A1d=20Hajd=C3=BA?= Date: Thu, 5 Dec 2024 14:46:08 +0100 Subject: [PATCH] [Clang] Improve error for `-fsanitize=function/kcfi -mexecute-only` incompatibility The current error message when using the `-fsanitize=function -mexecute-only` flags together points to the target triple as the reason that `-fsanitize=function` is not allowed to be used, even when the function sanitizer is otherwise supported on the target when not using `-mexecute-only`. The error message is improved to give `-mexecute-only` as the reason for disallowing `-fsanitize=function` if it was passed to the driver. --- clang/lib/Driver/SanitizerArgs.cpp | 10 -- clang/test/Driver/fsanitize.c | 4 ++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/clang/lib/Driver/SanitizerArgs.cpp b/clang/lib/Driver/SanitizerArgs.cpp index 1abfe8fd92807e..6d87e25b49237e 100644 --- a/clang/lib/Driver/SanitizerArgs.cpp +++ b/clang/lib/Driver/SanitizerArgs.cpp @@ -418,8 +418,14 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC, Add & NotAllowedWithExecuteOnly & ~DiagnosedKinds) { if (DiagnoseErrors) { std::string Desc = describeSanitizeArg(Arg, KindsToDiagnose); -D.Diag(diag::err_drv_argument_not_allowed_with) -<< Desc << Triple.str(); +llvm::opt::Arg *A = Args.getLastArgNoClaim( +options::OPT_mexecute_only, options::OPT_mno_execute_only); +if (A && A->getOption().matches(options::OPT_mexecute_only)) + D.Diag(diag::err_drv_argument_not_allowed_with) + << Desc << A->getAsString(Args); +else + D.Diag(diag::err_drv_argument_not_allowed_with) + << Desc << Triple.str(); } DiagnosedKinds |= KindsToDiagnose; } diff --git a/clang/test/Driver/fsanitize.c b/clang/test/Driver/fsanitize.c index 15f190165a7d73..a99bfb3e82ac95 100644 --- a/clang/test/Driver/fsanitize.c +++ b/clang/test/Driver/fsanitize.c @@ -1000,8 +1000,8 @@ // RUN: not %clang --target=armv6t2-eabi -mexecute-only -fsanitize=kcfi %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-KCFI // RUN: %clang --target=armv6t2-eabi -mexecute-only -fsanitize=undefined %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-UNDEFINED-VPTR -// CHECK-UBSAN-KCFI-DAG: error: invalid argument '-fsanitize=kcfi' not allowed with {{('x86_64-sie-ps5'|'armv6t2-unknown-unknown-eabi')}} -// CHECK-UBSAN-FUNCTION-DAG: error: invalid argument '-fsanitize=function' not allowed with {{('x86_64-sie-ps5'|'armv6t2-unknown-unknown-eabi')}} +// CHECK-UBSAN-KCFI-DAG: error: invalid argument '-fsanitize=kcfi' not allowed with {{('x86_64-sie-ps5'|'-mexecute-only')}} +// CHECK-UBSAN-FUNCTION-DAG: error: invalid argument '-fsanitize=function' not allowed with {{('x86_64-sie-ps5'|'-mexecute-only')}} // 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}"}} // * Test BareMetal toolchain sanitizer support * ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Add float type support to __builtin_reduce_add and __builtin_reduce_multipy (PR #120367)
Il-Capitano wrote: Just to clarify: `@llvm.vector.reduce.fadd` does sequential reduction by default, so I don't see a point in doing that manually in the frontend. Your previous implementation had the same behaviour. The inconsistency with the sequential approach is that Clang defines the `__builtin_reduce_*` operations to do recursive even-odd pairwise reduction (i.e. `(v[0] + v[1]) + (v[2] + v[3])` instead of `((v[0] + v[1]) + v[2]) + v[3])`), and since floating-poing addition is not associative, these two can have different results. My suggestion was to not use the existing `__builtin_reduce_add` and `mul` builtins, but to define a new one that is defined to do sequential reduction, matching the behaviour of `@llvm.vector.reduce.fadd`, and one that is unordered, i.e. `@llvm.vector.reduce.fadd` with the `reassoc` fast-math flag set (in practice this will do the even-odd pairwise reduction, but there is a difference in generated code quality between doing that in the frontend, and the backend: https://godbolt.org/z/a4rd44Eza). You can see the generated code difference of `@llvm.vector.reduce.fadd` with and without the `reassoc` flag here: https://godbolt.org/z/zeWjxrxo5. https://github.com/llvm/llvm-project/pull/120367 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Add float type support to __builtin_reduce_add and __builtin_reduce_multipy (PR #120367)
Il-Capitano wrote: `__builtin_reduce_add/mul` is defined to do _recursive even-odd pairwise reduction_ in Clang, and the `@llvm.vector.reduce.fadd` intrinsic doesn't do that. I'm not sure if there's any benefit to this definition over a sequential reduction. The only thing I can think that could be affected is signed-integer overflow being UB, but that doesn't seem to be optimized for, or checked with UBSan: https://godbolt.org/z/TEsc86rf5. Maybe, as RKSimon suggested, having a separate builtin for floating-point types could be better? Something like `__builtin_reduce_fadd/fmul` that does sequential reduction, and another one for unordered reduction? This builtin could also take a start value as the first argument to better match the LLVM intrinsic. > Or maybe an alternative `__builtin_reduce_fastmath_fadd / fmul` that makes it > clear whats happening, and have them always emit the reassoc variants of the > reductions? I think `__builtin_reduce_fadd_unordered` or something similar would be a better choice, since "fastmath" implies more restrictions/assumptions than `reassoc` (no nans, no signed zeros, etc.). https://github.com/llvm/llvm-project/pull/120367 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [Clang][AArch64] Add support for SHF_AARCH64_PURECODE ELF section flag (2/3) (PR #125688)
https://github.com/Il-Capitano created https://github.com/llvm/llvm-project/pull/125688 Add support for the new SHF_AARCH64_PURECODE ELF section flag: https://github.com/ARM-software/abi-aa/pull/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. Depends on https://github.com/llvm/llvm-project/pull/125687. The changes in that PR are included here as well for now, but will be removed once that gets merged. From 6ff1cc4abb39b0526cae22497b5147cae35a7d6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Csan=C3=A1d=20Hajd=C3=BA?= Date: Tue, 4 Feb 2025 14:32:58 +0100 Subject: [PATCH 1/2] [AArch64] Add support for SHF_AARCH64_PURECODE ELF section flag (1/3) Add support for the new SHF_AARCH64_PURECODE ELF section flag: https://github.com/ARM-software/abi-aa/pull/304 The general implementation follows the existing one for ARM targets. Generating object files with the `SHF_AARCH64_PURECODE` flag set is enabled by the `+execute-only` target feature. --- llvm/include/llvm/BinaryFormat/ELF.h | 5 ++- .../CodeGen/TargetLoweringObjectFileImpl.cpp | 13 +++--- llvm/lib/MC/MCParser/ELFAsmParser.cpp | 7 ++- llvm/lib/MC/MCSectionELF.cpp | 3 ++ llvm/lib/ObjectYAML/ELFYAML.cpp | 3 ++ llvm/lib/Target/AArch64/AArch64Features.td| 5 +++ .../AArch64/AArch64TargetObjectFile.cpp | 26 +++ .../Target/AArch64/AArch64TargetObjectFile.h | 6 +++ .../AArch64/AArch64TargetTransformInfo.cpp| 17 +++- .../AArch64/AArch64TargetTransformInfo.h | 2 + .../MCTargetDesc/AArch64ELFStreamer.cpp | 18 .../CodeGen/AArch64/execute-only-section.ll | 21 + .../execute-only-populated-text-section.s | 27 .../MC/ELF/AArch64/execute-only-section.s | 43 +++ .../AArch64/execute-only-text-section-data.s | 27 llvm/test/MC/ELF/section-flags-unknown.s | 3 ++ .../Inline/AArch64/inline-target-attr.ll | 25 +++ llvm/tools/llvm-readobj/ELFDumper.cpp | 8 18 files changed, 250 insertions(+), 9 deletions(-) create mode 100644 llvm/test/CodeGen/AArch64/execute-only-section.ll create mode 100644 llvm/test/MC/ELF/AArch64/execute-only-populated-text-section.s create mode 100644 llvm/test/MC/ELF/AArch64/execute-only-section.s create mode 100644 llvm/test/MC/ELF/AArch64/execute-only-text-section-data.s diff --git a/llvm/include/llvm/BinaryFormat/ELF.h b/llvm/include/llvm/BinaryFormat/ELF.h index 8853c4a88b0b59..a5979d029a9eaf 100644 --- a/llvm/include/llvm/BinaryFormat/ELF.h +++ b/llvm/include/llvm/BinaryFormat/ELF.h @@ -1300,7 +1300,10 @@ enum : unsigned { SHF_MIPS_STRING = 0x8000, // Make code section unreadable when in execute-only mode - SHF_ARM_PURECODE = 0x2000 + SHF_ARM_PURECODE = 0x2000, + + // Section contains only program instructions and no program data. + SHF_AARCH64_PURECODE = 0x2000 }; // Section Group Flags diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp index 3c2c7c8c9fed69..6cfebca9a4d576 100644 --- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -547,7 +547,7 @@ static unsigned getELFSectionType(StringRef Name, SectionKind K) { return ELF::SHT_PROGBITS; } -static unsigned getELFSectionFlags(SectionKind K) { +static unsigned getELFSectionFlags(SectionKind K, const Triple &T) { unsigned Flags = 0; if (!K.isMetadata() && !K.isExclude()) @@ -559,9 +559,12 @@ static unsigned getELFSectionFlags(SectionKind K) { if (K.isText()) Flags |= ELF::SHF_EXECINSTR; - if (K.isExecuteOnly()) + if ((T.isARM() || T.isThumb()) && K.isExecuteOnly()) Flags |= ELF::SHF_ARM_PURECODE; + if (T.isAArch64() && K.isExecuteOnly()) +Flags |= ELF::SHF_AARCH64_PURECODE; + if (K.isWriteable()) Flags |= ELF::SHF_WRITE; @@ -840,7 +843,7 @@ static MCSection *selectExplicitSectionGlobal(const GlobalObject *GO, // Infer section flags from the section name if we can. Kind = getELFKindForNamedSection(SectionName, Kind); - unsigned Flags = getELFSectionFlags(Kind); + unsigned Flags = getELFSectionFlags(Kind, TM.getTargetTriple()); auto [Group, IsComdat, ExtraFlags] = getGlobalObjectInfo(GO, TM); Flags |= ExtraFlags; @@ -947,7 +950,7 @@ static MCSection *selectELFSectionForGlobal( MCSection *TargetLoweringObjectFileELF::SelectSectionForGlobal( const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const { - unsigned Flags = getELFSectionFlags(Kind); + unsigned Flags = getELFSectionFlags(Kind, TM.getTargetTriple()); // If we have -ffunction-section or -fdata-section then we should emit the // global value to a uniqued section specifically for it. @@ -967,7 +
[clang] [llvm] [Clang][AArch64] Add support for SHF_AARCH64_PURECODE ELF section flag (2/3) (PR #125688)
https://github.com/Il-Capitano converted_to_draft https://github.com/llvm/llvm-project/pull/125688 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Improve error for `-fsanitize=function/kcfi -mexecute-only` incompatibility (PR #118816)
Il-Capitano wrote: Thanks for reviewing! I updated the code to use `err_drv_unsupported_opt_for_target`, and added test cases for the `-mpure-code` alias of `-mexecute-only` also. https://github.com/llvm/llvm-project/pull/118816 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Improve error for `-fsanitize=function/kcfi -mexecute-only` incompatibility (PR #118816)
https://github.com/Il-Capitano updated https://github.com/llvm/llvm-project/pull/118816 From 94c933e0e7b7497e76c541f3ea7ed210349d2044 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Csan=C3=A1d=20Hajd=C3=BA?= Date: Thu, 5 Dec 2024 14:46:08 +0100 Subject: [PATCH 1/2] [Clang] Improve error for `-fsanitize=function/kcfi -mexecute-only` incompatibility The current error message when using the `-fsanitize=function -mexecute-only` flags together points to the target triple as the reason that `-fsanitize=function` is not allowed to be used, even when the function sanitizer is otherwise supported on the target when not using `-mexecute-only`. The error message is improved to give `-mexecute-only` as the reason for disallowing `-fsanitize=function` if it was passed to the driver. --- clang/lib/Driver/SanitizerArgs.cpp | 10 -- clang/test/Driver/fsanitize.c | 4 ++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/clang/lib/Driver/SanitizerArgs.cpp b/clang/lib/Driver/SanitizerArgs.cpp index 1abfe8fd92807e..6a2d376e93d05b 100644 --- a/clang/lib/Driver/SanitizerArgs.cpp +++ b/clang/lib/Driver/SanitizerArgs.cpp @@ -418,8 +418,14 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC, Add & NotAllowedWithExecuteOnly & ~DiagnosedKinds) { if (DiagnoseErrors) { std::string Desc = describeSanitizeArg(Arg, KindsToDiagnose); -D.Diag(diag::err_drv_argument_not_allowed_with) -<< Desc << Triple.str(); +llvm::opt::Arg *A = Args.getLastArgNoClaim( +options::OPT_mexecute_only, options::OPT_mno_execute_only); +if (A && A->getOption().matches(options::OPT_mexecute_only)) + D.Diag(diag::err_drv_argument_not_allowed_with) + << Desc << A->getAsString(Args); +else + D.Diag(diag::err_drv_argument_not_allowed_with) + << Desc << Triple.str(); } DiagnosedKinds |= KindsToDiagnose; } diff --git a/clang/test/Driver/fsanitize.c b/clang/test/Driver/fsanitize.c index 15f190165a7d73..a99bfb3e82ac95 100644 --- a/clang/test/Driver/fsanitize.c +++ b/clang/test/Driver/fsanitize.c @@ -1000,8 +1000,8 @@ // RUN: not %clang --target=armv6t2-eabi -mexecute-only -fsanitize=kcfi %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-KCFI // RUN: %clang --target=armv6t2-eabi -mexecute-only -fsanitize=undefined %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-UNDEFINED-VPTR -// CHECK-UBSAN-KCFI-DAG: error: invalid argument '-fsanitize=kcfi' not allowed with {{('x86_64-sie-ps5'|'armv6t2-unknown-unknown-eabi')}} -// CHECK-UBSAN-FUNCTION-DAG: error: invalid argument '-fsanitize=function' not allowed with {{('x86_64-sie-ps5'|'armv6t2-unknown-unknown-eabi')}} +// CHECK-UBSAN-KCFI-DAG: error: invalid argument '-fsanitize=kcfi' not allowed with {{('x86_64-sie-ps5'|'-mexecute-only')}} +// CHECK-UBSAN-FUNCTION-DAG: error: invalid argument '-fsanitize=function' not allowed with {{('x86_64-sie-ps5'|'-mexecute-only')}} // 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}"}} // * Test BareMetal toolchain sanitizer support * From 7c352152d8d90bd02ca11071365b71af8f6678c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Csan=C3=A1d=20Hajd=C3=BA?= Date: Wed, 11 Dec 2024 11:41:56 +0100 Subject: [PATCH 2/2] Use `err_drv_unsupported_opt_for_target` and add test for `-mpure-code` --- clang/lib/Driver/SanitizerArgs.cpp | 2 +- clang/test/Driver/fsanitize.c | 22 ++ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/clang/lib/Driver/SanitizerArgs.cpp b/clang/lib/Driver/SanitizerArgs.cpp index 6a2d376e93d05b..e77857930996b2 100644 --- a/clang/lib/Driver/SanitizerArgs.cpp +++ b/clang/lib/Driver/SanitizerArgs.cpp @@ -424,7 +424,7 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC, D.Diag(diag::err_drv_argument_not_allowed_with) << Desc << A->getAsString(Args); else - D.Diag(diag::err_drv_argument_not_allowed_with) + D.Diag(diag::err_drv_unsupported_opt_for_target) << Desc << Triple.str(); } DiagnosedKinds |= KindsToDiagnose; diff --git a/clang/test/Driver/fsanitize.c b/clang/test/Driver/fsanitize.c index a99bfb3e82ac95..bb692b2aeea1d3 100644 --- a/clang/test/Driver/fsanitize.c +++ b/clang/test/Driver/fsanitize.c @@ -989,19 +989,25 @@ // RUN: not %clang --target=x86_64-linux-gnu -fsanitize=undefined,function -mcmodel=large %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-FUNCTION-CODE-MODEL // CHECK-UBSAN-FUNCTION-CODE-MODEL: error: invalid argument '-fsanitize=function' only allowed with '-mcmodel=small' -// RUN: not %clang --target=x86
[clang] [Clang] Improve error for `-fsanitize=function/kcfi -mexecute-only` incompatibility (PR #118816)
Il-Capitano wrote: @MaskRay Can I ask you to review/add appropriate reviewers for this patch? https://github.com/llvm/llvm-project/pull/118816 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Improve error for `-fsanitize=function/kcfi -mexecute-only` incompatibility (PR #118816)
https://github.com/Il-Capitano edited https://github.com/llvm/llvm-project/pull/118816 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Improve error for `-fsanitize=function/kcfi -mexecute-only` incompatibility (PR #118816)
@@ -418,8 +418,14 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC, Add & NotAllowedWithExecuteOnly & ~DiagnosedKinds) { if (DiagnoseErrors) { std::string Desc = describeSanitizeArg(Arg, KindsToDiagnose); -D.Diag(diag::err_drv_argument_not_allowed_with) -<< Desc << Triple.str(); +llvm::opt::Arg *A = Args.getLastArgNoClaim( +options::OPT_mexecute_only, options::OPT_mno_execute_only); +if (A && A->getOption().matches(options::OPT_mexecute_only)) + D.Diag(diag::err_drv_argument_not_allowed_with) + << Desc << A->getAsString(Args); +else + D.Diag(diag::err_drv_argument_not_allowed_with) + << Desc << Triple.str(); Il-Capitano wrote: Maybe `diag::err_drv_unsupported_opt_for_target` would be a better diagnostic in this case? That would produce ``` error: unsupported option '-fsanitize=function' for target '' ``` https://github.com/llvm/llvm-project/pull/118816 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Add float type support to __builtin_reduce_add and __builtin_reduce_multipy (PR #120367)
@@ -4274,12 +4274,37 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, *this, E, GetIntrinsicID(E->getArg(0)->getType()), "rdx.min")); } - case Builtin::BI__builtin_reduce_add: + case Builtin::BI__builtin_reduce_add: { +// Note: vector_reduce_fadd takes two arguments a +// scalar start value and a vector. That would mean to +// correctly call it we would need emitBuiltinWithOneOverloadedType<2> +// To keep the builtin sema behavior the same despite type we will +// popululate vector_reduce_fadd scalar value with a 0. +if (E->getArg(0)->getType()->hasFloatingRepresentation()) { + Value *X = EmitScalarExpr(E->getArg(0)); + auto EltTy = X->getType()->getScalarType(); + Value *Seed = ConstantFP::get(EltTy, 0); + return RValue::get(Builder.CreateIntrinsic( + /*ReturnType=*/EltTy, llvm::Intrinsic::vector_reduce_fadd, + ArrayRef{Seed, X}, nullptr, "rdx.fadd")); +} +assert(E->getArg(0)->getType()->hasIntegerRepresentation()); return RValue::get(emitBuiltinWithOneOverloadedType<1>( *this, E, llvm::Intrinsic::vector_reduce_add, "rdx.add")); - case Builtin::BI__builtin_reduce_mul: + } + case Builtin::BI__builtin_reduce_mul: { +if (E->getArg(0)->getType()->hasFloatingRepresentation()) { + Value *X = EmitScalarExpr(E->getArg(0)); + auto EltTy = X->getType()->getScalarType(); + Value *Seed = ConstantFP::get(EltTy, 0); Il-Capitano wrote: Use `1.0` as the initial value. https://github.com/llvm/llvm-project/pull/120367 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Add float type support to __builtin_reduce_add and __builtin_reduce_multipy (PR #120367)
@@ -4274,12 +4274,37 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, *this, E, GetIntrinsicID(E->getArg(0)->getType()), "rdx.min")); } - case Builtin::BI__builtin_reduce_add: + case Builtin::BI__builtin_reduce_add: { +// Note: vector_reduce_fadd takes two arguments a +// scalar start value and a vector. That would mean to +// correctly call it we would need emitBuiltinWithOneOverloadedType<2> +// To keep the builtin sema behavior the same despite type we will +// popululate vector_reduce_fadd scalar value with a 0. +if (E->getArg(0)->getType()->hasFloatingRepresentation()) { + Value *X = EmitScalarExpr(E->getArg(0)); + auto EltTy = X->getType()->getScalarType(); + Value *Seed = ConstantFP::get(EltTy, 0); Il-Capitano wrote: Use `-0.0` as the initial value, as that's the neutral additive float, i.e. `-0.0 + x == x`. This can have an effect on code generation, see for example https://github.com/rust-lang/rust/issues/130028. https://github.com/llvm/llvm-project/pull/120367 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Add float type support to __builtin_reduce_add and __builtin_reduce_multipy (PR #120367)
https://github.com/Il-Capitano edited https://github.com/llvm/llvm-project/pull/120367 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Docs] Add release note for execute-only support on AArch64 (PR #134802)
https://github.com/Il-Capitano updated https://github.com/llvm/llvm-project/pull/134802 From c48168df95781b8fe5d6f72c9bdcbe1ad6a94fe5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Csan=C3=A1d=20Hajd=C3=BA?= Date: Tue, 8 Apr 2025 09:47:46 +0200 Subject: [PATCH 1/2] [Clang][Docs] Add release note for execute-only support on AArch64 --- clang/docs/ReleaseNotes.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index e671183522565..2ca9b0e4b0ae1 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -190,6 +190,9 @@ Modified Compiler Flags - The compiler flag `-fbracket-depth` default value is increased from 256 to 2048. (#GH94728) +- The ``-mexecute-only`` and ``-mpure-code`` flags are now accepted for AArch64 targets, + allowing the generation of binaries with executable-only code sections. (#GH125688) + Removed Compiler Flags - From e3a97bca7622846ad1b55829c8242dc91fa55ee7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Csan=C3=A1d=20Hajd=C3=BA?= Date: Tue, 8 Apr 2025 11:54:30 +0200 Subject: [PATCH 2/2] Add note in "Arm and AArch64 support" section too --- clang/docs/ReleaseNotes.rst | 6 -- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 2ca9b0e4b0ae1..17e18eae9e36b 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -190,8 +190,7 @@ Modified Compiler Flags - The compiler flag `-fbracket-depth` default value is increased from 256 to 2048. (#GH94728) -- The ``-mexecute-only`` and ``-mpure-code`` flags are now accepted for AArch64 targets, - allowing the generation of binaries with executable-only code sections. (#GH125688) +- The ``-mexecute-only`` and ``-mpure-code`` flags are now accepted for AArch64 targets. (#GH125688) Removed Compiler Flags - @@ -474,6 +473,9 @@ X86 Support Arm and AArch64 Support ^^^ +- For AArch64, added support for generating executable-only code sections by using the + ``-mexecute-only`` or ``-mpure-code`` compiler flags. (#GH125688) + Android Support ^^^ ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Docs] Add release note for execute-only support on AArch64 (PR #134802)
Il-Capitano wrote: > There is a `Arm and AArch64 Support` section too, is it worth adding a note > there either instead or as well? It could maybe just be a note that points > back to the Modified Compiler Flags section. Thanks, I didn't notice that section. I simplified the note in "Modified Compiler Flags" and added one in "Arm and AArch64 Support". https://github.com/llvm/llvm-project/pull/134802 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Docs] Add release note for execute-only support on AArch64 (PR #134802)
https://github.com/Il-Capitano created https://github.com/llvm/llvm-project/pull/134802 None From c48168df95781b8fe5d6f72c9bdcbe1ad6a94fe5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Csan=C3=A1d=20Hajd=C3=BA?= Date: Tue, 8 Apr 2025 09:47:46 +0200 Subject: [PATCH] [Clang][Docs] Add release note for execute-only support on AArch64 --- clang/docs/ReleaseNotes.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index e671183522565..2ca9b0e4b0ae1 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -190,6 +190,9 @@ Modified Compiler Flags - The compiler flag `-fbracket-depth` default value is increased from 256 to 2048. (#GH94728) +- The ``-mexecute-only`` and ``-mpure-code`` flags are now accepted for AArch64 targets, + allowing the generation of binaries with executable-only code sections. (#GH125688) + Removed Compiler Flags - ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Docs] Add release note for execute-only support on AArch64 (PR #134802)
https://github.com/Il-Capitano closed https://github.com/llvm/llvm-project/pull/134802 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Docs] Add release note for execute-only support on AArch64 (PR #134802)
https://github.com/Il-Capitano updated https://github.com/llvm/llvm-project/pull/134802 From f41bcb085ac07ed5a05c1246a13048896e63d54c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Csan=C3=A1d=20Hajd=C3=BA?= Date: Tue, 8 Apr 2025 09:47:46 +0200 Subject: [PATCH 1/2] [Clang][Docs] Add release note for execute-only support on AArch64 --- clang/docs/ReleaseNotes.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 0ea8498351c24..c99033fae4d39 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -219,6 +219,9 @@ Modified Compiler Flags - `-Wpadded` option implemented for the `x86_64-windows-msvc` target. Fixes #61702 +- The ``-mexecute-only`` and ``-mpure-code`` flags are now accepted for AArch64 targets, + allowing the generation of binaries with executable-only code sections. (#GH125688) + Removed Compiler Flags - From 87fec09c9fbff9637979465c0286ba2a56866995 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Csan=C3=A1d=20Hajd=C3=BA?= Date: Tue, 8 Apr 2025 11:54:30 +0200 Subject: [PATCH 2/2] Add note in "Arm and AArch64 support" section too --- clang/docs/ReleaseNotes.rst | 6 -- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index c99033fae4d39..0a46bbea96f6c 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -219,8 +219,7 @@ Modified Compiler Flags - `-Wpadded` option implemented for the `x86_64-windows-msvc` target. Fixes #61702 -- The ``-mexecute-only`` and ``-mpure-code`` flags are now accepted for AArch64 targets, - allowing the generation of binaries with executable-only code sections. (#GH125688) +- The ``-mexecute-only`` and ``-mpure-code`` flags are now accepted for AArch64 targets. (#GH125688) Removed Compiler Flags - @@ -572,6 +571,9 @@ Arm and AArch64 Support - Support for __ptrauth type qualifier has been added. +- For AArch64, added support for generating executable-only code sections by using the + ``-mexecute-only`` or ``-mpure-code`` compiler flags. (#GH125688) + Android Support ^^^ ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Add support for SHF_AARCH64_PURECODE ELF section flag (2/3) (PR #125688)
https://github.com/Il-Capitano updated https://github.com/llvm/llvm-project/pull/125688 From a25845dcb484514c83022a21ee924e31a39882f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Csan=C3=A1d=20Hajd=C3=BA?= Date: Tue, 4 Feb 2025 14:51:55 +0100 Subject: [PATCH 1/2] [Clang][AArch64] Add support for SHF_AARCH64_PURECODE ELF section flag (2/3) Add support for the new SHF_AARCH64_PURECODE ELF section flag: https://github.com/ARM-software/abi-aa/pull/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. --- clang/include/clang/Driver/Options.td| 4 ++-- clang/lib/Driver/ToolChains/Arch/AArch64.cpp | 11 + clang/test/CodeGen/aarch64-execute-only.c| 24 clang/test/Driver/aarch64-execute-only.c | 6 + clang/test/Driver/fsanitize.c| 8 ++- 5 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 clang/test/CodeGen/aarch64-execute-only.c create mode 100644 clang/test/Driver/aarch64-execute-only.c diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 5ad187926e710..0c8c4e5e0fae4 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -4692,9 +4692,9 @@ def mno_long_calls : Flag<["-"], "mno-long-calls">, Group, HelpText<"Restore the default behaviour of not generating long calls">; } // let Flags = [TargetSpecific] def mexecute_only : Flag<["-"], "mexecute-only">, Group, - HelpText<"Disallow generation of data access to code sections (ARM only)">; + HelpText<"Disallow generation of data access to code sections (AArch64/ARM only)">; def mno_execute_only : Flag<["-"], "mno-execute-only">, Group, - HelpText<"Allow generation of data access to code sections (ARM only)">; + HelpText<"Allow generation of data access to code sections (AArch64/ARM only)">; let Flags = [TargetSpecific] in { def mtp_mode_EQ : Joined<["-"], "mtp=">, Group, Values<"soft,cp15,tpidrurw,tpidruro,tpidrprw,el0,el1,el2,el3,tpidr_el0,tpidr_el1,tpidr_el2,tpidr_el3,tpidrro_el0">, HelpText<"Thread pointer access method. " diff --git a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp index 1e2ac4e501baf..1248fea50f9de 100644 --- a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp +++ b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp @@ -332,6 +332,17 @@ void aarch64::getAArch64TargetFeatures(const Driver &D, } else if (Triple.isOSOpenBSD()) Features.push_back("+strict-align"); + // Generate execute-only output (no data access to code sections). + // This only makes sense for the compiler, not for the assembler. + if (!ForAS) { +if (Arg *A = Args.getLastArg(options::OPT_mexecute_only, + options::OPT_mno_execute_only)) { + if (A->getOption().matches(options::OPT_mexecute_only)) { +Features.push_back("+execute-only"); + } +} + } + if (Args.hasArg(options::OPT_ffixed_x1)) Features.push_back("+reserve-x1"); diff --git a/clang/test/CodeGen/aarch64-execute-only.c b/clang/test/CodeGen/aarch64-execute-only.c new file mode 100644 index 0..d885e954166f6 --- /dev/null +++ b/clang/test/CodeGen/aarch64-execute-only.c @@ -0,0 +1,24 @@ +// RUN: %clang -target aarch64 -### %s 2>&1 \ +// RUN:| FileCheck %s -check-prefix CHECK-NO-EXECUTE-ONLY + +// RUN: %clang -target aarch64 -### -mexecute-only %s 2>&1 \ +// RUN:| FileCheck %s -check-prefix CHECK-EXECUTE-ONLY + +// RUN: %clang -target aarch64 -### -mexecute-only -mno-execute-only %s 2>&1 \ +// RUN:| FileCheck %s -check-prefix CHECK-NO-EXECUTE-ONLY + + +// -mpure-code flag for GCC compatibility +// RUN: %clang -target aarch64 -### %s 2>&1 \ +// RUN:| FileCheck %s -check-prefix CHECK-NO-EXECUTE-ONLY + +// RUN: %clang -target aarch64 -### -mpure-code %s 2>&1 \ +// RUN:| FileCheck %s -check-prefix CHECK-EXECUTE-ONLY + +// RUN: %clang -target aarch64 -### -mpure-code -mno-pure-code %s 2>&1 \ +// RUN:| FileCheck %s -check-prefix CHECK-NO-EXECUTE-ONLY + +// CHECK-NO-EXECUTE-ONLY-NOT: "+execute-only" +// CHECK-EXECUTE-ONLY: "+execute-only" + +void a() {} diff --git a/clang/test/Driver/aarch64-execute-only.c b/clang/test/Driver/aarch64-execute-only.c new file mode 100644 index 0..67c6d4a5eb066 --- /dev/null +++ b/clang/test/Driver/aarch64-execute-only.c @@ -0,0 +1,6 @@ +// RUN: %clang --sysroot=%S/Inputs -c -fdriver-only -Werror --target=aarch64-unknown-linux-gnu \ +// RUN: -mexecute-only %s 2>&1 | count 0 + +// RUN: %clang -### --target=aarch64-unknown-linux-gnu -x assembler -mexecute-only %s -c -### 2>&1 \ +// RUN:| FileCheck %s --check-prefix=CHECK-NO-EXECUTE-ONLY-ASM +// CHECK-NO-EXECUTE-ONLY-ASM: warning: argument unused during compilation: '-mexecute-only' diff --git a/clang/test/Driver/fsaniti
[clang] [Clang][AArch64] Add support for SHF_AARCH64_PURECODE ELF section flag (2/3) (PR #125688)
@@ -0,0 +1,6 @@ +// RUN: %clang --sysroot=%S/Inputs -c -fdriver-only -Werror --target=aarch64-unknown-linux-gnu \ Il-Capitano wrote: There must have been a good reason I removed the `!ForMultilib` check, but I can't remember now... You're right, the check is needed for bare metal targets. As is, the test would pass with `--target=aarch64-none-elf`, but that's because there's no `sysroot/aarch64-none-elf/multilib.yaml` file found. However I was able to test for this by passing the `--multi-lib-config=%S/Inputs/multilib/empty.yaml` flag. https://github.com/llvm/llvm-project/pull/125688 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Add support for SHF_AARCH64_PURECODE ELF section flag (2/3) (PR #125688)
Il-Capitano wrote: Ping. https://github.com/llvm/llvm-project/pull/125688 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Add support for SHF_AARCH64_PURECODE ELF section flag (2/3) (PR #125688)
Il-Capitano wrote: @jansvoboda11 You're tagged as the compiler options maintainer for Clang, so this may be of interest to you as well. https://github.com/llvm/llvm-project/pull/125688 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Add support for SHF_AARCH64_PURECODE ELF section flag (2/3) (PR #125688)
https://github.com/Il-Capitano updated https://github.com/llvm/llvm-project/pull/125688 From a25845dcb484514c83022a21ee924e31a39882f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Csan=C3=A1d=20Hajd=C3=BA?= Date: Tue, 4 Feb 2025 14:51:55 +0100 Subject: [PATCH] [Clang][AArch64] Add support for SHF_AARCH64_PURECODE ELF section flag (2/3) Add support for the new SHF_AARCH64_PURECODE ELF section flag: https://github.com/ARM-software/abi-aa/pull/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. --- clang/include/clang/Driver/Options.td| 4 ++-- clang/lib/Driver/ToolChains/Arch/AArch64.cpp | 11 + clang/test/CodeGen/aarch64-execute-only.c| 24 clang/test/Driver/aarch64-execute-only.c | 6 + clang/test/Driver/fsanitize.c| 8 ++- 5 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 clang/test/CodeGen/aarch64-execute-only.c create mode 100644 clang/test/Driver/aarch64-execute-only.c diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 5ad187926e710..0c8c4e5e0fae4 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -4692,9 +4692,9 @@ def mno_long_calls : Flag<["-"], "mno-long-calls">, Group, HelpText<"Restore the default behaviour of not generating long calls">; } // let Flags = [TargetSpecific] def mexecute_only : Flag<["-"], "mexecute-only">, Group, - HelpText<"Disallow generation of data access to code sections (ARM only)">; + HelpText<"Disallow generation of data access to code sections (AArch64/ARM only)">; def mno_execute_only : Flag<["-"], "mno-execute-only">, Group, - HelpText<"Allow generation of data access to code sections (ARM only)">; + HelpText<"Allow generation of data access to code sections (AArch64/ARM only)">; let Flags = [TargetSpecific] in { def mtp_mode_EQ : Joined<["-"], "mtp=">, Group, Values<"soft,cp15,tpidrurw,tpidruro,tpidrprw,el0,el1,el2,el3,tpidr_el0,tpidr_el1,tpidr_el2,tpidr_el3,tpidrro_el0">, HelpText<"Thread pointer access method. " diff --git a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp index 1e2ac4e501baf..1248fea50f9de 100644 --- a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp +++ b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp @@ -332,6 +332,17 @@ void aarch64::getAArch64TargetFeatures(const Driver &D, } else if (Triple.isOSOpenBSD()) Features.push_back("+strict-align"); + // Generate execute-only output (no data access to code sections). + // This only makes sense for the compiler, not for the assembler. + if (!ForAS) { +if (Arg *A = Args.getLastArg(options::OPT_mexecute_only, + options::OPT_mno_execute_only)) { + if (A->getOption().matches(options::OPT_mexecute_only)) { +Features.push_back("+execute-only"); + } +} + } + if (Args.hasArg(options::OPT_ffixed_x1)) Features.push_back("+reserve-x1"); diff --git a/clang/test/CodeGen/aarch64-execute-only.c b/clang/test/CodeGen/aarch64-execute-only.c new file mode 100644 index 0..d885e954166f6 --- /dev/null +++ b/clang/test/CodeGen/aarch64-execute-only.c @@ -0,0 +1,24 @@ +// RUN: %clang -target aarch64 -### %s 2>&1 \ +// RUN:| FileCheck %s -check-prefix CHECK-NO-EXECUTE-ONLY + +// RUN: %clang -target aarch64 -### -mexecute-only %s 2>&1 \ +// RUN:| FileCheck %s -check-prefix CHECK-EXECUTE-ONLY + +// RUN: %clang -target aarch64 -### -mexecute-only -mno-execute-only %s 2>&1 \ +// RUN:| FileCheck %s -check-prefix CHECK-NO-EXECUTE-ONLY + + +// -mpure-code flag for GCC compatibility +// RUN: %clang -target aarch64 -### %s 2>&1 \ +// RUN:| FileCheck %s -check-prefix CHECK-NO-EXECUTE-ONLY + +// RUN: %clang -target aarch64 -### -mpure-code %s 2>&1 \ +// RUN:| FileCheck %s -check-prefix CHECK-EXECUTE-ONLY + +// RUN: %clang -target aarch64 -### -mpure-code -mno-pure-code %s 2>&1 \ +// RUN:| FileCheck %s -check-prefix CHECK-NO-EXECUTE-ONLY + +// CHECK-NO-EXECUTE-ONLY-NOT: "+execute-only" +// CHECK-EXECUTE-ONLY: "+execute-only" + +void a() {} diff --git a/clang/test/Driver/aarch64-execute-only.c b/clang/test/Driver/aarch64-execute-only.c new file mode 100644 index 0..67c6d4a5eb066 --- /dev/null +++ b/clang/test/Driver/aarch64-execute-only.c @@ -0,0 +1,6 @@ +// RUN: %clang --sysroot=%S/Inputs -c -fdriver-only -Werror --target=aarch64-unknown-linux-gnu \ +// RUN: -mexecute-only %s 2>&1 | count 0 + +// RUN: %clang -### --target=aarch64-unknown-linux-gnu -x assembler -mexecute-only %s -c -### 2>&1 \ +// RUN:| FileCheck %s --check-prefix=CHECK-NO-EXECUTE-ONLY-ASM +// CHECK-NO-EXECUTE-ONLY-ASM: warning: argument unused during compilation: '-mexecute-only' diff --git a/clang/test/Driver/fsanitize.c
[clang] [Clang][AArch64] Add support for SHF_AARCH64_PURECODE ELF section flag (2/3) (PR #125688)
https://github.com/Il-Capitano edited https://github.com/llvm/llvm-project/pull/125688 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Add support for SHF_AARCH64_PURECODE ELF section flag (2/3) (PR #125688)
https://github.com/Il-Capitano ready_for_review https://github.com/llvm/llvm-project/pull/125688 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Add support for SHF_AARCH64_PURECODE ELF section flag (2/3) (PR #125688)
Il-Capitano wrote: I've rebased this patch onto main, since https://github.com/llvm/llvm-project/pull/125687 has been merged, so it's now ready for review. https://github.com/llvm/llvm-project/pull/125688 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Add support for SHF_AARCH64_PURECODE ELF section flag (2/3) (PR #125688)
Il-Capitano wrote: @smithp35 @davemgreen @paulwalker-arm @jh7370 Pinging to ask for more reviews on this, please. https://github.com/llvm/llvm-project/pull/125688 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] Add CMake option to enable execute-only code generation on AArch64 (PR #140554)
https://github.com/Il-Capitano created https://github.com/llvm/llvm-project/pull/140554 For a full toolchain supporting execute-only code generation the runtime libraries also need to be pre-compiled with it enabled. For libunwind this can now be enabled with the `LIBUNWIND_EXECUTE_ONLY_CODE` CMake option during build configuration. The build option can only be enabled for a runtimes build of libunwind, because a recent version of Clang is needed to correctly compile assembly files with execute-only code support. Related RFC: https://discourse.llvm.org/t/rfc-execute-only-code-support-for-runtime-libraries-on-aarch64/86180 From c69f17edaceb95154e25f0e9062363d88498a775 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Csan=C3=A1d=20Hajd=C3=BA?= Date: Mon, 19 May 2025 12:29:43 +0200 Subject: [PATCH] [libunwind] Add CMake option to enable execute-only code generation on AArch64 For a full toolchain supporting execute-only code generation the runtime libraries also need to be pre-compiled with it enabled. For libunwind this can now be enabled with the `LIBUNWIND_EXECUTE_ONLY_CODE` CMake option during build configuration. The build option can only be enabled for a runtimes build of libunwind, because a recent version of Clang is needed to correctly compile assembly files with execute-only code support. Related RFC: https://discourse.llvm.org/t/rfc-execute-only-code-support-for-runtime-libraries-on-aarch64/86180 --- libunwind/CMakeLists.txt | 18 ++ libunwind/src/UnwindRegistersRestore.S | 2 ++ libunwind/src/UnwindRegistersSave.S| 2 ++ 3 files changed, 22 insertions(+) diff --git a/libunwind/CMakeLists.txt b/libunwind/CMakeLists.txt index e27f3c2e2fc17..75195fe022d4b 100644 --- a/libunwind/CMakeLists.txt +++ b/libunwind/CMakeLists.txt @@ -55,6 +55,7 @@ option(LIBUNWIND_USE_FRAME_HEADER_CACHE "Cache frame headers for unwinding. Requ option(LIBUNWIND_REMEMBER_HEAP_ALLOC "Use heap instead of the stack for .cfi_remember_state." OFF) option(LIBUNWIND_INSTALL_HEADERS "Install the libunwind headers." ON) option(LIBUNWIND_ENABLE_FRAME_APIS "Include libgcc-compatible frame apis." OFF) +option(LIBUNWIND_EXECUTE_ONLY_CODE "Compile libunwind as execute-only." OFF) set(LIBUNWIND_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING "Define suffix of library directory name (32/64)") @@ -109,6 +110,11 @@ endif() option(LIBUNWIND_HIDE_SYMBOLS "Do not export any symbols from the static library." ${LIBUNWIND_DEFAULT_HIDE_SYMBOLS}) +if (LIBUNWIND_EXECUTE_ONLY_CODE AND NOT LLVM_RUNTIMES_BUILD) + message(SEND_ERROR "LIBUNWIND_EXECUTE_ONLY_CODE is only supported " + "for runtimes build of libunwind.") +endif() + # If toolchain is FPXX, we switch to FP64 to save the full FPRs. See: # https://web.archive.org/web/20180828210612/https://dmz-portal.mips.com/wiki/MIPS_O32_ABI_-_FR0_and_FR1_Interlinking check_symbol_exists(__mips_hard_float "" __MIPSHF) @@ -330,6 +336,18 @@ if (C_SUPPORTS_COMMENT_LIB_PRAGMA) endif() endif() +if (LIBUNWIND_EXECUTE_ONLY_CODE) + add_compile_flags_if_supported(-mexecute-only) + if (NOT CXX_SUPPORTS_MEXECUTE_ONLY_FLAG) +add_compile_flags_if_supported(-mpure-code) +if (NOT CXX_SUPPORTS_MPURE_CODE_FLAG) + message(SEND_ERROR +"Compiler doesn't support -mexecute-only or -mpure-code option!") +endif() + endif() + add_compile_definitions(_LIBUNWIND_EXECUTE_ONLY_CODE) +endif() + #=== # Setup Source Code #=== diff --git a/libunwind/src/UnwindRegistersRestore.S b/libunwind/src/UnwindRegistersRestore.S index 5e199188945df..2a0e81a9794eb 100644 --- a/libunwind/src/UnwindRegistersRestore.S +++ b/libunwind/src/UnwindRegistersRestore.S @@ -16,6 +16,8 @@ #if defined(_AIX) .toc +#elif defined(__aarch64__) && defined(__ELF__) && defined(_LIBUNWIND_EXECUTE_ONLY_CODE) + .section .text,"axy",@progbits,unique,0 #else .text #endif diff --git a/libunwind/src/UnwindRegistersSave.S b/libunwind/src/UnwindRegistersSave.S index 5139a551ad245..1ff14cf272b61 100644 --- a/libunwind/src/UnwindRegistersSave.S +++ b/libunwind/src/UnwindRegistersSave.S @@ -16,6 +16,8 @@ #if defined(_AIX) .toc +#elif defined(__aarch64__) && defined(__ELF__) && defined(_LIBUNWIND_EXECUTE_ONLY_CODE) +.section .text,"axy",@progbits,unique,0 #else .text #endif ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] Add CMake option to enable execute-only code generation on AArch64 (PR #140554)
https://github.com/Il-Capitano edited https://github.com/llvm/llvm-project/pull/140554 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] Add CMake option to enable execute-only code generation on AArch64 (PR #140554)
https://github.com/Il-Capitano updated https://github.com/llvm/llvm-project/pull/140554 From c69f17edaceb95154e25f0e9062363d88498a775 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Csan=C3=A1d=20Hajd=C3=BA?= Date: Mon, 19 May 2025 12:29:43 +0200 Subject: [PATCH 1/2] [libunwind] Add CMake option to enable execute-only code generation on AArch64 For a full toolchain supporting execute-only code generation the runtime libraries also need to be pre-compiled with it enabled. For libunwind this can now be enabled with the `LIBUNWIND_EXECUTE_ONLY_CODE` CMake option during build configuration. The build option can only be enabled for a runtimes build of libunwind, because a recent version of Clang is needed to correctly compile assembly files with execute-only code support. Related RFC: https://discourse.llvm.org/t/rfc-execute-only-code-support-for-runtime-libraries-on-aarch64/86180 --- libunwind/CMakeLists.txt | 18 ++ libunwind/src/UnwindRegistersRestore.S | 2 ++ libunwind/src/UnwindRegistersSave.S| 2 ++ 3 files changed, 22 insertions(+) diff --git a/libunwind/CMakeLists.txt b/libunwind/CMakeLists.txt index e27f3c2e2fc17..75195fe022d4b 100644 --- a/libunwind/CMakeLists.txt +++ b/libunwind/CMakeLists.txt @@ -55,6 +55,7 @@ option(LIBUNWIND_USE_FRAME_HEADER_CACHE "Cache frame headers for unwinding. Requ option(LIBUNWIND_REMEMBER_HEAP_ALLOC "Use heap instead of the stack for .cfi_remember_state." OFF) option(LIBUNWIND_INSTALL_HEADERS "Install the libunwind headers." ON) option(LIBUNWIND_ENABLE_FRAME_APIS "Include libgcc-compatible frame apis." OFF) +option(LIBUNWIND_EXECUTE_ONLY_CODE "Compile libunwind as execute-only." OFF) set(LIBUNWIND_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING "Define suffix of library directory name (32/64)") @@ -109,6 +110,11 @@ endif() option(LIBUNWIND_HIDE_SYMBOLS "Do not export any symbols from the static library." ${LIBUNWIND_DEFAULT_HIDE_SYMBOLS}) +if (LIBUNWIND_EXECUTE_ONLY_CODE AND NOT LLVM_RUNTIMES_BUILD) + message(SEND_ERROR "LIBUNWIND_EXECUTE_ONLY_CODE is only supported " + "for runtimes build of libunwind.") +endif() + # If toolchain is FPXX, we switch to FP64 to save the full FPRs. See: # https://web.archive.org/web/20180828210612/https://dmz-portal.mips.com/wiki/MIPS_O32_ABI_-_FR0_and_FR1_Interlinking check_symbol_exists(__mips_hard_float "" __MIPSHF) @@ -330,6 +336,18 @@ if (C_SUPPORTS_COMMENT_LIB_PRAGMA) endif() endif() +if (LIBUNWIND_EXECUTE_ONLY_CODE) + add_compile_flags_if_supported(-mexecute-only) + if (NOT CXX_SUPPORTS_MEXECUTE_ONLY_FLAG) +add_compile_flags_if_supported(-mpure-code) +if (NOT CXX_SUPPORTS_MPURE_CODE_FLAG) + message(SEND_ERROR +"Compiler doesn't support -mexecute-only or -mpure-code option!") +endif() + endif() + add_compile_definitions(_LIBUNWIND_EXECUTE_ONLY_CODE) +endif() + #=== # Setup Source Code #=== diff --git a/libunwind/src/UnwindRegistersRestore.S b/libunwind/src/UnwindRegistersRestore.S index 5e199188945df..2a0e81a9794eb 100644 --- a/libunwind/src/UnwindRegistersRestore.S +++ b/libunwind/src/UnwindRegistersRestore.S @@ -16,6 +16,8 @@ #if defined(_AIX) .toc +#elif defined(__aarch64__) && defined(__ELF__) && defined(_LIBUNWIND_EXECUTE_ONLY_CODE) + .section .text,"axy",@progbits,unique,0 #else .text #endif diff --git a/libunwind/src/UnwindRegistersSave.S b/libunwind/src/UnwindRegistersSave.S index 5139a551ad245..1ff14cf272b61 100644 --- a/libunwind/src/UnwindRegistersSave.S +++ b/libunwind/src/UnwindRegistersSave.S @@ -16,6 +16,8 @@ #if defined(_AIX) .toc +#elif defined(__aarch64__) && defined(__ELF__) && defined(_LIBUNWIND_EXECUTE_ONLY_CODE) +.section .text,"axy",@progbits,unique,0 #else .text #endif From debdd954146a2d564c95be5bc565a53a884f3069 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Csan=C3=A1d=20Hajd=C3=BA?= Date: Wed, 11 Jun 2025 11:13:11 +0200 Subject: [PATCH 2/2] Simplify CMake configuration based on RFC feedback --- libunwind/CMakeLists.txt | 16 +--- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/libunwind/CMakeLists.txt b/libunwind/CMakeLists.txt index 75195fe022d4b..48a29a2a7ed9c 100644 --- a/libunwind/CMakeLists.txt +++ b/libunwind/CMakeLists.txt @@ -55,7 +55,6 @@ option(LIBUNWIND_USE_FRAME_HEADER_CACHE "Cache frame headers for unwinding. Requ option(LIBUNWIND_REMEMBER_HEAP_ALLOC "Use heap instead of the stack for .cfi_remember_state." OFF) option(LIBUNWIND_INSTALL_HEADERS "Install the libunwind headers." ON) option(LIBUNWIND_ENABLE_FRAME_APIS "Include libgcc-compatible frame apis." OFF) -option(LIBUNWIND_EXECUTE_ONLY_CODE "Compile libunwind as execute-only." OFF) set(LIBUNWIND_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING "Define suffix of library directory name (32/64)")
[libunwind] [libunwind] Add CMake option to enable execute-only code generation on AArch64 (PR #140554)
Il-Capitano wrote: I simplified the configuration based on the discussion in the RFC. C and C++ compiler flags will be handled by the change in https://github.com/llvm/llvm-project/pull/143698. https://github.com/llvm/llvm-project/pull/140554 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits