This is an archive of the discontinued LLVM Phabricator instance.

[MC][ELF] Don't emit .note.GNU-stack sections on Solaris
ClosedPublic

Authored by ro on Aug 30 2023, 1:33 AM.

Details

Summary

LLVM currently emits .note.GNU-stack sections on all ELF targets.

However, Solaris ld doesn't know/care about them. Even worse, with the revised Solaris GNU ld patch (D85309), there are hundreds of warnings:

/usr/gnu/bin/ld: warning: /usr/lib/amd64/crtn.o: missing .note.GNU-stack section implies executable stack
/usr/gnu/bin/ld: NOTE: This behaviour is deprecated and will be removed in a future version of the linker

The Solaris crts are not going to change here, and even if they were, GNU ld would emit PT_GNU_STACK segments that Solaris ld.so.1 ignores.

So the note sections are completely useless on Solaris and this patch disables their creation.

Instead, Solaris has its own mechanisms to control stack executability: PT_SUNW_STACK, DT_SUNW_SX_NXSTACK and the system-wide control via sxadm where nxstack defaults to on.

Tested on amd64-pc-solaris2.11 and sparcv9-sun-solaris2.11 with Solaris ld and GNU ld, and x86_64-pc-linux-gnu.

Diff Detail

Event Timeline

ro created this revision.Aug 30 2023, 1:33 AM
ro requested review of this revision.Aug 30 2023, 1:33 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 30 2023, 1:33 AM

This needs a test. We can create a file similar to test/CodeGen/X86/segmented-stacks.ll, but with just a Linux target triple and a Solaris target triple.

llvm/lib/MC/MCAsmInfoELF.cpp
32

The prevailing style is to omit else here

ro marked an inline comment as done.Aug 31 2023, 1:50 AM
ro added inline comments.
llvm/lib/MC/MCAsmInfoELF.cpp
32

I tend to forget, it seems...

ro updated this revision to Diff 554936.Aug 31 2023, 1:52 AM
ro marked an inline comment as done.
  • Formatting fix.
  • Add testcase.

I could add a SPARC testcase, too, but don't think there's much point.

MaskRay accepted this revision.Aug 31 2023, 2:16 PM
MaskRay added inline comments.
llvm/test/CodeGen/X86/execstack.ll
10

I know that Solaris has alternative section syntax?

Perhaps ; CHECK-NOGNUSTACK-NOT: .section ".note.GNU-stack" is better

This revision is now accepted and ready to land.Aug 31 2023, 2:16 PM
ro added inline comments.Sep 1 2023, 2:15 AM
llvm/test/CodeGen/X86/execstack.ll
10

It's true that the Solaris/SPARC and x86 native assemblers have differences in assembler syntax (considerable, like #progbits for the section type, and especially for the section flags on SPARC, minor on x86), but the llc output always uses gas syntax as accepted by the integrated assembler, so we can rely on that. I'll therefore leave the check as is.

clang on Solaris doesn't support external assemblers right now (not even gas). I may change that at some point, but it's low priority.

This revision was landed with ongoing or failed builds.Sep 1 2023, 2:21 AM
This revision was automatically updated to reflect the committed changes.