]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: check DWARF section sizes separately
authorCherry Mui <cherryyz@google.com>
Thu, 11 May 2023 18:31:31 +0000 (14:31 -0400)
committerCherry Mui <cherryyz@google.com>
Thu, 11 May 2023 20:14:54 +0000 (20:14 +0000)
Currently, we check the total size of all data+DWARF sections
doesn't exceed 2 GB, which doesn't make sense. We should check
data and DWARF separately. And for DWARF, check each section
separately, as we use section offset for references.

Change-Id: I723cde6a2f46e55cc5cb0621926722272581eb48
Reviewed-on: https://go-review.googlesource.com/c/go/+/494439
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>

src/cmd/link/internal/ld/data.go

index 0a0c17e9281d419773a9832365d2db6573b7fec4..d651e2e346411f0839005c914e0e133964bfef02 100644 (file)
@@ -1357,9 +1357,19 @@ func (p *GCProg) AddSym(s loader.Sym) {
 // (see issue #9862).
 const cutoff = 2e9 // 2 GB (or so; looks better in errors than 2^31)
 
+// check accumulated size of data sections
 func (state *dodataState) checkdatsize(symn sym.SymKind) {
        if state.datsize > cutoff {
-               Errorf(nil, "too much data in section %v (over %v bytes)", symn, cutoff)
+               Errorf(nil, "too much data, last section %v (%d, over %v bytes)", symn, state.datsize, cutoff)
+       }
+}
+
+func checkSectSize(sect *sym.Section) {
+       // TODO: consider using 4 GB size limit for DWARF sections, and
+       // make sure we generate unsigned offset in relocations and check
+       // for overflow.
+       if sect.Length > cutoff {
+               Errorf(nil, "too much data in section %s (%d, over %v bytes)", sect.Name, sect.Length, cutoff)
        }
 }
 
@@ -2162,7 +2172,7 @@ func (state *dodataState) allocateDwarfSections(ctxt *Link) {
                        }
                }
                sect.Length = uint64(state.datsize) - sect.Vaddr
-               state.checkdatsize(curType)
+               checkSectSize(sect)
        }
 }