Skip to content

Commit d81ba78

Browse files
committed
Merge support for no co-re universal
1 parent c3727d1 commit d81ba78

File tree

4 files changed

+307
-38
lines changed

4 files changed

+307
-38
lines changed

.github/workflows/build.yaml

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,38 @@ jobs:
2121
2222
- name: Compile with Make
2323
run: |
24-
make CORE=1 static
24+
make MODE=core STATIC=1
2525
26-
- name: Upload x64 binary
26+
- name: Upload x64 CORE binary
2727
uses: actions/upload-artifact@v4
2828
with:
29-
name: lemon.x86_64
30-
path: "lemon.x86_64"
29+
name: lemon.core.x86_64
30+
path: "lemon.core.x86_64"
3131
continue-on-error: true
3232

33-
- name: Upload ARM64 binary
33+
- name: Upload ARM64 CORE binary
3434
uses: actions/upload-artifact@v4
3535
with:
36-
name: lemon.aarch64
37-
path: "lemon.aarch64"
36+
name: lemon.core.aarch64
37+
path: "lemon.core.aarch64"
38+
continue-on-error: true
39+
40+
- name: Compile with Make
41+
run: |
42+
make MODE=nocoreuni STATIC=1
43+
44+
- name: Upload x64 NO-CORE universal binary
45+
uses: actions/upload-artifact@v4
46+
with:
47+
name: lemon.nocoreuni.x86_64
48+
path: "lemon.nocoreuni.x86_64"
49+
continue-on-error: true
50+
51+
- name: Upload ARM64 NO-CORE universal binary
52+
uses: actions/upload-artifact@v4
53+
with:
54+
name: lemon.nocoreuni.aarch64
55+
path: "lemon.nocoreuni.aarch64"
3856
continue-on-error: true
3957

4058
run:
@@ -48,6 +66,9 @@ jobs:
4866
uses: actions/download-artifact@v4
4967
- name: Run dump to disk
5068
run: |
51-
sudo chmod +x ./lemon.$(uname -m)/lemon.$(uname -m)
52-
sudo ./lemon.$(uname -m)/lemon.$(uname -m) -d /dev/null
53-
# TODO build and run on NO CORE
69+
sudo chmod +x ./lemon.core.$(uname -m)/lemon.core.$(uname -m)
70+
sudo ./lemon.core.$(uname -m)/lemon.core.$(uname -m) -d /dev/null
71+
- name: Run dump to disk
72+
run: |
73+
sudo chmod +x ./lemon.nocoreuni.$(uname -m)/lemon.nocoreuni.$(uname -m)
74+
sudo ./lemon.nocoreuni.$(uname -m)/lemon.nocoreuni.$(uname -m) -d /dev/null

Makefile

Lines changed: 72 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,65 @@
11
# Optional build flags (can be overridden via command line)
2-
STATIC ?= # Default is not static
3-
CORE ?= 1 # Default to CORE=1, can be disabled via CORE=0
2+
STATIC ?=
3+
MODE ?= core
4+
5+
# Validate MODE value
6+
VALID_MODES := core nocore nocoreuni
7+
ifeq ($(filter $(MODE),$(VALID_MODES)),)
8+
$(error Invalid MODE value: $(MODE). Valid values are: $(VALID_MODES))
9+
endif
410

511
# System and architecture detection
612
ARCH := $(shell uname -m)
713
BPFTOOL := bpftool
814

915
# Detect architecture for eBPF
1016
ifeq ($(ARCH), x86_64)
11-
TARGET_ARCH := __TARGET_ARCH_x86
17+
TARGET_ARCH := __TARGET_ARCH_x86
1218
else ifeq ($(ARCH), aarch64)
13-
TARGET_ARCH := __TARGET_ARCH_arm64
19+
TARGET_ARCH := __TARGET_ARCH_arm64
1420
else
15-
$(error Unsupported architecture: $(ARCH))
21+
$(error Unsupported architecture: $(ARCH))
1622
endif
1723

1824
# Define compiler and flags
19-
CLANG := clang
20-
CFLAGS := -Wall -O2 -D$(TARGET_ARCH)
25+
CLANG := clang
26+
CFLAGS := -Wall -O2 -D$(TARGET_ARCH)
2127
LDFLAGS := -lbpf -lelf -lz -lzstd -lcap
2228

23-
# Conditional flags
24-
ifeq ($(CORE), 1)
25-
CFLAGS += -DCORE
26-
BPF_CORE_FLAG := -DCORE
29+
# MODE-based flags
30+
ifeq ($(MODE), core)
31+
CFLAGS += -DCORE
32+
BPF_FLAGS := -DCORE
33+
NEEDS_VMLINUX := 1
34+
else ifeq ($(MODE), nocore)
35+
CFLAGS += -DNOCORE
36+
BPF_FLAGS := -DNOCORE
37+
NEEDS_VMLINUX := 0
38+
else ifeq ($(MODE), nocoreuni)
39+
CFLAGS += -DNOCOREUNI
40+
BPF_FLAGS := -DNOCOREUNI
41+
NEEDS_VMLINUX := 0
2742
endif
2843

44+
# Static linking flag
2945
ifeq ($(STATIC), 1)
30-
LDFLAGS += -static
46+
LDFLAGS += -static
3147
endif
3248

