[clang] [Driver] Enable IBT by default on OpenBSD/amd64 (PR #125395)

2025-02-06 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `llvm-clang-aarch64-darwin` 
running on `doug-worker-4` while building `clang` at step 6 
"test-build-unified-tree-check-all".

Full details are available at: 
https://lab.llvm.org/buildbot/#/builders/190/builds/14184


Here is the relevant piece of the build log for the reference

```
Step 6 (test-build-unified-tree-check-all) failure: test (failure)
 TEST 'Clang :: Analysis/live-stmts.cpp' FAILED 

Exit Code: 1

Command Output (stderr):
--
RUN: at line 1: /Users/buildbot/buildbot-root/aarch64-darwin/build/bin/clang 
-cc1 -internal-isystem 
/Users/buildbot/buildbot-root/aarch64-darwin/build/lib/clang/21/include 
-nostdsysteminc -analyze -analyzer-constraints=range -setup-static-analyzer -w 
-analyzer-checker=debug.DumpLiveExprs 
/Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang/test/Analysis/live-stmts.cpp
 2>&1   | /Users/buildbot/buildbot-root/aarch64-darwin/build/bin/FileCheck 
/Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang/test/Analysis/live-stmts.cpp
+ /Users/buildbot/buildbot-root/aarch64-darwin/build/bin/clang -cc1 
-internal-isystem 
/Users/buildbot/buildbot-root/aarch64-darwin/build/lib/clang/21/include 
-nostdsysteminc -analyze -analyzer-constraints=range -setup-static-analyzer -w 
-analyzer-checker=debug.DumpLiveExprs 
/Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang/test/Analysis/live-stmts.cpp
+ /Users/buildbot/buildbot-root/aarch64-darwin/build/bin/FileCheck 
/Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang/test/Analysis/live-stmts.cpp
/Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang/test/Analysis/live-stmts.cpp:239:16:
 error: CHECK-EMPTY: is not on the line after the previous 
match
// CHECK-EMPTY:
   ^
:180:1: note: 'next' match was here

^
:177:1: note: previous match ended here

^
:178:1: note: non-matching line after 
previous match is here
ImplicitCastExpr 0x136932f78 '_Bool' 
^

Input file: 
Check file: 
/Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang/test/Analysis/live-stmts.cpp

-dump-input=help explains the following input dump.

Input was:
<<
   1:  
   2: [ B0 (live expressions at block 
exit) ] 
check:21  ^~~
   3:  
empty:22  ^
   4:  
empty:23  ^
   5: [ B1 (live expressions at block 
exit) ] 
check:24  ^~~
   6:  
empty:25  ^
   7:  
empty:26  ^
   8: [ B2 (live expressions at block 
exit) ] 
check:27  ^~~
   9:  
empty:28  ^
  10: DeclRefExpr 0x13692fce0 'int' 
lvalue ParmVar 0x136915870 'y' 'int' 
next:29   
^~
  11:  
empty:30  ^
  12: DeclRefExpr 0x13692fd00 'int' 
lvalue ParmVar 0x1369158f0 'z' 'int' 
...

```



https://github.com/llvm/llvm-project/pull/125395
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Enable IBT by default on OpenBSD/amd64 (PR #125395)

2025-02-05 Thread Brad Smith via cfe-commits

https://github.com/brad0 closed https://github.com/llvm/llvm-project/pull/125395
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Enable IBT by default on OpenBSD/amd64 (PR #125395)

2025-02-05 Thread Brad Smith via cfe-commits

https://github.com/brad0 updated 
https://github.com/llvm/llvm-project/pull/125395

>From bf29a1cd3720b223572184b2d11576e4c382a7d7 Mon Sep 17 00:00:00 2001
From: Brad Smith 
Date: Sun, 2 Feb 2025 05:25:18 -0500
Subject: [PATCH] [Driver] Enable IBT by default on OpenBSD/amd64

---
 clang/lib/Driver/ToolChains/Clang.cpp | 5 +
 clang/test/Driver/openbsd.c   | 5 +
 2 files changed, 10 insertions(+)

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 9ca56f5bdf4d814..a0757d71b140c20 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -7064,6 +7064,11 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
 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 (Arg *A = Args.getLastArg(options::OPT_mfunction_return_EQ))
diff --git a/clang/test/Driver/openbsd.c b/clang/test/Driver/openbsd.c
index 68c114f063d04cd..6639e9d2d9d677a 100644
--- a/clang/test/Driver/openbsd.c
+++ b/clang/test/Driver/openbsd.c
@@ -141,3 +141,8 @@
 // RUN: %clang --target=aarch64-unknown-openbsd -### -c %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHECK-AARCH64-BTI-PAC %s
 // CHECK-AARCH64-BTI-PAC: "-msign-return-address=non-leaf" 
"-msign-return-address-key=a_key" "-mbranch-target-enforce"
+
+// Check 64-bit X86 for IBT flags
+// RUN: %clang --target=amd64-unknown-openbsd -### -c %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-AMD64-IBT %s
+// CHECK-AMD64-IBT: "-fcf-protection=branch" "-fno-jump-tables"

___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Enable IBT by default on OpenBSD/amd64 (PR #125395)

2025-02-05 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay approved this pull request.


https://github.com/llvm/llvm-project/pull/125395
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Enable IBT by default on OpenBSD/amd64 (PR #125395)

2025-02-02 Thread Brad Smith via cfe-commits

https://github.com/brad0 updated 
https://github.com/llvm/llvm-project/pull/125395

>From 0f4a9508206b4918a47fc6bc2659a766206b5d5e Mon Sep 17 00:00:00 2001
From: Brad Smith 
Date: Sun, 2 Feb 2025 05:25:18 -0500
Subject: [PATCH] [Driver] Enable IBT by default on OpenBSD/amd64

---
 clang/lib/Driver/ToolChains/Clang.cpp | 5 +
 clang/test/Driver/openbsd.c   | 5 +
 2 files changed, 10 insertions(+)

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 9b5132c5625faa0..c6bbe5ca82ebdbb 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -7054,6 +7054,11 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
 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 (Arg *A = Args.getLastArg(options::OPT_mfunction_return_EQ))
diff --git a/clang/test/Driver/openbsd.c b/clang/test/Driver/openbsd.c
index 672cd3adf44a691..5485f749a3f94d2 100644
--- a/clang/test/Driver/openbsd.c
+++ b/clang/test/Driver/openbsd.c
@@ -136,3 +136,8 @@
 // RUN: %clang --target=amd64-unknown-openbsd -flto -### %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHECK-LTO-FLAGS %s
 // CHECK-LTO-FLAGS: "-plugin-opt=mcpu=x86-64"
+
+// Check 64-bit X86 for IBT flags
+// RUN: %clang --target=amd64-unknown-openbsd -### -c %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-AMD64-IBT %s
+// CHECK-AMD64-IBT: "-fcf-protection=branch" "-fno-jump-tables"

___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Enable IBT by default on OpenBSD/amd64 (PR #125395)

2025-02-02 Thread Brad Smith via cfe-commits

https://github.com/brad0 edited https://github.com/llvm/llvm-project/pull/125395
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits