This is an archive of the discontinued LLVM Phabricator instance.

[ELF] - Fix incorrect object file use with --reproduce option.
AbandonedPublic

Authored by grimar on Jul 14 2017, 5:39 AM.

Details

Reviewers
ruiu
rafael
Summary

This patch is mostly for discussion, it is not ideal, but I have no better solution in mind atm.

I observed this issue few times earlier, but last days I am facing it too often when running
other people reproduces.

Problem is next. I can following invocation under ubuntu:
~/LLVM/llvm-build/bin/clang-5.0 -fuse-ld=lld test.c -l stdc++ -o out -v -Wl,--reproduce,out.tar

Result out.tar contains usr\lib64\libc.so which is a linker script and has GROUP command:
GROUP ( /lib64/libc.so.6 /usr/lib64/libc_nonshared.a AS_NEEDED ( /lib64/ld-linux-x86-64.so.2 ) )

Our --reproduce logic correctly includes these 3 files into result tar. Final reproduce file works fine
under the same ubuntu, but if I want to run this reproduce under windows or on system that does not have these
files at absolute path, e.g. there is no file /lib64/libc.so.6, then LLD will fail.

It happens because even running the reproduce, such files from GROUP options are taken
from outside, what breaks concept of "black box".
It is sure undesirable and incorrect and makes sometimes hard to run wild repro files.

I though about we can rewrite such scripts before including them into Tar, but at the same time
it is probably not too nice to modify original files used for reproduce, so I refused from this idea.

In this patch I added new option --reproduce-use which informs linker that it runs under
debug reproduce environment and should never use absolute pathes, but convert them to relative.
That fixes issue I am observing.

No testcase included beause would like to discuss possible solutions at first.

Diff Detail

Event Timeline

grimar created this revision.Jul 14 2017, 5:39 AM

May be it is better to modify scripts before pushing them to Tar ? Adding one more gnu incompatible option is inconvinent
for case when we link reproduce using bfd/gold/LLD together for output comparsion.

ruiu edited edge metadata.Jul 14 2017, 12:58 PM

I think I'm not convinced that this would worth to be added. I usually add fakechroot chroot before ld.lld and it'd just work, so unless there's a strong reason to avoid doing that, I wouldn't add this function.

ruiu added a comment.Jul 17 2017, 4:11 PM

I might be OK with the feature, but this particular patch needs fixing from my point of view.

  • --reproduce-use doesn't sound quite right as an option name. I'd vote for --chroot <dirname>.
  • Handling this case in ScriptParser::addFile is not right. You should do this in Driver::addFile.
  • If you do this, you probably should remove rewritePath as it is no longer needed.
ruiu added a comment.Jul 17 2017, 4:34 PM

I did an experiment based on that idea, and it seems to be working, so I sent it to you as https://reviews.llvm.org/D35517.

grimar abandoned this revision.Jul 24 2017, 1:34 AM

D35517 was landed instead.