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: unresolvable R_RISCV_HI20 relocation against symbol `stderr@@GLIBC_2.27' #70076

Open
BoyaoWang430 opened this issue Oct 28, 2024 · 5 comments
Labels
arch-riscv Issues solely affecting the riscv64 architecture. 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

@BoyaoWang430
Copy link

BoyaoWang430 commented Oct 28, 2024

Go version

1.23.2 linux amd64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='riscv64'
GOBIN=''
GOCACHE='/workspace/build/.cache/go-build'
GOENV='/root/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/workspace/build/pkg/mod'
GOOS='linux'
GOPATH='/workspace/build'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/workspace/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/workspace/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.23.2'
GODEBUG=''
GOTELEMETRY='local'
GOTELEMETRYDIR='/root/.config/go/telemetry'
GCCGO='gccgo'
GORISCV64='rva20u64'
AR='riscv64-unknown-linux-gnu-ar'
CC='riscv64-unknown-linux-gnu-gcc'
CXX='riscv64-unknown-linux-gnu-g++'
CGO_ENABLED='1'
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 -pthread -fmessage-length=0 -ffile-prefix-map=/workspace/tmp/go-build4021815613=/tmp/go-build -gno-record-gcc-switches'

What did you do?

I was compiling a large Go project, which includes cgo and has a Go cache size of approximately 15GB. Target arch is RISCV64. When linker called ld, there’s an issue related to glibc symbols.

What did you see happen?

/workspace/go/pkg/tool/linux_amd64/link: running riscv64-unknown-linux-gnu-g++ failed: exit status 1
/usr/local/bin/riscv64-unknown-linux-gnu-g++ -Wl,-z,now -Wl,-z,nocopyreloc -o $WORK/b001/exe/a.out -rdynamic -Wl,--compress-debug-sections=zlib /workspace/tmp/go-link-3293404590/go.o /workspace/tmp/go-link-3293404590/000000.o /workspace/tmp/go-link-3293404590/000001.o /workspace/tmp/go-link-3293404590/000002.o /workspace/tmp/go-link-3293404590/000003.o /workspace/tmp/go-link-3293404590/000004.o /workspace/tmp/go-link-3293404590/000005.o /workspace/tmp/go-link-3293404590/000006.o /workspace/tmp/go-link-3293404590/000007.o /workspace/tmp/go-link-3293404590/000008.o /workspace/tmp/go-link-3293404590/000009.o /workspace/tmp/go-link-3293404590/000010.o /workspace/tmp/go-link-3293404590/000011.o /workspace/tmp/go-link-3293404590/000012.o /workspace/tmp/go-link-3293404590/000013.o /workspace/tmp/go-link-3293404590/000014.o /workspace/tmp/go-link-3293404590/000015.o /workspace/tmp/go-link-3293404590/000016.o /workspace/tmp/go-link-3293404590/000017.o /workspace/tmp/go-link-3293404590/000018.o /workspace/tmp/go-link-3293404590/000019.o /workspace/tmp/go-link-3293404590/000020.o /workspace/tmp/go-link-3293404590/000021.o /workspace/tmp/go-link-3293404590/000022.o /workspace/tmp/go-link-3293404590/000023.o /workspace/tmp/go-link-3293404590/000024.o /workspace/tmp/go-link-3293404590/000025.o /workspace/tmp/go-link-3293404590/000026.o /workspace/tmp/go-link-3293404590/000027.o /workspace/tmp/go-link-3293404590/000028.o /workspace/tmp/go-link-3293404590/000029.o /workspace/tmp/go-link-3293404590/000030.o /workspace/tmp/go-link-3293404590/000031.o /workspace/tmp/go-link-3293404590/000032.o /workspace/tmp/go-link-3293404590/000033.o /workspace/tmp/go-link-3293404590/000034.o /workspace/tmp/go-link-3293404590/000035.o /workspace/tmp/go-link-3293404590/000036.o /workspace/tmp/go-link-3293404590/000037.o /workspace/tmp/go-link-3293404590/000038.o /workspace/tmp/go-link-3293404590/000039.o /workspace/tmp/go-link-3293404590/000040.o /workspace/tmp/go-link-3293404590/000041.o /workspace/tmp/go-link-3293404590/000042.o /workspace/tmp/go-link-3293404590/000043.o /workspace/tmp/go-link-3293404590/000044.o /workspace/tmp/go-link-3293404590/000045.o /workspace/tmp/go-link-3293404590/000046.o /workspace/tmp/go-link-3293404590/000047.o /workspace/tmp/go-link-3293404590/000048.o /workspace/tmp/go-link-3293404590/000049.o /workspace/tmp/go-link-3293404590/000050.o /workspace/tmp/go-link-3293404590/000051.o /workspace/tmp/go-link-3293404590/000052.o /workspace/tmp/go-link-3293404590/000053.o /workspace/tmp/go-link-3293404590/000054.o -O2 -g --sysroot=/usr/local/sysroot -lresolv -O2 -g --sysroot=/usr/local/sysroot -O2 -g --sysroot=/usr/local/sysroot -ldl -O2 -g --sysroot=/usr/local/sysroot -lpthread -O2 -g --sysroot=/usr/local/sysroot -O2 -g --sysroot=/usr/local/sysroot -O2 -g --sysroot=/usr/local/sysroot -ldl -ldl -O2 -g --sysroot=/usr/local/sysroot -ldl -O2 -g --sysroot=/usr/local/sysroot /workspace/build/pkg/mod/code.byted.org/iesarch/gozstd@v1.17.4/libzstd_linux_riscv64.a -no-pie
/usr/local/lib/gcc/riscv64-unknown-linux-gnu/13.2.1/../../../../riscv64-unknown-linux-gnu/bin/ld: unresolvable R_RISCV_HI20 relocation against symbol stderr@@GLIBC_2.27' /usr/local/lib/gcc/riscv64-unknown-linux-gnu/13.2.1/../../../../riscv64-unknown-linux-gnu/bin/ld: unresolvable R_RISCV_HI20 relocation against symbol stderr@@GLIBC_2.27'
/usr/local/lib/gcc/riscv64-unknown-linux-gnu/13.2.1/../../../../riscv64-unknown-linux-gnu/bin/ld: unresolvable R_RISCV_HI20 relocation against symbol `stderr@@GLIBC_2.27'
collect2: error: ld returned 1 exit status

