This is an archive of the discontinued LLVM Phabricator instance.

[ELF] Fix crash on invalid undefined local symbols
ClosedPublic

Authored by smeenai on Oct 2 2018, 5:14 PM.

Details

Summary

r320770 made LLD handle invalid DSOs where local symbols were found in
the global part of the symbol table. Unfortunately, it didn't handle the
case where those local symbols were also undefined, and r326242 exposed
an assertion failure in that case. Just warn on that case instead of
crashing, by moving the local binding check before the undefined symbol
addition.

The input file for the test is crafted by hand, since I don't know of
any tool that would produce such a broken DSO. I also don't understand
what it even means for a symbol to be undefined but have STB_LOCAL
binding - I don't think that combination makes any sense - but we have
found broken DSOs of this nature that we were linking against.

Diff Detail

Repository
rL LLVM

Event Timeline

smeenai created this revision.Oct 2 2018, 5:14 PM
grimar added a comment.Oct 3 2018, 1:32 AM

We have a subfolder test\ELF\invalid for the tests that have invalid inputs. I think the test case should be placed there.

test/ELF/invalid-undefined-local-symbol-in-dso.s
3 ↗(On Diff #168057)

Please expand the comment to describe what is exactly wrong with the object.

4 ↗(On Diff #168057)

Can you use yaml for the test case?

You perhaps can use obj2yaml on the file you have.

smeenai updated this revision to Diff 168204.Oct 3 2018, 4:32 PM

Address review comments

test/ELF/invalid-undefined-local-symbol-in-dso.s
4 ↗(On Diff #168057)

I tried using obj2yaml, but it's unable to produce a broken DSO of this nature. I need to have a local symbol in the global section of the dynamic symbol table, i.e. have a local symbol with index >= the dynamic symbol table section's sh_info. I don't think obj2yaml is able to produce an output file like that. I added super detailed instructions for creating the broken DSO instead.

ruiu accepted this revision.Oct 3 2018, 4:34 PM

LGTM

I agree with you that it is not easy to create a broken object file. In this case, checking in a binary is fine.

This revision is now accepted and ready to land.Oct 3 2018, 4:34 PM
smeenai added inline comments.Oct 3 2018, 4:37 PM
test/ELF/invalid/undefined-local-symbol-in-dso.test
64 ↗(On Diff #168204)

Whoops, this is a leftover line. I'll remove before committing.

This revision was automatically updated to reflect the committed changes.
This revision was automatically updated to reflect the committed changes.