forked from OSchip/llvm-project
COFF: Add /include option.
It does not involve notions of virtual archives or virtual files, nor store a list of undefined symbols somewhere else to consume them later. We did that before. In this patch, undefined symbols are just added to the symbol table, which now can be done in very few lines of code. llvm-svn: 238681
This commit is contained in:
parent
a603c4076c
commit
e042fa9aa5
|
@ -271,9 +271,16 @@ bool LinkerDriver::link(int Argc, const char *Argv[]) {
|
|||
if (Optional<StringRef> Path = findLib(Arg->getValue()))
|
||||
Inputs.push_back(*Path);
|
||||
|
||||
// Create a symbol table.
|
||||
SymbolTable Symtab;
|
||||
|
||||
// Add undefined symbols given via the command line.
|
||||
// (/include is equivalent to Unix linker's -u option.)
|
||||
for (auto *Arg : Args->filtered(OPT_incl))
|
||||
Symtab.addUndefined(Arg->getValue());
|
||||
|
||||
// Parse all input files and put all symbols to the symbol table.
|
||||
// The symbol table will take care of name resolution.
|
||||
SymbolTable Symtab;
|
||||
for (StringRef Path : Inputs) {
|
||||
if (auto EC = Symtab.addFile(createFile(Path))) {
|
||||
llvm::errs() << Path << ": " << EC.message() << "\n";
|
||||
|
|
|
@ -23,7 +23,7 @@ namespace coff {
|
|||
SymbolTable::SymbolTable() {
|
||||
addSymbol(new DefinedAbsolute("__ImageBase", Config->ImageBase));
|
||||
if (!Config->EntryName.empty())
|
||||
addSymbol(new Undefined(Config->EntryName));
|
||||
addUndefined(Config->EntryName);
|
||||
}
|
||||
|
||||
std::error_code SymbolTable::addFile(std::unique_ptr<InputFile> File) {
|
||||
|
@ -183,6 +183,10 @@ ErrorOr<StringRef> SymbolTable::findDefaultEntry() {
|
|||
return make_dynamic_error_code("entry point must be defined");
|
||||
}
|
||||
|
||||
std::error_code SymbolTable::addUndefined(StringRef Name) {
|
||||
return addSymbol(new Undefined(Name));
|
||||
}
|
||||
|
||||
std::error_code SymbolTable::addSymbol(SymbolBody *Body) {
|
||||
OwningSymbols.push_back(std::unique_ptr<SymbolBody>(Body));
|
||||
return resolve(Body);
|
||||
|
|
|
@ -65,6 +65,9 @@ public:
|
|||
// The writer needs to infer the machine type from the object files.
|
||||
std::vector<std::unique_ptr<ObjectFile>> ObjectFiles;
|
||||
|
||||
// Creates an Undefined symbol for a given name.
|
||||
std::error_code addUndefined(StringRef Name);
|
||||
|
||||
private:
|
||||
std::error_code addObject(ObjectFile *File);
|
||||
std::error_code addArchive(ArchiveFile *File);
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
# RUN: yaml2obj < %p/Inputs/ret42.yaml > %t.obj
|
||||
|
||||
# RUN: lld -flavor link2 /out:%t.exe %t.obj
|
||||
# RUN: not lld -flavor link2 /out:%t.exe %t.obj /include:xyz >& %t.log
|
||||
# RUN: FileCheck %s < %t.log
|
||||
|
||||
CHECK: undefined symbol: xyz
|
Loading…
Reference in New Issue