Skip to content

Commit 0f4a950

Browse files
committed
[Driver] Enable IBT by default on OpenBSD/amd64
1 parent 1eac7cd commit 0f4a950

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7054,6 +7054,11 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
70547054
if (Arg *SA = Args.getLastArg(options::OPT_mcf_branch_label_scheme_EQ))
70557055
CmdArgs.push_back(Args.MakeArgString(Twine("-mcf-branch-label-scheme=") +
70567056
SA->getValue()));
7057+
} else if (Triple.isOSOpenBSD() && Triple.getArch() == llvm::Triple::x86_64) {
7058+
// Emit IBT endbr64 instructions by default
7059+
CmdArgs.push_back("-fcf-protection=branch");
7060+
// jump-table can generate indirect jumps, which are not permitted
7061+
CmdArgs.push_back("-fno-jump-tables");
70577062
}
70587063

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

clang/test/Driver/openbsd.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,8 @@
136136
// RUN: %clang --target=amd64-unknown-openbsd -flto -### %s 2>&1 \
137137
// RUN: | FileCheck -check-prefix=CHECK-LTO-FLAGS %s
138138
// CHECK-LTO-FLAGS: "-plugin-opt=mcpu=x86-64"
139+
140+
// Check 64-bit X86 for IBT flags
141+
// RUN: %clang --target=amd64-unknown-openbsd -### -c %s 2>&1 \
142+
// RUN: | FileCheck -check-prefix=CHECK-AMD64-IBT %s
143+
// CHECK-AMD64-IBT: "-fcf-protection=branch" "-fno-jump-tables"

0 commit comments

Comments
 (0)