]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: move XCOFF data addresses to an unreachable segment
authorClément Chigot <clement.chigot@atos.net>
Fri, 23 Nov 2018 14:12:04 +0000 (15:12 +0100)
committerIan Lance Taylor <iant@golang.org>
Mon, 17 Dec 2018 23:03:47 +0000 (23:03 +0000)
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>
src/cmd/link/internal/ld/data.go
src/cmd/link/internal/ld/xcoff.go

index 5209878b78c7d7fb19035373e87eaeb9df2abcdf..e0fad1acfdc90b4faef823afe42a9726e7e1297e 100644 (file)
@@ -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
index a82bbb65dfa4723bc2541d9a082de7d83afafb4b..1561ce8cd0d17eb75e6552f0b31873e1e42a53bf 100644 (file)
@@ -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
-)
-
-const (
-       XCOFFSECTALIGN int64 = 32          // base on dump -o
-       XCOFFBASE            = 0x100000000 // Address on 64 bits must start at this value.
+       // 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
+
+       // 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")