Skip to content

Conversation

@jrife
Copy link
Contributor

@jrife jrife commented Jul 22, 2025

Allow multiple commands to be specified inside BPF2GO_CC. Example:

BPF2GO_CC="ccache clang" go generate ../pkg/a/b

I'm working on cilium/cilium#38693 where one of the checks uses ccache clang instead of just clang as the compile command substitution. Currently, this doesn't work with bpf2go. This change makes it possible to use the same compile command as the rest of the build in cases like this.

@jrife jrife force-pushed the jrife/cc-multiple-commands branch from 7fcf7ff to d59b67e Compare July 22, 2025 02:38
@jrife jrife marked this pull request as ready for review July 22, 2025 02:44
@jrife jrife requested a review from a team as a code owner July 22, 2025 02:44
Copy link
Collaborator

@lmb lmb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity, does the following work?

bpf2go -cc ccache ... -- clang

Hunch: this will fail because of overrideFlags being passed to ccache before clang. Not sure that ccache likes that. If that's the case we can be a bit smarter in Compile and insert overrideFlags at the position where the first flags starts with -.

@jrife
Copy link
Contributor Author

jrife commented Jul 22, 2025

Hunch: this will fail because of overrideFlags being passed to ccache before clang. Not sure that ccache likes that. If that's the case we can be a bit smarter in Compile and insert overrideFlags at the position where the first flags starts with -

Yeah, it won't work currently. And yes, you could reposition overrideFlags to make this possible:

bpf2go -cc ccache ... -- clang

However, from the perspective of using bpf2go in the same Makefile as a bunch of other build commands, it would be inconvenient to need to do some special handling around its invocation to, e.g., split apart my CC variable. I think it makes a lot of sense to allow this sort of thing to be passed through via BPF2GO_CC.

@jrife jrife force-pushed the jrife/cc-multiple-commands branch from d59b67e to 874a074 Compare July 22, 2025 15:51
@jrife
Copy link
Contributor Author

jrife commented Jul 24, 2025

/test

@jrife
Copy link
Contributor Author

jrife commented Jul 24, 2025

@lmb Could you take another look at this when you get a chance? This is a blocker for me on cilium/cilium#38693

@lmb lmb force-pushed the jrife/cc-multiple-commands branch from 874a074 to 9107a5f Compare July 29, 2025 13:59
@github-actions github-actions bot added the breaking-change Changes exported API label Jul 29, 2025
lmb
lmb previously approved these changes Jul 29, 2025
@lmb lmb force-pushed the jrife/cc-multiple-commands branch from 9107a5f to 952e6e4 Compare July 29, 2025 14:01
@lmb
Copy link
Collaborator

lmb commented Jul 29, 2025

@github-actions github-actions bot removed the breaking-change Changes exported API label Jul 29, 2025
@jrife jrife force-pushed the jrife/cc-multiple-commands branch from 952e6e4 to 46a14b5 Compare July 29, 2025 15:12
@jrife
Copy link
Contributor Author

jrife commented Jul 29, 2025

@lmb

DCO is failing, please take a look at

Fixed. Author didn't match the Signed-off-by tag.

Also, switched back to Fields for the reasons I listed above and added a check to error out if ccParts is empty. Example:

BPF2GO_CC="   " BPF2GO_CFLAGS="-DSKIP_DEBUG=1 -DENABLE_IPV4=1 -DENABLE_IPV6=1 -DENABLE_ROUTING=1 -DPOLICY_VERDICT_NOTIFY=1 -DALLOW_ICMP_FRAG_NEEDED=1 -DENABLE_IDENTITY_MARK=1 -DMONITOR_AGGREGATION=3 -DCT_REPORT_FLAGS=0x0002 -DENABLE_HOST_FIREWALL=1 -DENABLE_ICMP_RULE=1 -DENABLE_CUSTOM_CALLS=1 -DENABLE_SRV6=1 -DENABLE_L7_LB=1 -DENABLE_MASQUERADE_IPV4=1 -DENABLE_IP_MASQ_AGENT_IPV4=1 -DENABLE_MASQUERADE_IPV6=1 -DENABLE_IP_MASQ_AGENT_IPV6=1 -DENABLE_SRC_RANGE_CHECK=1 -DENABLE_NODEPORT=1 -DENABLE_NODEPORT_ACCELERATION=1 -DENABLE_SESSION_AFFINITY=1 -DENABLE_DSR_ICMP_ERRORS=1 -DENABLE_DSR=1 -DENABLE_DSR_HYBRID=1 -DENABLE_IPV4_FRAGMENTS=1 -DENABLE_BANDWIDTH_MANAGER=1 -DENABLE_EGRESS_GATEWAY=1 -DENABLE_VTEP=1 -DENABLE_TPROXY=1 -DENABLE_HOST_ROUTING=1 -DENCAP_IFINDEX=1 -DTUNNEL_MODE=1 -DENABLE_MULTICAST=1 -DLB_SELECTION_PER_SERVICE=1 -DLB_SELECTION_MAGLEV=2 -DLB_SELECTION_RANDOM=1 -DENABLE_IPSEC=1 -I/go/src/github.com/cilium/cilium/bpf -I/go/src/github.com/cilium/cilium/bpf/include -O2 -g --target=bpf -std=gnu99 -nostdinc -ftrap-function=__undefined_trap -Wall -Wextra -Werror -Wshadow -Wno-address-of-packed-member -Wno-unknown-warning-option -Wno-gnu-variable-sized-type-not-at-end -Wimplicit-int-conversion -Wenum-conversion -Wimplicit-fallthrough -mcpu=v3" go generate ../pkg/datapath/loader
Error: no compiler specified

Allow multiple commands to be specified inside BPF2GO_CC. Example:

