[PATCH] D36874: [ELF] - Mention "-z notext" and -fPIC in some error messages

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 29 03:13:44 PDT 2017


grimar added inline comments.


================
Comment at: test/ELF/dynamic-reloc-in-ro.s:5-10
+// CHECK:      can't create dynamic relocation R_X86_64_64 against local symbol in readonly segment
+// CHECK-NEXT: >>> defined in {{.*}}.o
+// CHECK-NEXT: >>> referenced by {{.*}}.o:(.text+0x0)
+// CHECK-NEXT: >>> Usually this error happens when -fPIC flag is missing during compilation.
+// CHECK-NEXT: >>> Unintentional use of such relocations is undesirable, and not
+// CHECK-NEXT: >>> permited by default, consider using -z notext.
----------------
ruiu wrote:
> grimar wrote:
> > ruiu wrote:
> > > 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".
> > >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.
> 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.
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.


https://reviews.llvm.org/D36874





More information about the llvm-commits mailing list