for (StringRef inc : directives.includes)
addUndefined(inc);
+ // Handle /exclude-symbols: in bulk.
+ for (StringRef e : directives.excludes) {
+ SmallVector<StringRef, 2> vec;
+ e.split(vec, ',');
+ for (StringRef sym : vec)
+ excludedSymbols.insert(mangle(sym));
+ }
+
// https://docs.microsoft.com/en-us/cpp/preprocessor/comment-c-cpp?view=msvc-160
for (auto *arg : directives.args) {
switch (arg->getOption().getID()) {
return;
}
- AutoExporter exporter;
+ AutoExporter exporter(excludedSymbols);
for (auto *arg : args.filtered(OPT_wholearchive_file))
if (Optional<StringRef> path = doFindFile(arg->getValue()))
struct ParsedDirectives {
std::vector<StringRef> exports;
std::vector<StringRef> includes;
+ std::vector<StringRef> excludes;
llvm::opt::InputArgList args;
};
std::vector<MemoryBufferRef> resources;
llvm::DenseSet<StringRef> directivesExports;
+ llvm::DenseSet<StringRef> excludedSymbols;
COFFLinkerContext &ctx;
else if (tok.startswith_insensitive("/include:") ||
tok.startswith_insensitive("-include:"))
result.includes.push_back(tok.substr(strlen("/include:")));
+ else if (tok.startswith_insensitive("/exclude-symbols:") ||
+ tok.startswith_insensitive("-exclude-symbols:"))
+ result.excludes.push_back(tok.substr(strlen("/exclude-symbols:")));
else {
// Copy substrings that are not valid C strings. The tokenizer may have
// already copied quoted arguments for us, so those do not need to be
using namespace lld;
using namespace lld::coff;
-AutoExporter::AutoExporter() {
+AutoExporter::AutoExporter(
+ const llvm::DenseSet<StringRef> &manualExcludeSymbols)
+ : manualExcludeSymbols(manualExcludeSymbols) {
excludeLibs = {
"libgcc",
"libgcc_s",
// disallow import symbols.
if (!isa<DefinedRegular>(sym) && !isa<DefinedCommon>(sym))
return false;
- if (excludeSymbols.count(sym->getName()))
+ if (excludeSymbols.count(sym->getName()) || manualExcludeSymbols.count(sym->getName()))
return false;
for (StringRef prefix : excludeSymbolPrefixes.keys())
#include "Symbols.h"
#include "lld/Common/LLVM.h"
#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/StringSet.h"
#include "llvm/Option/ArgList.h"
#include <vector>
// symbols for MinGW.
class AutoExporter {
public:
- AutoExporter();
+ AutoExporter(const llvm::DenseSet<StringRef> &manualExcludeSymbols);
void addWholeArchive(StringRef path);
void addExcludedSymbol(StringRef symbol);
llvm::StringSet<> excludeLibs;
llvm::StringSet<> excludeObjects;
+ const llvm::DenseSet<StringRef> &manualExcludeSymbols;
+
bool shouldExport(const COFFLinkerContext &ctx, Defined *sym) const;
};
* The ``--exclude-symbols`` option is now supported.
(`D130118 <https://reviews.llvm.org/D130118>`_)
+* Support for an entirely new object file directive, ``-exclude-symbols:``,
+ has been implemented. (`D130120 <https://reviews.llvm.org/D130120>`_)
+
MachO Improvements
------------------
--- /dev/null
+// REQUIRES: x86
+// RUN: llvm-mc -filetype=obj -triple=i686-win32-gnu %s -o %t.o
+
+// RUN: lld-link -lldmingw -dll -out:%t.dll %t.o -noentry
+// RUN: llvm-readobj --coff-exports %t.dll | FileCheck --implicit-check-not=Name: %s
+
+// CHECK: Name:
+// CHECK: Name: sym1
+
+.global _sym1
+_sym1:
+ ret
+
+.global _sym2
+_sym2:
+ ret
+
+.global _sym3
+_sym3:
+ ret
+
+.section .drectve,"yn"
+.ascii " -exclude-symbols:sym2,unknownsym"
+.ascii " -exclude-symbols:unkonwnsym,sym3"