[lld] [LLD][ELF] Add `-z execute-only-report` that checks PURECODE section flags (PR #128883)
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sat Mar 1 11:53:32 PST 2025
=?utf-8?q?Csanád_Hajdú?= <csanad.hajdu at arm.com>,
=?utf-8?q?Csanád_Hajdú?= <csanad.hajdu at arm.com>,
=?utf-8?q?Csanád_Hajdú?= <csanad.hajdu at arm.com>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/128883 at github.com>
================
@@ -2176,6 +2178,37 @@ template <class ELFT> void Writer<ELFT>::checkExecuteOnly() {
"data and code";
}
+// Check which input sections of RX output sections don't have the
+// SHF_AARCH64_PURECODE or SHF_ARM_PURECODE flag set.
+template <class ELFT> void Writer<ELFT>::checkExecuteOnlyReport() {
+ if (ctx.arg.zExecuteOnlyReport == "none")
+ return;
+
+ auto reportUnless = [&](bool cond) -> ELFSyncStream {
+ if (cond)
+ return {ctx, DiagLevel::None};
+ if (ctx.arg.zExecuteOnlyReport == "error")
+ return {ctx, DiagLevel::Err};
+ if (ctx.arg.zExecuteOnlyReport == "warning")
+ return {ctx, DiagLevel::Warn};
+ return {ctx, DiagLevel::None};
+ };
+
+ uint64_t purecodeFlag =
+ ctx.arg.emachine == EM_AARCH64 ? SHF_AARCH64_PURECODE : SHF_ARM_PURECODE;
+ StringRef purecodeFlagName = ctx.arg.emachine == EM_AARCH64
+ ? "SHF_AARCH64_PURECODE"
+ : "SHF_ARM_PURECODE";
+ SmallVector<InputSection *, 0> storage;
+ for (OutputSection *osec : ctx.outputSections)
+ if (osec->getPhdrFlags() == (PF_R | PF_X))
----------------
MaskRay wrote:
Reduce indentation depth
```
for (OutputSection ...) {
if (...)
continue;
for (InputSection *...) {
if (Synthe...)
continue;
reportUnless
}
}
```
https://github.com/llvm/llvm-project/pull/128883
More information about the llvm-commits
mailing list