[lld] [lld][MachO] Support for -interposable (PR #131813)
John Holdsworth via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 18 09:12:50 PDT 2025
https://github.com/johnno1962 updated https://github.com/llvm/llvm-project/pull/131813
>From a4ca70fe98ed96344aad8b1ff3208a04f0d5fd1b 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 1/2] [lld][MachO] Support for -interposable
---
lld/MachO/Config.h | 1 +
lld/MachO/Driver.cpp | 1 +
lld/MachO/Options.td | 1 -
lld/MachO/SymbolTable.cpp | 6 +++---
4 files changed, 5 insertions(+), 4 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..abc7697fde873 100644
--- a/lld/MachO/Options.td
+++ b/lld/MachO/Options.td
@@ -875,7 +875,6 @@ def setuid_safe : Flag<["-"], "setuid_safe">,
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>,
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,
>From 718ddf31f16b618f1628bb85bf627950dce40dcf Mon Sep 17 00:00:00 2001
From: John Holdsworth <github at johnholdsworth.com>
Date: Tue, 18 Mar 2025 17:12:36 +0100
Subject: [PATCH 2/2] Move option.
---
lld/MachO/Options.td | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/lld/MachO/Options.td b/lld/MachO/Options.td
index abc7697fde873..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,9 +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">,
- Group<grp_rare>;
def multi_module : Flag<["-"], "multi_module">,
Alias<interposable>,
HelpText<"Alias for -interposable">,
More information about the llvm-commits
mailing list