This is an archive of the discontinued LLVM Phabricator instance.

ELF: Make .note.GNU-stack handling compatible with traditional linkers.
ClosedPublic

Authored by ruiu on Nov 19 2015, 4:27 PM.

Details

Reviewers
grimar
Summary

With this patch, lld creates PT_GNU_STACK segments only when all input
files have .note.GNU-stack sections. This is in line with other linkers
with a minor difference (we don't care about .note.GNU-stack rwx bits
you can always remove .note.GNU-stack sections instead of setting x bit.)

At least, NetBSD loader does not understand PT_GNU_STACK segments and
reject any executables that have the section. This patch makes lld
compatible with such operating systems.

Diff Detail

Event Timeline

ruiu updated this revision to Diff 40718.Nov 19 2015, 4:27 PM
ruiu retitled this revision from to ELF: Make .note.GNU-stack handling compatible with traditional linkers..
ruiu updated this object.
ruiu added a reviewer: grimar.
ruiu added a subscriber: llvm-commits.
grimar added inline comments.Nov 20 2015, 1:50 AM
ELF/Driver.cpp
286

Currently with this patch logic next situation can happen:
Somebody specify -z noexecstack and have one input without gnu section. Output will have executable stack what is wrong because overriding anything looks not to work.

I would think about overriding not default value but result. So if we specify -z noexecstack then always create PT_GNU_STACK segment, if -z execstack then always dont create it.

ELF/InputFiles.cpp
247

What if I have too inputs, with and without .note.GNU-stack section ?
Having logic above ZExecStack will not be set to true and PT_GNU_STACK segment will be created,
But patch description says that all inputs should have .note.GNU-stack for that.

test/ELF/gnustack.s
35

Test does not check the case when 1 input has gnu stack section and other does not.

ruiu updated this revision to Diff 40817.Nov 20 2015, 12:40 PM
ruiu added inline comments.
ELF/Driver.cpp
286

This is I think what this code does. If -z noexecstack is given, PT_GNU_STACK segment is always created whether input files have .note.GNU-stack or not. if -z execstack is given, PT_GNU_STACK is not created likewise. The point is that this command line option is handled after all input files are read.

ELF/InputFiles.cpp
247

If you have at least one file that does not have .note.GNU-stack section, ZExecStack is set to true, so PT_GNU_STACK is not created. That is in line with the description, no?

test/ELF/gnustack.s
35

Done.

grimar accepted this revision.Nov 20 2015, 3:41 PM
grimar edited edge metadata.

LGTM

ELF/Driver.cpp
286

Oh, I missed this is called after handling files, sorry.

ELF/InputFiles.cpp
247

Yes, you`re right here too. I was for some reason sure that files are iterated in a loop in this method sharing the single flag.
Applied patch and everything became clear. Sorry, will always do that next time :)

This revision is now accepted and ready to land.Nov 20 2015, 3:41 PM
grimar added inline comments.Nov 21 2015, 12:52 AM
ELF/InputFiles.cpp
178

Wih a nit: variable uses low case, should be:

bool HasGnuStack = false;
ruiu added inline comments.Nov 21 2015, 2:17 PM
ELF/InputFiles.cpp
178

Done

Can we close this ? Its still open.

ruiu closed this revision.Nov 24 2015, 12:28 PM