This is an archive of the discontinued LLVM Phabricator instance.

[ELF] - Set DF_TEXTREL flag properly.
AbandonedPublic

Authored by grimar on May 10 2017, 8:56 AM.

Details

Reviewers
ruiu
rafael
Summary

Documentation says that DT_TEXTREL has been superseded by the DF_TEXTREL flag.

I think that happened 18 years ago in this commit:
https://sourceware.org/git/?p=glibc.git;a=commit;h=06535ae9487708dad9048552c9c92828d998a897

https://sourceware.org/git/?p=glibc.git;a=blobdiff;f=elf/dynamic-link.h;h=59a6001069f56b075c2bebaa9bff609b8ce92d9d;hp=d322c1231faa19900cf1f5e078d93d4203b8ce7a;hb=06535ae9487708dad9048552c9c92828d998a897;hpb=fc9cfb28c05def1bfc0edc099d8001f83654fd10

In that case it looks adding DT_TEXTREL is a bit outdated and we can use DF_TEXTREL always instead.

Diff Detail

Event Timeline

grimar updated this revision to Diff 98473.May 10 2017, 8:56 AM
grimar created this revision.
  • Uploaded correct patch.

This may be be fine, but it makes the strong assumption that the world is Linux.
@emaste / @joerg should take a look and make sure the dynamic loader in their *BSDs knows about the flag (at least Ed).

Side note: if everything works just fine as is (TM), why do we need to make this change?
It buys us a new shiny flag that is pretty much equivalent to the old one for systems supporting both the DT_ and the DF_ variant, but it potentially breaks backcompatibility with older loaders not supporting the new form.
I'm not entirely sure this risk is worth it.

grimar added a comment.EditedMay 10 2017, 9:19 AM

Side note: if everything works just fine as is (TM), why do we need to make this change?
It buys us a new shiny flag that is pretty much equivalent to the old one for systems supporting both the DT_ and the DF_ variant, but it potentially breaks backcompatibility with older loaders not supporting the new form.
I'm not entirely sure this risk is worth it.

We implemented -z notext initially because had no way to produce relocations to readonly segment (here LLD differs in default behavior with bfd). That was D30530 and feature was intended to be used for linux kernel.
There was no way to link it at all that time. And DT_TEXTREL was added just as a part of a patch, but in fact kernel does not use the flags or anything, it do all things on its side and just
needs something like this option to complete link. Later, I think I saw in llvm-mails that there are other possible users of feature, not sure what they exactly need.

And my point was that if there is no real users of depricated flag, why not to try to remove it ? That will be consistent with what spec says.
In LLD we usually did not implement things that are not known to be useful, I think when I implemented D30530 I should have use DF_ and not DT_ at first place.

Side note: if everything works just fine as is (TM), why do we need to make this change?
It buys us a new shiny flag that is pretty much equivalent to the old one for systems supporting both the DT_ and the DF_ variant, but it potentially breaks backcompatibility with older loaders not supporting the new form.
I'm not entirely sure this risk is worth it.

We implemented -z notext initially because had no way to produce relocations to readonly segment (here LLD differs in default behavior with bfd). That was D30530 and feature was intended to be used for linux kernel.
There was no way to link it at all that time. And DT_TEXTREL was added just as a part of a patch, but in fact kernel does not use the flags or anything, it do all things on its side and just
needs something like this option to complete link. Later, I think I saw in llvm-mails that there are other possible users of feature, not sure what they exactly need.

And my point was that if there is no real users of depricated flag, why not to try to remove it ? That will be consistent with what spec says.
In LLD we usually did not implement things that are not known to be useful, I think when I implemented D30530 I should have use DF_ and not DT_ at first place.

If there's only one user, and that works with DF_ then feel free to switch.
But:

  1. Make sure you point out in the review next time so people don't have to guess.
  2. Please double check there are no other reasonable uses of this flag before doing the switch.

(2) is less important, as we can always add the flag back).

ruiu edited edge metadata.May 10 2017, 10:27 AM

If the Linux kernel was the only reason you wanted -z text, and the Linux kernel doesn't actually use that flag, I'd support removing -z text flag entirely.

In D33046#751201, @ruiu wrote:

If the Linux kernel was the only reason you wanted -z text, and the Linux kernel doesn't actually use that flag, I'd support removing -z text flag entirely.

Indeed, that would be even better :)

joerg added a comment.May 10 2017, 1:28 PM

At least NetBSD doesn't support/use DF_TEXTREL and only DT_TEXTREL.

In D33046#751201, @ruiu wrote:

If the Linux kernel was the only reason you wanted -z text, and the Linux kernel doesn't actually use that flag, I'd support removing -z text flag entirely.

What I was trying to say that lunux kernel does not need DT_TEXTREL or DF_TEXTREL flags, because it self relocates and not depend on flags to do that.
But without -z notext it was impossible to link it when it configured with KASLR. Because bfd allows text relocations by default and we - don't. We reported an error,
option allows to fix that.

grimar abandoned this revision.May 11 2017, 1:35 AM

At least NetBSD doesn't support/use DF_TEXTREL and only DT_TEXTREL.

Thanks Joerg ! I am abandoning this patch then.