[lld] [lld][MachO] Support for -interposable (PR #131813)

John Holdsworth via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 18 09:19:45 PDT 2025


https://github.com/johnno1962 updated https://github.com/llvm/llvm-project/pull/131813

>From ab3ced40c11e409c676929d5059a1f6fae36015c Mon Sep 17 00:00:00 2001
From: John Holdsworth <1786033+johnno1962 at users.noreply.github.com>
Date: Tue, 18 Mar 2025 15:41:17 +0100
Subject: [PATCH] [lld][MachO] Support for -interposable

---
 lld/MachO/Config.h        | 1 +
 lld/MachO/Driver.cpp      | 1 +
 lld/MachO/Options.td      | 7 +++----
 lld/MachO/SymbolTable.cpp | 6 +++---
 4 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/lld/MachO/Config.h b/lld/MachO/Config.h
index f8dcc84e4ee1b..629fa2bfd0cb3 100644
--- a/lld/MachO/Config.h
+++ b/lld/MachO/Config.h
@@ -183,6 +183,7 @@ struct Configuration {
   bool deadStripDylibs = false;
   bool demangle = false;
   bool deadStrip = false;
+  bool interposable = false;
   bool errorForArchMismatch = false;
   bool ignoreAutoLink = false;
   // ld64 allows invalid auto link options as long as the link succeeds. LLD
diff --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp
index 4f6c9b4ddc798..a335b5750b3de 100644
--- a/lld/MachO/Driver.cpp
+++ b/lld/MachO/Driver.cpp
@@ -1676,6 +1676,7 @@ bool link(ArrayRef<const char *> argsArr, llvm::raw_ostream &stdoutOS,
 
   // Must be set before any InputSections and Symbols are created.
   config->deadStrip = args.hasArg(OPT_dead_strip);
+  config->interposable = args.hasArg(OPT_interposable);
 
   config->systemLibraryRoots = getSystemLibraryRoots(args);
   if (const char *path = getReproduceOption(args)) {
diff --git a/lld/MachO/Options.td b/lld/MachO/Options.td
index 9001e85582c12..f71d57828e7b5 100644
--- a/lld/MachO/Options.td
+++ b/lld/MachO/Options.td
@@ -390,6 +390,9 @@ def grp_opts : OptionGroup<"opts">, HelpText<"OPTIMIZATIONS">;
 def dead_strip : Flag<["-"], "dead_strip">,
     HelpText<"Remove unreachable functions and data">,
     Group<grp_opts>;
+def interposable : Flag<["-"], "interposable">,
+    HelpText<"Indirects access to all to exported symbols">,
+    Group<grp_rare>;
 def order_file : Separate<["-"], "order_file">,
     MetaVarName<"<file>">,
     HelpText<"Layout functions and data according to specification in <file>">,
@@ -873,10 +876,6 @@ def setuid_safe : Flag<["-"], "setuid_safe">,
     HelpText<"Set the MH_SETUID_SAFE bit in the mach-o header">,
     Flags<[HelpHidden]>,
     Group<grp_rare>;
-def interposable : Flag<["-"], "interposable">,
-    HelpText<"Indirects access to all to exported symbols in a dylib">,
-    Flags<[HelpHidden]>,
-    Group<grp_rare>;
 def multi_module : Flag<["-"], "multi_module">,
     Alias<interposable>,
     HelpText<"Alias for -interposable">,
diff --git a/lld/MachO/SymbolTable.cpp b/lld/MachO/SymbolTable.cpp
index a61e60a944fb4..ad48e909903b5 100644
--- a/lld/MachO/SymbolTable.cpp
+++ b/lld/MachO/SymbolTable.cpp
@@ -203,9 +203,9 @@ Defined *SymbolTable::addDefined(StringRef name, InputFile *file,
   }
 
   // With -flat_namespace, all extern symbols in dylibs are interposable.
-  // FIXME: Add support for `-interposable` (PR53680).
-  bool interposable = config->namespaceKind == NamespaceKind::flat &&
-                      config->outputType != MachO::MH_EXECUTE &&
+  bool interposable = ((config->namespaceKind == NamespaceKind::flat &&
+                        config->outputType != MachO::MH_EXECUTE) ||
+                       config->interposable) &&
                       !isPrivateExtern;
   Defined *defined = replaceSymbol<Defined>(
       s, name, file, isec, value, size, isWeakDef, /*isExternal=*/true,



More information about the llvm-commits mailing list