```
BPF2GO_CC="ccache clang" go generate ../pkg/a/b
```

Signed-off-by: Jordan Rife <[email protected]>
@jrife jrife force-pushed the jrife/cc-multiple-commands branch from 46a14b5 to c72a634 Compare July 29, 2025 15:29
@lmb lmb merged commit 8b53d11 into cilium:main Jul 29, 2025
19 checks passed
jrife added a commit to jrife/cilium that referenced this pull request Jul 29, 2025
bpf_sock_term.o was built from the start to be "clang free". Use bpf2go
to embed compiled BPF bytecode and generate Go skeletons. Reorder struct
definitions inside union u6addr to ensure that the generated Go struct
has a [16]uint8 for the Addr field and name the anonymous structs to get
bpf2go to stop complaining. Add llvm-strip to the builder image, a
dependency of bpf2go, and use the builder image for BPF generation
(`make -C bpf generate`) to ensure reproducible results on systems with
different LLVM versions.

Bump github.com/cilium/ebpf module version to pull in [1].

[1]: cilium/ebpf#1829

Fixes: cilium#37907

Signed-off-by: Jordan Rife <[email protected]>
jrife added a commit to jrife/cilium that referenced this pull request Jul 30, 2025
bpf_sock_term.o was built from the start to be "clang free". Use bpf2go
to embed compiled BPF bytecode and generate Go skeletons. Reorder struct
definitions inside union u6addr to ensure that the generated Go struct
has a [16]uint8 for the Addr field and name the anonymous structs to get
bpf2go to stop complaining. Add llvm-strip to the builder image, a
dependency of bpf2go, and use the builder image for BPF generation
(`make -C bpf generate`) to ensure reproducible results on systems with
different LLVM versions.

Bump github.com/cilium/ebpf module version to pull in [1].

[1]: cilium/ebpf#1829

Fixes: cilium#37907

Signed-off-by: Jordan Rife <[email protected]>
jrife added a commit to jrife/cilium that referenced this pull request Jul 30, 2025
bpf_sock_term.o was built from the start to be "clang free". Use bpf2go
to embed compiled BPF bytecode and generate Go skeletons. Reorder struct
definitions inside union u6addr to ensure that the generated Go struct
has a [16]uint8 for the Addr field and name the anonymous structs to get
bpf2go to stop complaining. Add llvm-strip to the builder image, a
dependency of bpf2go, and use the builder image for BPF generation
(`make -C bpf generate`) to ensure reproducible results on systems with
different LLVM versions.

Bump github.com/cilium/ebpf module version to pull in [1].

[1]: cilium/ebpf#1829

Fixes: cilium#37907

Signed-off-by: Jordan Rife <[email protected]>
jrife added a commit to jrife/cilium that referenced this pull request Aug 1, 2025
bpf_sock_term.o was built from the start to be "clang free". Use bpf2go
to embed compiled BPF bytecode and generate Go skeletons. Reorder struct
definitions inside union u6addr to ensure that the generated Go struct
has a [16]uint8 for the Addr field and name the anonymous structs to get
bpf2go to stop complaining. Add llvm-strip to the builder image, a
dependency of bpf2go, and use the builder image for BPF generation
(`make -C bpf generate`) to ensure reproducible results on systems with
different LLVM versions.

Bump github.com/cilium/ebpf module version to pull in [1].

[1]: cilium/ebpf#1829

Fixes: cilium#37907

Signed-off-by: Jordan Rife <[email protected]>
github-merge-queue bot pushed a commit to cilium/cilium that referenced this pull request Aug 4, 2025
bpf_sock_term.o was built from the start to be "clang free". Use bpf2go
to embed compiled BPF bytecode and generate Go skeletons. Reorder struct
definitions inside union u6addr to ensure that the generated Go struct
has a [16]uint8 for the Addr field and name the anonymous structs to get
bpf2go to stop complaining. Add llvm-strip to the builder image, a
dependency of bpf2go, and use the builder image for BPF generation
(`make -C bpf generate`) to ensure reproducible results on systems with
different LLVM versions.

Bump github.com/cilium/ebpf module version to pull in [1].

[1]: cilium/ebpf#1829

Fixes: #37907

Signed-off-by: Jordan Rife <[email protected]>
github-merge-queue bot pushed a commit to cilium/cilium that referenced this pull request Aug 4, 2025
bpf_sock_term.o was built from the start to be "clang free". Use bpf2go
to embed compiled BPF bytecode and generate Go skeletons. Reorder struct
definitions inside union u6addr to ensure that the generated Go struct
has a [16]uint8 for the Addr field and name the anonymous structs to get
bpf2go to stop complaining. Add llvm-strip to the builder image, a
dependency of bpf2go, and use the builder image for BPF generation
(`make -C bpf generate`) to ensure reproducible results on systems with
different LLVM versions.

Bump github.com/cilium/ebpf module version to pull in [1].

[1]: cilium/ebpf#1829

Fixes: #37907

Signed-off-by: Jordan Rife <[email protected]>
rabelmervin pushed a commit to rabelmervin/cilium that referenced this pull request Aug 18, 2025
bpf_sock_term.o was built from the start to be "clang free". Use bpf2go
to embed compiled BPF bytecode and generate Go skeletons. Reorder struct
definitions inside union u6addr to ensure that the generated Go struct
has a [16]uint8 for the Addr field and name the anonymous structs to get
bpf2go to stop complaining. Add llvm-strip to the builder image, a
dependency of bpf2go, and use the builder image for BPF generation
(`make -C bpf generate`) to ensure reproducible results on systems with
different LLVM versions.

Bump github.com/cilium/ebpf module version to pull in [1].

[1]: cilium/ebpf#1829

Fixes: cilium#37907

Signed-off-by: Jordan Rife <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants