This is an archive of the discontinued LLVM Phabricator instance.

lld-link: Use just one code path to process associative comdats, reject some invalid associated comdats
ClosedPublic

Authored by thakis on Jan 18 2019, 12:34 PM.

Details

Summary

Currently, if an associative comdat appears after the comdat it's associated with it's processed immediately, else it's deferred until the end of the object file. I found this confusing to think about while working on PR40094, so this patch makes it so that associated comdats are always processed at the end of the object file. Tests seem happy, are there problems with this?

If not: Now there's a natural place to reject the associated comdats referring to later associated comdats (associated comdats referring to associated comdats is invalid per COFF spec) that , so reject those. (A later patch will reject associated comdats referring to earlier comdats.)

Diff Detail

Repository
rL LLVM

Event Timeline

thakis updated this revision to Diff 182585.Jan 18 2019, 12:34 PM
thakis created this revision.

forgot to add test

thakis marked an inline comment as done.Jan 18 2019, 1:03 PM
thakis added inline comments.
lld/COFF/InputFiles.cpp
235 ↗(On Diff #182585)

Oh, this is probably wrong. ParentSection is a section index, not a symbol index. One sec...

thakis updated this revision to Diff 182594.Jan 18 2019, 1:21 PM

fix diag

pcc added a comment.Jan 22 2019, 1:28 PM

Currently, if an associative comdat appears after the comdat it's associated with it's processed immediately, else it's deferred until the end of the object file. I found this confusing to think about while working on PR40094, so this patch makes it so that associated comdats are always processed at the end of the object file. Tests seem happy, are there problems with this?

Nope, it was a (premature, as it turns out) optimization. According to my benchmarking, this patch is performance neutral linking chrome_child.dll.

lld/COFF/InputFiles.cpp
239 ↗(On Diff #182594)

I think this is not the only reason why we might end up here. We could also get here if an IMAGE_SCN_LNK_COMDAT section does not have any symbols at all (or just has a section definition) and another section is associative with it. I reckon it's probably not worth trying to disambiguate these cases in code so maybe the diagnostic should just say invalid COFF file? (I am slightly inclined to say that we shouldn't try to diagnose at all here and should just let the linker crash.)

339 ↗(On Diff #182594)

Comment needs to be updated.

ruiu added inline comments.Jan 22 2019, 3:37 PM
lld/COFF/InputFiles.cpp
239 ↗(On Diff #182594)

The error message is more user-friendly if you include the name of a file. You can do that by appending toString(this) to the error message.

thakis updated this revision to Diff 183006.Jan 22 2019, 6:01 PM

tweak diagnostic, add another test

ruiu accepted this revision.Jan 22 2019, 6:03 PM

LGTM

This revision is now accepted and ready to land.Jan 22 2019, 6:03 PM
thakis updated this revision to Diff 183008.Jan 22 2019, 6:04 PM
thakis marked 3 inline comments as done.

update comment

This revision was automatically updated to reflect the committed changes.