This is an archive of the discontinued LLVM Phabricator instance.

[ELF] - Mention -fPIC in some error messages
ClosedPublic

Authored by grimar on Aug 18 2017, 6:56 AM.

Details

Summary

This is PR32429.

We did not mention -fPIC in error about producing dynamic relocation
in readonly segment before. Patch changes that.

Diff Detail

Event Timeline

grimar created this revision.Aug 18 2017, 6:56 AM

I think that this is a worthwhile addition, I've seen at least a couple of questions on llvm-dev that this improvement might have helped to resolve.

ELF/Relocations.cpp
570

Typo: permited should be permitted.

We may want a bit more context with the -z notext option as well as to someone unfamiliar with the options could be a compiler or a linker option, and it isn't clear from the name what it will actually do. May I suggest something like:
"Unintentional use of such relocations is undesirable, and is not permitted by default, use linker option -z notext to allow.", not a strong opinion though.

ruiu added inline comments.Aug 18 2017, 4:03 PM
test/ELF/dynamic-reloc-in-ro.s
5–10

This error message style is not desirable, as two list elements ("defined in ..." and "referenced by ..." and the description text "Usually ..." are in the same list. That is just like this

Found an error
 - at file foo.c
 - on line 100
 - Usually this error happens when you made a mistake blah blah

and I believe you can see why this is wrong.

I also wonder if you really want to mention -z notext. We want to recommend or endorse the option because we want to avoid text relocations in general. In most cases, you just need to compile object files with -fPIC, so I believe you want to mention only that.

Overall, I'd change the message to "can't create dynamic relocation R_X86_64_64 against local symbol in readonly segment; recompile object files with -fPIC to fix this error".

ruiu edited edge metadata.Aug 18 2017, 4:05 PM

I also wonder if you really want to mention -z notext. We want to recommend or endorse the option because we want to avoid text relocations in general. In most cases, you just need to compile object files with -fPIC, so I believe you want to mention only that.

Sorry, I mean "We do not want to recommend or ..."

grimar added inline comments.Aug 21 2017, 12:05 AM
test/ELF/dynamic-reloc-in-ro.s
5–10

I also wonder if you really want to mention -z notext. We want to recommend or endorse the option because we want to avoid text relocations >in general. In most cases, you just need to compile object files with -fPIC, so I believe you want to mention only that.

Reason behind mentioning -z notext is that it is by default in GNU linkers and LLD has -z text as default behavior.
It may we worth to mention as it not obvious and I expect users generally not know about this difference and
wondering why ld.bfd links fine but LLD errors out.

ruiu added inline comments.Aug 22 2017, 11:49 AM
test/ELF/dynamic-reloc-in-ro.s
5–10

But how many moderm programs need text relocations? Printing out a hint for a rare error cause is more confusing than helpful. Even if you want to print out that hint, you still don't want to write it in a such way that you are not recommending the -z notext flag.

grimar updated this revision to Diff 113048.Aug 29 2017, 3:13 AM
  • Addressed comments.
test/ELF/dynamic-reloc-in-ro.s
5–10

Well. After playing with different ways of printing this error message I think am inclined to agree with your first suggestion.
Updated the diff.

(FWIW my last attemp was:

std::string Hint =
    "\n>>> Unintentional use of such relocations is undesirable, and not "
    "permitted by default"
    "\n>>> because makes impossible to share DSO code between processes."
    "\n>>> Normally this error happens when -fPIC is missing during "
    "compilation."
    "\n>>> (-z notext option can be used to ignore this error)";

)

It is probably too large to report.

grimar retitled this revision from [ELF] - Mention "-z notext" and -fPIC in some error messages to [ELF] - Mention -fPIC in some error messages.Aug 29 2017, 3:36 AM
grimar edited the summary of this revision. (Show Details)
ruiu accepted this revision.Aug 29 2017, 7:51 AM

LGTM

This revision is now accepted and ready to land.Aug 29 2017, 7:51 AM
This revision was automatically updated to reflect the committed changes.