This is an archive of the discontinued LLVM Phabricator instance.

[LLD] [COFF] Don't error out on duplicate absolute symbols with the same value
ClosedPublic

Authored by mstorsjo on Dec 29 2019, 2:56 PM.

Details

Summary

Both MS link.exe and GNU ld.bfd handle it this way; one can have multiple object files defining the same absolute symbols, as long as it defines it to the same value. But if there are multiple absolute symbols with differing values, it is treated as an error.

As a general related note - LLD differs from link.exe (and GNU ld.bfd) when it comes to conflicts between a defined absolute regular and defined regular; LLD silently accepts these (in both orders), while both link.exe and ld.bfd error out on it.

Diff Detail

Event Timeline

mstorsjo created this revision.Dec 29 2019, 2:56 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 29 2019, 2:56 PM
rnk added inline comments.Jan 2 2020, 4:48 PM
lld/COFF/SymbolTable.cpp
597

This looks like the code that makes LLD not report duplicates between absolute and regular symbols. Should we re-evaluate that decision?

The logic dates back to 79a5e6b1b77efe7770503ebce2a808f0b89d9e50, which doesn't explicitly mention this case. That makes me think this behavior is not intentional, and we can change it.

mstorsjo marked an inline comment as done.Jan 2 2020, 9:55 PM
mstorsjo added inline comments.
lld/COFF/SymbolTable.cpp
597

Yes, we could change it, but I'd treat it as a different change from this one.

As things stand right now, leaving D71711 should work fine, but if we make absolute+regular an error, we'd break the case with multiple objects referencing the same weak, if one object provides a default function which isn't absolute zero.

rnk resigned from this revision.Jan 3 2020, 3:35 PM

lgtm

This revision was not accepted when it landed; it landed in state Needs Review.Jan 4 2020, 2:37 AM
This revision was automatically updated to reflect the committed changes.
ruiu added inline comments.Jan 5 2020, 10:24 PM
lld/COFF/Symbols.h
232–238

Instead of adding these member functions, maybe we should just add an accessor getVA? It looks like there's no point to hide the actual VA from other classes.

MaskRay added inline comments.
lld/test/COFF/duplicate-absolute-same.s
5

If there is no diagnostic, use count 0. Then, CHECK-NOT can be turned into a comment.

Negative diagnostics checks may become stale when the message changes.

mstorsjo marked 2 inline comments as done.Jan 6 2020, 3:56 AM
mstorsjo added inline comments.
lld/COFF/Symbols.h
232–238

Sure, I can do that.

lld/test/COFF/duplicate-absolute-same.s
5

Ok, will do.

Yes, there's a clear risk with checking for the error message contents - but if really was an error, it would still be picked up as the lld-link command also would return a failure status. But worth fixing anyway.