Skip to content

cmd/cgo: Support functions in libgcc #3261

@minux

Description

@minux
What steps will reproduce the problem?
1. this program gccbuiltin.go 
package main
// int f(int x) { return __builtin_popcount(x); }
import "C"
func main() {
    println(C.f(100))
}

2. go build gccbuiltin.go

What is the expected output? What do you see instead?
It should compile OK. But I get errors instead:
 command-line-arguments
/tmp/go-build285777972/command-line-arguments.a(gccbuiltin.cgo2.)(.text): __popcountdi2:
not defined
__popcountdi2(0): not defined

Notes:
0. Discussion: http://groups.google.com/group/golang-dev/t/bf56f38944524389
1. this happens on Linux, FreeBSD and Windows (It doesn't fail on Mac OS X, because
libSystem includes libgcc.).
2. I use a gcc builtin to test this error, but this bug isn't caused by gcc builtin, it
is
caused by the general problem of gcc static linking libgcc by default.
3. We can fix this on FreeBSD and Linux quite easily, by providing -shared-libgcc to gcc.
But we can't fix this on Wndows this way, because libgcc isn't bundled with Windows.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions