8000 cmd/link: RISC-V mapping symbols aren't handled correctly · Issue #73591 · golang/go · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

cmd/link: RISC-V mapping symbols aren't handled correctly #73591

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
ziyao233 opened this issue May 3, 2025 · 3 comments · May be fixed by #73592
Closed

cmd/link: RISC-V mapping symbols aren't handled correctly #73591

ziyao233 opened this issue May 3, 2025 · 3 comments · May be fixed by #73592
Labels
arch-riscv Issues solely affecting the riscv64 architecture. BugReport Issues describing a possible bug in the Go implementation. compiler/runtime Issues related to the Go compiler and/or runtime.

Comments

@ziyao233
Copy link
ziyao233 commented May 3, 2025

Go version

go version go1.24.2 linux/riscv64

Output of go env in your module/workspace:

$ go env
AR='ar'
CC='/usr/bin/cc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='g++'
GCCGO='gccgo'
GO111MODULE=''
GOARCH='riscv64'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/home/ziyao/.cache/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/home/ziyao/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -pthread -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build1924204880=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='riscv64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='/dev/null'
GOMODCACHE='/home/ziyao/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/ziyao/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GORISCV64='rva20u64'
GOROOT='/usr/lib/go'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/home/ziyao/.config/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/lib/go/pkg/tool/linux_riscv64'
GOVCS=''
GOVERSION='go1.24.2'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

Build test.go,

package main                                                                                                                                                   
                                       
/*                                                                                                                                                             
#include <stdio.h>                     
#include <stdlib.h>                                                                                                                                            
*/                                     
import "C"                                                                                                                                                     
                                       
import "unsafe"                                                                                                                                                
                                       
func main() {                                                                                                                                                  
    cs := C.CString("Hello World")     
    C.puts(cs)                                                                                                                                                 
    C.free(unsafe.Pointer(cs))         
}                                                                                                                                                              

which makes use of CGO with Clang and Golang internal linker

CC=clang go build -ldflags '-linkmode internal' example.go

What did you see happen?

The file successfully compiles and the resulted binary runs correctly.

What did you expect to see?

# command-line-arguments                                                       
loadelf: $WORK/b001/_pkg_.a(_x001.o): 66084: sym#27 ("$d"): ignoring symbol in section 4 (".debug_loclists") (type 0)
loadelf: $WORK/b001/_pkg_.a(_x002.o): 66118: sym#33 ("$d"): ignoring symbol in section 4 (".debug_loclists") (type 0)
loadelf: $WORK/b003/_pkg_.a(_x001.o): 66120: sym#2 ("$d"): ignoring symbol in section 3 (".comment") (type 0)
loadelf: $WORK/b003/_pkg_.a(_x002.o): 66122: sym#2 ("$d"): ignoring symbol in section 3 (".comment") (type 0)
loadelf: $WORK/b003/_pkg_.a(_x003.o): 66145: sym#22 ("$d"): ignoring symbol in section 4 (".debug_loclists") (type 0)
loadelf: $WORK/b003/_pkg_.a(_x004.o): 66169: sym#22 ("$d"): ignoring symbol in section 5 (".debug_loclists") (type 0)
loadelf: $WORK/b003/_pkg_.a(_x005.o): 66399: sym#227 ("$d"): ignoring symbol in section 6 (".debug_loclists") (type 0)
loadelf: $WORK/b003/_pkg_.a(_x006.o): 66489: sym#87 ("$d"): ignoring symbol in section 6 (".debug_loclists") (type 0)
loadelf: $WORK/b003/_pkg_.a(_x007.o): 66508: sym#18 ("$d"): ignoring symbol in section 4 (".debug_loclists") (type 0)
loadelf: $WORK/b003/_pkg_.a(_x008.o): 66524: sym#15 ("$d"): ignoring symbol in section 4 (".debug_loclists") (type 0)
loadelf: $WORK/b003/_pkg_.a(_x009.o): 66542: sym#17 ("$d"): ignoring symbol in section 3 (".debug_loclists") (type 0)
loadelf: $WORK/b003/_pkg_.a(_x010.o): 66572: sym#27 ("$d"): ignoring symbol in section 6 (".debug_loclists") (type 0)
loadelf: $WORK/b003/_pkg_.a(_x011.o): 66728: sym#155 ("$d"): ignoring symbol in section 4 (".debug_loclists") (type 0)
loadelf: $WORK/b003/_pkg_.a(_x012.o): 66790: sym#63 ("$d"): ignoring symbol in section 4 (".riscv.attributes") (type 0)
main._cgo_de7e76e774d0_Cfunc_free: relocation target _cgo_de7e76e774d0_Cfunc_free not defined
main._cgo_de7e76e774d0_Cfunc_puts: relocation target _cgo_de7e76e774d0_Cfunc_puts not defined
main._cgo_de7e76e774d0_Cfunc__Cmalloc: relocation target _cgo_de7e76e774d0_Cfunc__Cmalloc not defined
runtime.cgo_yield: relocation target _cgo_yield not defined                    
_cgo_init: relocation target x_cgo_init not defined                            
_cgo_thread_start: relocation target x_cgo_thread_start not defined            
_cgo_pthread_key_created: relocation target x_cgo_pthread_key_created not defined
/usr/lib/go/pkg/tool/linux_riscv64/link: too many errors    

These symbols with type equal to zero are "mapping symbols" specified in RISC-V psABI. They aren't correctly handled (IOW, ignored), causing crazy errors.

@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label May 3, 2025
ziyao233 added a commit to ziyao233/go that referenced this issue May 3, 2025
Specified in RISC-V ELF psABI[1], mapping symbols are symbols starting
with "$d" or "$x" with STT_NOTYPE, STB_LOCAL and zero sizes, indicating
boundaries between code and data in the same section.

Let's simply ignore them as they're only markers instead of real
symbols. This fixes linking errors like

	sym#63 ("$d"): ignoring symbol in section 4 (".riscv.attributes") (type 0)

when using CGO together with Clang and internal linker, which are caused
by unnecessary (but technically correct) mapping symbols created by LLVM
for various sections.

Fixes golang#73591

[1]: https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/87aecf601722171c570120a46003be3c17ad3108/riscv-elf.adoc?plain=1#L1448
@seankhliao seankhliao added the arch-riscv Issues solely affecting the riscv64 architecture. label May 3, 2025
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/669675 mentions this issue: cmd/link: ignore mapping symbols on riscv64

@gabyhelp gabyhelp added the BugReport Issues describing a possible bug in the Go implementation. label May 3, 2025
@mengzhuo
Copy link
Contributor
mengzhuo commented May 4, 2025

I think this issue is duplicate with #73516

@mengzhuo mengzhuo closed this as completed May 4, 2025
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. BugReport Issues describing a possible bug in the Go implementation. compiler/runtime Issues related to the Go compiler and/or runtime.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants
0