pkg/proc: align memory size of tls arena to pointer sized boundary

The size of the TLS memory arena needs to be aligned to pointer sized
boundaries on 86x64 architectures, otherwise some programs using cgo
will not have the correct offset for the g struct.

No tests because reproducing this problem depends on behavior of the
GNU ld linker caused by unclear influences.

Fixes #1428.
This commit is contained in:
aarzilli 2018-11-28 18:26:01 +01:00 committed by Derek Parker
parent 2210debf6c
commit 7d06d2c032

@ -753,9 +753,12 @@ func (bi *BinaryInfo) setGStructOffsetElf(exe *elf.File, wg *sync.WaitGroup) {
break break
} }
} }
memsz := tls.Memsz
memsz = (memsz + uint64(bi.Arch.PtrSize()) - 1) & ^uint64(bi.Arch.PtrSize()-1) // align to pointer-sized-boundary
// The TLS register points to the end of the TLS block, which is // The TLS register points to the end of the TLS block, which is
// tls.Memsz long. runtime.tlsg is an offset from the beginning of that block. // tls.Memsz long. runtime.tlsg is an offset from the beginning of that block.
bi.gStructOffset = ^(tls.Memsz) + 1 + tlsg.Value // -tls.Memsz + tlsg.Value bi.gStructOffset = ^(memsz) + 1 + tlsg.Value // -tls.Memsz + tlsg.Value
} }
// PE //////////////////////////////////////////////////////////////// // PE ////////////////////////////////////////////////////////////////