[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
This commit is contained in:
Martin Storsjö 2020-10-04 01:19:41 +03:00
parent a2cc883368
commit 19e86336ef
3 changed files with 12 additions and 2 deletions

View File

@ -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);
}

View File

@ -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

View File

@ -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