From baf6df06c0525b0bbcf43066f3360eb31b8e7941 Mon Sep 17 00:00:00 2001 From: Meng Zhuo Date: Sat, 26 Mar 2022 15:15:45 +0800 Subject: [PATCH] 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 Trust: Than McIntosh Run-TryBot: mzh TryBot-Result: Gopher Robot Reviewed-by: Cherry Mui --- src/debug/elf/file_test.go | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/debug/elf/file_test.go b/src/debug/elf/file_test.go index 4c6fdeece9c..c0decdd66e4 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) } } }