This is an archive of the discontinued LLVM Phabricator instance.

Output ELF files after ThinLTO is run.
ClosedPublic

Authored by void on Dec 21 2018, 11:32 PM.

Details

Summary

The gold linker allowed you to output the ELF files after LTO was run. It did
it by using the 'obj-path' option. This replicates that behavior.

Event Timeline

void created this revision.Dec 21 2018, 11:32 PM

Is there a test case checking this behavior ?

ruiu added a comment.Dec 27 2018, 2:07 PM

Replicating the gold behavior sounds fine, but does this patch work? This change seems to leave Buf uninitialized while Buf will be used later. Also, in gold LTO plugin, -obj-path overwrites -save-temps, but this change doesn't seem to replicate that behavior. Could you add tests?

MaskRay added a comment.EditedDec 27 2018, 2:35 PM

The filenames of Task=0 and different. Is this preferable?

t.o t2.o were compiled with -module-summary

ld.lld --plugin-opt=obj-path=t3.o -shared t.o t2.o => creates t2.o0 t2.o1 t2.o2

gold --plugin=~/llvm/Release/lib/LLVMgold.so --plugin-opt=thinlto --plugin-opt=obj-path=t3.o -shared t.o t2.o => creates t2.o t2.o1 t2.o2

void added a comment.Dec 27 2018, 2:38 PM

Replicating the gold behavior sounds fine, but does this patch work? This change seems to leave Buf uninitialized while Buf will be used later. Also, in gold LTO plugin, -obj-path overwrites -save-temps, but this change doesn't seem to replicate that behavior. Could you add tests?

I'll add a test in a bit. I tested it and it did work, but I may have missed something. Let me get the test in and then you can take a look afterwards. Thanks!

void updated this revision to Diff 179789.Dec 31 2018, 10:04 PM

Add testcase.

void updated this revision to Diff 179790.Dec 31 2018, 10:08 PM

Don't append "0" to the object filename.

void added a comment.Dec 31 2018, 10:08 PM

The filenames of Task=0 and different. Is this preferable?

t.o t2.o were compiled with -module-summary

ld.lld --plugin-opt=obj-path=t3.o -shared t.o t2.o => creates t2.o0 t2.o1 t2.o2

gold --plugin=~/llvm/Release/lib/LLVMgold.so --plugin-opt=thinlto --plugin-opt=obj-path=t3.o -shared t.o t2.o => creates t2.o t2.o1 t2.o2

I'm not sure it's important, but I modified it to retain the original behavior just in case.

ruiu added inline comments.Jan 2 2019, 2:26 PM
test/ELF/lto/obj-path.ll
12

Can you also verify %t3 to make sure that lld outputs a correct output file even if obj-path is given?

void updated this revision to Diff 179984.Jan 2 2019, 5:32 PM

Add check that the object file is still valid after using "obj-path".

ruiu added inline comments.Jan 3 2019, 9:32 AM
ELF/LTO.cpp
225

I don't think we need this kind of sophisticated abstraction. I believe you can just write Buf contents to files after data is written to Buf. Please take a look at https://gist.github.com/rui314/836cc9dab97922271b63dba3d1d5a3f5. All tests still pass with that patch.

So, if my understanding is correct, the only difference between save-temps and obj-path is the basename of the created temporary files. Is this your expected behavior?

void updated this revision to Diff 180332.Jan 4 2019, 3:27 PM

Implement Rui's suggestion for how to output the ELF files.

void marked an inline comment as done.Jan 4 2019, 3:30 PM
void added inline comments.
ELF/LTO.cpp
225

I implemented your suggestion here. The two options are similar, but have some important differences; save-temps outputs a lot of intermediate bitcode files. A new basename is good because it allows you to place the temps in a different directory. It might be possible to combine the two somehow?

grimar added a subscriber: grimar.Jan 9 2019, 7:52 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 11 2019, 12:42 PM
void added a comment.Feb 14 2019, 12:54 PM

Friendly ping. :-)

void added a comment.Feb 20 2019, 2:26 PM

Another ping. Anyone? :-)

MaskRay added a reviewer: pcc.Feb 20 2019, 6:24 PM

Another ping. Anyone? :-)

I think it is correct, but I'm not confident to press the "Accept Revision" button :) Added another expert

MaskRay accepted this revision.Feb 26 2019, 5:54 AM
This revision is now accepted and ready to land.Feb 26 2019, 5:54 AM
pcc accepted this revision.Feb 26 2019, 9:34 AM

LGTM

test/ELF/lto/obj-path.ll
14

We don't normally split check lines into multiple files like this. Can you move the check line for SYMBOLS from the other file into this one (and remove the one for ELF since it is unused)?

void updated this revision to Diff 188426.Feb 26 2019, 11:27 AM

Move checks over to the main LL file, not Input file.

This revision was automatically updated to reflect the committed changes.