Skip to content

riscv64: can't build on FreeBSD with cgo #73516

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

Open
mengzhuo opened this issue Apr 28, 2025 · 3 comments · May be fixed by #73592
Open

riscv64: can't build on FreeBSD with cgo #73516

mengzhuo opened this issue Apr 28, 2025 · 3 comments · May be fixed by #73592
Assignees
Labels
arch-riscv Issues solely affecting the riscv64 architecture. OS-FreeBSD

Comments

@mengzhuo
Copy link
Contributor

Go version

go1.24.2

Output of go env in your module/workspace:

CC='clang'                                                                                      
CGO_CFLAGS='-O2 -g'                                                                             
CGO_CPPFLAGS=''                                                                                 
CGO_CXXFLAGS='-O2 -g'                                                                           
CGO_ENABLED='1'                                                                                 
CGO_FFLAGS='-O2 -g'                                                                             
CGO_LDFLAGS='-O2 -g'                                                                            
CXX='clang++'                                                                                   
GCCGO='gccgo'                                                                                   
GO111MODULE=''                                                                                  
GOARCH='riscv64'                                                                                
GOAUTH='netrc'                                                                                  
GOBIN=''                                                                                        
GOCACHE='/root/.cache/go-build'                                                                 
GOCACHEPROG=''                                                                                  
GODEBUG=''                                                                                      
GOENV='/root/.config/go/env'                                                                    
GOEXE=''                                                                                        
GOEXPERIMENT=''                                                                                 
GOFIPS140='off'                                                                                 
GOFLAGS=''                                                                                      
GOGCCFLAGS='-fPIC -pthread -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmess
file-prefix-map=/tmp/go-build207065778=/tmp/go-build -gno-record-gcc-switches'                  
GOHOSTARCH='riscv64'                                                                            
GOHOSTOS='freebsd'                                                                              
GOINSECURE=''                                                                                   
GOMOD='/root/go-go1.24.2/src/go.mod'                                                            
GOMODCACHE='/root/go/pkg/mod'                                                                   
GONOPROXY=''                                                                                    
GONOSUMDB=''                                                                                    
GOOS='freebsd'                                                                                  
GOPATH='/root/go'                                                                               
GOPRIVATE=''                                                                                    
GOPROXY='https://proxy.golang.org,direct'                                                       
GORISCV64='rva20u64'                                                                            
GOROOT='/usr/local/go'                                                                          
GOSUMDB='sum.golang.org'                                                                        
GOTELEMETRY='local'                                                                             
GOTELEMETRYDIR='/root/.config/go/telemetry'                                                     
GOTMPDIR=''                                                                                     
GOTOOLCHAIN='auto'                                                                              
GOTOOLDIR='/usr/local/go/pkg/tool/freebsd_riscv64'                                              
GOVCS=''                                                                                        
GOVERSION='go1.24.2'                                                                            
GOWORK=''                                                                                       
PKG_CONFIG='pkg-config'

What did you do?

run ./all.bash -v

What did you see happen?

