Skip to content

Commit 911455f

Browse files
committed
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 golang#75444. Change-Id: Ic0aa1a2bb7c6bd5c0023d4482405a482095ff68b Reviewed-on: https://go-review.googlesource.com/c/go/+/703375 Reviewed-by: Michael Pratt <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent f1fd130 commit 911455f

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/cmd/link/elf_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -627,30 +627,30 @@ func testFlagD(t *testing.T, dataAddr string, roundQuantum string, expectedAddr
627627
defer ef.Close()
628628

629629
// Find the first data-related section to verify segment placement
630-
var firstDataSectionAddr uint64
631-
var found bool = false
630+
var firstDataSection *elf.Section
632631
for _, sec := range ef.Sections {
633632
if sec.Type == elf.SHT_PROGBITS || sec.Type == elf.SHT_NOBITS {
634633
// These sections are writable, allocated at runtime, but not executable
634+
// nor TLS.
635635
isWrite := sec.Flags&elf.SHF_WRITE != 0
636636
isExec := sec.Flags&elf.SHF_EXECINSTR != 0
637637
isAlloc := sec.Flags&elf.SHF_ALLOC != 0
638+
isTLS := sec.Flags&elf.SHF_TLS != 0
638639

639-
if isWrite && !isExec && isAlloc {
640-
addrLower := sec.Addr < firstDataSectionAddr
641-
if !found || addrLower {
642-
firstDataSectionAddr = sec.Addr
643-
found = true
640+
if isWrite && !isExec && isAlloc && !isTLS {
641+
if firstDataSection == nil || sec.Addr < firstDataSection.Addr {
642+
firstDataSection = sec
644643
}
645644
}
646645
}
647646
}
648647

649-
if !found {
648+
if firstDataSection == nil {
650649
t.Fatalf("can't find any writable data sections")
651650
}
652-
if firstDataSectionAddr != expectedAddr {
653-
t.Errorf("data section starts at 0x%x, expected 0x%x", firstDataSectionAddr, expectedAddr)
651+
if firstDataSection.Addr != expectedAddr {
652+
t.Errorf("data section starts at 0x%x for section %s, expected 0x%x",
653+
firstDataSection.Addr, firstDataSection.Name, expectedAddr)
654654
}
655655
}
656656

0 commit comments

Comments
 (0)