This is an archive of the discontinued LLVM Phabricator instance.

[ELF] - Implemented -z wxneeded.
ClosedPublic

Authored by grimar on Oct 11 2016, 6:19 AM.

Details

Summary

-z wxneeded creates a PHDR PT_OPENBSD_WXNEEDED.

PT_OPENBSD_WXNEEDED
The array element specifies that a process executing this file may need to be able to map or protect memory regions as simultaneously executable and writable. If the system is unable or unwilling to permit that for this executable then it may fail immediately. This segment type is meaningful only for executable files and is ignored in other objects.

http://man.openbsd.org/OpenBSD-current/man5/elf.5

Diff Detail

Repository
rL LLVM

Event Timeline

grimar updated this revision to Diff 74238.Oct 11 2016, 6:19 AM
grimar retitled this revision from to [ELF] - Implemented -z wxneeded..
grimar updated this object.
grimar added reviewers: ruiu, rafael.
grimar added subscribers: llvm-commits, grimar, evgeny777.
ruiu edited edge metadata.Oct 11 2016, 11:02 AM

Could you give me a pointer to the OpenBSD-local patch to GNU ld which implements this -z wxneeded feature? I'd like to look at that patch to see if this patch does the same thing.

ELF/Config.h
129 ↗(On Diff #74238)

The variable naming rule here is to camel-case words with "-" as a word separator. Because "wxneeded" contains no hyphens, it should be handled as one word. Thus, ZWxneeded.

ELF/LinkerScript.cpp
1717 ↗(On Diff #74238)

Sort.

grimar updated this revision to Diff 74358.Oct 12 2016, 4:12 AM
grimar edited edge metadata.
  • Addressed review comments.
In D25472#567483, @ruiu wrote:

Could you give me a pointer to the OpenBSD-local patch to GNU ld which implements this -z wxneeded feature? I'd like to look at that patch to see if this patch does the same thing.

https://github.com/openbsd/src/commit/2a5a8fc7e30928c2cff57cfe5fb491c90d8478ad

ELF/Config.h
129 ↗(On Diff #74238)

Done.

ELF/LinkerScript.cpp
1717 ↗(On Diff #74238)

This switch is sorted by constant value I think.

ruiu accepted this revision.Oct 13 2016, 3:27 PM
ruiu edited edge metadata.

LGTM with this fix.

ELF/Writer.cpp
1112 ↗(On Diff #74358)

Just like other PT_ values in this function, this needs comment. We essentially should write more comments what it is and why we are doing this, because it is easy to forget and cannot always be inferred from what we are doing.

// PT_OPENBSD_WXNEEDED is a OpenBSD-specific header to mark the executable
// is expected to perform W^X violations, such as calling mprotect(2) or mmap(2)
// with PROT_WRITE | PROT_EXEC, which is prohibited by default on OpenBSD.
This revision is now accepted and ready to land.Oct 13 2016, 3:27 PM
This revision was automatically updated to reflect the committed changes.