From: Cherry Zhang Date: Mon, 24 Feb 2020 21:24:29 +0000 (-0500) Subject: cmd/link: improve gap detection in TestPIESize X-Git-Tag: go1.15beta1~1084 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=0fb1a49c1ae0e9e587c74947d6d6c3fe92c161df;p=gostls13.git 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 TryBot-Result: Gobot Gobot Reviewed-by: Than McIntosh Reviewed-by: Ian Lance Taylor --- diff --git a/src/cmd/link/elf_test.go b/src/cmd/link/elf_test.go index 88048ed2c5..2fb4dd8aaf 100644 --- a/src/cmd/link/elf_test.go +++ b/src/cmd/link/elf_test.go @@ -387,15 +387,15 @@ func TestPIESize(t *testing.T) { } } // also skip gaps between PT_LOAD segments - for i := range ef.Progs { - if i == 0 { + var prev *elf.Prog + for _, seg := range ef.Progs { + if seg.Type != elf.PT_LOAD { continue } - p1 := ef.Progs[i-1] - p2 := ef.Progs[i] - if p1.Type == elf.PT_LOAD && p2.Type == elf.PT_LOAD { - ret += p2.Off - p1.Off - p1.Filesz + if prev != nil { + ret += seg.Off - prev.Off - prev.Filesz } + prev = seg } return ret }