golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
123.71k stars 17.62k forks source link

cmd/go: allow linker flag -Wl,--push-state,--as-needed #70023

Open anuraaga opened 1 day ago

anuraaga commented 1 day ago

Go version

go1.23.2 linux/arm64

Output of go env in your module/workspace:

root@09f74314ef8f:/go-re2# go version
go version go1.23.2 linux/arm64
root@09f74314ef8f:/go-re2# go env
GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/root/.cache/go-build'
GOENV='/root/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/root/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/root/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/lib/go-1.23'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/lib/go-1.23/pkg/tool/linux_arm64'
GOVCS=''
GOVERSION='go1.23.2'
GODEBUG=''
GOTELEMETRY='local'
GOTELEMETRYDIR='/root/.config/go/telemetry'
GCCGO='gccgo'
GOARM64='v8.0'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/go-re2/go.mod'
GOWORK='/go-re2/go.work'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build3709859274=/tmp/go-build -gno-record-gcc-switches'

What did you do?

Try to compile https://github.com/wasilibs/go-re2 in cgo mode linking to ubuntu 24.10 provided libre2-dev, which works in other ubuntu versions.

docker run -it --rm ubuntu:24.10
apt install gcc libre2-dev git golang
git clone https://github.com/wasilibs/go-re2.git
cd go-re2
go test -tags=re2_cgo ./...

What did you see happen?

Failure with ld flag, which seems to be something new with the ubuntu 24.10 build chain / built packages.

root@09f74314ef8f:/go-re2# go test -tags=re2_cgo ./...
github.com/wasilibs/go-re2/internal/cre2: invalid flag in pkg-config --libs: -Wl,--push-state,--as-needed
FAIL    github.com/wasilibs/go-re2 [build failed]
FAIL    github.com/wasilibs/go-re2/experimental [build failed]
FAIL    github.com/wasilibs/go-re2/internal [build failed]
FAIL    github.com/wasilibs/go-re2/internal/cre2 [build failed]
FAIL
root@09f74314ef8f:/go-re2# pkg-config --libs re2

-pthread -lre2 -labsl_flags_internal -labsl_flags_marshalling -labsl_log_severity -labsl_flags_reflection -labsl_flags_private_handle_accessor -labsl_flags_commandlineflag -labsl_flags_commandlineflag_internal -labsl_flags_config -labsl_flags_program_name -labsl_raw_logging_internal -labsl_raw_logging_internal -labsl_cord -labsl_cordz_info -labsl_cord_internal -labsl_cordz_functions -labsl_cordz_handle -labsl_crc_cord_state -labsl_crc32c -labsl_crc_internal -labsl_crc_cpu_detect -labsl_raw_hash_set -labsl_hash -labsl_city -labsl_bad_variant_access -labsl_low_level_hash -labsl_hashtablez_sampler -labsl_exponential_biased -labsl_raw_logging_internal -labsl_bad_optional_access -labsl_str_format_internal -labsl_synchronization -labsl_graphcycles_internal -labsl_kernel_timeout_internal -labsl_stacktrace -labsl_symbolize -labsl_debugging_internal -labsl_demangle_internal -labsl_malloc_internal -labsl_time -labsl_civil_time -labsl_strings -labsl_string_view -labsl_strings_internal -labsl_base -Wl,--push-state,--as-needed -latomic -Wl,--pop-state -lrt -labsl_spinlock_wait -labsl_int128 -labsl_throw_delegate -labsl_raw_logging_internal -labsl_log_severity -labsl_time_zone

https://github.com/wasilibs/go-re2/blob/d9666878a10b4e2eee30a133fa4673c1e56ee1dd/internal/cre2/cre2_re2_cgo.go#L6

What did you expect to see?

Tests pass.

gabyhelp commented 1 day ago

Related Issues and Documentation

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

ianlancetaylor commented 11 hours ago

Until this is fixed, you should be able to build your program by setting CGO_LDFLAGS_ALLOW=-Wl,--push-state.* in the environment.

gopherbot commented 11 hours ago

Change https://go.dev/cl/622238 mentions this issue: cmd/go: permit linker flag -Wl,--push-state,--as-needed