[lld] r238681 - COFF: Add /include option.

Rui Ueyama ruiu at google.com
Sun May 31 12:55:41 PDT 2015


Author: ruiu
Date: Sun May 31 14:55:40 2015
New Revision: 238681

URL: http://llvm.org/viewvc/llvm-project?rev=238681&view=rev
Log:
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.

Added:
    lld/trunk/test/COFF/include.test
Modified:
    lld/trunk/COFF/Driver.cpp
    lld/trunk/COFF/SymbolTable.cpp
    lld/trunk/COFF/SymbolTable.h

Modified: lld/trunk/COFF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Driver.cpp?rev=238681&r1=238680&r2=238681&view=diff
==============================================================================
--- lld/trunk/COFF/Driver.cpp (original)
+++ lld/trunk/COFF/Driver.cpp Sun May 31 14:55:40 2015
@@ -271,9 +271,16 @@ bool LinkerDriver::link(int Argc, const
     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";

Modified: lld/trunk/COFF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/SymbolTable.cpp?rev=238681&r1=238680&r2=238681&view=diff
==============================================================================
--- lld/trunk/COFF/SymbolTable.cpp (original)
+++ lld/trunk/COFF/SymbolTable.cpp Sun May 31 14:55:40 2015
@@ -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::findDefa
   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);

Modified: lld/trunk/COFF/SymbolTable.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/SymbolTable.h?rev=238681&r1=238680&r2=238681&view=diff
==============================================================================
--- lld/trunk/COFF/SymbolTable.h (original)
+++ lld/trunk/COFF/SymbolTable.h Sun May 31 14:55:40 2015
@@ -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);

Added: lld/trunk/test/COFF/include.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/include.test?rev=238681&view=auto
==============================================================================
--- lld/trunk/test/COFF/include.test (added)
+++ lld/trunk/test/COFF/include.test Sun May 31 14:55:40 2015
@@ -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





More information about the llvm-commits mailing list