This is an archive of the discontinued LLVM Phabricator instance.

[ELF] FIx use-after-return of archive path
ClosedPublic

Authored by ikudrin on Jun 23 2017, 6:05 AM.

Details

Summary

There is a bug in lld which on some occasions causes InputFile::ArchiveName to store incorrect value. This happens because library name allocated on stack then converted to StringRef and assigned to member variable.

Diff Detail

Event Timeline

evgeny777 created this revision.Jun 23 2017, 6:05 AM
ruiu edited edge metadata.Jun 23 2017, 8:21 AM

I think a better approach would be to change the type of ArchiveName from StringRef to std::string. This patch may fix the issue, but I'm not 100% sure because it fixes only one path that can reach addFile function. There might be some other places at which we pass on-stack objects to the function.

Test case?

Any suggestions how to implement it?

ikudrin commandeered this revision.Feb 15 2018, 5:57 AM
ikudrin added a reviewer: evgeny777.

I asked @evgeny777 and he let me take this revision.

ikudrin updated this revision to Diff 134413.Feb 15 2018, 6:05 AM
  • Change type of ArchiveName to std::string.
  • Add a test.
ikudrin updated this revision to Diff 134415.Feb 15 2018, 6:08 AM
  • Remove "tee" in the test.
ruiu accepted this revision.Feb 15 2018, 10:31 AM

LGTM

test/ELF/whole-archive-name.s
8

I think you can remove test/ELF/Inputs/whole-archive-name.s because you only need single .s file. Since --whole-archive links everything, you don't need to pass any .o file. I.e. you can just pass an .a file.

This revision is now accepted and ready to land.Feb 15 2018, 10:31 AM
This revision was automatically updated to reflect the committed changes.