[lld] [LLD][ELF] Add `-z execute-only-report` that checks PURECODE section flags (PR #128883)
Csanád Hajdú via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 27 01:33:16 PST 2025
================
@@ -2177,6 +2179,38 @@ 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.emachine != EM_AARCH64 && ctx.arg.emachine != EM_ARM) ||
+ 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))
+ for (InputSection *sec : getInputSections(*osec, storage))
+ if (sec->file && sec->file->getName() != "<internal>")
----------------
Il-Capitano wrote:
That's a good point, thanks for the suggestion.
https://github.com/llvm/llvm-project/pull/128883
More information about the llvm-commits
mailing list