Skip to content

Commit 08b83e5

Browse files
committed
cilium, build: Use -ftrap-function=__undefined_trap
We use __builtin_trap() in various places to trigger a compilation error when code is reachable where it is not expected: # define __bpf_unreachable() __builtin_trap() Recently, in LLVM [0] the latter is being mapped into __bpf_trap() kfunc which also means that we do not get the desired behavior for __builtin_trap() in Cilium anymore once we upgrade LLVM. To work around this, use -ftrap-function=__undefined_trap to remap: $ cat test_trap.c int buz(int p) { __builtin_trap(); return 0; } $ clang --target=bpf -O2 -g -c test_trap.c $ clang --target=bpf -O2 -ftrap-function=__undefined_trap -g -c test_trap.c test_trap.c:1:18: error: A call to built-in function '__undefined_trap' is not supported. 1 | int buz(int p) { __builtin_trap(); return 0; } | ^ 1 error generated. $ Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Link: llvm/llvm-project#131731 [0]
1 parent 088c6fe commit 08b83e5

File tree

2 files changed

+2
-0
lines changed

2 files changed

+2
-0
lines changed

bpf/Makefile.bpf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ FLAGS := -I$(ROOT_DIR)/bpf -I$(ROOT_DIR)/bpf/include -O2 -g
66
CLANG_FLAGS := ${FLAGS} --target=bpf -std=gnu89 -nostdinc
77
# eBPF verifier enforces unaligned access checks where necessary, so don't
88
# let clang complain too early.
9+
CLANG_FLAGS += -ftrap-function=__undefined_trap
910
CLANG_FLAGS += -Wall -Wextra -Werror -Wshadow
1011
CLANG_FLAGS += -Wno-address-of-packed-member
1112
CLANG_FLAGS += -Wno-unknown-warning-option

pkg/datapath/loader/compile.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ type directoryInfo struct {
9999
var (
100100
StandardCFlags = []string{"-O2", "--target=bpf", "-std=gnu99",
101101
"-nostdinc",
102+
"-ftrap-function=__undefined_trap",
102103
"-Wall", "-Wextra", "-Werror", "-Wshadow",
103104
"-Wno-address-of-packed-member",
104105
"-Wno-unknown-warning-option",

0 commit comments

Comments
 (0)