[flang-commits] [flang] [llvm] [CodeGen] Take the executable stack from a module flag (PR #215152)

Sairudra More via flang-commits flang-commits at lists.llvm.org
Sun Aug 9 21:24:41 PDT 2026


================
@@ -192,6 +193,30 @@ class BoxprocTypeRewriter : public mlir::TypeConverter {
   mlir::Location loc;
 };
 
+/// Set the "executable-stack" LLVM module flag on \p module, which makes the
+/// backend mark the `.note.GNU-stack` section executable on ELF targets.
+static void requestExecutableStack(mlir::ModuleOp module) {
+  mlir::MLIRContext *context{module.getContext()};
+  auto flag{mlir::LLVM::ModuleFlagAttr::get(
+      context, mlir::LLVM::ModFlagBehavior::Max,
+      mlir::StringAttr::get(context, "executable-stack"),
+      mlir::IntegerAttr::get(mlir::IntegerType::get(context, 32), 1))};
+
+  // Append to the module flags that are already there, if any.
+  for (auto flagsOp : module.getOps<mlir::LLVM::ModuleFlagsOp>()) {
+    llvm::SmallVector<mlir::Attribute> flags{flagsOp.getFlags().getValue()};
+    if (llvm::is_contained(flags, flag))
----------------
Saieiei wrote:

Could this look up the existing flag by key and update it instead? A valid module may already contain `executable-stack = 0`; in that case, `is_contained(flags, flag)` will not match the new value-1 attribute, so this appends a second entry for the same module-flag ID. LLVM module flags require unique IDs within a module. Please also add a regression test covering `0 -> 1`.

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


More information about the flang-commits mailing list