[00:13:46.359] ##### Testing packages.                                                                         
[00:14:10.093] # archive/tar.test                                                                              
[00:14:10.094] loadelf: $WORK/b082/_pkg_.a(_x001.o): 170074: sym#2 ("$d.0"): ignoring symbol in section 3 (".co
mment") (type 0)                                                                                               
[00:14:10.097] loadelf: $WORK/b082/_pkg_.a(_x002.o): 170203: sym#128 ("$d.1"): ignoring symbol in section 4 (".
debug_loc") (type 0)                                                                                           
[00:14:10.099] loadelf: $WORK/b082/_pkg_.a(_x003.o): 170228: sym#24 ("$d.1"): ignoring symbol in section 4 (".d
ebug_loc") (type 0)                                                                                            
[00:14:10.102] loadelf: $WORK/b083/_pkg_.a(_x001.o): 170230: sym#2 ("$d.0"): ignoring symbol in section 3 (".co
mment") (type 0)                                                                                               
[00:14:10.104] loadelf: $WORK/b083/_pkg_.a(_x002.o): 170232: sym#2 ("$d.0"): ignoring symbol in section 3 (".co
mment") (type 0)                                                                                               
[00:14:10.106] loadelf: $WORK/b083/_pkg_.a(_x003.o): 170255: sym#22 ("$d.1"): ignoring symbol in section 4 (".d
ebug_loc") (type 0)                                                                                            
[00:14:10.109] loadelf: $WORK/b083/_pkg_.a(_x004.o): 170279: sym#22 ("$d.2"): ignoring symbol in section 5 (".d
ebug_loc") (type 0)                                                                                            
[00:14:10.111] loadelf: $WORK/b083/_pkg_.a(_x005.o): 170346: sym#64 ("$d.3"): ignoring symbol in section 6 (".d
ebug_loc") (type 0)                                                                                            
[00:14:10.114] loadelf: $WORK/b083/_pkg_.a(_x006.o): 170555: sym#206 ("$d.3"): ignoring symbol in section 6 (".
debug_loc") (type 0)                                                                                           
[00:14:10.116] loadelf: $WORK/b083/_pkg_.a(_x007.o): 170572: sym#16 ("$d.1"): ignoring symbol in section 4 (".d
ebug_loc") (type 0)                                                                                            
[00:14:10.119] loadelf: $WORK/b083/_pkg_.a(_x008.o): 170587: sym#14 ("$d.1"): ignoring symbol in section 4 (".d
ebug_loc") (type 0)                                                                                            
[00:14:10.121] loadelf: $WORK/b083/_pkg_.a(_x009.o): 170616: sym#26 ("$d.3"): ignoring symbol in section 6 (".d
ebug_loc") (type 0)                                                                                            
[00:14:10.124] loadelf: $WORK/b083/_pkg_.a(_x010.o): 170678: sym#63 ("$d.1"): ignoring symbol in section 4 (".r
iscv.attributes") (type 0)                                                                                     
[00:14:10.126] runtime.cgo_yield: relocation target _cgo_yield not defined                                     
[00:14:10.128] os/user._cgo_9bef24737d87_Cfunc_mygetgrgid_r: relocation target _cgo_9bef24737d87_Cfunc_mygetgrg
id_r not defined                                                                                               
[00:14:10.129] os/user._cgo_9bef24737d87_Cfunc_mygetpwuid_r: relocation target _cgo_9bef24737d87_Cfunc_mygetpwu
id_r not defined                                                                                               
[00:14:10.131] os/user._cgo_9bef24737d87_Cfunc_sysconf: relocation target _cgo_9bef24737d87_Cfunc_sysconf not d
efined                                                                                                         
[00:14:10.133] _cgo_init: relocation target x_cgo_init not defined                                             
[00:14:10.133] _cgo_thread_start: relocation target x_cgo_thread_start not defined                             
[00:14:10.134] _cgo_notify_runtime_init_done: relocation target x_cgo_notify_runtime_init_done not defined     
[00:14:10.135] _cgo_pthread_key_created: relocation target x_cgo_pthread_key_created not defined               
[00:14:10.136] /root/go-go1.24.2/pkg/tool/freebsd_riscv64/link: too many errors                                
[00:14:10.137] FAIL    archive/tar [build failed]                                                              

What did you expect to see?

test passed

@mengzhuo mengzhuo added OS-FreeBSD arch-riscv Issues solely affecting the riscv64 architecture. labels Apr 28, 2025
@mengzhuo mengzhuo self-assigned this Apr 28, 2025
@mengzhuo
Copy link
Contributor Author

cc @golang/riscv64

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/668516 mentions this issue: cmd/link: disable loading debug symbol for riscv64

ziyao233 added a commit to ziyao233/go that referenced this issue May 9, 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#73516

[1]: https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/87aecf601722171c570120a46003be3c17ad3108/riscv-elf.adoc?plain=1#L1448
@ziyao233 ziyao233 linked a pull request May 9, 2025 that will close this issue
@gopherbot
Copy link
Contributor

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

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. OS-FreeBSD
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants