summaryrefslogtreecommitdiff
path: root/lld/ELF/InputFiles.cpp
diff options
context:
space:
mode:
authorFangrui Song <i@maskray.me>2025-01-23 12:32:54 -0500
committerGitHub <noreply@github.com>2025-01-23 12:32:54 -0500
commite00f1f843610416f18a2fe4779c19310e808a1a4 (patch)
tree14a6c4e4f3ba8f7bcb7553d3b9a793d7ea102ae7 /lld/ELF/InputFiles.cpp
parenta2453097e3b4010162efacb4e7edcb121da8607f (diff)
[ELF] Error for executable .note.GNU-stack unless -z execstack or -r
.note.GNU-stack with the SHF_EXECINSTR flag requires an executable stack. This is exceedingly rare. We report an error to force the user to explicitly request an executable stack. Close #121234 Pull Request: https://github.com/llvm/llvm-project/pull/124068
Diffstat (limited to 'lld/ELF/InputFiles.cpp')
-rw-r--r--lld/ELF/InputFiles.cpp13
1 files changed, 11 insertions, 2 deletions
diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp
index c44773d0b7da..c3c6812c2620 100644
--- a/lld/ELF/InputFiles.cpp
+++ b/lld/ELF/InputFiles.cpp
@@ -1025,9 +1025,18 @@ InputSectionBase *ObjFile<ELFT>::createInputSection(uint32_t idx,
// Therefore, we make LLD always add PT_GNU_STACK unless it is
// explicitly told to do otherwise (by -z execstack). Because the stack
// executable-ness is controlled solely by command line options,
- // .note.GNU-stack sections are simply ignored.
- if (name == ".note.GNU-stack")
+ // .note.GNU-stack sections are, with one exception, ignored. Report
+ // an error if we encounter an executable .note.GNU-stack to force the
+ // user to explicitly request an executable stack.
+ if (name == ".note.GNU-stack") {
+ if ((sec.sh_flags & SHF_EXECINSTR) && !ctx.arg.relocatable &&
+ ctx.arg.zGnustack != GnuStackKind::Exec) {
+ Err(ctx) << this
+ << ": requires an executable stack, but -z execstack is not "
+ "specified";
+ }
return &InputSection::discarded;
+ }
// Object files that use processor features such as Intel Control-Flow
// Enforcement (CET) or AArch64 Branch Target Identification BTI, use a