[lld] r238570 - COFF: Add /version option.

Rui Ueyama ruiu at google.com
Fri May 29 09:28:30 PDT 2015


Author: ruiu
Date: Fri May 29 11:28:29 2015
New Revision: 238570

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

Added:
    lld/trunk/test/COFF/version.test
Modified:
    lld/trunk/COFF/Config.h
    lld/trunk/COFF/Driver.cpp
    lld/trunk/COFF/Driver.h
    lld/trunk/COFF/DriverUtils.cpp
    lld/trunk/COFF/Writer.cpp

Modified: lld/trunk/COFF/Config.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Config.h?rev=238570&r1=238569&r2=238570&view=diff
==============================================================================
--- lld/trunk/COFF/Config.h (original)
+++ lld/trunk/COFF/Config.h Fri May 29 11:28:29 2015
@@ -30,6 +30,8 @@ public:
   uint64_t StackCommit = 4096;
   uint64_t HeapReserve = 1024 * 1024;
   uint64_t HeapCommit = 4096;
+  uint32_t MajorImageVersion = 0;
+  uint32_t MinorImageVersion = 0;
 
   bool insertFile(llvm::StringRef Path) {
     return VisitedFiles.insert(Path.lower()).second;

Modified: lld/trunk/COFF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Driver.cpp?rev=238570&r1=238569&r2=238570&view=diff
==============================================================================
--- lld/trunk/COFF/Driver.cpp (original)
+++ lld/trunk/COFF/Driver.cpp Fri May 29 11:28:29 2015
@@ -152,6 +152,15 @@ bool link(int Argc, const char *Argv[])
     }
   }
 
+  // Handle /version
+  if (auto *Arg = Args->getLastArg(OPT_version)) {
+    if (auto EC = parseVersion(Arg->getValue(), &Config->MajorImageVersion,
+                               &Config->MinorImageVersion)) {
+      llvm::errs() << "/version: " << 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=238570&r1=238569&r2=238570&view=diff
==============================================================================
--- lld/trunk/COFF/Driver.h (original)
+++ lld/trunk/COFF/Driver.h Fri May 29 11:28:29 2015
@@ -47,6 +47,10 @@ ErrorOr<MachineTypes> getMachineType(llv
 std::error_code parseNumbers(StringRef Arg, uint64_t *Addr,
                              uint64_t *Size = nullptr);
 
+// Parses a string in the form of "<integer>[.<integer>]".
+// Minor's default value is 0.
+std::error_code parseVersion(StringRef Arg, uint32_t *Major, uint32_t *Minor);
+
 // 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=238570&r1=238569&r2=238570&view=diff
==============================================================================
--- lld/trunk/COFF/DriverUtils.cpp (original)
+++ lld/trunk/COFF/DriverUtils.cpp Fri May 29 11:28:29 2015
@@ -139,6 +139,19 @@ std::error_code parseNumbers(StringRef A
   return std::error_code();
 }
 
+// Parses a string in the form of "<integer>[.<integer>]".
+// If second number is not present, Minor is set to 0.
+std::error_code parseVersion(StringRef Arg, uint32_t *Major, uint32_t *Minor) {
+  StringRef S1, S2;
+  std::tie(S1, S2) = Arg.split('.');
+  if (S1.getAsInteger(0, *Major))
+    return make_dynamic_error_code(Twine("invalid number: ") + S1);
+  *Minor = 0;
+  if (!S2.empty() && S2.getAsInteger(0, *Minor))
+    return make_dynamic_error_code(Twine("invalid number: ") + S2);
+  return std::error_code();
+}
+
 // Create OptTable
 
 // Create prefix string literals used in Options.td

Modified: lld/trunk/COFF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Writer.cpp?rev=238570&r1=238569&r2=238570&view=diff
==============================================================================
--- lld/trunk/COFF/Writer.cpp (original)
+++ lld/trunk/COFF/Writer.cpp Fri May 29 11:28:29 2015
@@ -259,6 +259,8 @@ void Writer::writeHeader() {
   PE->ImageBase = Config->ImageBase;
   PE->SectionAlignment = SectionAlignment;
   PE->FileAlignment = FileAlignment;
+  PE->MajorImageVersion = Config->MajorImageVersion;
+  PE->MinorImageVersion = Config->MinorImageVersion;
   PE->MajorOperatingSystemVersion = 6;
   PE->MajorSubsystemVersion = 6;
   PE->Subsystem = IMAGE_SUBSYSTEM_WINDOWS_CUI;

Added: lld/trunk/test/COFF/version.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/version.test?rev=238570&view=auto
==============================================================================
--- lld/trunk/test/COFF/version.test (added)
+++ lld/trunk/test/COFF/version.test Fri May 29 11:28:29 2015
@@ -0,0 +1,19 @@
+# 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: MajorImageVersion: 0
+DEFAULT: MinorImageVersion: 0
+
+# RUN: lld -flavor link2 /entry:main /out:%t.exe /version:11 \
+# RUN:   %p/Inputs/ret42.obj
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=CHECK1 %s
+
+CHECK1: MajorImageVersion: 11
+CHECK1: MinorImageVersion: 0
+
+# RUN: lld -flavor link2 /entry:main /out:%t.exe /version:11.22 \
+# RUN:   %p/Inputs/ret42.obj
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=CHECK2 %s
+
+CHECK2: MajorImageVersion: 11
+CHECK2: MinorImageVersion: 22





More information about the llvm-commits mailing list