Skip to content

[Query] What's reason behind compiling bpf kernel code with -D__TARGET_ARCH_x86 #347

@nalreddy

Description

@nalreddy

I noticed that while compiling the BPF kernel code, the target architecture is set to x86.
Is there a specific reason for using x86 instead of x86_64? Understanding this would be helpful.

from https://github.com/libbpf/libbpf-bootstrap

libbpf-bootstrap/examples/c/Makefile

ARCH ?= $(shell uname -m | sed 's/x86_64/x86/'
| sed 's/arm./arm/'
| sed 's/aarch64/arm64/'
| sed 's/ppc64le/powerpc/'
| sed 's/mips.
/mips/'
| sed 's/riscv64/riscv/'
| sed 's/loongarch64/loongarch/')

# Build BPF code
$(OUTPUT)/%.bpf.o: %.bpf.c $(LIBBPF_OBJ) $(wildcard %.h) $(VMLINUX) | $(OUTPUT) $(BPFTOOL)
$(call msg,BPF,$@)
$(Q)$(CLANG) -g -O2 -target bpf -D__TARGET_ARCH_$(ARCH)
$(INCLUDES) $(CLANG_BPF_SYS_INCLUDES)
-c $(filter %.c,$^) -o $(patsubst %.bpf.o,%.tmp.bpf.o,$@)
$(Q)$(BPFTOOL) gen object $@ $(patsubst %.bpf.o,%.tmp.bpf.o,$@)

or
ARCH := $(subst x86_64,x86,$(shell arch))

clang -g -O2 -target bpf -D__TARGET_ARCH_$(ARCH) $(INCLUDES) -c $(SRC_DIR)/tracer.bpf.c -o $(SRC_DIR)/tracer.bpf.o

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions