Skip to content

Commit

Permalink
Fixes for arm64 (#158)
Browse files Browse the repository at this point in the history
This also creates a `GO` Make variable to make it easy to
override while trying golang binaries in non-standard paths
  • Loading branch information
javierhonduco committed May 3, 2022
1 parent fb3d682 commit 0850b8c
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 19 deletions.
12 changes: 6 additions & 6 deletions Makefile
Expand Up @@ -5,9 +5,9 @@ SELFTEST = ./selftest

CC = gcc
CLANG = clang
GO = go

ARCH := $(shell uname -m)
ARCH := $(subst x86_64,amd64,$(ARCH))
ARCH := $(shell uname -m | sed 's/x86_64/amd64/g; s/aarch64/arm64/g')

BTFFILE = /sys/kernel/btf/vmlinux
BPFTOOL = $(shell which bpftool || /bin/false)
Expand Down Expand Up @@ -55,13 +55,13 @@ libbpfgo-dynamic: $(OUTPUT)/libbpf
CC=$(CLANG) \
CGO_CFLAGS=$(CGO_CFLAGS_DYN) \
CGO_LDFLAGS=$(CGO_LDFLAGS_DYN) \
go build .
$(GO) build .

libbpfgo-dynamic-test: libbpfgo-test-bpf-dynamic
CC=$(CLANG) \
CGO_CFLAGS=$(CGO_CFLAGS_DYN) \
CGO_LDFLAGS=$(CGO_LDFLAGS_DYN) \
sudo -E go test .
sudo -E $(GO) test .

# libbpf: static

Expand All @@ -70,7 +70,7 @@ libbpfgo-static: $(VMLINUXH) | $(LIBBPF_OBJ)
CGO_CFLAGS=$(CGO_CFLAGS_STATIC) \
CGO_LDFLAGS=$(CGO_LDFLAGS_STATIC) \
GOOS=linux GOARCH=$(ARCH) \
go build \
$(GO) build \
-tags netgo -ldflags $(CGO_EXTLDFLAGS_STATIC) \
.

Expand All @@ -80,7 +80,7 @@ libbpfgo-static-test: libbpfgo-test-bpf-static
CGO_CFLAGS=$(CGO_CFLAGS_STATIC) \
CGO_LDFLAGS=$(CGO_LDFLAGS_STATIC) \
GOOS=linux GOARCH=$(ARCH) \
go test \
$(GO) test \
-v -tags netgo -ldflags $(CGO_EXTLDFLAGS_STATIC) \
.

Expand Down
3 changes: 2 additions & 1 deletion selftest/build/Makefile
Expand Up @@ -7,6 +7,7 @@ CLANG = clang

CFLAGS = -g -O2 -Wall -fpie
LDFLAGS =
ARCH := $(shell uname -m | sed 's/x86_64/amd64/g; s/aarch64/arm64/g')

TEST = libbpfgo_test

Expand All @@ -24,7 +25,7 @@ vmlinuxh: outputdir

$(TEST).bpf.o: $(TEST).bpf.c
$(MAKE) -C $(BASEDIR) vmlinuxh
$(CLANG) $(CFLAGS) -target bpf -I$(OUTPUT) -c $< -o $@
$(CLANG) $(CFLAGS) -target bpf -D__TARGET_ARCH_$(ARCH) -I$(OUTPUT) -c $< -o $@

## clean

Expand Down
10 changes: 5 additions & 5 deletions selftest/common/Makefile
Expand Up @@ -7,9 +7,9 @@ LIBBPF_OBJ = $(abspath $(OUTPUT)/libbpf.a)

CC = gcc
CLANG = clang
GO = go

ARCH := $(shell uname -m)
ARCH := $(subst x86_64,amd64,$(ARCH))
ARCH := $(shell uname -m | sed 's/x86_64/amd64/g; s/aarch64/arm64/g')

CFLAGS = -g -O2 -Wall -fpie
LDFLAGS =
Expand Down Expand Up @@ -51,7 +51,7 @@ outputdir:

$(TEST).bpf.o: $(TEST).bpf.c
$(MAKE) -C $(BASEDIR) vmlinuxh
$(CLANG) $(CFLAGS) -target bpf -I$(OUTPUT) -c $< -o $@
$(CLANG) $(CFLAGS) -target bpf -D__TARGET_ARCH_$(ARCH) -I$(OUTPUT) -c $< -o $@

## test

Expand All @@ -63,15 +63,15 @@ $(TEST)-static: libbpfgo-static | $(TEST).bpf.o
CGO_CFLAGS=$(CGO_CFLAGS_STATIC) \
CGO_LDFLAGS=$(CGO_LDFLAGS_STATIC) \
GOOS=linux GOARCH=$(ARCH) \
go build \
$(GO) build \
-tags netgo -ldflags $(CGO_EXTLDFLAGS_STATIC) \
-o $(TEST)-static ./$(TEST).go

$(TEST)-dynamic: libbpfgo-dynamic | $(TEST).bpf.o
CC=$(CLANG) \
CGO_CFLAGS=$(CGO_CFLAGS_DYN) \
CGO_LDFLAGS=$(CGO_LDFLAGS_DYN) \
go build -o ./$(TEST)-dynamic ./$(TEST).go
$(GO) build -o ./$(TEST)-dynamic ./$(TEST).go

## run

Expand Down
8 changes: 5 additions & 3 deletions selftest/tcpconnect/Makefile
Expand Up @@ -7,8 +7,10 @@ LIBBPF_OBJ = $(abspath $(OUTPUT)/libbpf.a)

CC = gcc
CLANG = clang
GO = go

ARCH := $(shell uname -m | sed 's/x86_64/amd64/g; s/aarch64/arm64/g')

ARCH = x86
GOARCH = amd64

BPFTOOL = $(shell which bpftool || /bin/false)
Expand Down Expand Up @@ -70,15 +72,15 @@ $(TEST)-static: libbpfgo-static | $(TEST).bpf.o
CGO_CFLAGS=$(CGO_CFLAGS_STATIC) \
CGO_LDFLAGS=$(CGO_LDFLAGS_STATIC) \
GOARCH=$(GOARCH) \
go build \
$(GO) build \
-tags netgo -ldflags $(CGO_EXTLDFLAGS_STATIC) \
-o $(TEST)-static ./$(TEST).go

$(TEST)-dynamic: libbpfgo-dynamic | $(TEST).bpf.o
CC=$(CLANG) \
CGO_CFLAGS=$(CGO_CFLAGS_DYN) \
CGO_LDFLAGS=$(CGO_LDFLAGS_DYN) \
go build -o ./$(TEST)-dynamic ./$(TEST).go
$(GO) build -o ./$(TEST)-dynamic ./$(TEST).go

## clean

Expand Down
9 changes: 5 additions & 4 deletions selftest/uprobe/Makefile
Expand Up @@ -10,6 +10,7 @@ CLANG = clang

CFLAGS = -g -O2 -Wall -fpie
LDFLAGS =
ARCH := $(shell uname -m | sed 's/x86_64/amd64/g; s/aarch64/arm64/g')

CGO_CFLAGS_STATIC = "-I$(abspath $(OUTPUT))"
CGO_LDFLAGS_STATIC = "-lelf -lz $(LIBBPF_OBJ)"
Expand Down Expand Up @@ -45,7 +46,7 @@ vmlinuxh:
.PHONY: $(TEST)-bpf

$(TEST)-bpf: vmlinuxh
$(CLANG) $(CFLAGS) -target bpf -I$(OUTPUT) -c $(TEST).bpf.c -o $(TEST).bpf.o
$(CLANG) $(CFLAGS) -target bpf -D__TARGET_ARCH_$(ARCH) -I$(OUTPUT) -c $(TEST).bpf.c -o $(TEST).bpf.o

## test deps

Expand All @@ -60,7 +61,7 @@ ctest:
.PHONY: gotest
gotest:
@if [ ! -x ctest ]; then \
go build -o gotest test.go; \
$(GO) build -o gotest test.go; \
fi

## test
Expand All @@ -70,11 +71,11 @@ gotest:

$(TEST)-static: $(TEST)-bpf libbpfgo-static $(DEPS)
CC=$(CLANG) CGO_CFLAGS=$(CGO_CFLAGS_STATIC) CGO_LDFLAGS=$(CGO_LDFLAGS_STATIC) \
go build -o $(TEST)-static ./$(TEST).go
$(GO) build -o $(TEST)-static ./$(TEST).go

$(TEST)-dynamic: $(TEST)-bpf libbpfgo-dynamic $(DEPS)
CC=$(CLANG) CGO_CFLAGS=$(CGO_CFLAGS_DYN) CGO_LDFLAGS=$(CGO_LDFLAGS_DYN) \
go build -o ./$(TEST)-dynamic ./$(TEST).go
$(GO) build -o ./$(TEST)-dynamic ./$(TEST).go

## run

Expand Down

0 comments on commit 0850b8c

Please sign in to comment.