[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
Sat Mar 1 12:08:45 PST 2025


================
@@ -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))
----------------
Il-Capitano wrote:

Done.

https://github.com/llvm/llvm-project/pull/128883


More information about the llvm-commits mailing list