This is an archive of the discontinued LLVM Phabricator instance.

[LLD][ELF] - Check the architecture of lazy objects earlier.
ClosedPublic

Authored by grimar on Aug 17 2018, 7:23 AM.

Details

Summary

Our code in LazyObjFile::parse() has an ELFT switch and
adds a lazy object by its ELFT kind.
Though it might be possible to add a file using a different architecture
and make LLD to silently accept it (if the file is empty or contains only week symbols).
That itself, not a huge issue perhaps (because the error would be reported later if the file is fetched),
but still does not look clean and correct.

It is possible to report an error earlier and clean up the
code. That is what the patch does.

Ideally, we might want to reuse isCompatible from SymbolTable.cpp,
but it is static and accepts a file as an argument, what is not convenient.
Since such a situation should be rare, I think it should be OK to go with the
way chosen in this patch.

Diff Detail

Repository
rL LLVM

Event Timeline

grimar created this revision.Aug 17 2018, 7:23 AM
grimar edited the summary of this revision. (Show Details)Aug 17 2018, 7:25 AM
ruiu added inline comments.Aug 19 2018, 9:59 PM
ELF/InputFiles.cpp
1265 ↗(On Diff #161238)

"incompatible file: " + this->MB.getBufferIdentifier() is perhaps better.

1267 ↗(On Diff #161238)

You can inline this function now.

grimar updated this revision to Diff 161451.Aug 20 2018, 2:23 AM
grimar marked 2 inline comments as done.
  • Addressed review comments.
ruiu accepted this revision.Aug 20 2018, 8:30 PM

LGTM

ELF/InputFiles.h
275 ↗(On Diff #161451)

Remove the blank line.

This revision is now accepted and ready to land.Aug 20 2018, 8:30 PM
This revision was automatically updated to reflect the committed changes.