-
Notifications
You must be signed in to change notification settings - Fork 18.3k
Closed
Labels
Milestone
Description
issue/a/a.go:
package a
/*
static long long mod(long long a, long long b) { return a % b; }
*/
import "C"
func F(a, b int64) int64 {
return int64(C.mod(C.longlong(a), C.longlong(b)))
}
issue/b/b.go exactly the same except "package b" instead of "package a".
issue/main.go:
package main
import (
"fmt"
"issue/a"
"issue/b"
)
func main() {
fmt.Println(a.F(1, 1), b.F(1, 1))
}
GOARCH=386 go build issue
# issue
/var/tmp/go-link-0Vel41/000001.o: In function `__moddi3':
(.text+0x70): multiple definition of `__moddi3'
/var/tmp/go-link-0Vel41/000000.o:(.text+0x70): first defined here
collect2: error: ld returned 1 exit status
/home/iant/go/pkg/tool/linux_amd64/8l: running gcc failed: unsuccessful exit status 0x100
The problem is that for GOARCH=386 both object files require __moddi3. The go command links both cgo objects against libgcc, because of issue #3261. So both object files define __moddi3, and the linker complains.
On systems that support external linking, which I think is everything but Windows, it should no longer be necessary to link libgcc into each cgo object file. Unless, of course, the standard packages that use cgo (net, crypto/x509) use a libgcc function.