[flang-commits] [flang] [Flang] mark safe external globals as dso_local (PR #189709)

Jason Van Beusekom via flang-commits flang-commits at lists.llvm.org
Tue Apr 7 12:31:40 PDT 2026


================
@@ -197,6 +197,38 @@ llvm::StringRef fir::getCommandline(mlir::ModuleOp mod) {
   return {};
 }
 
+static constexpr const char *relocationModelName = "fir.relocation_model";
+
+void fir::setRelocationModel(mlir::ModuleOp mod, llvm::Reloc::Model rm) {
+  auto *ctx = mod.getContext();
+  mod->setAttr(relocationModelName,
+               mlir::IntegerAttr::get(mlir::IntegerType::get(ctx, 32),
+                                      static_cast<unsigned>(rm)));
+}
+
+llvm::Reloc::Model fir::getRelocationModel(mlir::ModuleOp mod) {
+  if (auto attr = mod->getAttrOfType<mlir::IntegerAttr>(relocationModelName)) {
+    auto val = attr.getInt();
+    if (val >= llvm::Reloc::Static && val <= llvm::Reloc::ROPI_RWPI)
+      return static_cast<llvm::Reloc::Model>(val);
+  }
+  return llvm::Reloc::PIC_;
----------------
Jason-Van-Beusekom wrote:

Done in [fc75650](https://github.com/llvm/llvm-project/pull/189709/commits/fc7565083c38b9cb75e13ae832965ff109c9ce33)

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


More information about the flang-commits mailing list