3349
# Files
3450
LOADER_SRCS := lemon.c cpu_stealer.c mem.c dump.c disk.c net.c capabilities.c
35-
LOADER_BIN := lemon.$(ARCH)
36-
BPF_SRC := ebpf/mem.ebpf.c
37-
BPF_OBJ := ebpf/mem.ebpf.o
38-
BPF_SKEL := ebpf/mem.ebpf.skel.h
51+
LOADER_BIN := lemon.$(MODE).$(ARCH)
52+
BPF_SRC := ebpf/mem.ebpf.c
53+
BPF_OBJ := ebpf/mem.ebpf.o
54+
BPF_SKEL := ebpf/mem.ebpf.skel.h
3955

40-
# Default target: If CORE is enabled, make vmlinux first, then compile eBPF and loader
41-
all: clean $(if $(filter 1,$(CORE)), vmlinux) $(BPF_OBJ) $(LOADER_BIN)
56+
# Default target: If core mode is enabled, make vmlinux first, then compile eBPF and loader
57+
all: clean $(if $(filter 1,$(NEEDS_VMLINUX)), vmlinux) $(BPF_OBJ) $(LOADER_BIN)
4258

4359
# Build eBPF object and generate skeleton
4460
$(BPF_OBJ): $(BPF_SRC)
45-
$(CLANG) -target bpf -D$(TARGET_ARCH) $(BPF_CORE_FLAG) -I/usr/include/linux -I/usr/include/$(ARCH)-linux-gnu \
46-
-Wall -O2 -g -c $< -o $@
61+
$(CLANG) -target bpf -D$(TARGET_ARCH) $(BPF_FLAGS) -I/usr/include/linux -I/usr/include/$(ARCH)-linux-gnu \
62+
-Wall -O2 -g -c $< -o $@
4763
llvm-strip -g $(BPF_OBJ)
4864
$(BPFTOOL) gen skeleton $(BPF_OBJ) > $(BPF_SKEL)
4965

@@ -53,16 +69,46 @@ $(LOADER_BIN): $(LOADER_SRCS)
5369
objcopy --strip-all --keep-symbol=read_kernel_memory $@ $@_strip
5470
mv $@_strip $@
5571

56-
# Dump vmlinux BTF as C header (only if CORE is enabled)
72+
# Dump vmlinux BTF as C header (only if core mode is enabled)
5773
vmlinux:
5874
$(BPFTOOL) btf dump file /sys/kernel/btf/vmlinux format c > vmlinux.h
5975

60-
# Static target for convenience
61-
static:
62-
$(MAKE) STATIC=1
63-
6476
# Clean
6577
clean:
6678
rm -f $(LOADER_BIN) $(BPF_OBJ) $(BPF_SKEL) vmlinux.h
6779

68-
.PHONY: all static clean vmlinux
80+
# Help target
81+
help:
82+
@echo "Available targets:"
83+
@echo " all - Build the project (default, core, dynamic linked)"
84+
@echo " static - Build with static linking"
85+
@echo " clean - Clean build artifacts"
86+
@echo " vmlinux - Generate vmlinux.h (for core mode)"
87+
@echo " help - Show this help"
88+
@echo ""
89+
@echo "Variables:"
90+
@echo " MODE - Build mode (default: core)"
91+
@echo " core: Use eBPF CO-RE with vmlinux.h"
92+
@echo " nocore: Compile in legacy no CO-RE mode using installed Linux headers"
93+
@echo " nocoreuni: Compile in no CO-RE mode using universal header included"
94+
@echo " STATIC - Enable static linking (default: disabled)"
95+
@echo ""
96+
@echo "Usage examples:"
97+
@echo " make # Build with core mode"
98+
@echo " make MODE=nocore # Build in legacy no CO-RE mode using installed Linux headers"
99+
@echo " make MODE=nocoreuni # Build in no CO-RE mode using universal header included"
100+
@echo " make STATIC=1 MODE=nocore # Static build legacy NO CO-RE"
101+
102+
# Show current configuration
103+
config:
104+
@echo "Current configuration:"
105+
@echo " MODE: $(MODE)"
106+
@echo " STATIC: $(if $(STATIC),enabled,disabled)"
107+
@echo " ARCH: $(ARCH)"
108+
@echo " TARGET_ARCH: $(TARGET_ARCH)"
109+
@echo " NEEDS_VMLINUX: $(NEEDS_VMLINUX)"
110+
@echo " CFLAGS: $(CFLAGS)"
111+
@echo " BPF_FLAGS: $(BPF_FLAGS)"
112+
@echo " LDFLAGS: $(LDFLAGS)"
113+
114+
.PHONY: all static clean vmlinux help config

ebpf/mem.ebpf.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,19 @@
99
#ifndef IPPROTO_UDP
1010
#define IPPROTO_UDP 17
1111
#endif
12-
#else
13-
#include <asm/ptrace.h>
12+
13+
#elif NOCORE
1414
#include <linux/bpf.h>
15+
#include <asm/ptrace.h>
1516
#include <linux/if_ether.h>
1617
#include <linux/in.h>
1718
#include <linux/ip.h>
1819
#include <linux/udp.h>
20+
21+
#elif NOCOREUNI
22+
#include "../nocore_universal.h"
23+
#include <bpf/bpf_tracing.h>
24+
1925
#endif
2026

2127
#include <bpf/bpf_helpers.h>

0 commit comments

Comments
 (0)