Currently, WriteObjFile deduplicates symbols by name. This is a
strange and unexpected place to do this. But, worse, there's no
checking that it's reasonable to deduplicate two symbols, so this
makes it incredibly easy to mask errors involving duplicate symbols.
Dealing with duplicate symbols is better left to the linker. We're
also about to introduce multiple symbols with the same name but
different ABIs/versions, which would make this deduplication more
complicated. We just removed the only part of the compiler that
actually depended on this behavior.
This CL removes symbol deduplication from WriteObjFile, since it is no
longer needed.
For #27539.
Change-Id: I650c550e46e83f95c67cb6c6646f9b2f7f10df30
Reviewed-on: https://go-review.googlesource.com/c/146558
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
}
// addGCLocals adds gcargs, gclocals, gcregs, and stack object symbols to Ctxt.Data.
-// It takes care not to add any duplicates.
-// Though the object file format handles duplicates efficiently,
-// storing only a single copy of the data,
-// failure to remove these duplicates adds a few percent to object file size.
//
// This is done during the sequential phase after compilation, since
// global symbols can't be declared during parallel compilation.
// Temporary buffer for zigzag int writing.
varintbuf [10]uint8
- // Provide the index of a symbol reference by symbol name.
- // One map for versioned symbols and one for unversioned symbols.
- // Used for deduplicating the symbol reference list.
- refIdx map[string]int
- vrefIdx map[string]int
-
// Number of objects written of each type.
nRefs int
nData int
func newObjWriter(ctxt *Link, b *bufio.Writer) *objWriter {
return &objWriter{
- ctxt: ctxt,
- wr: b,
- vrefIdx: make(map[string]int),
- refIdx: make(map[string]int),
+ ctxt: ctxt,
+ wr: b,
}
}
if s == nil || s.RefIdx != 0 {
return
}
- var m map[string]int
- if !s.Static() {
- m = w.refIdx
- } else {
- m = w.vrefIdx
- }
-
- if idx := m[s.Name]; idx != 0 {
- s.RefIdx = idx
- return
- }
w.wr.WriteByte(symPrefix)
if isPath {
w.writeString(filepath.ToSlash(s.Name))
w.writeBool(s.Static())
w.nRefs++
s.RefIdx = w.nRefs
- m[s.Name] = w.nRefs
}
func (w *objWriter) writeRefs(s *LSym) {