This is an archive of the discontinued LLVM Phabricator instance.

[ELF] - Implemented -znotext
ClosedPublic

Authored by grimar on Mar 2 2017, 2:52 AM.

Details

Summary

gold linker manual describes them as:

-z text Do not permit relocations in read-only segments
-z notext Permit relocations in read-only segments (default)

In LLD default is to not permit them. Patch implements -z notext.

Diff Detail

Repository
rL LLVM

Event Timeline

grimar created this revision.Mar 2 2017, 2:52 AM
ruiu edited edge metadata.Mar 2 2017, 9:19 AM

What is a program do you want to use this for?

grimar added a comment.Mar 2 2017, 9:20 AM
In D30530#690725, @ruiu wrote:

What is a program do you want to use this for?

Linux kernel uses text relocations when KASLR (Kernel address space layout randomization) is enabled.

ruiu added a comment.Mar 2 2017, 9:25 AM

Does it pass -z text?

grimar added a comment.Mar 2 2017, 9:26 AM
In D30530#690735, @ruiu wrote:

Does it pass -z text?

No, we have no way not to fail with text relocations now.
ld.bfd accepts them by default. We - dont.
I think solution for them would be to pass -z notext.

ruiu added inline comments.Mar 2 2017, 9:31 AM
ELF/Driver.cpp
272 ↗(On Diff #90305)

Use llvm::reverse and return early.

ELF/SyntheticSections.cpp
1109–1110 ↗(On Diff #90305)

I don't think you need to check if there's actually text relocations. Set it unconditionally as long as Config->ZText is true.

grimar updated this revision to Diff 90465.Mar 3 2017, 5:37 AM
  • Addressed review comments.
grimar added inline comments.
ELF/Driver.cpp
272 ↗(On Diff #90305)

That would not work out of box with filtered.
I prepared patch for that: D30570

grimar updated this revision to Diff 90666.Mar 6 2017, 2:55 AM
  • Reimplemented getZOption()
grimar added inline comments.
ELF/Driver.cpp
270 ↗(On Diff #90666)

This can be reused, for example for "relro" vs "norelro", "execstack" vs "noexecstack" etc.

ruiu added inline comments.Mar 6 2017, 7:45 AM
ELF/Driver.cpp
614 ↗(On Diff #90666)

Do you actually need -z notext? You can just write hasZOption(Args, "text") like other options.

grimar added inline comments.Mar 6 2017, 7:55 AM
ELF/Driver.cpp
614 ↗(On Diff #90666)

The way other -z options implemented is incorrect I believe.
There are few options thatmake a pairs, like -z text/notext, -z execstack/noexecstack, -z relro/norelro, -z combreloc/nocombreloc.
Don't we want to be consistent and override previous -z options like we do for regular ones ?

ruiu added inline comments.Mar 6 2017, 8:08 AM
ELF/Driver.cpp
614 ↗(On Diff #90666)

Strictly speaking that is true, but for now focusing on -z text is better.

grimar updated this revision to Diff 90824.Mar 7 2017, 1:59 AM
grimar retitled this revision from [ELF] - Implemented -z text/-znotext to [ELF] - Implemented -znotext.
grimar edited the summary of this revision. (Show Details)
  • Addressed review comments.
ruiu accepted this revision.Mar 7 2017, 9:47 AM

LGTM

This revision is now accepted and ready to land.Mar 7 2017, 9:47 AM
This revision was automatically updated to reflect the committed changes.