Skip to content

Support go:linkname compiler directive #1000

Closed
@nevkontakte

Description

@nevkontakte

Motivation: this directive is actively used in low-level standard library code, in particular with the runtime package. Not having it available in GopherJS forces us to introduce inelegant hacks in standard library overlays. This functionality becomes particularly important when a function is exposed into several packages, making then share state (e.g. runtime.fastrand()).

Specification from https://pkg.go.dev/cmd/compile:

//go:linkname localname [importpath.name]

This special directive does not apply to the Go code that follows it. Instead, the //go:linkname directive instructs the compiler to use “importpath.name” as the object file symbol name for the variable or function declared as “localname” in the source code. If the “importpath.name” argument is omitted, the directive uses the symbol's default object file symbol name and only has the effect of making the symbol accessible to other packages. Because this directive can subvert the type system and package modularity, it is only enabled in files that have imported "unsafe".

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions