This is an archive of the discontinued LLVM Phabricator instance.

[ELF] - Do not crash when discarding sections that are referenced by others.
ClosedPublic

Authored by grimar on Feb 16 2017, 2:10 AM.

Details

Summary

SHF_LINK_ORDER sections adds special ordering requirements.
Such sections references other sections. Previously we would crash
if section that other were referenced to was discarded by script.

Patch fixes that by discarding all dependent sections in that case.
It supports chained dependencies, testcase is provided.

Diff Detail

Repository
rL LLVM

Event Timeline

grimar created this revision.Feb 16 2017, 2:10 AM
tpimh added a subscriber: tpimh.Feb 16 2017, 3:01 AM
This revision was automatically updated to reflect the committed changes.
ruiu added inline comments.Feb 16 2017, 11:49 AM
lld/trunk/ELF/LinkerScript.cpp
282

You don't need to check if a container is empty before passing it to a for-each-ish function, just like you don't check for emptiness foo before doing for (auto bar : foo).

grimar added inline comments.Feb 17 2017, 12:42 AM
lld/trunk/ELF/LinkerScript.cpp
282

I know. And even applied that for simplicity in D29273.
But there I do not have cast. Since in this patch I had to do cast and anyways had to check !IS condition, I see nothing wrong in checking empty container to exit early. Code would not became simpler here, early continue still simplifies reading.