https://github.com/frobtech updated https://github.com/llvm/llvm-project/pull/236000
>From c15c4299b994d6c590218b31c80aa6f8eee466f9 Mon Sep 17 00:00:00 2001 From: Roland McGrath <[email protected]> Date: Tue, 27 Oct 2026 00:17:47 -0700 Subject: [PATCH 1/4] [lld][ELF] Add -z ibt-report and -z shstk-report for x86 CET properties Previously, -z cet-report=[none|warning|error] reported missing GNU_PROPERTY_X86_FEATURE_1_IBT and GNU_PROPERTY_X86_FEATURE_1_SHSTK together, with no way to enforce only IBT (when compiling with -fcf-protection=branch) or only SHSTK (when compiling with -fcf-protection=return). Add -z ibt-report=[none|warning|error] and -z shstk-report=[none|warning|error] to configure reporting for each feature bit individually while keeping -z cet-report=[none|warning|error] as shorthand for setting both. Also route the default missing-IBT warning from -z force-ibt through zIbtReport (matching commit 4c4925f1a259 for -z force-bti and -z bti-report) so that -z ibt-report=none or -z cet-report=none can silence warnings from -z force-ibt. Assisted-by: Gemini --- lld/ELF/Config.h | 4 +++ lld/ELF/Driver.cpp | 54 +++++++++++++++++++++--------- lld/docs/ReleaseNotes.md | 2 ++ lld/docs/ld.lld.1 | 10 ++++++ lld/test/ELF/aarch64-feature-bti.s | 5 +++ lld/test/ELF/i386-feature-cet.s | 18 +++++++++- lld/test/ELF/x86-64-feature-cet.s | 34 ++++++++++++++++++- 7 files changed, 110 insertions(+), 17 deletions(-) diff --git a/lld/ELF/Config.h b/lld/ELF/Config.h index 0c76e3854e6608..bf9ef6f54c7e54 100644 --- a/lld/ELF/Config.h +++ b/lld/ELF/Config.h @@ -286,6 +286,10 @@ struct Config { ReportPolicy zBtiReport = ReportPolicy::None; llvm::StringRef zBtiReportSource; ReportPolicy zCetReport = ReportPolicy::None; + ReportPolicy zIbtReport = ReportPolicy::None; + llvm::StringRef zIbtReportSource; + ReportPolicy zShstkReport = ReportPolicy::None; + llvm::StringRef zShstkReportSource; ReportPolicy zPauthReport = ReportPolicy::None; ReportPolicy zGcsReport = ReportPolicy::None; llvm::StringRef zGcsReportSource; diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index a08f6f2d384bc1..bd61f62c96add0 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -401,9 +401,16 @@ static void checkOptions(Ctx &ctx) { ErrAlways(ctx) << "-z zicfiss is only supported on RISC-V targets"; } - if (ctx.arg.emachine != EM_386 && ctx.arg.emachine != EM_X86_64 && - ctx.arg.zCetReport != ReportPolicy::None) - ErrAlways(ctx) << "-z cet-report only supported on X86 and X86_64"; + if (ctx.arg.emachine != EM_386 && ctx.arg.emachine != EM_X86_64) { + if (ctx.arg.zCetReport != ReportPolicy::None) + ErrAlways(ctx) << "-z cet-report only supported on X86 and X86_64"; + if (ctx.arg.zIbtReport != ReportPolicy::None && + ctx.arg.zIbtReportSource == "-z ibt-report") + ErrAlways(ctx) << "-z ibt-report only supported on X86 and X86_64"; + if (ctx.arg.zShstkReport != ReportPolicy::None && + ctx.arg.zShstkReportSource == "-z shstk-report") + ErrAlways(ctx) << "-z shstk-report only supported on X86 and X86_64"; + } if (ctx.arg.zMarkPlt) { if (ctx.arg.emachine != EM_X86_64) @@ -1753,18 +1760,29 @@ static void readConfigs(Ctx &ctx, opt::InputArgList &args) { ctx.arg.zBtiReport = ReportPolicy::Warning; ctx.arg.zBtiReportSource = "-z force-bti"; } + if (ctx.arg.zForceIbt) { + ctx.arg.zIbtReport = ReportPolicy::Warning; + ctx.arg.zIbtReportSource = "-z force-ibt"; + } if (ctx.arg.zGcs == GcsPolicy::Always) { ctx.arg.zGcsReport = ReportPolicy::Warning; ctx.arg.zGcsReportSource = "-z gcs"; } + // Parse `-z *-report=` options in command-line order. On x86, `-z cet-report` + // sets the report policy for both IBT and SHSTK, while `-z ibt-report` and + // `-z shstk-report` set them individually (allowing e.g. + // `-fcf-protection=branch` builds to require IBT without requiring SHSTK, or + // `-z ibt-report=none` to silence the default warning from `-z force-ibt`). auto reports = { std::make_pair("bti-report", &ctx.arg.zBtiReport), std::make_pair("cet-report", &ctx.arg.zCetReport), std::make_pair("execute-only-report", &ctx.arg.zExecuteOnlyReport), std::make_pair("gcs-report", &ctx.arg.zGcsReport), std::make_pair("gcs-report-dynamic", &ctx.arg.zGcsReportDynamic), + std::make_pair("ibt-report", &ctx.arg.zIbtReport), std::make_pair("pauth-report", &ctx.arg.zPauthReport), + std::make_pair("shstk-report", &ctx.arg.zShstkReport), std::make_pair("zicfilp-unlabeled-report", &ctx.arg.zZicfilpUnlabeledReport), std::make_pair("zicfilp-func-sig-report", &ctx.arg.zZicfilpFuncSigReport), @@ -1789,10 +1807,20 @@ static void readConfigs(Ctx &ctx, opt::InputArgList &args) { continue; } hasGcsReportDynamic |= option.first == "gcs-report-dynamic"; - if (option.first == "bti-report") + if (option.first == "bti-report") { ctx.arg.zBtiReportSource = "-z bti-report"; - else if (option.first == "gcs-report") + } else if (option.first == "cet-report") { + ctx.arg.zIbtReport = *reportArg.second; + ctx.arg.zIbtReportSource = "-z cet-report"; + ctx.arg.zShstkReport = *reportArg.second; + ctx.arg.zShstkReportSource = "-z cet-report"; + } else if (option.first == "gcs-report") { ctx.arg.zGcsReportSource = "-z gcs-report"; + } else if (option.first == "ibt-report") { + ctx.arg.zIbtReportSource = "-z ibt-report"; + } else if (option.first == "shstk-report") { + ctx.arg.zShstkReportSource = "-z shstk-report"; + } } } @@ -3059,15 +3087,15 @@ static void readSecurityNotes(Ctx &ctx) { << ": file does not have " "GNU_PROPERTY_AARCH64_FEATURE_1_GCS property"; - reportUnless(ctx.arg.zCetReport, features & GNU_PROPERTY_X86_FEATURE_1_IBT) - << f - << ": -z cet-report: file does not have " + reportUnless(ctx.arg.zIbtReport, features & GNU_PROPERTY_X86_FEATURE_1_IBT) + << f << ": " << ctx.arg.zIbtReportSource + << ": file does not have " "GNU_PROPERTY_X86_FEATURE_1_IBT property"; - reportUnless(ctx.arg.zCetReport, + reportUnless(ctx.arg.zShstkReport, features & GNU_PROPERTY_X86_FEATURE_1_SHSTK) - << f - << ": -z cet-report: file does not have " + << f << ": " << ctx.arg.zShstkReportSource + << ": file does not have " "GNU_PROPERTY_X86_FEATURE_1_SHSTK property"; if (ctx.arg.emachine == EM_RISCV) { @@ -3113,10 +3141,6 @@ static void readSecurityNotes(Ctx &ctx) { features |= GNU_PROPERTY_AARCH64_FEATURE_1_BTI; } else if (ctx.arg.zForceIbt && !(features & GNU_PROPERTY_X86_FEATURE_1_IBT)) { - if (ctx.arg.zCetReport == ReportPolicy::None) - Warn(ctx) << f - << ": -z force-ibt: file does not have " - "GNU_PROPERTY_X86_FEATURE_1_IBT property"; features |= GNU_PROPERTY_X86_FEATURE_1_IBT; } if (ctx.arg.zPacPlt && !(hasValidPauthAbiCoreInfo || diff --git a/lld/docs/ReleaseNotes.md b/lld/docs/ReleaseNotes.md index 8cd9e8fedd71c6..56478810cc7b89 100644 --- a/lld/docs/ReleaseNotes.md +++ b/lld/docs/ReleaseNotes.md @@ -31,6 +31,8 @@ from the [LLVM releases web site](https://llvm.org/releases/). * `--mmap-output-file` and `--no-mmap-output-file` were swapped in LLVM 21 and 22. They now mean what they say again; the default behavior is unchanged. +* Added `-z ibt-report=[none|warning|error]` and `-z shstk-report=[none|warning|error]` on x86 and x86-64 to report missing `GNU_PROPERTY_X86_FEATURE_1_IBT` and `GNU_PROPERTY_X86_FEATURE_1_SHSTK` properties individually (for example, when building with `-fcf-protection=branch` or `-fcf-protection=return`). + `-z ibt-report=none` and `-z cet-report=none` also silence warnings from `-z force-ibt`. ### Breaking changes diff --git a/lld/docs/ld.lld.1 b/lld/docs/ld.lld.1 index c7d452c96339ea..f1805ab6218d34 100644 --- a/lld/docs/ld.lld.1 +++ b/lld/docs/ld.lld.1 @@ -815,6 +815,16 @@ Specify how to report the missing GNU_PROPERTY_X86_FEATURE_1_IBT or GNU_PROPERTY .Cm none is the default, linker will not report the missing property otherwise will be reported as a warning or an error. .Pp +.It Cm ibt-report Ns = Ns Ar [none|warning|error] +Specify how to report the missing GNU_PROPERTY_X86_FEATURE_1_IBT property. +.Cm none +is the default, linker will not report the missing property otherwise will be reported as a warning or an error. +.Pp +.It Cm shstk-report Ns = Ns Ar [none|warning|error] +Specify how to report the missing GNU_PROPERTY_X86_FEATURE_1_SHSTK property. +.Cm none +is the default, linker will not report the missing property otherwise will be reported as a warning or an error. +.Pp .It Cm gcs-report Ns = Ns Ar [none|warning|error] Specify how to report missing .Cm GNU_PROPERTY_AARCH64_FEATURE_1_GCS diff --git a/lld/test/ELF/aarch64-feature-bti.s b/lld/test/ELF/aarch64-feature-bti.s index 53676c8835ada3..3cc064a87a3f2e 100644 --- a/lld/test/ELF/aarch64-feature-bti.s +++ b/lld/test/ELF/aarch64-feature-bti.s @@ -233,6 +233,11 @@ ## Ensure that warnings from force-bti can be silenced with bti-report=none. # RUN: ld.lld %t.o %t2.o -z force-bti -z bti-report=none %t.so -o %t.so 2>&1 | count 0 +# RUN: not ld.lld %t.o -z cet-report=error -z ibt-report=error -z shstk-report=error -o /dev/null 2>&1 | FileCheck --check-prefix=ERR-X86 %s +# ERR-X86: error: -z cet-report only supported on X86 and X86_64 +# ERR-X86-NEXT: error: -z ibt-report only supported on X86 and X86_64 +# ERR-X86-NEXT: error: -z shstk-report only supported on X86 and X86_64 + # RUN: llvm-readelf -n %tforcebti.exe | FileCheck --check-prefix=BTIPROP %s # RUN: llvm-readelf --dynamic-table %tforcebti.exe | FileCheck --check-prefix BTIDYN %s # RUN: llvm-objdump --no-print-imm-hex -d --mattr=+bti --no-show-raw-insn %tforcebti.exe | FileCheck --check-prefix=FORCE %s diff --git a/lld/test/ELF/i386-feature-cet.s b/lld/test/ELF/i386-feature-cet.s index 13760a03fbbb42..dddc816aeed48e 100644 --- a/lld/test/ELF/i386-feature-cet.s +++ b/lld/test/ELF/i386-feature-cet.s @@ -40,8 +40,24 @@ # CET_REPORT_ERROR: {{.*}}.o: -z cet-report: file does not have GNU_PROPERTY_X86_FEATURE_1_SHSTK property # CET_REPORT_ERROR-EMPTY: -# RUN: ld.lld -e func1 %t.o %t4.o -o %t +# RUN: ld.lld -e func1 %t.o %t3.o -o /dev/null -z ibt-report=warning 2>&1 \ +# RUN: | FileCheck --check-prefix=IBT_REPORT %s +# RUN: not ld.lld -e func1 %t.o %t3.o -o /dev/null -z ibt-report=error 2>&1 \ +# RUN: | FileCheck --check-prefix=IBT_REPORT %s +# IBT_REPORT: {{.*}}.o: -z ibt-report: file does not have GNU_PROPERTY_X86_FEATURE_1_IBT property +# IBT_REPORT-EMPTY: + +# RUN: ld.lld -e func1 %t.o %t3.o -o /dev/null -z shstk-report=warning 2>&1 \ +# RUN: | FileCheck --check-prefix=SHSTK_REPORT %s +# RUN: not ld.lld -e func1 %t.o %t3.o -o /dev/null -z shstk-report=error 2>&1 \ +# RUN: | FileCheck --check-prefix=SHSTK_REPORT %s +# SHSTK_REPORT: {{.*}}.o: -z shstk-report: file does not have GNU_PROPERTY_X86_FEATURE_1_SHSTK property +# SHSTK_REPORT-EMPTY: + +# RUN: ld.lld -e func1 %t.o %t4.o -o %t -z ibt-report=error 2>&1 | count 0 # RUN: llvm-readelf -n %t | FileCheck --check-prefix=NOSHSTK %s +# RUN: not ld.lld -e func1 %t.o %t4.o -o /dev/null -z shstk-report=error 2>&1 \ +# RUN: | FileCheck --check-prefix=SHSTK_REPORT %s # Check .note.gnu.protery without property SHSTK. # NOSHSTK: Properties: x86 feature: IBT{{$}} diff --git a/lld/test/ELF/x86-64-feature-cet.s b/lld/test/ELF/x86-64-feature-cet.s index d64fdbad22051b..e477da0e3f0188 100644 --- a/lld/test/ELF/x86-64-feature-cet.s +++ b/lld/test/ELF/x86-64-feature-cet.s @@ -28,12 +28,23 @@ # REPORT_INVALID: error: unknown -z cet-report= value 'something' # REPORT_INVALID-EMPTY: +# RUN: not ld.lld -e func1 %t.o %t3.o -o /dev/null -z ibt-report=something \ +# RUN: -z shstk-report=something 2>&1 \ +# RUN: | FileCheck --check-prefix=IBT_SHSTK_REPORT_INVALID %s +# IBT_SHSTK_REPORT_INVALID: error: unknown -z ibt-report= value 'something' +# IBT_SHSTK_REPORT_INVALID: error: unknown -z shstk-report= value 'something' +# IBT_SHSTK_REPORT_INVALID-EMPTY: + # RUN: ld.lld -e func1 %t.o %t3.o -o /dev/null -z force-ibt -z cet-report=warning 2>&1 \ # RUN: | FileCheck --check-prefix=REPORT_FORCE %s # REPORT_FORCE: {{.*}}.o: -z cet-report: file does not have GNU_PROPERTY_X86_FEATURE_1_IBT property # REPORT_FORCE: {{.*}}.o: -z cet-report: file does not have GNU_PROPERTY_X86_FEATURE_1_SHSTK property # REPORT_FORCE-EMPTY: +## Ensure that warnings from force-ibt can be silenced with ibt-report=none or cet-report=none. +# RUN: ld.lld -e func1 %t.o %t3.o -o /dev/null -z force-ibt -z ibt-report=none 2>&1 | count 0 +# RUN: ld.lld -e func1 %t.o %t3.o -o /dev/null -z force-ibt -z cet-report=none 2>&1 | count 0 + # RUN: ld.lld -e func1 %t.o %t3.o -o /dev/null -z cet-report=warning 2>&1 \ # RUN: | FileCheck --check-prefix=CET_REPORT_WARN %s # CET_REPORT_WARN: {{.*}}.o: -z cet-report: file does not have GNU_PROPERTY_X86_FEATURE_1_IBT property @@ -46,8 +57,29 @@ # CET_REPORT_ERROR: {{.*}}.o: -z cet-report: file does not have GNU_PROPERTY_X86_FEATURE_1_SHSTK property # CET_REPORT_ERROR-EMPTY: -# RUN: ld.lld -e func1 %t.o %t4.o -o %t +# RUN: ld.lld -e func1 %t.o %t3.o -o /dev/null -z ibt-report=warning 2>&1 \ +# RUN: | FileCheck --check-prefix=IBT_REPORT %s +# RUN: not ld.lld -e func1 %t.o %t3.o -o /dev/null -z ibt-report=error 2>&1 \ +# RUN: | FileCheck --check-prefix=IBT_REPORT %s +# IBT_REPORT: {{.*}}.o: -z ibt-report: file does not have GNU_PROPERTY_X86_FEATURE_1_IBT property +# IBT_REPORT-EMPTY: + +# RUN: ld.lld -e func1 %t.o %t3.o -o /dev/null -z shstk-report=warning 2>&1 \ +# RUN: | FileCheck --check-prefix=SHSTK_REPORT %s +# RUN: not ld.lld -e func1 %t.o %t3.o -o /dev/null -z shstk-report=error 2>&1 \ +# RUN: | FileCheck --check-prefix=SHSTK_REPORT %s +# SHSTK_REPORT: {{.*}}.o: -z shstk-report: file does not have GNU_PROPERTY_X86_FEATURE_1_SHSTK property +# SHSTK_REPORT-EMPTY: + +# RUN: ld.lld -e func1 %t.o %t4.o -o %t -z ibt-report=error 2>&1 | count 0 +# RUN: ld.lld -e func1 %t.o %t4.o -o %t -z cet-report=error -z shstk-report=none 2>&1 | count 0 # RUN: llvm-readelf -n %t | FileCheck --check-prefix=NOSHSTK %s +# RUN: not ld.lld -e func1 %t.o %t4.o -o /dev/null -z shstk-report=error 2>&1 \ +# RUN: | FileCheck --check-prefix=SHSTK_REPORT %s +# RUN: not ld.lld -e func1 %t.o %t4.o -o /dev/null -z cet-report=error 2>&1 \ +# RUN: | FileCheck --check-prefix=NOSHSTK_CET_ERROR %s +# NOSHSTK_CET_ERROR: {{.*}}.o: -z cet-report: file does not have GNU_PROPERTY_X86_FEATURE_1_SHSTK property +# NOSHSTK_CET_ERROR-EMPTY: # Check .note.gnu.protery without property SHSTK. # NOSHSTK: Properties: x86 feature: IBT{{$}} >From 92c087a448738a55da75a67f65b5866fd8f7f25d Mon Sep 17 00:00:00 2001 From: Roland McGrath <[email protected]> Date: Thu, 15 Oct 2026 11:20:14 -0700 Subject: [PATCH 2/4] [clang][Fuchsia] Enable branch target protection by default Enable branch target protection by default for 64-bit Fuchsia targets. On AArch64, pass -mbranch-target-enforce by default (and keep it enabled when -msign-return-address= is used alone); 32-bit ARM (armv8-a) is unchanged as A-profile AArch32 has no BTI support. On RISC-V (Zicfilp lpad), pass -fcf-protection=branch by default when no -fcf-protection= option is given, and forward -mcf-branch-label-scheme= when branch protection is active by default. On x86-64 (IBT), pass -fcf-protection=branch and -fno-jump-tables by default when no -fcf-protection= option is given, avoiding `notrack` indirect jumps as the preferred security choice. When these control-flow protection features are enabled for code generation on Fuchsia targets, also pass the corresponding ld.lld report switches (-z bti-report=error, -z gcs-report=error, -z zicfilp-unlabeled-report=error, -z zicfilp-func-sig-report=error, -z zicfiss-report=error, -z ibt-report=error, and -z shstk-report=error) so the linker requires every input object file to carry the matching .note.gnu.property feature bit. Increment __Fuchsia_Compiler_ABI__ from 1 to 2 so that Fuchsia code can rely on branch target protection being enabled by default across all supported architectures. Assisted-by: Gemini --- clang/lib/Basic/Targets/OSTargets.cpp | 15 +++- clang/lib/Driver/ToolChains/Clang.cpp | 54 +++++++++---- clang/lib/Driver/ToolChains/Fuchsia.cpp | 82 ++++++++++++++++++++ clang/test/Driver/aarch64-security-options.c | 12 +++ clang/test/Driver/fuchsia.c | 72 +++++++++++++++-- clang/test/Preprocessor/init-fuchsia.c | 2 +- 6 files changed, 212 insertions(+), 25 deletions(-) diff --git a/clang/lib/Basic/Targets/OSTargets.cpp b/clang/lib/Basic/Targets/OSTargets.cpp index 04d9e13d3c9a6b..3795c71095821d 100644 --- a/clang/lib/Basic/Targets/OSTargets.cpp +++ b/clang/lib/Basic/Targets/OSTargets.cpp @@ -322,9 +322,22 @@ void getFuchsiaDefines(MacroBuilder &Builder, const LangOptions &Opts, // * Version 1 is first iteration formalizing the version number scheme. // - SafeStack ABI no longer supported on aarch64, riscv64 (x86 only) // + // * Version 2 is entirely backward-compatible with version 1, but also + // adds new guarantees that can be presumed of all ABI-compatible code. + // - aarch64 BTI support (-mbranch-protection=bti) is on by default, with + // linker enforcement (-z bti-report=error). + // (32-bit armv8-a has no BTI support; 32-bit BTI only exists in M-profile + // armv8.1-m.main and is not backward-compatible with armv8-a.) + // - RISC-V lpad support (-fcf-protection=branch) is on by default, with + // linker enforcement (-z zicfilp-unlabeled-report=error). + // - x86-64 IBT support (-fcf-protection=branch) is on by default, with + // linker enforcement (-z ibt-report=error) and jump tables disabled + // (-fno-jump-tables) to avoid `notrack` indirect jumps as the + // preferred security choice. + // // The predefine can be checked by code relying on the Fuchsia Compiler ABI // to ensure that a compiler new enough for the required version is in use. - Builder.defineMacro("__Fuchsia_Compiler_ABI__", Twine(1)); + Builder.defineMacro("__Fuchsia_Compiler_ABI__", Twine(2)); } } // namespace targets diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 5a1c8531812bd3..cf3e71c7c686e3 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -1401,6 +1401,14 @@ static void CollectARMPACBTIOptions(const ToolChain &TC, const ArgList &Args, : Args.getLastArg(options::OPT_mbranch_protection_EQ); const Arg *HardenPACRetArg = Args.getLastArg(options::OPT_mharden_pac_ret_EQ); const Driver &D = TC.getDriver(); + // Fuchsia (like Android and OpenBSD) enables BTI by default only on AArch64; + // 32-bit Armv8-A is not compatible with BTI (which in 32-bit ARM only exists + // on Armv8.1-M M-profile). + const bool DefaultIndirectBranches = + (Triple.isOSOpenBSD() || Triple.isAndroid() || Triple.isOSFuchsia()) && + isAArch64; + const bool DefaultPACNonLeafKeyA = + (Triple.isOSOpenBSD() || Triple.isAndroid()) && isAArch64; if (HardenPACRetArg) { if (!isAArch64) { @@ -1441,14 +1449,13 @@ static void CollectARMPACBTIOptions(const ToolChain &TC, const ArgList &Args, }; if (!A) { - if ((Triple.isOSOpenBSD() || Triple.isAndroid()) && isAArch64) { + if (DefaultPACNonLeafKeyA) { CmdArgs.push_back("-msign-return-address=non-leaf"); CmdArgs.push_back("-msign-return-address-key=a_key"); - CmdArgs.push_back("-mbranch-target-enforce"); - RenderHardenPACRet("non-leaf"); - } else { - RenderHardenPACRet("none"); } + if (DefaultIndirectBranches) + CmdArgs.push_back("-mbranch-target-enforce"); + RenderHardenPACRet(DefaultPACNonLeafKeyA ? "non-leaf" : "none"); return; } @@ -1467,8 +1474,7 @@ static void CollectARMPACBTIOptions(const ToolChain &TC, const ArgList &Args, // This spelling cannot express a key, and AArch64 Windows and UEFI only // support B-key, so default to it there as parseBranchProtection() does. Key = isAArch64 && Triple.isOSWindowsOrUEFI() ? "b_key" : "a_key"; - IndirectBranches = - (Triple.isOSOpenBSD() || Triple.isAndroid()) && isAArch64; + IndirectBranches = DefaultIndirectBranches; BranchProtectionPAuthLR = false; GuardedControlStack = false; } else { @@ -7513,19 +7519,37 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, if (!Args.hasFlag(options::OPT_offloadlib, options::OPT_no_offloadlib, true)) CmdArgs.push_back("--no-offloadlib"); + const bool DefaultCfProtectionBranch = + (Triple.getArch() == llvm::Triple::x86_64 && + (Triple.isOSOpenBSD() || Triple.isOSFuchsia())) || + (Triple.getArch() == llvm::Triple::riscv64 && Triple.isOSFuchsia()); + // On x86-64 with -fcf-protection=branch, jump tables emit `notrack jmp` + // rather than `endbr64` on target blocks. Targets that avoid `notrack` (so + // CET can disallow `notrack` indirect branches) disable jump tables by + // default when branch protection is enabled. For OpenBSD and Fuchsia on + // x86-64, avoiding `notrack` is the preferred security choice. + const bool DefaultX86NoTrackAvoided = + Triple.getArch() == llvm::Triple::x86_64 && + (Triple.isOSOpenBSD() || Triple.isOSFuchsia()); + + bool CFProtectionBranch = false; if (Arg *A = Args.getLastArg(options::OPT_fcf_protection_EQ)) { - CmdArgs.push_back( - Args.MakeArgString(Twine("-fcf-protection=") + A->getValue())); - + StringRef Val = A->getValue(); + CmdArgs.push_back(Args.MakeArgString(Twine("-fcf-protection=") + Val)); + CFProtectionBranch = Val == "branch" || Val == "full"; + } else if (DefaultCfProtectionBranch) { + // Emit IBT endbr64 / Zicfilp lpad instructions by default. + CmdArgs.push_back("-fcf-protection=branch"); + CFProtectionBranch = true; + } + if (CFProtectionBranch || Args.hasArg(options::OPT_fcf_protection_EQ)) { if (Arg *SA = Args.getLastArg(options::OPT_mcf_branch_label_scheme_EQ)) CmdArgs.push_back(Args.MakeArgString(Twine("-mcf-branch-label-scheme=") + SA->getValue())); - } else if (Triple.isOSOpenBSD() && Triple.getArch() == llvm::Triple::x86_64) { - // Emit IBT endbr64 instructions by default - CmdArgs.push_back("-fcf-protection=branch"); - // jump-table can generate indirect jumps, which are not permitted - CmdArgs.push_back("-fno-jump-tables"); } + if (CFProtectionBranch && DefaultX86NoTrackAvoided && + !Args.hasArg(options::OPT_fjump_tables, options::OPT_fno_jump_tables)) + CmdArgs.push_back("-fno-jump-tables"); if (Arg *A = Args.getLastArg(options::OPT_mfunction_return_EQ)) CmdArgs.push_back( diff --git a/clang/lib/Driver/ToolChains/Fuchsia.cpp b/clang/lib/Driver/ToolChains/Fuchsia.cpp index 3b5729b45e7e8e..1dbfa745cb2e8d 100644 --- a/clang/lib/Driver/ToolChains/Fuchsia.cpp +++ b/clang/lib/Driver/ToolChains/Fuchsia.cpp @@ -18,6 +18,7 @@ #include "llvm/Support/FileSystem.h" #include "llvm/Support/Path.h" #include "llvm/Support/VirtualFileSystem.h" +#include "llvm/TargetParser/ARMTargetParserCommon.h" using namespace clang::driver; using namespace clang::driver::toolchains; @@ -66,6 +67,87 @@ void fuchsia::Linker::ConstructJob(Compilation &C, const JobAction &JA, CmdArgs.push_back("-z"); CmdArgs.push_back("rel"); CmdArgs.push_back("--pack-dyn-relocs=relr"); + + // When hardware control-flow protection is enabled for code generation (by + // default on 64-bit Fuchsia targets or via explicit compiler flags), pass + // the corresponding ld.lld report switches so the linker requires every + // input object file to carry the matching .note.gnu.property feature bit. + // Querying Args.getLastArg() here also claims these options on link-only + // driver invocations (e.g., `clang foo.o -mbranch-protection=none`), and + // placing the switches before AddLinkerInputs allows explicit `-Wl,-z,...` + // flags to override them. + if (ToolChain.getArch() == llvm::Triple::aarch64) { + // On AArch64 Fuchsia, BTI is enabled by default unless overridden by + // `-mbranch-protection=` (matching CollectARMPACBTIOptions in Clang.cpp; + // `-msign-return-address=` only changes PAC scope and leaves BTI at the + // target default). + bool IndirectBranches = true; + bool GuardedControlStack = false; + if (const Arg *A = Args.getLastArg(options::OPT_msign_return_address_EQ, + options::OPT_mbranch_protection_EQ)) { + if (A->getOption().matches(options::OPT_mbranch_protection_EQ)) { + StringRef DiagMsg; + llvm::ARM::ParsedBranchProtection PBP; + if (llvm::ARM::parseBranchProtection(A->getValue(), PBP, DiagMsg, + Triple)) { + IndirectBranches = PBP.BranchTargetEnforcement; + GuardedControlStack = PBP.GuardedControlStack; + } else { + IndirectBranches = false; + } + } + } + if (IndirectBranches) { + CmdArgs.push_back("-z"); + CmdArgs.push_back("bti-report=error"); + } + if (GuardedControlStack) { + CmdArgs.push_back("-z"); + CmdArgs.push_back("gcs-report=error"); + } + } else if (Triple.isRISCV64() || + ToolChain.getArch() == llvm::Triple::x86_64) { + // On RISC-V and x86-64 Fuchsia, `-fcf-protection=branch` is enabled by + // default unless overridden by `-fcf-protection=` (note that bare + // `-fcf-protection` is an alias for `-fcf-protection=full`). + StringRef CFProtection = "branch"; + if (const Arg *A = Args.getLastArg(options::OPT_fcf_protection_EQ)) + CFProtection = A->getValue(); + const bool Branch = CFProtection == "branch" || CFProtection == "full"; + const bool Return = CFProtection == "return" || CFProtection == "full"; + if (Triple.isRISCV64()) { + // On RISC-V, `-fcf-protection=branch` uses the `unlabeled` Zicfilp + // scheme (`GNU_PROPERTY_RISCV_FEATURE_1_CFI_LP_UNLABELED`) by default + // unless `-mcf-branch-label-scheme=func-sig` is specified, and + // `-fcf-protection=return` enables Zicfiss shadow stack + // (`GNU_PROPERTY_RISCV_FEATURE_1_CFI_SS`). + if (Branch) { + const Arg *SA = + Args.getLastArg(options::OPT_mcf_branch_label_scheme_EQ); + CmdArgs.push_back("-z"); + if (SA && StringRef(SA->getValue()) == "func-sig") + CmdArgs.push_back("zicfilp-func-sig-report=error"); + else + CmdArgs.push_back("zicfilp-unlabeled-report=error"); + } + if (Return) { + CmdArgs.push_back("-z"); + CmdArgs.push_back("zicfiss-report=error"); + } + } else { + // On x86-64, `-fcf-protection=branch` enables CET IBT + // (`GNU_PROPERTY_X86_FEATURE_1_IBT`) and `-fcf-protection=return` + // enables CET shadow stack (`GNU_PROPERTY_X86_FEATURE_1_SHSTK`). + if (Branch) { + CmdArgs.push_back("-z"); + CmdArgs.push_back("ibt-report=error"); + } + if (Return) { + CmdArgs.push_back("-z"); + CmdArgs.push_back("shstk-report=error"); + } + } + } } if (!D.SysRoot.empty()) diff --git a/clang/test/Driver/aarch64-security-options.c b/clang/test/Driver/aarch64-security-options.c index 81a7d7c571542c..9df5b24c666048 100644 --- a/clang/test/Driver/aarch64-security-options.c +++ b/clang/test/Driver/aarch64-security-options.c @@ -65,6 +65,18 @@ // RUN: %clang --target=aarch64-linux-android -msign-return-address=non-leaf -### -c %s 2>&1 | \ // RUN: FileCheck %s --check-prefix=RA-NON-LEAF --check-prefix=KEY-A --check-prefix=BTE-ON --check-prefix=GCS-OFF --check-prefix=WARN +// Check that Fuchsia enables BTI by default on AArch64. +// RUN: %clang --target=aarch64-unknown-fuchsia -### -c %s 2>&1 | \ +// RUN: FileCheck %s --check-prefix=BTE-ON --check-prefix=GCS-OFF --check-prefix=WARN + +// Check that the Fuchsia default can be overridden. +// RUN: %clang --target=aarch64-unknown-fuchsia -mbranch-protection=none -### -c %s 2>&1 | \ +// RUN: FileCheck %s --check-prefix=RA-OFF --check-prefix=KEY --check-prefix=BTE-OFF --check-prefix=GCS-OFF --check-prefix=WARN + +// Check that Fuchsia enables BTI by default when -msign-return-address is passed. +// RUN: %clang --target=aarch64-unknown-fuchsia -msign-return-address=non-leaf -### -c %s 2>&1 | \ +// RUN: FileCheck %s --check-prefix=RA-NON-LEAF --check-prefix=KEY-A --check-prefix=BTE-ON --check-prefix=GCS-OFF --check-prefix=WARN + // WARN-NOT: warning: ignoring '-mbranch-protection=' option because the 'aarch64' architecture does not support it [-Wbranch-protection] // RUN: %clang -target aarch64 -c %s -### 2>&1 | \ diff --git a/clang/test/Driver/fuchsia.c b/clang/test/Driver/fuchsia.c index 10135b204ffffc..848fc627907671 100644 --- a/clang/test/Driver/fuchsia.c +++ b/clang/test/Driver/fuchsia.c @@ -1,51 +1,107 @@ // RUN: %clang -### %s --target=x86_64-unknown-fuchsia \ // RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \ // RUN: --sysroot=%S/platform -fuse-ld=ld 2>&1 \ -// RUN: | FileCheck -check-prefixes=CHECK,CHECK-X86_64 %s +// RUN: | FileCheck -check-prefixes=CHECK,CHECK-X86_64,CHECK-CF-PROT,CHECK-X86-IBT,CHECK-DEF-NO-JT %s // RUN: %clang -### %s --target=arm-unknown-fuchsia \ // RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \ // RUN: --sysroot=%S/platform -fuse-ld=ld 2>&1 \ -// RUN: | FileCheck -check-prefixes=CHECK,CHECK-ARMV8A %s +// RUN: | FileCheck -check-prefixes=CHECK,CHECK-ARMV8A,CHECK-ARM-NOBTI,CHECK-JT %s // RUN: %clang -### %s --target=aarch64-unknown-fuchsia \ // RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \ // RUN: --sysroot=%S/platform -fuse-ld=ld 2>&1 \ -// RUN: | FileCheck -check-prefixes=CHECK,CHECK-AARCH64 %s +// RUN: | FileCheck -check-prefixes=CHECK,CHECK-AARCH64,CHECK-ARM-BTI,CHECK-JT %s // RUN: %clang -### %s --target=riscv64-unknown-fuchsia \ // RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \ // RUN: --sysroot=%S/platform -fuse-ld=ld 2>&1 \ -// RUN: | FileCheck -check-prefixes=CHECK,CHECK-RISCV64 %s +// RUN: | FileCheck -check-prefixes=CHECK,CHECK-RISCV64,CHECK-CF-PROT,CHECK-ZICFILP,CHECK-JT %s // RUN: %clang -### %s --target=x86_64-fuchsia \ // RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \ // RUN: --sysroot=%S/platform -fuse-ld=ld 2>&1 \ -// RUN: | FileCheck -check-prefixes=CHECK,CHECK-X86_64 %s +// RUN: | FileCheck -check-prefixes=CHECK,CHECK-X86_64,CHECK-CF-PROT,CHECK-X86-IBT,CHECK-DEF-NO-JT %s +// RUN: %clang -### %s --target=x86_64-fuchsia -fjump-tables \ +// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \ +// RUN: --sysroot=%S/platform -fuse-ld=ld 2>&1 \ +// RUN: | FileCheck -check-prefixes=CHECK,CHECK-X86_64,CHECK-CF-PROT,CHECK-X86-IBT,CHECK-JT %s +// RUN: %clang -### %s --target=x86_64-fuchsia -fcf-protection=none \ +// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \ +// RUN: --sysroot=%S/platform -fuse-ld=ld 2>&1 \ +// RUN: | FileCheck -check-prefixes=CHECK,CHECK-X86_64,CHECK-CF-NOPROT,CHECK-JT %s +// RUN: %clang -### %s --target=x86_64-fuchsia -fcf-protection=none -fno-jump-tables \ +// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \ +// RUN: --sysroot=%S/platform -fuse-ld=ld 2>&1 \ +// RUN: | FileCheck -check-prefixes=CHECK,CHECK-X86_64,CHECK-CF-NOPROT,CHECK-EXPL-NO-JT %s +// RUN: %clang -### %s --target=x86_64-fuchsia -fcf-protection=full \ +// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \ +// RUN: --sysroot=%S/platform -fuse-ld=ld 2>&1 \ +// RUN: | FileCheck -check-prefixes=CHECK,CHECK-X86_64,CHECK-CF-FULL,CHECK-X86-IBT,CHECK-X86-SHSTK,CHECK-DEF-NO-JT %s // RUN: %clang -### %s --target=arm-fuchsia \ // RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \ // RUN: --sysroot=%S/platform -fuse-ld=ld 2>&1 \ -// RUN: | FileCheck -check-prefixes=CHECK,CHECK-ARMV8A %s +// RUN: | FileCheck -check-prefixes=CHECK,CHECK-ARMV8A,CHECK-ARM-NOBTI,CHECK-JT %s // RUN: %clang -### %s --target=aarch64-fuchsia \ // RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \ // RUN: --sysroot=%S/platform -fuse-ld=ld 2>&1 \ -// RUN: | FileCheck -check-prefixes=CHECK,CHECK-AARCH64 %s +// RUN: | FileCheck -check-prefixes=CHECK,CHECK-AARCH64,CHECK-ARM-BTI,CHECK-JT %s +// RUN: %clang -### %s --target=aarch64-fuchsia -mbranch-protection=none \ +// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \ +// RUN: --sysroot=%S/platform -fuse-ld=ld 2>&1 \ +// RUN: | FileCheck -check-prefixes=CHECK,CHECK-AARCH64,CHECK-ARM-NOBTI,CHECK-JT %s +// RUN: %clang -### %s --target=aarch64-fuchsia -mbranch-protection=standard \ +// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \ +// RUN: --sysroot=%S/platform -fuse-ld=ld 2>&1 \ +// RUN: | FileCheck -check-prefixes=CHECK,CHECK-AARCH64,CHECK-ARM-BTI,CHECK-ARM-GCS,CHECK-JT %s // RUN: %clang -### %s --target=riscv64-fuchsia \ // RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \ // RUN: --sysroot=%S/platform -fuse-ld=ld 2>&1 \ -// RUN: | FileCheck -check-prefixes=CHECK,CHECK-RISCV64 %s +// RUN: | FileCheck -check-prefixes=CHECK,CHECK-RISCV64,CHECK-CF-PROT,CHECK-ZICFILP,CHECK-JT %s +// RUN: %clang -### %s --target=riscv64-fuchsia -fcf-protection=none \ +// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \ +// RUN: --sysroot=%S/platform -fuse-ld=ld 2>&1 \ +// RUN: | FileCheck -check-prefixes=CHECK,CHECK-RISCV64,CHECK-CF-NOPROT,CHECK-JT %s +// RUN: %clang -### %s --target=riscv64-fuchsia -fcf-protection=full \ +// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \ +// RUN: --sysroot=%S/platform -fuse-ld=ld 2>&1 \ +// RUN: | FileCheck -check-prefixes=CHECK,CHECK-RISCV64,CHECK-CF-FULL,CHECK-ZICFILP,CHECK-ZICFISS,CHECK-JT %s +// RUN: %clang -### %s --target=riscv64-fuchsia -mcf-branch-label-scheme=func-sig \ +// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \ +// RUN: --sysroot=%S/platform -fuse-ld=ld 2>&1 \ +// RUN: | FileCheck -check-prefixes=CHECK,CHECK-RISCV64,CHECK-CF-PROT,CHECK-ZICFILP-FUNC-SIG,CHECK-JT %s // CHECK: "-cc1" // CHECK-X86_64: "-triple" "x86_64-unknown-fuchsia" // CHECK-ARMV8A: "-triple" "thumbv8a-unknown-fuchsia" // CHECK-AARCH64: "-triple" "aarch64-unknown-fuchsia" // CHECK-RISCV64: "-triple" "riscv64-unknown-fuchsia" +// CHECK-EXPL-NO-JT: "-fno-jump-tables" +// CHECK-JT-NOT: "-fno-jump-tables" // CHECK: "-funwind-tables=2" +// CHECK-ARM-BTI: "-mbranch-target-enforce" +// CHECK-ARM-NOBTI-NOT: "-mbranch-target-enforce" +// CHECK-ARM-GCS: "-mguarded-control-stack" // CHECK: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]" // CHECK: "-isysroot" "[[SYSROOT:[^"]+]]" // CHECK: "-internal-externc-isystem" "[[SYSROOT]]{{/|\\\\}}include" // CHECK: "-stack-protector" "2" +// CHECK-CF-PROT: "-fcf-protection=branch" +// CHECK-CF-FULL: "-fcf-protection=full" +// CHECK-CF-NOPROT: "-fcf-protection=none" +// CHECK-ZICFILP-FUNC-SIG: "-mcf-branch-label-scheme=func-sig" +// CHECK-DEF-NO-JT: "-fno-jump-tables" +// CHECK-JT-NOT: "-fno-jump-tables" // CHECK-AARCH64: "-fsanitize=shadow-call-stack" // CHECK-RISCV64: "-fsanitize=shadow-call-stack" // CHECK-X86_64: "-fsanitize=safe-stack" // CHECK-AARCH64: "-target-feature" "+outline-atomics" // CHECK-NOT: "-fcommon" // CHECK: {{.*}}ld.lld{{.*}}" "-z" "max-page-size=4096" "-z" "now" "-z" "start-stop-visibility=hidden" "-z" "rodynamic" "-z" "separate-loadable-segments" "-z" "rel" "--pack-dyn-relocs=relr" +// CHECK-ARM-BTI-SAME: "-z" "bti-report=error" +// CHECK-ARM-GCS-SAME: "-z" "gcs-report=error" +// CHECK-ARM-NOBTI-NOT: "bti-report=error" +// CHECK-ZICFILP-SAME: "-z" "zicfilp-unlabeled-report=error" +// CHECK-ZICFILP-FUNC-SIG-SAME: "-z" "zicfilp-func-sig-report=error" +// CHECK-ZICFISS-SAME: "-z" "zicfiss-report=error" +// CHECK-X86-IBT-SAME: "-z" "ibt-report=error" +// CHECK-X86-SHSTK-SAME: "-z" "shstk-report=error" +// CHECK-CF-NOPROT-NOT: "-report=error" // CHECK: "--sysroot=[[SYSROOT]]" // CHECK: "-pie" // CHECK: "--build-id" diff --git a/clang/test/Preprocessor/init-fuchsia.c b/clang/test/Preprocessor/init-fuchsia.c index 04b5ef573cc077..c45742c868f124 100644 --- a/clang/test/Preprocessor/init-fuchsia.c +++ b/clang/test/Preprocessor/init-fuchsia.c @@ -9,4 +9,4 @@ // FUCHSIA-DAG: #define __Fuchsia__ 1 // FUCHSIA-DAG: #define __Fuchsia_API_level__ {{[0-9]+}} -// FUCHSIA-DAG: #define __Fuchsia_Compiler_ABI__ 1 +// FUCHSIA-DAG: #define __Fuchsia_Compiler_ABI__ 2 >From fb2e605aa6efe6c4b462633e04c333cb06889a03 Mon Sep 17 00:00:00 2001 From: Roland McGrath <[email protected]> Date: Wed, 4 Nov 2026 08:44:35 -0800 Subject: [PATCH 3/4] [lld][ELF] Drop stacked lld changes split off to #236023 Revert commit c15c4299b994 on this branch now that the lld changes are reviewed separately in #236023. Assisted-by: Gemini --- lld/ELF/Config.h | 4 --- lld/ELF/Driver.cpp | 54 +++++++++--------------------- lld/docs/ReleaseNotes.md | 2 -- lld/docs/ld.lld.1 | 10 ------ lld/test/ELF/aarch64-feature-bti.s | 5 --- lld/test/ELF/i386-feature-cet.s | 18 +--------- lld/test/ELF/x86-64-feature-cet.s | 34 +------------------ 7 files changed, 17 insertions(+), 110 deletions(-) diff --git a/lld/ELF/Config.h b/lld/ELF/Config.h index bf9ef6f54c7e54..0c76e3854e6608 100644 --- a/lld/ELF/Config.h +++ b/lld/ELF/Config.h @@ -286,10 +286,6 @@ struct Config { ReportPolicy zBtiReport = ReportPolicy::None; llvm::StringRef zBtiReportSource; ReportPolicy zCetReport = ReportPolicy::None; - ReportPolicy zIbtReport = ReportPolicy::None; - llvm::StringRef zIbtReportSource; - ReportPolicy zShstkReport = ReportPolicy::None; - llvm::StringRef zShstkReportSource; ReportPolicy zPauthReport = ReportPolicy::None; ReportPolicy zGcsReport = ReportPolicy::None; llvm::StringRef zGcsReportSource; diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index bd61f62c96add0..a08f6f2d384bc1 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -401,16 +401,9 @@ static void checkOptions(Ctx &ctx) { ErrAlways(ctx) << "-z zicfiss is only supported on RISC-V targets"; } - if (ctx.arg.emachine != EM_386 && ctx.arg.emachine != EM_X86_64) { - if (ctx.arg.zCetReport != ReportPolicy::None) - ErrAlways(ctx) << "-z cet-report only supported on X86 and X86_64"; - if (ctx.arg.zIbtReport != ReportPolicy::None && - ctx.arg.zIbtReportSource == "-z ibt-report") - ErrAlways(ctx) << "-z ibt-report only supported on X86 and X86_64"; - if (ctx.arg.zShstkReport != ReportPolicy::None && - ctx.arg.zShstkReportSource == "-z shstk-report") - ErrAlways(ctx) << "-z shstk-report only supported on X86 and X86_64"; - } + if (ctx.arg.emachine != EM_386 && ctx.arg.emachine != EM_X86_64 && + ctx.arg.zCetReport != ReportPolicy::None) + ErrAlways(ctx) << "-z cet-report only supported on X86 and X86_64"; if (ctx.arg.zMarkPlt) { if (ctx.arg.emachine != EM_X86_64) @@ -1760,29 +1753,18 @@ static void readConfigs(Ctx &ctx, opt::InputArgList &args) { ctx.arg.zBtiReport = ReportPolicy::Warning; ctx.arg.zBtiReportSource = "-z force-bti"; } - if (ctx.arg.zForceIbt) { - ctx.arg.zIbtReport = ReportPolicy::Warning; - ctx.arg.zIbtReportSource = "-z force-ibt"; - } if (ctx.arg.zGcs == GcsPolicy::Always) { ctx.arg.zGcsReport = ReportPolicy::Warning; ctx.arg.zGcsReportSource = "-z gcs"; } - // Parse `-z *-report=` options in command-line order. On x86, `-z cet-report` - // sets the report policy for both IBT and SHSTK, while `-z ibt-report` and - // `-z shstk-report` set them individually (allowing e.g. - // `-fcf-protection=branch` builds to require IBT without requiring SHSTK, or - // `-z ibt-report=none` to silence the default warning from `-z force-ibt`). auto reports = { std::make_pair("bti-report", &ctx.arg.zBtiReport), std::make_pair("cet-report", &ctx.arg.zCetReport), std::make_pair("execute-only-report", &ctx.arg.zExecuteOnlyReport), std::make_pair("gcs-report", &ctx.arg.zGcsReport), std::make_pair("gcs-report-dynamic", &ctx.arg.zGcsReportDynamic), - std::make_pair("ibt-report", &ctx.arg.zIbtReport), std::make_pair("pauth-report", &ctx.arg.zPauthReport), - std::make_pair("shstk-report", &ctx.arg.zShstkReport), std::make_pair("zicfilp-unlabeled-report", &ctx.arg.zZicfilpUnlabeledReport), std::make_pair("zicfilp-func-sig-report", &ctx.arg.zZicfilpFuncSigReport), @@ -1807,20 +1789,10 @@ static void readConfigs(Ctx &ctx, opt::InputArgList &args) { continue; } hasGcsReportDynamic |= option.first == "gcs-report-dynamic"; - if (option.first == "bti-report") { + if (option.first == "bti-report") ctx.arg.zBtiReportSource = "-z bti-report"; - } else if (option.first == "cet-report") { - ctx.arg.zIbtReport = *reportArg.second; - ctx.arg.zIbtReportSource = "-z cet-report"; - ctx.arg.zShstkReport = *reportArg.second; - ctx.arg.zShstkReportSource = "-z cet-report"; - } else if (option.first == "gcs-report") { + else if (option.first == "gcs-report") ctx.arg.zGcsReportSource = "-z gcs-report"; - } else if (option.first == "ibt-report") { - ctx.arg.zIbtReportSource = "-z ibt-report"; - } else if (option.first == "shstk-report") { - ctx.arg.zShstkReportSource = "-z shstk-report"; - } } } @@ -3087,15 +3059,15 @@ static void readSecurityNotes(Ctx &ctx) { << ": file does not have " "GNU_PROPERTY_AARCH64_FEATURE_1_GCS property"; - reportUnless(ctx.arg.zIbtReport, features & GNU_PROPERTY_X86_FEATURE_1_IBT) - << f << ": " << ctx.arg.zIbtReportSource - << ": file does not have " + reportUnless(ctx.arg.zCetReport, features & GNU_PROPERTY_X86_FEATURE_1_IBT) + << f + << ": -z cet-report: file does not have " "GNU_PROPERTY_X86_FEATURE_1_IBT property"; - reportUnless(ctx.arg.zShstkReport, + reportUnless(ctx.arg.zCetReport, features & GNU_PROPERTY_X86_FEATURE_1_SHSTK) - << f << ": " << ctx.arg.zShstkReportSource - << ": file does not have " + << f + << ": -z cet-report: file does not have " "GNU_PROPERTY_X86_FEATURE_1_SHSTK property"; if (ctx.arg.emachine == EM_RISCV) { @@ -3141,6 +3113,10 @@ static void readSecurityNotes(Ctx &ctx) { features |= GNU_PROPERTY_AARCH64_FEATURE_1_BTI; } else if (ctx.arg.zForceIbt && !(features & GNU_PROPERTY_X86_FEATURE_1_IBT)) { + if (ctx.arg.zCetReport == ReportPolicy::None) + Warn(ctx) << f + << ": -z force-ibt: file does not have " + "GNU_PROPERTY_X86_FEATURE_1_IBT property"; features |= GNU_PROPERTY_X86_FEATURE_1_IBT; } if (ctx.arg.zPacPlt && !(hasValidPauthAbiCoreInfo || diff --git a/lld/docs/ReleaseNotes.md b/lld/docs/ReleaseNotes.md index 56478810cc7b89..8cd9e8fedd71c6 100644 --- a/lld/docs/ReleaseNotes.md +++ b/lld/docs/ReleaseNotes.md @@ -31,8 +31,6 @@ from the [LLVM releases web site](https://llvm.org/releases/). * `--mmap-output-file` and `--no-mmap-output-file` were swapped in LLVM 21 and 22. They now mean what they say again; the default behavior is unchanged. -* Added `-z ibt-report=[none|warning|error]` and `-z shstk-report=[none|warning|error]` on x86 and x86-64 to report missing `GNU_PROPERTY_X86_FEATURE_1_IBT` and `GNU_PROPERTY_X86_FEATURE_1_SHSTK` properties individually (for example, when building with `-fcf-protection=branch` or `-fcf-protection=return`). - `-z ibt-report=none` and `-z cet-report=none` also silence warnings from `-z force-ibt`. ### Breaking changes diff --git a/lld/docs/ld.lld.1 b/lld/docs/ld.lld.1 index f1805ab6218d34..c7d452c96339ea 100644 --- a/lld/docs/ld.lld.1 +++ b/lld/docs/ld.lld.1 @@ -815,16 +815,6 @@ Specify how to report the missing GNU_PROPERTY_X86_FEATURE_1_IBT or GNU_PROPERTY .Cm none is the default, linker will not report the missing property otherwise will be reported as a warning or an error. .Pp -.It Cm ibt-report Ns = Ns Ar [none|warning|error] -Specify how to report the missing GNU_PROPERTY_X86_FEATURE_1_IBT property. -.Cm none -is the default, linker will not report the missing property otherwise will be reported as a warning or an error. -.Pp -.It Cm shstk-report Ns = Ns Ar [none|warning|error] -Specify how to report the missing GNU_PROPERTY_X86_FEATURE_1_SHSTK property. -.Cm none -is the default, linker will not report the missing property otherwise will be reported as a warning or an error. -.Pp .It Cm gcs-report Ns = Ns Ar [none|warning|error] Specify how to report missing .Cm GNU_PROPERTY_AARCH64_FEATURE_1_GCS diff --git a/lld/test/ELF/aarch64-feature-bti.s b/lld/test/ELF/aarch64-feature-bti.s index 3cc064a87a3f2e..53676c8835ada3 100644 --- a/lld/test/ELF/aarch64-feature-bti.s +++ b/lld/test/ELF/aarch64-feature-bti.s @@ -233,11 +233,6 @@ ## Ensure that warnings from force-bti can be silenced with bti-report=none. # RUN: ld.lld %t.o %t2.o -z force-bti -z bti-report=none %t.so -o %t.so 2>&1 | count 0 -# RUN: not ld.lld %t.o -z cet-report=error -z ibt-report=error -z shstk-report=error -o /dev/null 2>&1 | FileCheck --check-prefix=ERR-X86 %s -# ERR-X86: error: -z cet-report only supported on X86 and X86_64 -# ERR-X86-NEXT: error: -z ibt-report only supported on X86 and X86_64 -# ERR-X86-NEXT: error: -z shstk-report only supported on X86 and X86_64 - # RUN: llvm-readelf -n %tforcebti.exe | FileCheck --check-prefix=BTIPROP %s # RUN: llvm-readelf --dynamic-table %tforcebti.exe | FileCheck --check-prefix BTIDYN %s # RUN: llvm-objdump --no-print-imm-hex -d --mattr=+bti --no-show-raw-insn %tforcebti.exe | FileCheck --check-prefix=FORCE %s diff --git a/lld/test/ELF/i386-feature-cet.s b/lld/test/ELF/i386-feature-cet.s index dddc816aeed48e..13760a03fbbb42 100644 --- a/lld/test/ELF/i386-feature-cet.s +++ b/lld/test/ELF/i386-feature-cet.s @@ -40,24 +40,8 @@ # CET_REPORT_ERROR: {{.*}}.o: -z cet-report: file does not have GNU_PROPERTY_X86_FEATURE_1_SHSTK property # CET_REPORT_ERROR-EMPTY: -# RUN: ld.lld -e func1 %t.o %t3.o -o /dev/null -z ibt-report=warning 2>&1 \ -# RUN: | FileCheck --check-prefix=IBT_REPORT %s -# RUN: not ld.lld -e func1 %t.o %t3.o -o /dev/null -z ibt-report=error 2>&1 \ -# RUN: | FileCheck --check-prefix=IBT_REPORT %s -# IBT_REPORT: {{.*}}.o: -z ibt-report: file does not have GNU_PROPERTY_X86_FEATURE_1_IBT property -# IBT_REPORT-EMPTY: - -# RUN: ld.lld -e func1 %t.o %t3.o -o /dev/null -z shstk-report=warning 2>&1 \ -# RUN: | FileCheck --check-prefix=SHSTK_REPORT %s -# RUN: not ld.lld -e func1 %t.o %t3.o -o /dev/null -z shstk-report=error 2>&1 \ -# RUN: | FileCheck --check-prefix=SHSTK_REPORT %s -# SHSTK_REPORT: {{.*}}.o: -z shstk-report: file does not have GNU_PROPERTY_X86_FEATURE_1_SHSTK property -# SHSTK_REPORT-EMPTY: - -# RUN: ld.lld -e func1 %t.o %t4.o -o %t -z ibt-report=error 2>&1 | count 0 +# RUN: ld.lld -e func1 %t.o %t4.o -o %t # RUN: llvm-readelf -n %t | FileCheck --check-prefix=NOSHSTK %s -# RUN: not ld.lld -e func1 %t.o %t4.o -o /dev/null -z shstk-report=error 2>&1 \ -# RUN: | FileCheck --check-prefix=SHSTK_REPORT %s # Check .note.gnu.protery without property SHSTK. # NOSHSTK: Properties: x86 feature: IBT{{$}} diff --git a/lld/test/ELF/x86-64-feature-cet.s b/lld/test/ELF/x86-64-feature-cet.s index e477da0e3f0188..d64fdbad22051b 100644 --- a/lld/test/ELF/x86-64-feature-cet.s +++ b/lld/test/ELF/x86-64-feature-cet.s @@ -28,23 +28,12 @@ # REPORT_INVALID: error: unknown -z cet-report= value 'something' # REPORT_INVALID-EMPTY: -# RUN: not ld.lld -e func1 %t.o %t3.o -o /dev/null -z ibt-report=something \ -# RUN: -z shstk-report=something 2>&1 \ -# RUN: | FileCheck --check-prefix=IBT_SHSTK_REPORT_INVALID %s -# IBT_SHSTK_REPORT_INVALID: error: unknown -z ibt-report= value 'something' -# IBT_SHSTK_REPORT_INVALID: error: unknown -z shstk-report= value 'something' -# IBT_SHSTK_REPORT_INVALID-EMPTY: - # RUN: ld.lld -e func1 %t.o %t3.o -o /dev/null -z force-ibt -z cet-report=warning 2>&1 \ # RUN: | FileCheck --check-prefix=REPORT_FORCE %s # REPORT_FORCE: {{.*}}.o: -z cet-report: file does not have GNU_PROPERTY_X86_FEATURE_1_IBT property # REPORT_FORCE: {{.*}}.o: -z cet-report: file does not have GNU_PROPERTY_X86_FEATURE_1_SHSTK property # REPORT_FORCE-EMPTY: -## Ensure that warnings from force-ibt can be silenced with ibt-report=none or cet-report=none. -# RUN: ld.lld -e func1 %t.o %t3.o -o /dev/null -z force-ibt -z ibt-report=none 2>&1 | count 0 -# RUN: ld.lld -e func1 %t.o %t3.o -o /dev/null -z force-ibt -z cet-report=none 2>&1 | count 0 - # RUN: ld.lld -e func1 %t.o %t3.o -o /dev/null -z cet-report=warning 2>&1 \ # RUN: | FileCheck --check-prefix=CET_REPORT_WARN %s # CET_REPORT_WARN: {{.*}}.o: -z cet-report: file does not have GNU_PROPERTY_X86_FEATURE_1_IBT property @@ -57,29 +46,8 @@ # CET_REPORT_ERROR: {{.*}}.o: -z cet-report: file does not have GNU_PROPERTY_X86_FEATURE_1_SHSTK property # CET_REPORT_ERROR-EMPTY: -# RUN: ld.lld -e func1 %t.o %t3.o -o /dev/null -z ibt-report=warning 2>&1 \ -# RUN: | FileCheck --check-prefix=IBT_REPORT %s -# RUN: not ld.lld -e func1 %t.o %t3.o -o /dev/null -z ibt-report=error 2>&1 \ -# RUN: | FileCheck --check-prefix=IBT_REPORT %s -# IBT_REPORT: {{.*}}.o: -z ibt-report: file does not have GNU_PROPERTY_X86_FEATURE_1_IBT property -# IBT_REPORT-EMPTY: - -# RUN: ld.lld -e func1 %t.o %t3.o -o /dev/null -z shstk-report=warning 2>&1 \ -# RUN: | FileCheck --check-prefix=SHSTK_REPORT %s -# RUN: not ld.lld -e func1 %t.o %t3.o -o /dev/null -z shstk-report=error 2>&1 \ -# RUN: | FileCheck --check-prefix=SHSTK_REPORT %s -# SHSTK_REPORT: {{.*}}.o: -z shstk-report: file does not have GNU_PROPERTY_X86_FEATURE_1_SHSTK property -# SHSTK_REPORT-EMPTY: - -# RUN: ld.lld -e func1 %t.o %t4.o -o %t -z ibt-report=error 2>&1 | count 0 -# RUN: ld.lld -e func1 %t.o %t4.o -o %t -z cet-report=error -z shstk-report=none 2>&1 | count 0 +# RUN: ld.lld -e func1 %t.o %t4.o -o %t # RUN: llvm-readelf -n %t | FileCheck --check-prefix=NOSHSTK %s -# RUN: not ld.lld -e func1 %t.o %t4.o -o /dev/null -z shstk-report=error 2>&1 \ -# RUN: | FileCheck --check-prefix=SHSTK_REPORT %s -# RUN: not ld.lld -e func1 %t.o %t4.o -o /dev/null -z cet-report=error 2>&1 \ -# RUN: | FileCheck --check-prefix=NOSHSTK_CET_ERROR %s -# NOSHSTK_CET_ERROR: {{.*}}.o: -z cet-report: file does not have GNU_PROPERTY_X86_FEATURE_1_SHSTK property -# NOSHSTK_CET_ERROR-EMPTY: # Check .note.gnu.protery without property SHSTK. # NOSHSTK: Properties: x86 feature: IBT{{$}} >From fd973f83b089877767dce8f46672e1e94944e05d Mon Sep 17 00:00:00 2001 From: Roland McGrath <[email protected]> Date: Mon, 2 Nov 2026 16:47:39 -0800 Subject: [PATCH 4/4] [clang][Fuchsia] Confine jump-table and linker report changes to forward-edge Fuchsia scope Keep OpenBSD x86-64 -fcf-protection=branch and -fno-jump-tables behavior unchanged, omit backward-edge linker report switches (-z gcs-report=error, -z shstk-report=error, -z zicfiss-report=error) so only forward-edge branch target protection is enforced at link time, and add a clang/docs/ReleaseNotes.md entry. Assisted-by: Gemini --- clang/docs/ReleaseNotes.md | 8 +++++ clang/lib/Driver/ToolChains/Clang.cpp | 29 +++++++++-------- clang/lib/Driver/ToolChains/Fuchsia.cpp | 41 ++++++------------------- clang/test/Driver/fuchsia.c | 18 +++++++---- 4 files changed, 44 insertions(+), 52 deletions(-) diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md index 200c41fb9e4a29..4206a1560fef09 100644 --- a/clang/docs/ReleaseNotes.md +++ b/clang/docs/ReleaseNotes.md @@ -1254,6 +1254,14 @@ documentation](CIR/index.md) for more information regarding ClangIR's status and - Enabled PAC and BTI by default for AArch64 Android targets. +#### Fuchsia Support + +- Enabled hardware forward-edge control-flow protection by default on 64-bit Fuchsia targets: Branch Target Identification (`-mbranch-target-enforce`) on AArch64, Indirect Branch Tracking (`-fcf-protection=branch` with `-fno-jump-tables`) on x86-64, and `Zicfilp` landing pads (`-fcf-protection=branch`) on RISC-V. + +- When linking with `ld.lld`, the Fuchsia driver now passes `-z bti-report=error`, `-z ibt-report=error`, `-z zicfilp-unlabeled-report=error`, or `-z zicfilp-func-sig-report=error` when the corresponding forward-edge protection is enabled. + +- Incremented `__Fuchsia_Compiler_ABI__` from `1` to `2`. + #### Windows Support - Clang now accepts ``_except`` as an alias for ``__except`` in SEH handler diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index cf3e71c7c686e3..3fc9fb04ec497d 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -7519,25 +7519,19 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, if (!Args.hasFlag(options::OPT_offloadlib, options::OPT_no_offloadlib, true)) CmdArgs.push_back("--no-offloadlib"); - const bool DefaultCfProtectionBranch = - (Triple.getArch() == llvm::Triple::x86_64 && - (Triple.isOSOpenBSD() || Triple.isOSFuchsia())) || - (Triple.getArch() == llvm::Triple::riscv64 && Triple.isOSFuchsia()); - // On x86-64 with -fcf-protection=branch, jump tables emit `notrack jmp` - // rather than `endbr64` on target blocks. Targets that avoid `notrack` (so - // CET can disallow `notrack` indirect branches) disable jump tables by - // default when branch protection is enabled. For OpenBSD and Fuchsia on - // x86-64, avoiding `notrack` is the preferred security choice. - const bool DefaultX86NoTrackAvoided = - Triple.getArch() == llvm::Triple::x86_64 && - (Triple.isOSOpenBSD() || Triple.isOSFuchsia()); - bool CFProtectionBranch = false; if (Arg *A = Args.getLastArg(options::OPT_fcf_protection_EQ)) { StringRef Val = A->getValue(); CmdArgs.push_back(Args.MakeArgString(Twine("-fcf-protection=") + Val)); CFProtectionBranch = Val == "branch" || Val == "full"; - } else if (DefaultCfProtectionBranch) { + } else if (Triple.isOSOpenBSD() && Triple.getArch() == llvm::Triple::x86_64) { + // Emit IBT endbr64 instructions by default + CmdArgs.push_back("-fcf-protection=branch"); + // jump-table can generate indirect jumps, which are not permitted + CmdArgs.push_back("-fno-jump-tables"); + } else if (Triple.isOSFuchsia() && + (Triple.getArch() == llvm::Triple::x86_64 || + Triple.getArch() == llvm::Triple::riscv64)) { // Emit IBT endbr64 / Zicfilp lpad instructions by default. CmdArgs.push_back("-fcf-protection=branch"); CFProtectionBranch = true; @@ -7547,7 +7541,12 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, CmdArgs.push_back(Args.MakeArgString(Twine("-mcf-branch-label-scheme=") + SA->getValue())); } - if (CFProtectionBranch && DefaultX86NoTrackAvoided && + // On x86-64 with -fcf-protection=branch, jump tables emit `notrack jmp` + // rather than `endbr64` on target blocks. On Fuchsia x86-64, disable jump + // tables by default when branch protection is enabled so `notrack` indirect + // branches are avoided unless `-fjump-tables` is passed explicitly. + if (CFProtectionBranch && Triple.isOSFuchsia() && + Triple.getArch() == llvm::Triple::x86_64 && !Args.hasArg(options::OPT_fjump_tables, options::OPT_fno_jump_tables)) CmdArgs.push_back("-fno-jump-tables"); diff --git a/clang/lib/Driver/ToolChains/Fuchsia.cpp b/clang/lib/Driver/ToolChains/Fuchsia.cpp index 1dbfa745cb2e8d..c912ff26c65316 100644 --- a/clang/lib/Driver/ToolChains/Fuchsia.cpp +++ b/clang/lib/Driver/ToolChains/Fuchsia.cpp @@ -68,7 +68,7 @@ void fuchsia::Linker::ConstructJob(Compilation &C, const JobAction &JA, CmdArgs.push_back("rel"); CmdArgs.push_back("--pack-dyn-relocs=relr"); - // When hardware control-flow protection is enabled for code generation (by + // When hardware branch target protection is enabled for code generation (by // default on 64-bit Fuchsia targets or via explicit compiler flags), pass // the corresponding ld.lld report switches so the linker requires every // input object file to carry the matching .note.gnu.property feature bit. @@ -82,29 +82,22 @@ void fuchsia::Linker::ConstructJob(Compilation &C, const JobAction &JA, // `-msign-return-address=` only changes PAC scope and leaves BTI at the // target default). bool IndirectBranches = true; - bool GuardedControlStack = false; if (const Arg *A = Args.getLastArg(options::OPT_msign_return_address_EQ, options::OPT_mbranch_protection_EQ)) { if (A->getOption().matches(options::OPT_mbranch_protection_EQ)) { StringRef DiagMsg; llvm::ARM::ParsedBranchProtection PBP; if (llvm::ARM::parseBranchProtection(A->getValue(), PBP, DiagMsg, - Triple)) { + Triple)) IndirectBranches = PBP.BranchTargetEnforcement; - GuardedControlStack = PBP.GuardedControlStack; - } else { + else IndirectBranches = false; - } } } if (IndirectBranches) { CmdArgs.push_back("-z"); CmdArgs.push_back("bti-report=error"); } - if (GuardedControlStack) { - CmdArgs.push_back("-z"); - CmdArgs.push_back("gcs-report=error"); - } } else if (Triple.isRISCV64() || ToolChain.getArch() == llvm::Triple::x86_64) { // On RISC-V and x86-64 Fuchsia, `-fcf-protection=branch` is enabled by @@ -114,38 +107,24 @@ void fuchsia::Linker::ConstructJob(Compilation &C, const JobAction &JA, if (const Arg *A = Args.getLastArg(options::OPT_fcf_protection_EQ)) CFProtection = A->getValue(); const bool Branch = CFProtection == "branch" || CFProtection == "full"; - const bool Return = CFProtection == "return" || CFProtection == "full"; if (Triple.isRISCV64()) { // On RISC-V, `-fcf-protection=branch` uses the `unlabeled` Zicfilp // scheme (`GNU_PROPERTY_RISCV_FEATURE_1_CFI_LP_UNLABELED`) by default - // unless `-mcf-branch-label-scheme=func-sig` is specified, and - // `-fcf-protection=return` enables Zicfiss shadow stack - // (`GNU_PROPERTY_RISCV_FEATURE_1_CFI_SS`). + // unless `-mcf-branch-label-scheme=func-sig` is specified. + const Arg *SA = + Args.getLastArg(options::OPT_mcf_branch_label_scheme_EQ); if (Branch) { - const Arg *SA = - Args.getLastArg(options::OPT_mcf_branch_label_scheme_EQ); CmdArgs.push_back("-z"); if (SA && StringRef(SA->getValue()) == "func-sig") CmdArgs.push_back("zicfilp-func-sig-report=error"); else CmdArgs.push_back("zicfilp-unlabeled-report=error"); } - if (Return) { - CmdArgs.push_back("-z"); - CmdArgs.push_back("zicfiss-report=error"); - } - } else { + } else if (Branch) { // On x86-64, `-fcf-protection=branch` enables CET IBT - // (`GNU_PROPERTY_X86_FEATURE_1_IBT`) and `-fcf-protection=return` - // enables CET shadow stack (`GNU_PROPERTY_X86_FEATURE_1_SHSTK`). - if (Branch) { - CmdArgs.push_back("-z"); - CmdArgs.push_back("ibt-report=error"); - } - if (Return) { - CmdArgs.push_back("-z"); - CmdArgs.push_back("shstk-report=error"); - } + // (`GNU_PROPERTY_X86_FEATURE_1_IBT`). + CmdArgs.push_back("-z"); + CmdArgs.push_back("ibt-report=error"); } } } diff --git a/clang/test/Driver/fuchsia.c b/clang/test/Driver/fuchsia.c index 848fc627907671..d57a2326af5691 100644 --- a/clang/test/Driver/fuchsia.c +++ b/clang/test/Driver/fuchsia.c @@ -33,7 +33,11 @@ // RUN: %clang -### %s --target=x86_64-fuchsia -fcf-protection=full \ // RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \ // RUN: --sysroot=%S/platform -fuse-ld=ld 2>&1 \ -// RUN: | FileCheck -check-prefixes=CHECK,CHECK-X86_64,CHECK-CF-FULL,CHECK-X86-IBT,CHECK-X86-SHSTK,CHECK-DEF-NO-JT %s +// RUN: | FileCheck -check-prefixes=CHECK,CHECK-X86_64,CHECK-CF-FULL,CHECK-X86-IBT,CHECK-DEF-NO-JT %s +// RUN: %clang -### %s --target=x86_64-fuchsia -fcf-protection=return \ +// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \ +// RUN: --sysroot=%S/platform -fuse-ld=ld 2>&1 \ +// RUN: | FileCheck -check-prefixes=CHECK,CHECK-X86_64,CHECK-CF-RET,CHECK-CF-NOPROT-LINK,CHECK-JT %s // RUN: %clang -### %s --target=arm-fuchsia \ // RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \ // RUN: --sysroot=%S/platform -fuse-ld=ld 2>&1 \ @@ -57,11 +61,11 @@ // RUN: %clang -### %s --target=riscv64-fuchsia -fcf-protection=none \ // RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \ // RUN: --sysroot=%S/platform -fuse-ld=ld 2>&1 \ -// RUN: | FileCheck -check-prefixes=CHECK,CHECK-RISCV64,CHECK-CF-NOPROT,CHECK-JT %s +// RUN: | FileCheck -check-prefixes=CHECK,CHECK-RISCV64,CHECK-CF-NOPROT,CHECK-CF-NOPROT-LINK,CHECK-JT %s // RUN: %clang -### %s --target=riscv64-fuchsia -fcf-protection=full \ // RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \ // RUN: --sysroot=%S/platform -fuse-ld=ld 2>&1 \ -// RUN: | FileCheck -check-prefixes=CHECK,CHECK-RISCV64,CHECK-CF-FULL,CHECK-ZICFILP,CHECK-ZICFISS,CHECK-JT %s +// RUN: | FileCheck -check-prefixes=CHECK,CHECK-RISCV64,CHECK-CF-FULL,CHECK-ZICFILP,CHECK-JT %s // RUN: %clang -### %s --target=riscv64-fuchsia -mcf-branch-label-scheme=func-sig \ // RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \ // RUN: --sysroot=%S/platform -fuse-ld=ld 2>&1 \ @@ -83,6 +87,7 @@ // CHECK: "-stack-protector" "2" // CHECK-CF-PROT: "-fcf-protection=branch" // CHECK-CF-FULL: "-fcf-protection=full" +// CHECK-CF-RET: "-fcf-protection=return" // CHECK-CF-NOPROT: "-fcf-protection=none" // CHECK-ZICFILP-FUNC-SIG: "-mcf-branch-label-scheme=func-sig" // CHECK-DEF-NO-JT: "-fno-jump-tables" @@ -94,14 +99,15 @@ // CHECK-NOT: "-fcommon" // CHECK: {{.*}}ld.lld{{.*}}" "-z" "max-page-size=4096" "-z" "now" "-z" "start-stop-visibility=hidden" "-z" "rodynamic" "-z" "separate-loadable-segments" "-z" "rel" "--pack-dyn-relocs=relr" // CHECK-ARM-BTI-SAME: "-z" "bti-report=error" -// CHECK-ARM-GCS-SAME: "-z" "gcs-report=error" +// CHECK-ARM-GCS-NOT: "gcs-report=error" // CHECK-ARM-NOBTI-NOT: "bti-report=error" // CHECK-ZICFILP-SAME: "-z" "zicfilp-unlabeled-report=error" // CHECK-ZICFILP-FUNC-SIG-SAME: "-z" "zicfilp-func-sig-report=error" -// CHECK-ZICFISS-SAME: "-z" "zicfiss-report=error" // CHECK-X86-IBT-SAME: "-z" "ibt-report=error" -// CHECK-X86-SHSTK-SAME: "-z" "shstk-report=error" +// CHECK-CF-FULL-NOT: "zicfiss-report=error" +// CHECK-CF-FULL-NOT: "shstk-report=error" // CHECK-CF-NOPROT-NOT: "-report=error" +// CHECK-CF-NOPROT-LINK-NOT: "-report=error" // CHECK: "--sysroot=[[SYSROOT]]" // CHECK: "-pie" // CHECK: "--build-id" _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
