Skip to content

cmd/ld, runtime: all ELF go binaries contain two symbols called 'runtime.main.f' #9934

@mwhudson

Description

@mwhudson

On Linux:

mwhudson@narsil:go-test-cases$ cat trivial.go
package main

func main() {

}
mwhudson@narsil:go-test-cases$ go build trivial.go
mwhudson@narsil:go-test-cases$ nm trivial | grep -F runtime.main.f
0000000000470e90 R runtime.main.f
0000000000470e98 R runtime.main.f

This is because the linker normalizes middle dots to periods. The source of the two symbols:

  1. The runtime package defines a variable called runtime·main·f (in asm_$GOARCH.s)
  2. As with all functions, the compiler creates a symbol called "".main·f to support indirect calls to runtime.main, which is read by the linker as runtime.main·f

This doesn't really cause problems today because the collision happens so late in the writing process, when you're executing an elf binary nothing really cares about the symbol names. It's a problem when you want to do dynamic linking stuff though, because the symbol names start mattering again.

It feels like these two symbols are actually meant to be the same, but I don't know how to make that happen. The simplest fix would be to make the names different enough to not collide in the symbol table.

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