Skip to content

gollvm: multiple definition of 'runtime.nanotime..f' #53807

@johnnyyu029

Description

@johnnyyu029

As shown in the sample code, since Nanotime is declared in both package main and packagea(using: //go:linkname Nanotime runtime.nanotime), and package packagea is imported to package main.
gofrontend creates the function descriptor with the same name "runtime.nanotime..f" for Nanotime in both packages main and packagea, resulting in a multiple definition error during the link phase.

What version of Go are you using (go version)?

gollvm master

$ go version
go version unknown linux/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env

What did you do?

The issue may be reproduced with the following sample:

go build linkname.go

File linkname.go

package main
  
import (
    "fmt"
    "linkname/packagea"
    _ "unsafe"
)

//go:linkname Nanotime runtime.nanotime
func Nanotime() int64

func main() {
    fmt.Println(Nanotime())
    fmt.Println(packagea.Nanotime)
}

File packagea/a.go

package packagea
  
import (
        _ "unsafe"
)

//go:linkname Nanotime runtime.nanotime
func Nanotime() int64

What did you expect to see?

No error, successful build.

What did you see instead?

[root@kwephis525702 test]# go build linkname.go 
# command-line-arguments
/usr/bin/ld.gold: error: /root/.cache/go-build/72/72a31748b9a7e4660f3fbe9b02046db2b83d204da0b133c508593d4b82ac82b3-d(_go_.o): multiple definition of 'runtime.nanotime..f'
/usr/bin/ld.gold: $WORK/b001/_pkg_.a(_go_.o): previous definition here

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions