Skip to content

Commit

Permalink
[v15] build: Build mac arm64 binaries with -extldflags=-ld_classic (#…
Browse files Browse the repository at this point in the history
…42736)

* [v15] build: Factor Go LDFLAGS into own make variable

Factor out the Go LDFLAGS (the argument to `-ldflags`) into a separate
`GO_LDFLAGS` variable so that it can be extended conditionally for
certain build scenarios.

* [v15] build: Set arm ldflags via GO_LDFLAGS

Set the arm-specific ldflags via the new `GO_LDFLAGS` var that was added
in 265b58c instead of overriding `BUILDFLAGS`. Without this, the arm
ldflags were being overridden when building teleport on CI as that needs
to set extra ldflags for the community-licensed build.

* [v15] build: Build mac arm64 binaries with -extldflags=-ld_classic

Add the flag `-extldflags=-ld_classic` to the Go build command line when
building the teleport binaries. This is needed to get around a new issue
with the xcode linker on macOS when building enterprise `build/teleport`
emitting the error:

    ld: B/BL out of range -153903124 (max +/-128MB) to '_runtime.memequal'

This change has not been added to the enterprise makefile as the vars
are propagated when we build enterprise from the OSS makefile.
  • Loading branch information
camscale committed Jun 11, 2024
1 parent 83cc934 commit a4da066
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,14 @@ CGOFLAG ?= CGO_ENABLED=1
# should be an absolute directory as it is used by e/Makefile too, from the e/ directory.
RELEASE_DIR := $(CURDIR)/$(BUILDDIR)/artifacts

GO_LDFLAGS ?= -w -s $(KUBECTL_SETVERSION)

# When TELEPORT_DEBUG is true, set flags to produce
# debugger-friendly builds.
ifeq ("$(TELEPORT_DEBUG)","true")
BUILDFLAGS ?= $(ADDFLAGS) -gcflags=all="-N -l"
else
BUILDFLAGS ?= $(ADDFLAGS) -ldflags '-w -s $(KUBECTL_SETVERSION)' -trimpath -buildmode=pie
BUILDFLAGS ?= $(ADDFLAGS) -ldflags '$(GO_LDFLAGS)' -trimpath -buildmode=pie
endif

GO_ENV_OS := $(shell go env GOOS)
Expand Down Expand Up @@ -246,10 +248,17 @@ CC=arm-linux-gnueabihf-gcc
endif

# Add -debugtramp=2 to work around 24 bit CALL/JMP instruction offset.
BUILDFLAGS = $(ADDFLAGS) -ldflags '-extldflags "-Wl,--long-plt" -w -s -debugtramp=2 $(KUBECTL_SETVERSION)' -trimpath -buildmode=pie
# Add "-extldflags -Wl,--long-plt" to avoid ld assertion failure on large binaries
GO_LDFLAGS += -extldflags=-Wl,--long-plt -debugtramp=2
endif
endif # OS == linux

ifeq ("$(OS)-$(ARCH)","darwin-arm64")
# Temporary link flags due to changes in Apple's linker
# https://github.com/golang/go/issues/67854
GO_LDFLAGS += -extldflags=-ld_classic
endif

# Windows requires extra parameters to cross-compile with CGO.
ifeq ("$(OS)","windows")
ARCH ?= amd64
Expand Down

0 comments on commit a4da066

Please sign in to comment.