aboutsummaryrefslogtreecommitdiff
path: root/src/debug
diff options
context:
space:
mode:
authorMeng Zhuo <mzh@golangcn.org>2022-03-26 15:15:45 +0800
committermzh <mzh@golangcn.org>2022-04-01 01:06:18 +0000
commitbaf6df06c0525b0bbcf43066f3360eb31b8e7941 (patch)
tree08c49d0bea01b4e974fa6c3d7c25a17747ca53f4 /src/debug
parenta4ffeb9edd23e1edbea87eb9ebd8cbb84fad6efa (diff)
downloadgo-baf6df06c0525b0bbcf43066f3360eb31b8e7941.tar.xz
debug/elf: ajdust SectionOverlap test for proper fields
The current SectionOverlap tests Size (addr) with Offset (file) This CL set this test for overlap of Size + Addr and Offset + FileSize Fixes #51939 Change-Id: Ied4c0b87f61c4d5e52139a8295c371f55abc776f Reviewed-on: https://go-review.googlesource.com/c/go/+/395920 Trust: mzh <mzh@golangcn.org> Trust: Than McIntosh <thanm@google.com> Run-TryBot: mzh <mzh@golangcn.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com>
Diffstat (limited to 'src/debug')
-rw-r--r--src/debug/elf/file_test.go26
1 files changed, 22 insertions, 4 deletions
diff --git a/src/debug/elf/file_test.go b/src/debug/elf/file_test.go
index 4c6fdeece9..c0decdd66e 100644
--- a/src/debug/elf/file_test.go
+++ b/src/debug/elf/file_test.go
@@ -913,14 +913,32 @@ func TestNoSectionOverlaps(t *testing.T) {
if sih.Type == SHT_NOBITS {
continue
}
+ // checking for overlap in file
for j, sj := range f.Sections {
sjh := sj.SectionHeader
- if i == j || sjh.Type == SHT_NOBITS || sih.Offset == sjh.Offset && sih.Size == 0 {
+ if i == j || sjh.Type == SHT_NOBITS || sih.Offset == sjh.Offset && sih.FileSize == 0 {
continue
}
- if sih.Offset >= sjh.Offset && sih.Offset < sjh.Offset+sjh.Size {
- t.Errorf("ld produced ELF with section %s within %s: 0x%x <= 0x%x..0x%x < 0x%x",
- sih.Name, sjh.Name, sjh.Offset, sih.Offset, sih.Offset+sih.Size, sjh.Offset+sjh.Size)
+ if sih.Offset >= sjh.Offset && sih.Offset < sjh.Offset+sjh.FileSize {
+ t.Errorf("ld produced ELF with section offset %s within %s: 0x%x <= 0x%x..0x%x < 0x%x",
+ sih.Name, sjh.Name, sjh.Offset, sih.Offset, sih.Offset+sih.FileSize, sjh.Offset+sjh.FileSize)
+ }
+ }
+
+ if sih.Flags&SHF_ALLOC == 0 {
+ continue
+ }
+
+ // checking for overlap in address space
+ for j, sj := range f.Sections {
+ sjh := sj.SectionHeader
+ if i == j || sjh.Flags&SHF_ALLOC == 0 || sjh.Type == SHT_NOBITS ||
+ sih.Addr == sjh.Addr && sih.Size == 0 {
+ continue
+ }
+ if sih.Addr >= sjh.Addr && sih.Addr < sjh.Addr+sjh.Size {
+ t.Errorf("ld produced ELF with section address %s within %s: 0x%x <= 0x%x..0x%x < 0x%x",
+ sih.Name, sjh.Name, sjh.Addr, sih.Addr, sih.Addr+sih.Size, sjh.Addr+sjh.Size)
}
}
}