Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
anuraaga opened this issue Oct 24, 2024 · 4 comments
Closed

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

anuraaga opened this issue Oct 24, 2024 · 4 comments
Labels
GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@anuraaga
Copy link
Contributor

anuraaga commented Oct 24, 2024

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.

@anuraaga anuraaga changed the title cmd/go: unsupported ld flags with ubuntu 24.10 cmd/go: unsupported ld flags with ubuntu 24.10 building libre2-dev with cgo Oct 24, 2024
@seankhliao seankhliao changed the title cmd/go: unsupported ld flags with ubuntu 24.10 building libre2-dev with cgo cmd/go: allow linker flag -Wl,--push-state,--as-needed Oct 24, 2024
@ianlancetaylor
Copy link
Contributor

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

@gopherbot
Copy link
Contributor

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

@cagedmantis cagedmantis added GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Oct 28, 2024
@cagedmantis cagedmantis added this to the Go1.24 milestone Oct 28, 2024
@cagedmantis
Copy link
Contributor

cc @matloob @samthanawalla

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

5 participants