]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link/internal/ld: remove R_ADDR relocations inside XCOFF text sections
authorClément Chigot <clement.chigot@atos.net>
Fri, 2 Nov 2018 12:50:59 +0000 (13:50 +0100)
committerIan Lance Taylor <iant@golang.org>
Mon, 26 Nov 2018 23:37:00 +0000 (23:37 +0000)
On XCOFF, it is forbidden relocation of a DATA pointer to a text
section. It happens when a RODATA symbol needs a DATA symbol's address.
This commit moves every RODATA symbols with a R_ADDR on a data symbol to
.data sections to avoid these relocations.

Change-Id: I7f34d8e0ebdc8352a74e6b40e4c893d8d9419f4d
Reviewed-on: https://go-review.googlesource.com/c/146977
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/cmd/link/internal/ld/data.go
src/cmd/link/internal/ld/xcoff.go
src/runtime/alg.go

index f424f1d17b279a5a601dad2cd9a08b4eaa3b1d23..ef796b623aa093d29e2d4f55c9067b73f4d84e1c 100644 (file)
@@ -318,8 +318,7 @@ func relocsym(ctxt *Link, s *sym.Symbol) {
                        // must be done by the loader, as the section .data will be moved.
                        // The "default" symbol address is still needed by the loader so
                        // the current relocation can't be skipped.
-                       // runtime.algarray is different because it will end up in .rodata section
-                       if ctxt.HeadType == objabi.Haix && r.Sym.Sect.Seg == &Segdata && r.Sym.Name != "runtime.algarray" {
+                       if ctxt.HeadType == objabi.Haix && r.Sym.Sect.Seg == &Segdata {
                                // It's not possible to make a loader relocation to a DWARF section.
                                // FIXME
                                if s.Sect.Seg != &Segdwarf {
index f06b498594493c1a1136858d1f5b2c96746c34e8..e39f1bb9f06674b65982f07fd986fc5cedc874ab 100644 (file)
@@ -878,6 +878,38 @@ func (ctxt *Link) doxcoff() {
        toc := ctxt.Syms.Lookup("TOC", 0)
        toc.Type = sym.SXCOFFTOC
        toc.Attr |= sym.AttrReachable
+
+       // XCOFF does not allow relocations of data symbol address to a text symbol.
+       // Such case occurs when a RODATA symbol retrieves a data symbol address.
+       // When it happens, this RODATA symbol is moved to .data section.
+       // runtime.algarray is a readonly symbol but stored inside .data section.
+       // If it stays in .data, all type symbols will be moved to .data which
+       // cannot be done.
+       algarray := ctxt.Syms.Lookup("runtime.algarray", 0)
+       algarray.Type = sym.SRODATA
+       for {
+               again := false
+               for _, s := range ctxt.Syms.Allsym {
+                       if s.Type != sym.SRODATA {
+                               continue
+                       }
+                       for ri := range s.R {
+                               r := &s.R[ri]
+                               if r.Type != objabi.R_ADDR {
+                                       continue
+                               }
+                               if r.Sym.Type != sym.Sxxx && r.Sym.Type != sym.STEXT && r.Sym.Type != sym.SRODATA {
+                                       s.Type = sym.SDATA
+                                       again = true
+                                       break
+                               }
+                       }
+
+               }
+               if !again {
+                       break
+               }
+       }
 }
 
 // Loader section
index 8e931fd7658c6cbc0c6d2754311fe06dc334a6ab..887dbebdeb074a5c4dfcc1b81e6ac427d2571300 100644 (file)
@@ -301,6 +301,10 @@ func alginit() {
 }
 
 func initAlgAES() {
+       if GOOS == "aix" {
+               // runtime.algarray is immutable on AIX: see cmd/link/internal/ld/xcoff.go
+               return
+       }
        useAeshash = true
        algarray[alg_MEM32].hash = aeshash32
        algarray[alg_MEM64].hash = aeshash64