[lld] r206647 - [PECOFF] Support LIBRARY directive.

Rui Ueyama ruiu at google.com
Fri Apr 18 13:48:21 PDT 2014


Author: ruiu
Date: Fri Apr 18 15:48:20 2014
New Revision: 206647

URL: http://llvm.org/viewvc/llvm-project?rev=206647&view=rev
Log:
[PECOFF] Support LIBRARY directive.

LIBRARY directive in a module definition file specifies the output
DLL file name. It also takes an optional value for the base address.

Modified:
    lld/trunk/include/lld/Driver/WinLinkModuleDef.h
    lld/trunk/lib/Driver/WinLinkDriver.cpp
    lld/trunk/lib/Driver/WinLinkModuleDef.cpp
    lld/trunk/test/pecoff/Inputs/exports.def

Modified: lld/trunk/include/lld/Driver/WinLinkModuleDef.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Driver/WinLinkModuleDef.h?rev=206647&r1=206646&r2=206647&view=diff
==============================================================================
--- lld/trunk/include/lld/Driver/WinLinkModuleDef.h (original)
+++ lld/trunk/include/lld/Driver/WinLinkModuleDef.h Fri Apr 18 15:48:20 2014
@@ -33,6 +33,7 @@ enum class Kind {
   kw_data,
   kw_exports,
   kw_heapsize,
+  kw_library,
   kw_name,
   kw_noname,
   kw_stacksize,
@@ -64,7 +65,7 @@ private:
 
 class Directive {
 public:
-  enum class Kind { exports, heapsize, name, stacksize, version };
+  enum class Kind { exports, heapsize, library, name, stacksize, version };
 
   Kind getKind() const { return _kind; }
   virtual ~Directive() {}
@@ -131,6 +132,23 @@ private:
   const uint64_t _baseaddr;
 };
 
+class Library : public Directive {
+public:
+  Library(StringRef name, uint64_t baseaddr)
+      : Directive(Kind::library), _name(name), _baseaddr(baseaddr) {}
+
+  static bool classof(const Directive *dir) {
+    return dir->getKind() == Kind::library;
+  }
+
+  StringRef getName() const { return _name; }
+  uint64_t getBaseAddress() const { return _baseaddr; }
+
+private:
+  const std::string _name;
+  const uint64_t _baseaddr;
+};
+
 class Version : public Directive {
 public:
   Version(int major, int minor)

Modified: lld/trunk/lib/Driver/WinLinkDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/WinLinkDriver.cpp?rev=206647&r1=206646&r2=206647&view=diff
==============================================================================
--- lld/trunk/lib/Driver/WinLinkDriver.cpp (original)
+++ lld/trunk/lib/Driver/WinLinkDriver.cpp Fri Apr 18 15:48:20 2014
@@ -1062,6 +1062,11 @@ bool WinLinkDriver::parse(int argc, cons
       } else if (auto *hs = dyn_cast<moduledef::Heapsize>(dir.getValue())) {
         ctx.setHeapReserve(hs->getReserve());
         ctx.setHeapCommit(hs->getCommit());
+      } else if (auto *lib = dyn_cast<moduledef::Library>(dir.getValue())) {
+        ctx.setIsDll(true);
+        ctx.setOutputPath(ctx.allocate(lib->getName()));
+        if (lib->getBaseAddress() && !ctx.getBaseAddress())
+          ctx.setBaseAddress(lib->getBaseAddress());
       } else if (auto *name = dyn_cast<moduledef::Name>(dir.getValue())) {
         if (!name->getOutputPath().empty() && ctx.outputPath().empty())
           ctx.setOutputPath(ctx.allocate(name->getOutputPath()));

Modified: lld/trunk/lib/Driver/WinLinkModuleDef.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/WinLinkModuleDef.cpp?rev=206647&r1=206646&r2=206647&view=diff
==============================================================================
--- lld/trunk/lib/Driver/WinLinkModuleDef.cpp (original)
+++ lld/trunk/lib/Driver/WinLinkModuleDef.cpp Fri Apr 18 15:48:20 2014
@@ -52,6 +52,7 @@ Token Lexer::lex() {
                     .Case("DATA", Kind::kw_data)
                     .Case("EXPORTS", Kind::kw_exports)
                     .Case("HEAPSIZE", Kind::kw_heapsize)
+                    .Case("LIBRARY", Kind::kw_library)
                     .Case("NAME", Kind::kw_name)
                     .Case("NONAME", Kind::kw_noname)
                     .Case("STACKSIZE", Kind::kw_stacksize)
@@ -124,6 +125,14 @@ llvm::Optional<Directive *> Parser::pars
       return llvm::None;
     return new (_alloc) Heapsize(reserve, commit);
   }
+  case Kind::kw_library: {
+    // LIBRARY
+    std::string name;
+    uint64_t baseaddr;
+    if (!parseName(name, baseaddr))
+      return llvm::None;
+    return new (_alloc) Library(name, baseaddr);
+  }
   case Kind::kw_stacksize: {
     // STACKSIZE
     uint64_t reserve, commit;

Modified: lld/trunk/test/pecoff/Inputs/exports.def
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/Inputs/exports.def?rev=206647&r1=206646&r2=206647&view=diff
==============================================================================
--- lld/trunk/test/pecoff/Inputs/exports.def (original)
+++ lld/trunk/test/pecoff/Inputs/exports.def Fri Apr 18 15:48:20 2014
@@ -1,3 +1,4 @@
+LIBRARY foo.dll
 EXPORTS
   exportfn1 @5
   exportfn2





More information about the llvm-commits mailing list