cmd/link,runtime/cgo: enable PT_TLS generation on OpenBSD

OpenBSD 6.0 and later have support for PT_TLS in ld.so(1). Now that OpenBSD
6.1 has been released, OpenBSD 5.9 is no longer officially supported and Go
can start generating PT_TLS for OpenBSD cgo binaries. This also allows us
to remove the workarounds in the OpenBSD cgo runtime.

This change also removes the environ and progname exports - these are now
provided directly by ld.so(1) itself.

Fixes #19932

Change-Id: I42e75ef9feb5dcd4696add5233497e3cbc48ad52
Reviewed-on: https://go-review.googlesource.com/40331
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
Joel Sing 2017-04-12 01:10:01 +10:00
parent 2122fc6358
commit 9417c022c6
8 changed files with 25 additions and 380 deletions

View file

@ -1894,14 +1894,11 @@ func (ctxt *Link) doelf() {
Addstring(shstrtab, ".bss")
Addstring(shstrtab, ".noptrbss")
// generate .tbss section (except for OpenBSD where it's not supported)
// for dynamic internal linker or external linking, so that various
// binutils could correctly calculate PT_TLS size.
// see https://golang.org/issue/5200.
if Headtype != obj.Hopenbsd {
if !*FlagD || Linkmode == LinkExternal {
Addstring(shstrtab, ".tbss")
}
// generate .tbss section for dynamic internal linker or external
// linking, so that various binutils could correctly calculate
// PT_TLS size. See https://golang.org/issue/5200.
if !*FlagD || Linkmode == LinkExternal {
Addstring(shstrtab, ".tbss")
}
if Headtype == obj.Hnetbsd {
Addstring(shstrtab, ".note.netbsd.ident")
@ -2525,24 +2522,19 @@ func Asmbelf(ctxt *Link, symo int64) {
/*
* Thread-local storage segment (really just size).
*/
// Do not emit PT_TLS for OpenBSD since ld.so(1) does
// not currently support it. This is handled
// appropriately in runtime/cgo.
if Headtype != obj.Hopenbsd {
tlssize := uint64(0)
for sect := Segdata.Sect; sect != nil; sect = sect.Next {
if sect.Name == ".tbss" {
tlssize = sect.Length
}
}
if tlssize != 0 {
ph := newElfPhdr()
ph.type_ = PT_TLS
ph.flags = PF_R
ph.memsz = tlssize
ph.align = uint64(SysArch.RegSize)
tlssize := uint64(0)
for sect := Segdata.Sect; sect != nil; sect = sect.Next {
if sect.Name == ".tbss" {
tlssize = sect.Length
}
}
if tlssize != 0 {
ph := newElfPhdr()
ph.type_ = PT_TLS
ph.flags = PF_R
ph.memsz = tlssize
ph.align = uint64(SysArch.RegSize)
}
}
if Headtype == obj.Hlinux {