Skip to content

Commit

Permalink
package/go: disable stack protector for cgo
Browse files Browse the repository at this point in the history
Enabling the C stack protector for Cgo causes a build failure on i386:

runtime/cgo(.text): unknown symbol __stack_chk_fail_local in pcrel
runtime/cgo(.text): unknown symbol __stack_chk_fail_local in pcrel
runtime/cgo(.text): unknown symbol __stack_chk_fail_local in pcrel
runtime/cgo(.text): unknown symbol __stack_chk_fail_local in pcrel
runtime/cgo(.text): unknown symbol __stack_chk_fail_local in pcrel
runtime/cgo(.text): relocation target __stack_chk_fail_local not defined
runtime/cgo(.text): relocation target __stack_chk_fail_local not defined

Add: CGO_CFLAGS=-fno-stack-protector

golang/go#52919

Set CGO_CFLAGS and other flags while building Go with make.bash as well.

Signed-off-by: Christian Stewart <[email protected]>
  • Loading branch information
paralin committed Nov 6, 2022
1 parent ced3521 commit 896a791
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions package/go/go.mk
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ else ifeq ($(BR2_aarch64),y)
GO_GOARCH = arm64
else ifeq ($(BR2_i386),y)
GO_GOARCH = 386
# stack-protector causes a build failure on i386.
HOST_GO_CGO_CFLAGS += -fno-stack-protector
# i386: use softfloat if no SSE2: https://golang.org/doc/go1.16#386
ifneq ($(BR2_X86_CPU_HAS_SSE2),y)
GO_GO386 = softfloat
Expand Down Expand Up @@ -77,7 +79,7 @@ HOST_GO_TARGET_ENV = \
GOCACHE="$(HOST_GO_TARGET_CACHE)" \
CC="$(TARGET_CC)" \
CXX="$(TARGET_CXX)" \
CGO_CFLAGS="$(TARGET_CFLAGS)" \
CGO_CFLAGS="$(TARGET_CFLAGS) $(HOST_GO_CGO_CFLAGS)" \
CGO_CXXFLAGS="$(TARGET_CXXFLAGS)" \
CGO_LDFLAGS="$(TARGET_LDFLAGS)" \
GOTOOLDIR="$(HOST_GO_TOOLDIR)"
Expand Down Expand Up @@ -113,14 +115,15 @@ HOST_GO_DEPENDENCIES += toolchain
endif

# For the convenience of host golang packages
# stack-protector causes a build failure on some architectures.
HOST_GO_HOST_ENV = \
$(HOST_GO_COMMON_ENV) \
GOOS="" \
GOARCH="" \
GOCACHE="$(HOST_GO_HOST_CACHE)" \
CC="$(HOSTCC_NOCCACHE)" \
CXX="$(HOSTCXX_NOCCACHE)" \
CGO_CFLAGS="$(HOST_CFLAGS)" \
CGO_CFLAGS="$(HOST_CFLAGS) $(HOST_GO_CGO_CFLAGS)" \
CGO_CXXFLAGS="$(HOST_CXXFLAGS)" \
CGO_LDFLAGS="$(HOST_LDFLAGS)"

Expand All @@ -136,6 +139,9 @@ HOST_GO_MAKE_ENV = \
CC=$(HOSTCC_NOCCACHE) \
CXX=$(HOSTCXX_NOCCACHE) \
CGO_ENABLED=$(HOST_GO_CGO_ENABLED) \
CGO_CFLAGS="$(HOST_CFLAGS) $(HOST_GO_CGO_CFLAGS)" \
CGO_CXXFLAGS="$(HOST_CXXFLAGS)" \
CGO_LDFLAGS="$(HOST_LDFLAGS)" \
$(HOST_GO_CROSS_ENV)

# Use the Go compiler bootstrapped by Buildroot if available.
Expand Down

0 comments on commit 896a791

Please sign in to comment.