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.
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.