From ad170e18540be19bd6db012ff221c01e8c9745e9 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Fri, 30 Jan 2026 19:15:31 -0800 Subject: [PATCH] cmd/link: make TestTypePlacement work on AIX 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 Auto-Submit: Ian Lance Taylor Reviewed-by: Cherry Mui Reviewed-by: Michael Pratt --- src/cmd/link/link_test.go | 45 ++++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/src/cmd/link/link_test.go b/src/cmd/link/link_test.go index 541733b8e6..19607c324c 100644 --- a/src/cmd/link/link_test.go +++ b/src/cmd/link/link_test.go @@ -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 { -- 2.52.0