Skip to content

Commit cacab64

Browse files
committed
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: David Chase <[email protected]>
1 parent 697f418 commit cacab64

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1797,6 +1797,7 @@ func dwarfGenerateDebugInfo(ctxt *Link) {
17971797

17981798
// fake root DIE for compile unit DIEs
17991799
var dwroot dwarf.DWDie
1800+
flagVariants := make(map[string]bool)
18001801

18011802
for _, lib := range ctxt.Library {
18021803
unit := &compilationUnit{lib: lib}
@@ -1825,7 +1826,11 @@ func dwarfGenerateDebugInfo(ctxt *Link) {
18251826
// version, so it should be safe for readers to scan
18261827
// forward to the semicolon.
18271828
producer += "; " + string(producerExtra.P)
1829+
flagVariants[string(producerExtra.P)] = true
1830+
} else {
1831+
flagVariants[""] = true
18281832
}
1833+
18291834
newattr(unit.dwinfo, dwarf.DW_AT_producer, dwarf.DW_CLS_STRING, int64(len(producer)), producer)
18301835

18311836
if len(lib.Textp) == 0 {
@@ -1876,6 +1881,13 @@ func dwarfGenerateDebugInfo(ctxt *Link) {
18761881
}
18771882
}
18781883

1884+
// Fix for 31034: if the objects feeding into this link were compiled
1885+
// with different sets of flags, then don't issue an error if
1886+
// the -strictdups checks fail.
1887+
if checkStrictDups > 1 && len(flagVariants) > 1 {
1888+
checkStrictDups = 1
1889+
}
1890+
18791891
// Create DIEs for global variables and the types they use.
18801892
genasmsym(ctxt, defdwsymb)
18811893

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,10 @@ var (
200200

201201
nerrors int
202202
liveness int64
203+
204+
// See -strictdups command line flag.
205+
checkStrictDups int // 0=off 1=warning 2=error
206+
strictDupMsgCount int
203207
)
204208

205209
var (
@@ -283,6 +287,9 @@ func errorexit() {
283287
if nerrors != 0 {
284288
Exit(2)
285289
}
290+
if checkStrictDups > 1 && strictDupMsgCount > 0 {
291+
Exit(2)
292+
}
286293
Exit(0)
287294
}
288295

@@ -1745,7 +1752,8 @@ func ldobj(ctxt *Link, f *bio.Reader, lib *sym.Library, length int64, pn string,
17451752
default:
17461753
log.Fatalf("invalid -strictdups flag value %d", *FlagStrictDups)
17471754
}
1748-
objfile.Load(ctxt.Arch, ctxt.Syms, f, lib, eof-f.Offset(), pn, flags)
1755+
c := objfile.Load(ctxt.Arch, ctxt.Syms, f, lib, eof-f.Offset(), pn, flags)
1756+
strictDupMsgCount += c
17491757
addImports(ctxt, lib, pn)
17501758
return nil
17511759
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ func Main(arch *sys.Arch, theArch Arch) {
148148
if objabi.Fieldtrack_enabled != 0 {
149149
ctxt.Reachparent = make(map[*sym.Symbol]*sym.Symbol)
150150
}
151+
checkStrictDups = *FlagStrictDups
151152

152153
startProfile()
153154
if ctxt.BuildMode == BuildModeUnset {

src/cmd/link/internal/objfile/objfile.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ type objReader struct {
4242
dupSym *sym.Symbol
4343
localSymVersion int
4444
flags int
45+
strictDupMsgs int
4546

4647
// rdBuf is used by readString and readSymName as scratch for reading strings.
4748
rdBuf []byte
@@ -72,7 +73,7 @@ const (
7273

7374
// Load loads an object file f into library lib.
7475
// The symbols loaded are added to syms.
75-
func Load(arch *sys.Arch, syms *sym.Symbols, f *bio.Reader, lib *sym.Library, length int64, pn string, flags int) {
76+
func Load(arch *sys.Arch, syms *sym.Symbols, f *bio.Reader, lib *sym.Library, length int64, pn string, flags int) int {
7677
start := f.Offset()
7778
r := &objReader{
7879
rd: f.Reader,
@@ -88,6 +89,7 @@ func Load(arch *sys.Arch, syms *sym.Symbols, f *bio.Reader, lib *sym.Library, le
8889
if f.Offset() != start+length {
8990
log.Fatalf("%s: unexpected end at %d, want %d", pn, f.Offset(), start+length)
9091
}
92+
return r.strictDupMsgs
9193
}
9294

9395
func (r *objReader) loadObjFile() {
@@ -376,9 +378,8 @@ overwrite:
376378
// params; I am guessing that the pos is being inherited
377379
// from the spot where the wrapper is needed.
378380
whitelist := strings.HasPrefix(dup.Name, "go.info.go.interface")
379-
380-
if r.flags&StrictDupsErrFlag != 0 && !whitelist {
381-
log.Fatalf("failed duplicate symbol check on '%s' reading %s", dup.Name, r.pn)
381+
if !whitelist {
382+
r.strictDupMsgs++
382383
}
383384
}
384385
}

0 commit comments

Comments
 (0)