build_linux.sh 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. # 遍历所有参数
  2. for arg in "$@"
  3. do
  4. # 分割参数名和值
  5. key="${arg%%=*}"
  6. value="${arg#*=}"
  7. # 检查参数名并根据需要处理参数值
  8. case "$key" in
  9. pid)
  10. pid="$value"
  11. ;;
  12. debug)
  13. debug="$value"
  14. ;;
  15. *)
  16. echo "Unknown parameter: $key"
  17. ;;
  18. esac
  19. done
  20. # 打印解析的参数值
  21. echo "pid: $pid"
  22. echo "debug: $debug"
  23. #clang -isystem/usr/src/linux-headers-5.15.0-89-generic/arch/x86/include -isystem/usr/src/linux-headers-5.15.0-89-generic/arch/x86/include/generated -isystem/usr/src/linux-headers-5.15.0-89-generic/include -isystem/usr/src/linux-headers-5.15.0-89-generic/arch/x86/include/uapi -isystem/usr/src/linux-headers-5.15.0-89-generic/arch/x86/include/generated/uapi -isystem/usr/src/linux-headers-5.15.0-89-generic/include/uapi -isystem/usr/src/linux-headers-5.15.0-89-generic/include/generated/uapi -include linux/kconfig.h -I./ebpf/c/common -include asm_goto_workaround.h -D__KERNEL__ -D__BPF_TRACING__ "" -fno-stack-protector -g -Wno-unused-value -Wno-pointer-sign -Wno-compare-distinct-pointer-types -Wno-gnu-variable-sized-type-not-at-end -Wno-address-of-packed-member -Wno-tautological-compare -Wno-unknown-warning-option -O2 -target bpf -D__KERNEL_FROM=512 -D__TARGET_ARCH_x86 -c ./ebpf/ebpf.c -o ./ebpf512x86.o
  24. #clang -isystem/usr/src/linux-headers-5.15.0-89-generic/arch/x86/include -isystem/usr/src/linux-headers-5.15.0-89-generic/arch/x86/include/generated -isystem/usr/src/linux-headers-5.15.0-89-generic/include -isystem/usr/src/linux-headers-5.15.0-89-generic/arch/x86/include/uapi -isystem/usr/src/linux-headers-5.15.0-89-generic/arch/x86/include/generated/uapi -isystem/usr/src/linux-headers-5.15.0-89-generic/include/uapi -isystem/usr/src/linux-headers-5.15.0-89-generic/include/generated/uapi -include linux/kconfig.h -g -O2 -target bpf -D__KERNEL_FROM=512 -D__TARGET_ARCH_x86 -c ./ebpf/ebpf.c -o ebpf512x86.o
  25. #clang -g -O2 -target bpf -D__KERNEL_FROM=512 -D__TARGET_ARCH_x86 -D__x86_64__ $debug $TAG -c ./ebpf/ebpf.c -o ebpf512x86.o && llvm-strip --strip-debug ebpf512x86.o
  26. #llvm-strip --strip-debug ./ebpf512x86.o
  27. #chown 501:dialout ./ebpf512x86.o
  28. /usr/bin/clang -I. -Ivmlinux -Iinclude -Iebpf/include -Iebpf/utrace/go/include -Iebpf/utrace/java/include -D__BPF_TRACING__ -D GROUP_LEADER_OFFSET_OVERRIDE=0 -DSTART_BOOTTIME_OFFSET_OVERRIDE=0 -DSTART_BOOTTIME_VARNAME=real_start_time -std=gnu99 -Wimplicit-function-declaration \
  29. -ffreestanding -fno-builtin -Wall \
  30. -Wno-deprecated-declarations \
  31. -Wno-gnu-variable-sized-type-not-at-end \
  32. -Wno-pragma-once-outside-header \
  33. -Wno-address-of-packed-member \
  34. -Wno-unknown-warning-option \
  35. -fno-color-diagnostics \
  36. -fno-unwind-tables \
  37. -fno-stack-protector \
  38. -fno-asynchronous-unwind-tables -g -O2 -emit-llvm -D__KERNEL_FROM=416 -D__TARGET_ARCH_arm64 -D__aarch64__ -D__AARCH64EB__ $debug -o ebpf.ll -c ./ebpf/ebpf.c && /usr/bin/llc -march=bpf -filetype=obj -mcpu=v2 -o ebpf.elf ebpf.ll
  39. /usr/bin/llvm-strip -g ebpf.elf && mv ebpf.elf ebpf416arm64.o
  40. echo -en '// generated - do not edit\npackage ebpftracer\n\nvar ebpfProg = map[string][]struct {\n' > ebpf.go \
  41. && echo -en '\tv string\n' >> ebpf.go \
  42. && echo -en '\tp []byte\n' >> ebpf.go \
  43. && echo -en '}{\n' >> ebpf.go \
  44. && echo -en '\t"amd64": {\n' >> ebpf.go \
  45. && echo -en '\t\t{"v4.16", []byte("' >> ebpf.go && hexdump -v -e '"\\\x" 1/1 "%02x"' ebpf416arm64.o >> ebpf.go && echo '")},' >> ebpf.go \
  46. && echo -en '\t},\n'>> ebpf.go \
  47. && echo -en '\t"arm64": {\n' >> ebpf.go \
  48. && echo -en '\t\t{"v4.16", []byte("' >> ebpf.go && hexdump -v -e '"\\\x" 1/1 "%02x"' ebpf416arm64.o >> ebpf.go && echo '")},' >> ebpf.go \
  49. && echo -en '\t},\n'>> ebpf.go \
  50. && echo -en '}\n'>> ebpf.go
  51. if [ $? -ne 0 ]; then
  52. echo "error!"
  53. exit 1
  54. fi
  55. echo "success!"
  56. #apk add bcc-dev
  57. #apk add musl-dev