From c2becd70c5dad379def219e60452072ab6e72617 Mon Sep 17 00:00:00 2001 From: Cherry Mui Date: Thu, 11 May 2023 14:31:31 -0400 Subject: [PATCH] cmd/link: check DWARF section sizes separately 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 Reviewed-by: Than McIntosh Run-TryBot: Cherry Mui --- src/cmd/link/internal/ld/data.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/cmd/link/internal/ld/data.go b/src/cmd/link/internal/ld/data.go index 0a0c17e928..d651e2e346 100644 --- a/src/cmd/link/internal/ld/data.go +++ b/src/cmd/link/internal/ld/data.go @@ -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) } } -- 2.48.1