This is an archive of the discontinued LLVM Phabricator instance.

[ELF] - Do not crash when -r output uses linker script with `/DISCARD/`
ClosedPublic

Authored by grimar on Oct 30 2018, 3:23 AM.

Details

Summary

This is https://bugs.llvm.org/show_bug.cgi?id=39493.

We crashed previously because did not handle /DISCARD/ properly
when -r was used. I think it is uncommon to use scripts with -r, though I see
nothing wrong to handle the /DISCARD/ so that we will not crash at least.

Diff Detail

Repository
rL LLVM

Event Timeline

grimar created this revision.Oct 30 2018, 3:23 AM
grimar edited the summary of this revision. (Show Details)Oct 30 2018, 3:24 AM
grimar updated this revision to Diff 171654.Oct 30 2018, 3:27 AM
  • Simplify checks in the test.

I can confirm that this change does fix the problem observed in pr39493.

ELF/InputFiles.cpp
648 ↗(On Diff #171653)

This bit of code looks like it could be merged with if (Config->EmitRelocs) on line 692

By doing so we wouldn't be skipping the code at 672 for Config->Relocatable I don't think that this code has any side-effects that would affect a discarded section though.

652 ↗(On Diff #171653)

My understanding is that it is all Linux kernel modules use that fragment of linker script and not just arm64.

grimar updated this revision to Diff 171671.Oct 30 2018, 4:25 AM

Thanks, Peter!

  • Rewrote the comment.
ELF/InputFiles.cpp
648 ↗(On Diff #171653)

I would prefer keeping early return, that is a bit simpler IMO. Let's see what others think.

652 ↗(On Diff #171653)

Maybe it is just better to omit the name completely. It does not seem to be important that we observed this in Linux kernel, it could be anywhere.

ruiu added inline comments.Oct 30 2018, 1:16 PM
ELF/InputFiles.cpp
652 ↗(On Diff #171653)

I think it is actually important to mention Linux kernel module as a use case of linker script + the -r flag, because using -r with a linker script sounds like a really bad idea (perhaps it is though).

grimar updated this revision to Diff 171894.Oct 31 2018, 5:00 AM
  • Mentioned the Linux kernel as a user of -r + /DISCARD/ in the comment.
ruiu accepted this revision.Oct 31 2018, 10:51 AM

LGTM

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