[lld] r238567 - COFF: Add /base option.

Rui Ueyama ruiu at google.com
Fri May 29 09:18:15 PDT 2015


Author: ruiu
Date: Fri May 29 11:18:15 2015
New Revision: 238567

URL: http://llvm.org/viewvc/llvm-project?rev=238567&view=rev
Log:
COFF: Add /base option.

Added:
    lld/trunk/test/COFF/base.test
Modified:
    lld/trunk/COFF/Driver.cpp
    lld/trunk/COFF/Driver.h
    lld/trunk/COFF/DriverUtils.cpp

Modified: lld/trunk/COFF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Driver.cpp?rev=238567&r1=238566&r2=238567&view=diff
==============================================================================
--- lld/trunk/COFF/Driver.cpp (original)
+++ lld/trunk/COFF/Driver.cpp Fri May 29 11:18:15 2015
@@ -126,6 +126,14 @@ bool link(int Argc, const char *Argv[])
   }
   Config->MachineType = MTOrErr.get();
 
+  // Handle /base
+  if (auto *Arg = Args->getLastArg(OPT_base)) {
+    if (auto EC = parseNumbers(Arg->getValue(), &Config->ImageBase)) {
+      llvm::errs() << EC.message() << "\n";
+      return false;
+    }
+  }
+
   // Parse all input files and put all symbols to the symbol table.
   // The symbol table will take care of name resolution.
   SymbolTable Symtab;

Modified: lld/trunk/COFF/Driver.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Driver.h?rev=238567&r1=238566&r2=238567&view=diff
==============================================================================
--- lld/trunk/COFF/Driver.h (original)
+++ lld/trunk/COFF/Driver.h Fri May 29 11:18:15 2015
@@ -43,6 +43,10 @@ std::string findFile(StringRef Filename)
 // For /machine option.
 ErrorOr<MachineTypes> getMachineType(llvm::opt::InputArgList *Args);
 
+// Parses a string in the form of "<integer>[,<integer>]".
+std::error_code parseNumbers(StringRef Arg, uint64_t *Addr,
+                             uint64_t *Size = nullptr);
+
 // Create enum with OPT_xxx values for each option in Options.td
 enum {
   OPT_INVALID = 0,

Modified: lld/trunk/COFF/DriverUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/DriverUtils.cpp?rev=238567&r1=238566&r2=238567&view=diff
==============================================================================
--- lld/trunk/COFF/DriverUtils.cpp (original)
+++ lld/trunk/COFF/DriverUtils.cpp Fri May 29 11:18:15 2015
@@ -128,6 +128,17 @@ ErrorOr<MachineTypes> getMachineType(llv
   return IMAGE_FILE_MACHINE_UNKNOWN;
 }
 
+// Parses a string in the form of "<integer>[,<integer>]".
+std::error_code parseNumbers(StringRef Arg, uint64_t *Addr, uint64_t *Size) {
+  StringRef S1, S2;
+  std::tie(S1, S2) = Arg.split(',');
+  if (S1.getAsInteger(0, *Addr))
+    return make_dynamic_error_code(Twine("invalid number: ") + S1);
+  if (Size && !S2.empty() && S2.getAsInteger(0, *Size))
+    return make_dynamic_error_code(Twine("invalid number: ") + S2);
+  return std::error_code();
+}
+
 // Create OptTable
 
 // Create prefix string literals used in Options.td

Added: lld/trunk/test/COFF/base.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/base.test?rev=238567&view=auto
==============================================================================
--- lld/trunk/test/COFF/base.test (added)
+++ lld/trunk/test/COFF/base.test Fri May 29 11:18:15 2015
@@ -0,0 +1,10 @@
+# RUN: lld -flavor link2 /entry:main /out:%t.exe %p/Inputs/ret42.obj
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=DEFAULT %s
+
+DEFAULT: ImageBase: 0x140000000
+
+# RUN: lld -flavor link2 /entry:main /out:%t.exe /base:0x280000000 \
+# RUN:   %p/Inputs/ret42.obj
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=BASE %s
+
+BASE: ImageBase: 0x280000000





More information about the llvm-commits mailing list