This is an archive of the discontinued LLVM Phabricator instance.

[ELF] - DT_TEXTREL/DF_TEXTREL flags implemented.
ClosedPublic

Authored by grimar on Mar 3 2016, 10:27 AM.

Details

Summary

This patch implements DT_TEXTREL/DF_TEXTREL flags. Actually I am not sure in current implementation and would be happy to know the side opinion about it.
Problem of that feature is that somehow we should know that relocation should cause a modification of read only segment.

To do that I am checking that relocation OKind field is DynamicReloc<ELFT>::Off_Sec. Looks it is safe and correct way to use it for that ?
Also for simplification I am not iterating through sections in LOADs and just checking the read/write flag of output sections when adding relocations during Writer<ELFT>::scanRelocs().

DT_TEXTREL description:
This member's absence signifies that no relocation entry should cause a modification to a non-writable segment, as specified by the segment permissions in the program header table. If this member is present, one or more relocation entries might request modifications to a non-writable segment, and the dynamic linker can prepare accordingly. This entry is at level 2. Its use has been superseded by the DF_TEXTREL flag.

Diff Detail

Repository
rL LLVM

Event Timeline

grimar updated this revision to Diff 49750.Mar 3 2016, 10:27 AM
grimar retitled this revision from to [ELF] - DT_TEXTREL/DF_TEXTREL flags implemented..
grimar updated this object.
grimar added reviewers: ruiu, rafael.
grimar added subscribers: llvm-commits, grimar.
davide added a subscriber: davide.Mar 3 2016, 10:54 AM
davide added inline comments.
ELF/OutputSections.cpp
245 ↗(On Diff #49750)

I'm not entirely sure this is correct. Ideally you should scan through the list of segments that have dynamic rels and set the flag if flags & PF_W and type == PT_LOAD.

621 ↗(On Diff #49750)

So, DT_TEXTREL tag is not needed. It's for compatibility with older loaders, which is unlikely we're going to support anyway. I'd like to keep it away until somebody asks for it.

Also, very nitpicky comment, DT_* are generally referred as tags and not only flags in ELF jargon.
You might want to adjust your commit message accordingly.

rafael edited edge metadata.Mar 3 2016, 12:03 PM
rafael added a subscriber: rafael.

Is this actually needed?

It was noticed in freebsd because we were incorrectly creating text
relocations. Short of bugs, is it actually common to have relocations
pointing to text these days?

Cheers,
Rafael

Is this actually needed?

It was noticed in freebsd because we were incorrectly creating text
relocations. Short of bugs, is it actually common to have relocations
pointing to text these days?

Cheers,
Rafael

Doesn't all R_*_RELATIVE relocations are doing that ? I think they are used still at least for some targets. But I dont know actually how much it is needed.

ELF/OutputSections.cpp
245 ↗(On Diff #49750)

Yep, I mentioned that simplification in commit message. I think it can work and does not need the one more iteration. I am not completely sure though.

This revision was automatically updated to reflect the committed changes.
grimar added a comment.EditedMar 3 2016, 12:33 PM

I am sorry, that was closed by mistake.

I placed wrong "Differential revision: " ID when commited another patch:
http://reviews.llvm.org/D17817, r262650.

Per discussion in llvm-mails, this one will not be sumbited until a real need comes up,
so that patch should have be abandoned for now anyways.