Skip to content
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

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

Open
johnnyyu029 opened this issue Jul 12, 2022 · 4 comments
Open

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

johnnyyu029 opened this issue Jul 12, 2022 · 4 comments
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@johnnyyu029
Copy link

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
@mknyszek mknyszek added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jul 12, 2022
@mknyszek mknyszek added this to the gollvm milestone Jul 12, 2022
@mknyszek
Copy link
Contributor

CC @thanm @cherrymui

@cherrymui
Copy link
Member

As shown in the sample code, since Nanotime is declared in both package main and packagea(using: //go:linkname Nanotime runtime.nanotime)

Do not do this. Using linkname to access runtime internal functions is not supported. Thanks.

@cherrymui cherrymui closed this as not planned Won't fix, can't repro, duplicate, stale Jul 12, 2022
@johnnyyu029
Copy link
Author

johnnyyu029 commented Jul 13, 2022

@cherrymui
As shown in the sample code, using linkname on non-runtime function GetTime defined in "linkname/a.go" has the same problem:

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

File linkname.go

package main

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

//go:linkname GetTime linkname_1packagea.GetTime
func GetTime() int64

func main() {
    fmt.Println(GetTime())
    fmt.Println(GetTime)
}  

File linkname/a.go

package packagea                                                                                                                                                                                                                               

import (
    _ "unsafe"
)

func GetTime() int64 {
    return 0
}

@ianlancetaylor
Copy link
Contributor

Thanks, I think there is a bug here. But in general go:linkname is not well supported. Patches welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants