Commit cacab645 authored by Than McIntosh's avatar Than McIntosh

cmd/link: change -strictdups checking to handle mix of flags

Update the recently-added '-strictdups' sanity checking to avoid
failing the link in cases where we have objects feeding into the link
with a mix of command line flags (and in particular some with "-N" and
some without). This scenario will trigger errors/warnings due to
inlinable functions and wrapper functions that have different sizes
due to presence or lack of optimization.

Update #31034.

Change-Id: I1dd9e37c2f9bea5da0ab82e32e6fc210aebf6a65
Reviewed-on: https://go-review.googlesource.com/c/go/+/169160
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarDavid Chase <drchase@google.com>
parent 697f4183
...@@ -1797,6 +1797,7 @@ func dwarfGenerateDebugInfo(ctxt *Link) { ...@@ -1797,6 +1797,7 @@ func dwarfGenerateDebugInfo(ctxt *Link) {
// fake root DIE for compile unit DIEs // fake root DIE for compile unit DIEs
var dwroot dwarf.DWDie var dwroot dwarf.DWDie
flagVariants := make(map[string]bool)
for _, lib := range ctxt.Library { for _, lib := range ctxt.Library {
unit := &compilationUnit{lib: lib} unit := &compilationUnit{lib: lib}
...@@ -1825,7 +1826,11 @@ func dwarfGenerateDebugInfo(ctxt *Link) { ...@@ -1825,7 +1826,11 @@ func dwarfGenerateDebugInfo(ctxt *Link) {
// version, so it should be safe for readers to scan // version, so it should be safe for readers to scan
// forward to the semicolon. // forward to the semicolon.
producer += "; " + string(producerExtra.P) producer += "; " + string(producerExtra.P)
flagVariants[string(producerExtra.P)] = true
} else {
flagVariants[""] = true
} }
newattr(unit.dwinfo, dwarf.DW_AT_producer, dwarf.DW_CLS_STRING, int64(len(producer)), producer) newattr(unit.dwinfo, dwarf.DW_AT_producer, dwarf.DW_CLS_STRING, int64(len(producer)), producer)
if len(lib.Textp) == 0 { if len(lib.Textp) == 0 {
...@@ -1876,6 +1881,13 @@ func dwarfGenerateDebugInfo(ctxt *Link) { ...@@ -1876,6 +1881,13 @@ func dwarfGenerateDebugInfo(ctxt *Link) {
} }
} }
// Fix for 31034: if the objects feeding into this link were compiled
// with different sets of flags, then don't issue an error if
// the -strictdups checks fail.
if checkStrictDups > 1 && len(flagVariants) > 1 {
checkStrictDups = 1
}
// Create DIEs for global variables and the types they use. // Create DIEs for global variables and the types they use.
genasmsym(ctxt, defdwsymb) genasmsym(ctxt, defdwsymb)
......
...@@ -200,6 +200,10 @@ var ( ...@@ -200,6 +200,10 @@ var (
nerrors int nerrors int
liveness int64 liveness int64
// See -strictdups command line flag.
checkStrictDups int // 0=off 1=warning 2=error
strictDupMsgCount int
) )
var ( var (
...@@ -283,6 +287,9 @@ func errorexit() { ...@@ -283,6 +287,9 @@ func errorexit() {
if nerrors != 0 { if nerrors != 0 {
Exit(2) Exit(2)
} }
if checkStrictDups > 1 && strictDupMsgCount > 0 {
Exit(2)
}
Exit(0) Exit(0)
} }
...@@ -1745,7 +1752,8 @@ func ldobj(ctxt *Link, f *bio.Reader, lib *sym.Library, length int64, pn string, ...@@ -1745,7 +1752,8 @@ func ldobj(ctxt *Link, f *bio.Reader, lib *sym.Library, length int64, pn string,
default: default:
log.Fatalf("invalid -strictdups flag value %d", *FlagStrictDups) log.Fatalf("invalid -strictdups flag value %d", *FlagStrictDups)
} }
objfile.Load(ctxt.Arch, ctxt.Syms, f, lib, eof-f.Offset(), pn, flags) c := objfile.Load(ctxt.Arch, ctxt.Syms, f, lib, eof-f.Offset(), pn, flags)
strictDupMsgCount += c
addImports(ctxt, lib, pn) addImports(ctxt, lib, pn)
return nil return nil
} }
......
...@@ -148,6 +148,7 @@ func Main(arch *sys.Arch, theArch Arch) { ...@@ -148,6 +148,7 @@ func Main(arch *sys.Arch, theArch Arch) {
if objabi.Fieldtrack_enabled != 0 { if objabi.Fieldtrack_enabled != 0 {
ctxt.Reachparent = make(map[*sym.Symbol]*sym.Symbol) ctxt.Reachparent = make(map[*sym.Symbol]*sym.Symbol)
} }
checkStrictDups = *FlagStrictDups
startProfile() startProfile()
if ctxt.BuildMode == BuildModeUnset { if ctxt.BuildMode == BuildModeUnset {
......
...@@ -42,6 +42,7 @@ type objReader struct { ...@@ -42,6 +42,7 @@ type objReader struct {
dupSym *sym.Symbol dupSym *sym.Symbol
localSymVersion int localSymVersion int
flags int flags int
strictDupMsgs int
// rdBuf is used by readString and readSymName as scratch for reading strings. // rdBuf is used by readString and readSymName as scratch for reading strings.
rdBuf []byte rdBuf []byte
...@@ -72,7 +73,7 @@ const ( ...@@ -72,7 +73,7 @@ const (
// Load loads an object file f into library lib. // Load loads an object file f into library lib.
// The symbols loaded are added to syms. // The symbols loaded are added to syms.
func Load(arch *sys.Arch, syms *sym.Symbols, f *bio.Reader, lib *sym.Library, length int64, pn string, flags int) { func Load(arch *sys.Arch, syms *sym.Symbols, f *bio.Reader, lib *sym.Library, length int64, pn string, flags int) int {
start := f.Offset() start := f.Offset()
r := &objReader{ r := &objReader{
rd: f.Reader, rd: f.Reader,
...@@ -88,6 +89,7 @@ func Load(arch *sys.Arch, syms *sym.Symbols, f *bio.Reader, lib *sym.Library, le ...@@ -88,6 +89,7 @@ func Load(arch *sys.Arch, syms *sym.Symbols, f *bio.Reader, lib *sym.Library, le
if f.Offset() != start+length { if f.Offset() != start+length {
log.Fatalf("%s: unexpected end at %d, want %d", pn, f.Offset(), start+length) log.Fatalf("%s: unexpected end at %d, want %d", pn, f.Offset(), start+length)
} }
return r.strictDupMsgs
} }
func (r *objReader) loadObjFile() { func (r *objReader) loadObjFile() {
...@@ -376,9 +378,8 @@ overwrite: ...@@ -376,9 +378,8 @@ overwrite:
// params; I am guessing that the pos is being inherited // params; I am guessing that the pos is being inherited
// from the spot where the wrapper is needed. // from the spot where the wrapper is needed.
whitelist := strings.HasPrefix(dup.Name, "go.info.go.interface") whitelist := strings.HasPrefix(dup.Name, "go.info.go.interface")
if !whitelist {
if r.flags&StrictDupsErrFlag != 0 && !whitelist { r.strictDupMsgs++
log.Fatalf("failed duplicate symbol check on '%s' reading %s", dup.Name, r.pn)
} }
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment