Skip to content

Commit 066de68

Browse files
committed
Initialize eBPF eh_frame stack unwinding
Signed-off-by: Kemal Akkoyun <[email protected]>
1 parent 31f6fcf commit 066de68

File tree

5 files changed

+125563
-4
lines changed

5 files changed

+125563
-4
lines changed

3rdparty/include/stdarg.h

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*===---- stdarg.h - Variable argument handling ----------------------------===
2+
*
3+
* Copyright (c) 2008 Eli Friedman
4+
*
5+
* Permission is hereby granted, free of charge, to any person obtaining a copy
6+
* of this software and associated documentation files (the "Software"), to deal
7+
* in the Software without restriction, including without limitation the rights
8+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
* copies of the Software, and to permit persons to whom the Software is
10+
* furnished to do so, subject to the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be included in
13+
* all copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
* THE SOFTWARE.
22+
*
23+
*===-----------------------------------------------------------------------===
24+
*/
25+
26+
#ifndef __STDARG_H
27+
#define __STDARG_H
28+
29+
#ifndef _VA_LIST
30+
typedef __builtin_va_list va_list;
31+
#define _VA_LIST
32+
#endif
33+
#define va_start(ap, param) __builtin_va_start(ap, param)
34+
#define va_end(ap) __builtin_va_end(ap)
35+
#define va_arg(ap, type) __builtin_va_arg(ap, type)
36+
37+
/* GCC always defines __va_copy, but does not define va_copy unless in c99 mode
38+
* or -ansi is not specified, since it was not part of C90.
39+
*/
40+
#define __va_copy(d,s) __builtin_va_copy(d,s)
41+
42+
#if __STDC_VERSION__ >= 199901L || __cplusplus >= 201103L || !defined(__STRICT_ANSI__)
43+
#define va_copy(dest, src) __builtin_va_copy(dest, src)
44+
#endif
45+
46+
/* Hack required to make standard headers work, at least on Ubuntu */
47+
#ifndef __GNUC_VA_LIST
48+
#define __GNUC_VA_LIST 1
49+
#endif
50+
typedef __builtin_va_list __gnuc_va_list;
51+
52+
#endif /* __STDARG_H */

Makefile

+3-2
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,11 @@ go/deps:
124124
bpf: $(OUT_BPF)
125125

126126
ifndef DOCKER
127-
$(OUT_BPF): $(BPF_SRC) | $(OUT_DIR)
127+
$(OUT_BPF): $(BPF_SRC) libbpf | $(OUT_DIR)
128128
mkdir -p $(OUT_BPF_DIR)
129129
$(MAKE) -C bpf build
130-
cp bpf/target/bpfel-unknown-none/release/cpu-profiler $(OUT_BPF)
130+
# cp bpf/target/bpfel-unknown-none/release/cpu-profiler $(OUT_BPF)
131+
cp bpf/cpu/cpu.bpf.o $(OUT_BPF)
131132
else
132133
$(OUT_BPF): $(DOCKER_BUILDER) | $(OUT_DIR)
133134
$(call docker_builder_make,$@)

bpf/Makefile

+83-2
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,22 @@ setup:
1212
LLVM_SYS_140_PREFIX=$(LLVM_SYS_140_PREFIX) cargo install --locked --git https://github.com/aya-rs/bpf-linker --tag $(BPF_LINKER_VERSION) --no-default-features --features system-llvm -- bpf-linker
1313

1414
.PHONY: build
15-
build:
15+
build: clang
1616
cargo xtask build-ebpf --release
1717

1818
.PHONY: clean
1919
clean:
2020
cargo clean
21+
rm -f $(OUT_BPF)
2122

2223
.PHONY: format
23-
format:
24+
format: c/fmt
2425
cargo fmt
2526

27+
.PHONY: c/fmt
28+
c/fmt:
29+
clang-format -i --style=LLVM $(BPF_SRC)
30+
2631
.PHONY: format-check
2732
format-check:
2833
cargo fmt --check
@@ -34,3 +39,79 @@ lint:
3439

3540
lint-fix:
3641
cargo clippy --fix
42+
43+
# environment:
44+
ALL_ARCH ?= amd64 arm64
45+
ARCH_UNAME := $(shell uname -m)
46+
ifeq ($(ARCH_UNAME), x86_64)
47+
ARCH ?= amd64
48+
else
49+
ARCH ?= arm64
50+
endif
51+
ifeq ($(ARCH), amd64)
52+
LINUX_ARCH ?= x86_64=x86
53+
else
54+
LINUX_ARCH ?= aarch64=arm64
55+
endif
56+
57+
# tools:
58+
CLANG ?= clang
59+
CMD_LLC ?= llc
60+
CMD_CC ?= $(CLANG)
61+
62+
# output:
63+
OUT_DIR ?= ../dist
64+
65+
OUT_BPF_DIR := cpu
66+
OUT_BPF := $(OUT_BPF_DIR)/cpu.bpf.o
67+
BPF_BUNDLE := $(OUT_DIR)/parca-agent.bpf.tar.gz
68+
69+
# input:
70+
BPF_HEADERS := ../3rdparty/include
71+
LIBBPF_HEADERS := $(OUT_DIR)/libbpf/$(ARCH)/usr/include
72+
LIBBPF_OBJ := $(OUT_DIR)/libbpf/$(ARCH)/libbpf.a
73+
74+
VMLINUX := cpu/vmlinux.h
75+
BPF_SRC := cpu/cpu.bpf.c
76+
77+
# tasks:
78+
.PHONY: clang
79+
clang: $(OUT_BPF)
80+
81+
bpf_bundle_dir := $(OUT_DIR)/parca-agent.bpf
82+
$(BPF_BUNDLE): $(BPF_SRC) $(LIBBPF_HEADERS)/bpf $(BPF_HEADERS)
83+
mkdir -p $(bpf_bundle_dir)
84+
cp $$(find $^ -type f) $(bpf_bundle_dir)
85+
86+
$(OUT_BPF): $(BPF_SRC) $(LIBBPF_HEADERS) $(LIBBPF_OBJ) $(BPF_HEADERS) | $(OUT_DIR)
87+
mkdir -p $(OUT_BPF_DIR)
88+
$(CMD_CC) -S \
89+
-D__BPF_TRACING__ \
90+
-D__KERNEL__ \
91+
-D__TARGET_ARCH_$(LINUX_ARCH) \
92+
-I $(LIBBPF_HEADERS)/bpf \
93+
-I $(BPF_HEADERS) \
94+
-Wno-address-of-packed-member \
95+
-Wno-compare-distinct-pointer-types \
96+
-Wno-deprecated-declarations \
97+
-Wno-gnu-variable-sized-type-not-at-end \
98+
-Wno-pointer-sign \
99+
-Wno-pragma-once-outside-header \
100+
-Wno-unknown-warning-option \
101+
-Wno-unused-value \
102+
-Wdate-time \
103+
-Wunused \
104+
-Wall \
105+
-fno-stack-protector \
106+
-fno-jump-tables \
107+
-fno-unwind-tables \
108+
-fno-asynchronous-unwind-tables \
109+
-xc \
110+
-nostdinc \
111+
-target bpf \
112+
-O2 -emit-llvm -c -g $< -o $(@:.o=.ll)
113+
$(CMD_LLC) -march=bpf -filetype=obj -o $@ $(@:.o=.ll)
114+
rm $(@:.o=.ll)
115+
116+
$(VMLINUX):
117+
bpftool btf dump file /sys/kernel/btf/vmlinux format c > $@

0 commit comments

Comments
 (0)