cmd/link: don't count tbss section in TestFlagD

TestFlagD looks for a data-like section at the lowest address.
On OpenBSD, the .tbss section matches the current condition, which
has address 0, causing the test fail. Don't count TLS sections.

Also, print the section name on error.

Fixes #75444.

Change-Id: Ic0aa1a2bb7c6bd5c0023d4482405a482095ff68b
Reviewed-on: https://go-review.googlesource.com/c/go/+/703375
Reviewed-by: Michael Pratt <mpratt@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
Cherry Mui 2025-09-12 12:36:38 -04:00
parent f1fd13016a
commit 911455fe18

View file

@ -627,30 +627,30 @@ func testFlagD(t *testing.T, dataAddr string, roundQuantum string, expectedAddr
defer ef.Close() defer ef.Close()
// Find the first data-related section to verify segment placement // Find the first data-related section to verify segment placement
var firstDataSectionAddr uint64 var firstDataSection *elf.Section
var found bool = false
for _, sec := range ef.Sections { for _, sec := range ef.Sections {
if sec.Type == elf.SHT_PROGBITS || sec.Type == elf.SHT_NOBITS { if sec.Type == elf.SHT_PROGBITS || sec.Type == elf.SHT_NOBITS {
// These sections are writable, allocated at runtime, but not executable // These sections are writable, allocated at runtime, but not executable
// nor TLS.
isWrite := sec.Flags&elf.SHF_WRITE != 0 isWrite := sec.Flags&elf.SHF_WRITE != 0
isExec := sec.Flags&elf.SHF_EXECINSTR != 0 isExec := sec.Flags&elf.SHF_EXECINSTR != 0
isAlloc := sec.Flags&elf.SHF_ALLOC != 0 isAlloc := sec.Flags&elf.SHF_ALLOC != 0
isTLS := sec.Flags&elf.SHF_TLS != 0
if isWrite && !isExec && isAlloc { if isWrite && !isExec && isAlloc && !isTLS {
addrLower := sec.Addr < firstDataSectionAddr if firstDataSection == nil || sec.Addr < firstDataSection.Addr {
if !found || addrLower { firstDataSection = sec
firstDataSectionAddr = sec.Addr
found = true
} }
} }
} }
} }
if !found { if firstDataSection == nil {
t.Fatalf("can't find any writable data sections") t.Fatalf("can't find any writable data sections")
} }
if firstDataSectionAddr != expectedAddr { if firstDataSection.Addr != expectedAddr {
t.Errorf("data section starts at 0x%x, expected 0x%x", firstDataSectionAddr, expectedAddr) t.Errorf("data section starts at 0x%x for section %s, expected 0x%x",
firstDataSection.Addr, firstDataSection.Name, expectedAddr)
} }
} }