libgo: handle linking to NetBSD's versioned symbols
commit0cdde1e7ae197366e17e5ef50bf68d4d5760df01
authorNikhil Benesch <nikhil.benesch@gmail.com>
Mon, 26 Oct 2020 18:42:08 +0000 (26 18:42 +0000)
committerIan Lance Taylor <iant@golang.org>
Thu, 29 Oct 2020 01:20:50 +0000 (28 18:20 -0700)
tree35bfb1e6e1551c39558abb3b699b032e952823c4
parente93aae4a497c38b46df818a629c78149fe6af24b
libgo: handle linking to NetBSD's versioned symbols

On NetBSD, for backwards compatibility, various libc symbols are
renamed to a symbol with a version suffix. For example, this is the
(abbreviated) definition of sigaction:

    int sigaction(...) __asm__ ("__sigaction14")

This poses a challenge for libgo, which attempts to link sigaction by
way of an "//extern" comment:

    //extern sigaction
    func sigaction(...)

This results in a reference to the deprecated compatibility symbol
"sigaction", rather than the desired "__sigaction14" symbol.

This patch introduces a new "//extern-sysinfo" comment to handle this
situation. The new mklinknames.awk script scans a package for these
comments and outputs a "//go:linkname" directive that links the wrapper
to the correct versioned symbol, as determined by parsing the __asm__
annotation on the function's declaration in gen-sysinfo.go.

For now, only the following packages are scanned by mklinknames.awk:

    os
    os/user
    runtime
    syscall

gotools/:
* Makefile.am (check-runtime): Add runtime_linknames.go to
--extrafiles.
* Makefile.in: Regenerate.

Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/265125
18 files changed:
gcc/go/gofrontend/MERGE
gotools/Makefile.am
gotools/Makefile.in
libgo/Makefile.am
libgo/Makefile.in
libgo/config.h.in
libgo/configure
libgo/configure.ac
libgo/go/os/dir_regfile.go
libgo/go/os/user/decls_unix.go
libgo/go/runtime/netpoll_kqueue.go
libgo/go/runtime/os_gccgo.go
libgo/go/runtime/os_netbsd.go
libgo/go/runtime/signal_gccgo.go
libgo/go/runtime/stubs2.go
libgo/go/syscall/mksyscall.awk
libgo/mklinknames.awk [new file with mode: 0644]
libgo/sysinfo.c