[PATCH] D115775: [lld-macho] Handle $ld$hide[$os] symbols.
Vy Nguyen via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 14 18:08:19 PST 2021
oontvoo created this revision.
Herald added a project: lld-macho.
Herald added a reviewer: lld-macho.
oontvoo requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
PR/52708
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D115775
Files:
lld/MachO/InputFiles.cpp
lld/MachO/InputFiles.h
Index: lld/MachO/InputFiles.h
===================================================================
--- lld/MachO/InputFiles.h
+++ lld/MachO/InputFiles.h
@@ -190,7 +190,10 @@
bool handleLDSymbol(StringRef originalName);
void handleLDPreviousSymbol(StringRef name, StringRef originalName);
void handleLDInstallNameSymbol(StringRef name, StringRef originalName);
+ void handleHideSymbol(StringRef name, StringRef originalName);
void checkAppExtensionSafety(bool dylibIsAppExtensionSafe) const;
+
+ llvm::DenseSet<llvm::CachedStringRef> hiddenSymbols;
};
// .a file
Index: lld/MachO/InputFiles.cpp
===================================================================
--- lld/MachO/InputFiles.cpp
+++ lld/MachO/InputFiles.cpp
@@ -1154,6 +1154,8 @@
return;
bool isWeakDef = flags & EXPORT_SYMBOL_FLAGS_WEAK_DEFINITION;
bool isTlv = flags & EXPORT_SYMBOL_FLAGS_KIND_THREAD_LOCAL;
+ if (hiddenSymbols.contains(cachedHashStringRef(savedName)))
+ return;
symbols.push_back(symtab->addDylib(savedName, exportingFile,
isWeakDef, isTlv));
});
@@ -1289,6 +1291,8 @@
handleLDPreviousSymbol(name, originalName);
else if (action == "install_name")
handleLDInstallNameSymbol(name, originalName);
+ else if (action == "hide")
+ handleHideSymbol(name, originalName);
return true;
}
@@ -1357,6 +1361,28 @@
this->installName = saver.save(installName);
}
+void DylibFile::handleHideSymbol(StringRef name, StringRef originalName) {
+ StringRef symbolName;
+ bool shouldHide = true;
+ if (name.startswith("os")) {
+ // If it's hidden based on versions.
+ StringRef minVersion;
+ std::tie(minVersion, symbolName) = name.split('$');
+ VersionTuple versionTup;
+ if (versionTup.tryParse(minVersion)) {
+ warn("Failed to parse hidden version, symbol `" + originalName +
+ "` ignored.");
+ return;
+ }
+ shouldHide = versionTup == config->platformInfo.minimum;
+ } else
+ symbolName = name;
+
+ if (!shouldHide)
+ return;
+ hiddenSymbol.insert(CachedHashStringRef(symbolName));
+}
+
void DylibFile::checkAppExtensionSafety(bool dylibIsAppExtensionSafe) const {
if (config->applicationExtension && !dylibIsAppExtensionSafe)
warn("using '-application_extension' with unsafe dylib: " + toString(this));
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D115775.394433.patch
Type: text/x-patch
Size: 2448 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211215/514e731e/attachment.bin>
More information about the llvm-commits
mailing list