오류코드

NFO: Analyzed target //:rr_agent (0 packages loaded, 5 targets configured).
INFO: Found 1 target...
ERROR: /home/kbh/dream/ghost-userspace/BUILD:878:17: Compiling lib/enclave.cc failed: (Exit 1): gcc failed: error executing command /usr/bin/gcc -U_FORTIFY_SOURCE -fstack-protector -Wall -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer -g0 -O2 '-D_FORTIFY_SOURCE=1' -DNDEBUG -ffunction-sections ... (remaining 27 arguments skipped)

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
In file included from ./bpf/user/agent.h:12,
                 from lib/enclave.cc:18:
bazel-out/k8-opt/bin/external/linux/libbpf/include/libbpf/bpf.h:244:6: error: use of enum 'bpf_stats_type' without previous declaration
  244 | enum bpf_stats_type; /* defined in up-to-date linux/bpf.h */
      |      ^~~~
bazel-out/k8-opt/bin/external/linux/libbpf/include/libbpf/bpf.h:245:38: error: use of enum 'bpf_stats_type' without previous declaration
  245 | LIBBPF_API int bpf_enable_stats(enum bpf_stats_type type);
      |                                      ^~~~
Target //:rr_agent failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 18.796s, Critical Path: 15.09s
INFO: 19 processes: 8 internal, 11 linux-sandbox.
FAILED: Build did NOT complete successfully

libbpf가 bpf_stats_typelinux/bpf.h에서 가져오려 했는데, 해당 enum이 없다는 의미입니다. bpf_stats_typeLinux 5.8부터 커널 UAPI 헤더에 추가된 enum입니다.

이 줄이 ghost 커널(5.11)의 UAPI 헤더를 /usr에 설치합니다. 이 단계를 거치면 /usr/include/linux/bpf.h가 ghost 커널 기준으로 교체되어 bpf_stats_type이 정의된 상태가 됩니다.

직접 커널을 컴파일할 때 이 단계를 빠뜨렸다면:

상황 결과
make headers_install 실행 O /usr/include/linux/bpf.h → ghost 커널 5.11 기준, bpf_stats_type 존재
make headers_install 실행 X 시스템 기본 커널 헤더 사용 → 구버전이면 bpf_stats_type 없음 → 이 오류 발생

libbpf/bpf.h:244: enum bpf_stats_type; /* defined in up-to-date linux/bpf.h */ 흐름을 보면:

ghost userspace 코드 └─ libbpf (external/linux 번들) └─ bpf_stats_type enum이 필요 └─ /usr/include/linux/bpf.h (UAPI 헤더) 에서 찾음 └─ 시스템 기본 헤더가 구버전 → enum 없음 → 오류 make headers_install INSTALL_HDR_PATH=/usr을 실행하면:

ghost 커널 소스 (5.11) └─ include/uapi/linux/bpf.h (bpf_stats_type 정의됨) └─ /usr/include/linux/bpf.h 로 복사 └─ libbpf가 정상적으로 참조 → 빌드 성공