Skip to content

cmd/link: linkname to runtime.addmoduledata is not forbidden #75180

@wdvxdr1123

Description

@wdvxdr1123
package main

import (
	_ "unsafe"
)

//go:linkname addmoduledata runtime.addmoduledata
func addmoduledata()

func main() {
	addmoduledata()
}

This program can compile ok. However, comment said do NOT call from Go.

go/src/runtime/stubs.go

Lines 427 to 428 in ebc763f

// Called from linker-generated .initarray; declared for go vet; do NOT call from Go.
func addmoduledata()

And using linkname on this function will cause a linker crash when building with buildmode=plugin.

package main

import (
	_ "unsafe"
)

//go:linkname addmoduledata runtime.addmoduledata
func addmoduledata()

func FOO() {
	addmoduledata()
}
go build -buildmode=plugin a.go
# command-line-arguments
runtime.gcWriteBarrier1: phase error: addr=0x63750 but val=0x5dc00 sym=runtime.gcWriteBarrier1 type=STEXT sect=.text sect.addr=0x0 prev=runtime.addmoduledata

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugReportIssues describing a possible bug in the Go implementation.FixPendingIssues that have a fix which has not yet been reviewed or submitted.compiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions