This is an archive of the discontinued LLVM Phabricator instance.

[ELF] Allow --noinhibit-exec to produce corrupted executable with relocation overflow
ClosedPublic

Authored by MaskRay on Nov 16 2018, 2:13 PM.

Details

Summary

When --noinhibit-exec is used, ld.bfd/gold emit errors but allow to produce corrupted executable, which is handy for debugging purpose. lld's --noinhibit-exec has a different meaning and changes some errors to warnings. This patch replaces "error" with "errorOrWarn" to exploit that property.

We may revisit this: if we should keep them as errors but allow to produce a corrupted executable.

Diff Detail

Repository
rL LLVM

Event Timeline

MaskRay created this revision.Nov 16 2018, 2:13 PM
grimar added inline comments.Nov 18 2018, 11:28 PM
test/ELF/x86-64-reloc-range.s
4 ↗(On Diff #174447)

I think you should change the \lld\test\ELF\no-inhibit-exec.s test case instead.

Functionality wise, this seems like a reasonable idea to me. Personally, I think I'd prefer --noinhibit-exec to more closely match the BFD approach of still emitting an actual error, but that's orthogonal to the issue this is trying to solve.

Timmmm added a subscriber: Timmmm.Nov 19 2018, 2:14 AM

This seems like a good change to me. Although if I'm understanding this correctly it isn't exactly the same as our --ignore-relocations option because other errors (e.g. undefined symbols) would cause an error in that case and they won't with --noinhibit-exec. Is that correct? I suspect we may be able to make things work even if that is the case though (hopefully without resorting to parsing the linker output).

Although if I'm understanding this correctly it isn't exactly the same as our --ignore-relocations option because other errors (e.g. undefined symbols) would cause an error in that case and they won't with --noinhibit-exec. Is that correct?

Yes.

MaskRay added inline comments.Nov 19 2018, 10:21 AM
test/ELF/x86-64-reloc-range.s
4 ↗(On Diff #174447)

When more than features interact it may be hazy where we should put the test but I do think the check should be put here as it checks that relocation overflow isn't fatal in the case of --noinhibit-exec. --noinhibit-exec is also used in other tests.

grimar accepted this revision.Nov 20 2018, 2:01 AM

LGTM.

This revision is now accepted and ready to land.Nov 20 2018, 2:01 AM

Functionality wise, this seems like a reasonable idea to me. Personally, I think I'd prefer --noinhibit-exec to more closely match the BFD approach of still emitting an actual error, but that's orthogonal to the issue this is trying to solve.

@jhenderson I'm also in favor of this: producing an executable but still an error. The current framework cannot express this as I've noted in the description. Making this possible can be a future improvement.

This revision was automatically updated to reflect the committed changes.
ruiu added a comment.Nov 27 2018, 2:29 PM

In order to make lld's --noinhibit-exec behave like GNU linkers', we need to classify errors into "hard errors" (when that happens we need to stop at a nearest checkpoint) or "soft errors" (when that happens we can continue but the output is not likely to make sense.) We cannot simply continue executing the linker after all error()s until the linker creates an output file because some errors are not continuable, and if we force linker to continue, the linker may crash because of an internal inconsistency. I'm fairly satisfied with the current lld's error handling, so I personally don't think categorizing errors into two groups is worth doing though.