Skip to content
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

cmd/link: unexpected R_386_GOT32 relocation #71293

Open
dbenoit17 opened this issue Jan 16, 2025 · 1 comment
Open

cmd/link: unexpected R_386_GOT32 relocation #71293

dbenoit17 opened this issue Jan 16, 2025 · 1 comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@dbenoit17
Copy link

dbenoit17 commented Jan 16, 2025

Go version

go version go1.23.4 linux/386

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='386'
GOBIN=''
GOCACHE='/builddir/.cache/go-build'
GOENV='/builddir/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='386'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/builddir/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/builddir/go'
GOPRIVATE=''
GOPROXY='direct'
GOROOT='/usr/lib/golang'
GOSUMDB='off'
GOTMPDIR=''
GOTOOLCHAIN='local'
GOTOOLDIR='/usr/lib/golang/pkg/tool/linux_386'
GOVCS=''
GOVERSION='go1.23.4'
GODEBUG=''
GOTELEMETRY='local'
GOTELEMETRYDIR='/builddir/.config/go/telemetry'
GCCGO='gccgo'
GO386='sse2'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/dev/null'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m32 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build3544270386=/tmp/go-build -gno-record-gcc-switches'

What did you do?

Compile the following program using GCC 15.0.1.

sh-5.2# gcc --version
gcc (GCC) 15.0.1 20250114 (Red Hat 15.0.1-0)

sh-5.2# cat test.go
package main

/*
extern void crosscall2 (void (*fn) (void *, int), void *, int);
extern void _cgo_panic (void *, int);
extern void _cgo_allocate (void *, int);

void
callPanic (void)
{
	  struct { const char *p; } a;
	  a.p = "panic from C";
	  crosscall2 (_cgo_panic, &a, sizeof a);
	  *(int*) 1 = 1;
}
*/
import "C"

func main() {
	C.callPanic()
}

sh-5.2# CGO_CFLAGS="-O2 -m32 -fpic" go build -ldflags "-linkmode internal" test.go 

This issue is also present when running go tool dist test -run=^cmd/cgo/internal/test:internal$ using GCC 15.0.1.

What did you see happen?

The Go linker encounters an unexpected relocation in GCC emitted object code.

sh-5.2# CGO_CFLAGS="-O2 -m32 -fpic" go build -ldflags "-linkmode internal" test.go 
# command-line-arguments
main(.text): unexpected GOT reloc for non-dynamic symbol _cgo_panic
main(.text): unsupported dynamic relocation for symbol _cgo_panic (type=259 (R_386_GOT32) stype=1 (STEXT))

The linker is expecting to find the instruction pushl _cgo_panic@GOT(%ebx), but instead encounters pushl _cgo_panic@GOT(%eax). According to gcc devs, this is valid (though sub optimal) code that the Go linker should handle.

What did you expect to see?

The example program should build and link correctly.

@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Jan 16, 2025
@mknyszek
Copy link
Contributor

CC @golang/compiler

@mknyszek mknyszek added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jan 16, 2025
@mknyszek mknyszek added this to the Backlog milestone Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. 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

3 participants