diff options
author | Bob Van Landuyt <bob@vanlanduyt.co> | 2022-01-25 17:38:22 +0300 |
---|---|---|
committer | Bob Van Landuyt <bob@vanlanduyt.co> | 2022-01-26 22:11:12 +0300 |
commit | 783ec4e5328ac4106fc1f1e931e5fde7c9bc95af (patch) | |
tree | fa1947074355d21f72ef97fa8f5c033f573623a5 /Makefile.build.mk | |
parent | 58a67cf0f0152a87b4944c92c701be602ac33c2e (diff) |
Add a Gnu build-id to gitlab-pages binary
By default go binaries only include a Go build-id. Which is
deterministic and unique.
They don't include a Gnu build-id that should have the same
properties.
The Gnu build-id is used by several observably tools including
perf. Having a Gnu build-id allow these tools to uniquely identify a
binary and avoid conflicts when resolving debug symbols for those
binaries.
We're generating a Gnu build-id from the Go build-id, that way we're
sure to also have a deterministic and unique build-id. We do this by
compiling the binary once, getting the Go build-id from that, and then
re-building including a Gnu build-id.
Diffstat (limited to 'Makefile.build.mk')
-rw-r--r-- | Makefile.build.mk | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/Makefile.build.mk b/Makefile.build.mk index 562c9b86..cd765bb9 100644 --- a/Makefile.build.mk +++ b/Makefile.build.mk @@ -1,5 +1,12 @@ +BINDIR := $(CURDIR)/bin GO_BUILD_TAGS := continuous_profiler_stackdriver +# To compute a unique and deterministic value for GNU build-id, we build the Go binary a second time. +# From the first build, we extract its unique and deterministic Go build-id, and use that to derive +# a comparably unique and deterministic GNU build-id to inject into the final binary. +## Skip generation of the GNU build ID if set to speed up builds. +WITHOUT_BUILD_ID ?= + .PHONY: all setup generate-mocks build clean all: gitlab-pages @@ -20,10 +27,15 @@ generate-mocks: .GOPATH/.ok $Q bin/mockgen -source=internal/mocks/api/client_stub.go -destination=internal/mocks/client.go -package=mocks build: .GOPATH/.ok - $Q GOBIN=$(CURDIR)/bin go install $(if $V,-v) $(VERSION_FLAGS) -tags "${GO_BUILD_TAGS}" -buildmode exe $(IMPORT_PATH) + $Q GOBIN=$(BINDIR) go install $(if $V,-v) -ldflags="$(VERSION_FLAGS)" -tags "${GO_BUILD_TAGS}" -buildmode exe $(IMPORT_PATH) +ifndef WITHOUT_BUILD_ID + GO_BUILD_ID=$$( go tool buildid $(BINDIR)/gitlab-pages ) && \ + GNU_BUILD_ID=$$( echo $$GO_BUILD_ID | sha1sum | cut -d' ' -f1 ) && \ + $Q GOBIN=$(BINDIR) go install $(if $V,-v) -ldflags="$(VERSION_FLAGS) -B 0x$$GNU_BUILD_ID" -tags "${GO_BUILD_TAGS}" -buildmode exe $(IMPORT_PATH) +endif clean: - $Q GOBIN=$(CURDIR)/bin go clean -i -modcache -x + $Q GOBIN=$(BINDIR) go clean -i -modcache -x gitlab-pages: build - $Q cp -f ./bin/gitlab-pages . + $Q cp -f $(BINDIR)/gitlab-pages . |