]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: make TestTypePlacement work on AIX
authorIan Lance Taylor <iant@golang.org>
Sat, 31 Jan 2026 03:15:31 +0000 (19:15 -0800)
committerGopher Robot <gobot@golang.org>
Fri, 6 Feb 2026 23:30:44 +0000 (15:30 -0800)
The existing code was just wrong. On AIX the go.type section is
folded into the .text section (when internally linking),
or the .data section (when externally linking).
It follows that the data section adjustment is useless when
internally linking, which is currently what happens with this test.

Change-Id: Icf8ac07f754fdcf08b9d3dfffde83b3391c9404b
Reviewed-on: https://go-review.googlesource.com/c/go/+/740821
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
src/cmd/link/link_test.go

index 541733b8e615f0d7a9abb33e7d6cb626c10f4433..19607c324ceaefc371ee5a947436ddbdd40bb5e9 100644 (file)
@@ -2416,20 +2416,37 @@ func TestTypePlacement(t *testing.T) {
        case xf != nil:
                defer xf.Close()
 
-               for _, sec := range xf.Sections {
-                       if sec.Name == ".go.type" {
-                               typeStart = sec.VirtualAddress
-                               typeEnd = sec.VirtualAddress + sec.Size
-                               break
+               // On XCOFF the .go.type section,
+               // like all relro sections,
+               //  gets folded into the .data section.
+               var typeSym, eTypeSym *xcoff.Symbol
+               for _, sym := range xf.Symbols {
+                       switch sym.Name {
+                       case "runtime.types":
+                               typeSym = sym
+                       case "runtime.etypes":
+                               eTypeSym = sym
+                       case globalName:
+                               globalSec := xf.Sections[sym.SectionNumber-1]
+                               globalObjAddr = uint64(globalSec.VirtualAddress + sym.Value)
                        }
                }
 
-               for _, sym := range xf.Symbols {
-                       if sym.Name == globalName {
-                               globalObjAddr = sym.Value
-                               break
-                       }
+               if typeSym == nil {
+                       t.Fatal("could not find symbol runtime.types")
                }
+               if eTypeSym == nil {
+                       t.Fatal("could not find symbol runtime.etypes")
+               }
+               if typeSym.SectionNumber != eTypeSym.SectionNumber {
+                       t.Fatalf("runtime.types section %d != runtime.etypes section %d", typeSym.SectionNumber, eTypeSym.SectionNumber)
+               }
+
+               sec := xf.Sections[typeSym.SectionNumber-1]
+
+               typeStart = uint64(sec.VirtualAddress + typeSym.Value)
+
+               typeEnd = uint64(sec.VirtualAddress + eTypeSym.Value)
        }
 
        if typeStart == 0 || typeEnd == 0 {
@@ -2440,6 +2457,14 @@ func TestTypePlacement(t *testing.T) {
        offset := globalExeAddr - globalObjAddr
        t.Logf("execution offset: %#x", offset)
 
+       // On AIX with internal linking the type descriptors are
+       // currently put in the .text section, whereas the global
+       // variable will be in the .data section. We must ignore
+       // the offset. This would change if using external linking.
+       if runtime.GOOS == "aix" {
+               offset = 0
+       }
+
        for _, addr := range addrs {
                addr -= offset
                if addr < typeStart || addr >= typeEnd {