Skip to content

Commit a7584bb

Browse files
brad0github-actions[bot]
authored andcommitted
Automerge: [Driver] Enable IBT by default on OpenBSD/amd64 (#125395)
2 parents 49364eb + c4f5463 commit a7584bb

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -7064,6 +7064,11 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
70647064
if (Arg *SA = Args.getLastArg(options::OPT_mcf_branch_label_scheme_EQ))
70657065
CmdArgs.push_back(Args.MakeArgString(Twine("-mcf-branch-label-scheme=") +
70667066
SA->getValue()));
7067+
} else if (Triple.isOSOpenBSD() && Triple.getArch() == llvm::Triple::x86_64) {
7068+
// Emit IBT endbr64 instructions by default
7069+
CmdArgs.push_back("-fcf-protection=branch");
7070+
// jump-table can generate indirect jumps, which are not permitted
7071+
CmdArgs.push_back("-fno-jump-tables");
70677072
}
70687073

70697074
if (Arg *A = Args.getLastArg(options::OPT_mfunction_return_EQ))

clang/test/Driver/openbsd.c

+5
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,8 @@
141141
// RUN: %clang --target=aarch64-unknown-openbsd -### -c %s 2>&1 \
142142
// RUN: | FileCheck -check-prefix=CHECK-AARCH64-BTI-PAC %s
143143
// CHECK-AARCH64-BTI-PAC: "-msign-return-address=non-leaf" "-msign-return-address-key=a_key" "-mbranch-target-enforce"
144+
145+
// Check 64-bit X86 for IBT flags
146+
// RUN: %clang --target=amd64-unknown-openbsd -### -c %s 2>&1 \
147+
// RUN: | FileCheck -check-prefix=CHECK-AMD64-IBT %s
148+
// CHECK-AMD64-IBT: "-fcf-protection=branch" "-fno-jump-tables"

0 commit comments

Comments
 (0)