This is an archive of the discontinued LLVM Phabricator instance.

[lto] Make sure that ctors are added to the combined module.
ClosedPublic

Authored by silvas on Mar 9 2016, 2:31 PM.

Diff Detail

Repository
rL LLVM

Event Timeline

silvas updated this revision to Diff 50198.Mar 9 2016, 2:31 PM
silvas retitled this revision from to [lto] Make sure that ctors are added to the combined module..
silvas updated this object.
silvas added reviewers: rafael, ruiu.
silvas added subscribers: llvm-commits, Bigcheese.
ruiu edited edge metadata.Mar 9 2016, 2:37 PM

Can you describe what this patch is for?

silvas added a comment.Mar 9 2016, 2:40 PM

Without this patch, llvm.global_ctors is not added to the combined module and so the final output contains no ctors. Programs that need these are thus mis-linked/mis-compiled.

silvas added a comment.Mar 9 2016, 2:42 PM

The need for ExtraKeeps is because llvm.global_ctors and the other SF_FormatSpecific have names in IR but those names are not symbols for the linker.

ruiu added inline comments.Mar 9 2016, 2:51 PM
ELF/InputFiles.cpp
454 ↗(On Diff #50198)

Do you need to copy strings? Because Symtab has unique_ptrs to BitcodeFiles, they are not freed until the program ends.

silvas added inline comments.Mar 9 2016, 3:21 PM
ELF/InputFiles.cpp
454 ↗(On Diff #50198)

Yes. M goes away at the end of this function.

ruiu accepted this revision.Mar 9 2016, 3:23 PM
ruiu edited edge metadata.

LGTM with a nit.

ELF/InputFiles.h
192 ↗(On Diff #50198)

Add a comment for this member (for those like me who don't know why we need this.)

This revision is now accepted and ready to land.Mar 9 2016, 3:23 PM
silvas updated this revision to Diff 50208.Mar 9 2016, 3:35 PM
silvas edited edge metadata.

Update for Rui's comments.

silvas added a comment.Mar 9 2016, 8:32 PM

@rafael, could you comment on the high level design here? I think this is fairly reasonable but as with the other patches I think you may have a specific idea of the "right" way to do things.

rafael edited edge metadata.Mar 10 2016, 7:48 AM
rafael added a subscriber: rafael.

looking.

So, the horrible special case is appending linkage. Long term we should delete it. For now you can check just for it instead of all SF_FormatSpecific.

The other issue is how we propagate information on which symbols are needed. Currently we create SymbolBodies. There are a few problem with that

  • As you point out, we don't want to create them for appending linkage.
  • It requires doing a hash lookup to get the GV on the other side.

There are two possible solutions that fix both issues

  • Use a single LLVMContext and keep the modules alive.
  • Create a IRObjectFile again addBitcodeFile instead of using getLazyBitcodeModule. That would let us match GV and SymbolBody by the index instead of name.
silvas updated this revision to Diff 50348.Mar 10 2016, 1:58 PM
silvas edited edge metadata.

Address Rafael's comment. Don't check SF_FormatSpecific for now.

This revision was automatically updated to reflect the committed changes.