Skip to content

Commit

Permalink
pkg/proc: add build scripts & docker image for ebpf (go-delve#2847)
Browse files Browse the repository at this point in the history
Adds a few build scripts and a container image for reproducible builds
of the ebpf programs.
  • Loading branch information
derekparker authored Dec 30, 2021
1 parent 3841099 commit a88c9bd
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 2 deletions.
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.DEFAULT_GOAL=test

SHELL := /bin/bash
GO_SRC := $(shell find . -type f -not -path './_fixtures/*' -not -path './vendor/*' -not -path './_scripts/*' -not -path './localtests/*' -name '*.go')

check-cert:
Expand Down Expand Up @@ -29,4 +30,10 @@ test-integration-run:
vendor:
@go run _scripts/make.go vendor

.PHONY: vendor test-integration-run test-proc-run test check-cert install build vet uninstall
build-ebpf-image:
./pkg/proc/internal/ebpf/build/build-ebpf-builder-img.sh

build-ebpf-object: build-ebpf-image
./pkg/proc/internal/ebpf/build/build-ebpf-objects.sh

.PHONY: vendor test-integration-run test-proc-run test check-cert install build vet uninstall build-ebpf-image build-ebpf-object
1 change: 0 additions & 1 deletion cmd/dlv/dlv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ func getDlvBin(t *testing.T) (string, string) {
}

func getDlvBinEBPF(t *testing.T) (string, string) {
os.Setenv("CGO_LDFLAGS", "/usr/lib/libbpf.a")
return getDlvBinInternal(t, "-tags", "ebpf")
}

Expand Down
5 changes: 5 additions & 0 deletions pkg/proc/internal/ebpf/build/build-ebpf-builder-img.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash -e

sudo docker build \
-t delve-ebpf-builder:v0.0.1 \
-f pkg/proc/internal/ebpf/build/ebpf-Dockerfile ./pkg/proc/internal/ebpf/build
17 changes: 17 additions & 0 deletions pkg/proc/internal/ebpf/build/build-ebpf-objects.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash -e

# The go generate command seems to not like being run from
# the vendor directory. Remove it and restore it after.
rm -rf vendor

restore_vendor() {
git checkout vendor
}

trap restore_vendor EXIT

docker run \
-it \
--rm \
-v "$(pwd)":/delve-bpf \
delve-ebpf-builder:v0.0.1
19 changes: 19 additions & 0 deletions pkg/proc/internal/ebpf/build/ebpf-Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM ubuntu:21.04

ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && apt-get install -y \
build-essential \
gcc-multilib \
git \
wget \
clang \
linux-headers-5.11.0-40 \
libbpf-dev

RUN wget https://golang.org/dl/go1.17.3.linux-amd64.tar.gz
RUN tar -C /usr/local -xzf go1.17.3.linux-amd64.tar.gz
RUN cp /usr/local/go/bin/go /usr/bin/go

WORKDIR /delve-bpf/pkg/proc/internal/ebpf/

CMD [ "go", "generate", "./..." ]
Binary file modified pkg/proc/internal/ebpf/trace_bpfel_x86.o
Binary file not shown.

0 comments on commit a88c9bd

Please sign in to comment.