What did you expect to see?

Maybe Go generated an incorrect relocation type for the symbol reference to stderr.

@BoyaoWang430 BoyaoWang430 changed the title RISCV: unresolvable R_RISCV_HI20 relocation against symbol `stderr@@GLIBC_2.27' cmd/link: unresolvable R_RISCV_HI20 relocation against symbol `stderr@@GLIBC_2.27' Oct 28, 2024
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Oct 28, 2024
@seankhliao seankhliao added the arch-riscv Issues solely affecting the riscv64 architecture. label Oct 28, 2024
@mengzhuo
Copy link
Contributor

It looks like a mis-configuration on cross compile environment. that glibc didn't contains stderr@@GLIBC_2.27

@BoyaoWang430
Copy link
Author

It looks like a mis-configuration on cross compile environment. that glibc didn't contains stderr@@GLIBC_2.27

I can find the symbol stderr@@GLIBC_2.27 in my RISCV libc.so.
`file /usr/local/sysroot/lib/libc.so.6

/usr/local/sysroot/lib/libc.so.6: ELF 64-bit LSB pie executable, UCB RISC-V, version 1 (GNU/Linux), dynamically linked, interpreter /lib/ld-linux-riscv64-lp64d.so.1, for GNU/Linux 4.15.0, with debug_info, not stripped

readelf -s /usr/local/sysroot/lib/libc.so.6 | grep stderr

146: 000000000014c398 224 OBJECT GLOBAL DEFAULT 29 IO_2_1_stderr@@GLIBC_2.27

1771: 000000000014c558 8 OBJECT GLOBAL DEFAULT 29 stderr@@GLIBC_2.27

9353: 000000000014c398 224 OBJECT GLOBAL DEFAULT 29 IO_2_1_stderr

9538: 000000000014c558 8 OBJECT GLOBAL DEFAULT 29 stderr`

@BoyaoWang430
Copy link
Author

After I removed the option " -Wl,-z,nocopyreloc" added by golang in src/cmd/link/internal/ld/lib.go:1654, I can successfully link the file now.

      if ctxt.IsELF && ctxt.DynlinkingGo() {
            // Do not let the host linker generate COPY relocations. These
            // can move symbols out of sections that rely on stable offsets
            // from the beginning of the section (like sym.STYPE).
            argv = append(argv, "-Wl,-z,nocopyreloc")

@mknyszek
Copy link
Contributor

CC @golang/riscv64

@mknyszek mknyszek added this to the Backlog milestone Oct 30, 2024
@mknyszek mknyszek added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arch-riscv Issues solely affecting the riscv64 architecture. 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
Development

No branches or pull requests

6 participants