Skip to content

Commit 0fb1a49

Browse files
committed
cmd/link: improve gap detection in TestPIESize
In CL 210180 we detect gaps between PT_LOAD segments and subtract them from size calculation. The code there only works when PT_LOAD segments are next to each other. But it is possible that there are other segments in between (e.g. a GNU_RELRO segment). Relax the gap detection to count gaps between PT_LOAD segments regardless of whether they are next to each other. Updates #36023. Updates #35545. Change-Id: I8b94506359fa649a4478acc742d86d4b16022dbc Reviewed-on: https://go-review.googlesource.com/c/go/+/220654 Run-TryBot: Cherry Zhang <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Than McIntosh <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent e0c3ded commit 0fb1a49

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/cmd/link/elf_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -387,15 +387,15 @@ func TestPIESize(t *testing.T) {
387387
}
388388
}
389389
// also skip gaps between PT_LOAD segments
390-
for i := range ef.Progs {
391-
if i == 0 {
390+
var prev *elf.Prog
391+
for _, seg := range ef.Progs {
392+
if seg.Type != elf.PT_LOAD {
392393
continue
393394
}
394-
p1 := ef.Progs[i-1]
395-
p2 := ef.Progs[i]
396-
if p1.Type == elf.PT_LOAD && p2.Type == elf.PT_LOAD {
397-
ret += p2.Off - p1.Off - p1.Filesz
395+
if prev != nil {
396+
ret += seg.Off - prev.Off - prev.Filesz
398397
}
398+
prev = seg
399399
}
400400
return ret
401401
}

0 commit comments

Comments
 (0)