[lld] 19e8633 - [LLD] [COFF] Fix parsing version numbers with leading zeros

Martin Storsjö via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 5 13:08:49 PDT 2020


Author: Martin Storsjö
Date: 2020-10-05T23:08:00+03:00
New Revision: 19e86336efa75456469a2a3491fc58e65af6bd0a

URL: https://github.com/llvm/llvm-project/commit/19e86336efa75456469a2a3491fc58e65af6bd0a
DIFF: https://github.com/llvm/llvm-project/commit/19e86336efa75456469a2a3491fc58e65af6bd0a.diff

LOG: [LLD] [COFF] Fix parsing version numbers with leading zeros

Parse the components as decimal, instead of decuding the base from
the string. This avoids ambiguity if the second number contains leading
zeros, which previously were parsed as indicating an octal number.

MS link.exe doesn't support hexadecimal numbers in the version numbers,
neither in /version nor in /subsystem.

Differential Revision: https://reviews.llvm.org/D88801

Added: 
    

Modified: 
    lld/COFF/DriverUtils.cpp
    lld/test/COFF/subsystem.test
    lld/test/COFF/version.test

Removed: 
    


################################################################################
diff  --git a/lld/COFF/DriverUtils.cpp b/lld/COFF/DriverUtils.cpp
index de78359bb446..d4449709e1b7 100644
--- a/lld/COFF/DriverUtils.cpp
+++ b/lld/COFF/DriverUtils.cpp
@@ -88,10 +88,10 @@ void parseNumbers(StringRef arg, uint64_t *addr, uint64_t *size) {
 void parseVersion(StringRef arg, uint32_t *major, uint32_t *minor) {
   StringRef s1, s2;
   std::tie(s1, s2) = arg.split('.');
-  if (s1.getAsInteger(0, *major))
+  if (s1.getAsInteger(10, *major))
     fatal("invalid number: " + s1);
   *minor = 0;
-  if (!s2.empty() && s2.getAsInteger(0, *minor))
+  if (!s2.empty() && s2.getAsInteger(10, *minor))
     fatal("invalid number: " + s2);
 }
 

diff  --git a/lld/test/COFF/subsystem.test b/lld/test/COFF/subsystem.test
index 5c38390c71f9..a43035eb396e 100644
--- a/lld/test/COFF/subsystem.test
+++ b/lld/test/COFF/subsystem.test
@@ -12,6 +12,10 @@ CHECK1: Subsystem: IMAGE_SUBSYSTEM_WINDOWS_GUI
 # RUN:   %p/Inputs/ret42.obj
 # RUN: llvm-readobj --file-headers %t.exe | FileCheck -check-prefix=CHECK2 %s
 
+# RUN: lld-link /entry:main /out:%t.exe /subsystem:windows,8.09 \
+# RUN:   %p/Inputs/ret42.obj
+# RUN: llvm-readobj --file-headers %t.exe | FileCheck -check-prefix=CHECK2 %s
+
 CHECK2: MajorOperatingSystemVersion: 8
 CHECK2: MinorOperatingSystemVersion: 9
 CHECK2: MajorSubsystemVersion: 8

diff  --git a/lld/test/COFF/version.test b/lld/test/COFF/version.test
index 3ec12e3ba74e..ba1f8638ab4f 100644
--- a/lld/test/COFF/version.test
+++ b/lld/test/COFF/version.test
@@ -17,3 +17,9 @@ CHECK1: MinorImageVersion: 0
 
 CHECK2: MajorImageVersion: 11
 CHECK2: MinorImageVersion: 22
+
+# RUN: lld-link /out:%t.exe /entry:main %t.obj /version:8.09
+# RUN: llvm-readobj --file-headers %t.exe | FileCheck -check-prefix=CHECK3 %s
+
+CHECK3: MajorImageVersion: 8
+CHECK3: MinorImageVersion: 9


        


More information about the llvm-commits mailing list