]> Cypherpunks repositories - gostls13.git/commitdiff
debug/elf: ajdust SectionOverlap test for proper fields
authorMeng Zhuo <mzh@golangcn.org>
Sat, 26 Mar 2022 07:15:45 +0000 (15:15 +0800)
committermzh <mzh@golangcn.org>
Fri, 1 Apr 2022 01:06:18 +0000 (01:06 +0000)
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>
src/debug/elf/file_test.go

index 4c6fdeece9c941bed02b6b4493bfc67787611657..c0decdd66e482dfe21f7abe7ec3e89a44cf292c6 100644 (file)
@@ -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)
                        }
                }
        }