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:
parent
2210debf6c
commit
7d06d2c032
@ -753,9 +753,12 @@ func (bi *BinaryInfo) setGStructOffsetElf(exe *elf.File, wg *sync.WaitGroup) {
|
||||
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
|
||||
// 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 ////////////////////////////////////////////////////////////////
|
||||
|
Loading…
Reference in New Issue
Block a user