From 19e86336efa75456469a2a3491fc58e65af6bd0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Sun, 4 Oct 2020 01:19:41 +0300 Subject: [PATCH] [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 --- lld/COFF/DriverUtils.cpp | 4 ++-- lld/test/COFF/subsystem.test | 4 ++++ lld/test/COFF/version.test | 6 ++++++ 3 files changed, 12 insertions(+), 2 deletions(-) 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