mirror of
https://github.com/golang/go
synced 2024-11-12 03:00:22 -07:00
cmd/link: move XCOFF data addresses to an unreachable segment
This commit move data addresses to 0x200000000 for XCOFF executables. .data and .bss must always be position-independent on AIX. This modification allows to detect more easily if they aren't, as segfault will be triggered. Change-Id: Ied7a5b72b9f4ff9f870a1626cf07c48110635e62 Reviewed-on: https://go-review.googlesource.com/c/151040 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
d924c3336c
commit
9a3c1a1bc8
@ -2036,6 +2036,11 @@ func (ctxt *Link) address() []*sym.Segment {
|
||||
}
|
||||
|
||||
va = uint64(Rnd(int64(va), int64(*FlagRound)))
|
||||
if ctxt.HeadType == objabi.Haix {
|
||||
// Data sections are moved to an unreachable segment
|
||||
// to ensure that they are position-independent.
|
||||
va += uint64(XCOFFDATABASE) - uint64(XCOFFTEXTBASE)
|
||||
}
|
||||
order = append(order, &Segdata)
|
||||
Segdata.Rwx = 06
|
||||
Segdata.Vaddr = va
|
||||
|
@ -17,17 +17,20 @@ import (
|
||||
// as PE and XCOFF are based on COFF files.
|
||||
// XCOFF files generated are 64 bits.
|
||||
|
||||
// Total amount of space to reserve at the start of the file
|
||||
// for FileHeader, Auxiliary Header, and Section Headers.
|
||||
// May waste some.
|
||||
// Based on 24(fhdr) + 120(ahdr) + 23(max sections number) * 72(scnhdr)
|
||||
const (
|
||||
XCOFFHDRRESERVE = FILHSZ_64 + AOUTHSZ_EXEC64 + SCNHSZ_64*23
|
||||
)
|
||||
// Total amount of space to reserve at the start of the file
|
||||
// for File Header, Auxiliary Header, and Section Headers.
|
||||
// May waste some.
|
||||
XCOFFHDRRESERVE = FILHSZ_64 + AOUTHSZ_EXEC64 + SCNHSZ_64*23
|
||||
XCOFFSECTALIGN int64 = 32 // base on dump -o
|
||||
|
||||
const (
|
||||
XCOFFSECTALIGN int64 = 32 // base on dump -o
|
||||
XCOFFBASE = 0x100000000 // Address on 64 bits must start at this value.
|
||||
// XCOFF binaries should normally have all its sections position-independent.
|
||||
// However, this is not yet possible for .text because of some R_ADDR relocations
|
||||
// inside RODATA symbols.
|
||||
// .data and .bss are position-independent so their address start inside a unreachable
|
||||
// segment during execution to force segfault if something is wrong.
|
||||
XCOFFTEXTBASE = 0x100000000 // Start of text address
|
||||
XCOFFDATABASE = 0x200000000 // Start of data address
|
||||
)
|
||||
|
||||
// File Header
|
||||
@ -367,12 +370,6 @@ type xcoffFile struct {
|
||||
loaderReloc []*xcoffLoaderReloc // Reloc that must be made inside loader
|
||||
}
|
||||
|
||||
// Those values will latter be computed in XcoffInit
|
||||
var (
|
||||
XCOFFFILEHDR int
|
||||
XCOFFSECTHDR int
|
||||
)
|
||||
|
||||
// Var used by XCOFF Generation algorithms
|
||||
var (
|
||||
xfile xcoffFile
|
||||
@ -489,14 +486,11 @@ func (f *xcoffFile) getXCOFFscnum(sect *sym.Section) int16 {
|
||||
func Xcoffinit(ctxt *Link) {
|
||||
xfile.dynLibraries = make(map[string]int)
|
||||
|
||||
XCOFFFILEHDR = int(Rnd(XCOFFHDRRESERVE, XCOFFSECTALIGN))
|
||||
XCOFFSECTHDR = int(Rnd(int64(XCOFFFILEHDR), XCOFFSECTALIGN))
|
||||
|
||||
HEADR = int32(XCOFFFILEHDR)
|
||||
HEADR = int32(Rnd(XCOFFHDRRESERVE, XCOFFSECTALIGN))
|
||||
if *FlagTextAddr != -1 {
|
||||
Errorf(nil, "-T not available on AIX")
|
||||
}
|
||||
*FlagTextAddr = XCOFFBASE + int64(XCOFFSECTHDR)
|
||||
*FlagTextAddr = XCOFFTEXTBASE + int64(HEADR)
|
||||
*FlagDataAddr = 0
|
||||
if *FlagRound != -1 {
|
||||
Errorf(nil, "-R not available on AIX")
|
||||
|
Loading…
Reference in New Issue
Block a user