[lld] r190986 - [PECOFF][Driver] Support /version command line option
Rui Ueyama
ruiu at google.com
Wed Sep 18 19:37:36 PDT 2013
Author: ruiu
Date: Wed Sep 18 21:37:36 2013
New Revision: 190986
URL: http://llvm.org/viewvc/llvm-project?rev=190986&view=rev
Log:
[PECOFF][Driver] Support /version command line option
Modified:
lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h
lld/trunk/lib/Driver/WinLinkDriver.cpp
lld/trunk/lib/Driver/WinLinkOptions.td
lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
lld/trunk/test/pecoff/trivial.test
lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp
Modified: lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h?rev=190986&r1=190985&r2=190986&view=diff
==============================================================================
--- lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h (original)
+++ lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h Wed Sep 18 21:37:36 2013
@@ -31,15 +31,15 @@ public:
: _baseAddress(0x400000), _stackReserve(1024 * 1024), _stackCommit(4096),
_heapReserve(1024 * 1024), _heapCommit(4096),
_subsystem(llvm::COFF::IMAGE_SUBSYSTEM_UNKNOWN),
- _machineType(llvm::COFF::IMAGE_FILE_MACHINE_I386),
+ _machineType(llvm::COFF::IMAGE_FILE_MACHINE_I386), _imageVersion(0, 0),
_minOSVersion(6, 0), _nxCompat(true), _largeAddressAware(false),
_baseRelocationEnabled(true), _terminalServerAware(true),
_dynamicBaseEnabled(true), _imageType(ImageType::IMAGE_EXE) {
setDeadStripping(true);
}
- struct OSVersion {
- OSVersion(int v1, int v2) : majorVersion(v1), minorVersion(v2) {}
+ struct Version {
+ Version(int v1, int v2) : majorVersion(v1), minorVersion(v2) {}
int majorVersion;
int minorVersion;
};
@@ -108,8 +108,11 @@ public:
void setMachineType(MachineTypes type) { _machineType = type; }
MachineTypes getMachineType() const { return _machineType; }
- void setMinOSVersion(const OSVersion &version) { _minOSVersion = version; }
- OSVersion getMinOSVersion() const { return _minOSVersion; }
+ void setImageVersion(const Version &version) { _imageVersion = version; }
+ Version getImageVersion() const { return _imageVersion; }
+
+ void setMinOSVersion(const Version &version) { _minOSVersion = version; }
+ Version getMinOSVersion() const { return _minOSVersion; }
void setNxCompat(bool nxCompat) { _nxCompat = nxCompat; }
bool isNxCompat() const { return _nxCompat; }
@@ -163,7 +166,8 @@ private:
uint64_t _heapCommit;
WindowsSubsystem _subsystem;
MachineTypes _machineType;
- OSVersion _minOSVersion;
+ Version _imageVersion;
+ Version _minOSVersion;
bool _nxCompat;
bool _largeAddressAware;
bool _baseRelocationEnabled;
Modified: lld/trunk/lib/Driver/WinLinkDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/WinLinkDriver.cpp?rev=190986&r1=190985&r2=190986&view=diff
==============================================================================
--- lld/trunk/lib/Driver/WinLinkDriver.cpp (original)
+++ lld/trunk/lib/Driver/WinLinkDriver.cpp Wed Sep 18 21:37:36 2013
@@ -98,6 +98,20 @@ bool parseMemoryOption(StringRef arg, ui
return false;
}
+// Parse an argument for /version or /subsystem. The expected string is
+// "<integer>[.<integer>]".
+bool parseVersion(StringRef arg, uint32_t &major, uint32_t &minor) {
+ StringRef majorVersion, minorVersion;
+ llvm::tie(majorVersion, minorVersion) = arg.split('.');
+ if (minorVersion.empty())
+ minorVersion = "0";
+ if (majorVersion.getAsInteger(0, major))
+ return true;
+ if (minorVersion.getAsInteger(0, minor))
+ return true;
+ return false;
+}
+
// Returns subsystem type for the given string.
llvm::COFF::WindowsSubsystem stringToWinSubsystem(StringRef str) {
return llvm::StringSwitch<llvm::COFF::WindowsSubsystem>(str.lower())
@@ -326,6 +340,13 @@ bool WinLinkDriver::parse(int argc, cons
ctx.setMachineType(type);
break;
}
+ case OPT_version: {
+ uint32_t major, minor;
+ if (parseVersion(inputArg->getValue(), major, minor))
+ return true;
+ ctx.setImageVersion(PECOFFLinkingContext::Version(major, minor));
+ break;
+ }
case OPT_subsystem: {
// Parse /subsystem command line option. The form of /subsystem is
// "subsystem_name[,majorOSVersion[.minorOSVersion]]".
@@ -333,16 +354,10 @@ bool WinLinkDriver::parse(int argc, cons
llvm::tie(subsystemStr, osVersion) =
StringRef(inputArg->getValue()).split(',');
if (!osVersion.empty()) {
- StringRef majorVersion, minorVersion;
- llvm::tie(majorVersion, minorVersion) = osVersion.split('.');
- if (minorVersion.empty())
- minorVersion = "0";
- int32_t major, minor;
- if (majorVersion.getAsInteger(0, major))
- return true;
- if (minorVersion.getAsInteger(0, minor))
+ uint32_t major, minor;
+ if (parseVersion(osVersion, major, minor))
return true;
- ctx.setMinOSVersion(PECOFFLinkingContext::OSVersion(major, minor));
+ ctx.setMinOSVersion(PECOFFLinkingContext::Version(major, minor));
}
// Parse subsystem name.
llvm::COFF::WindowsSubsystem subsystem =
Modified: lld/trunk/lib/Driver/WinLinkOptions.td
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/WinLinkOptions.td?rev=190986&r1=190985&r2=190986&view=diff
==============================================================================
--- lld/trunk/lib/Driver/WinLinkOptions.td (original)
+++ lld/trunk/lib/Driver/WinLinkOptions.td Wed Sep 18 21:37:36 2013
@@ -20,6 +20,7 @@ defm mllvm : P<"mllvm", "Options to pa
defm out : P<"out", "Path to file to write output">;
defm stack : P<"stack", "Size of the stack">;
defm machine : P<"machine", "Specify target platform">;
+defm version : P<"version", "Specify a version number in the PE header">;
defm subsystem : P<"subsystem", "Specify subsystem">;
// We cannot use multiclass P because class name "incl" is different
Modified: lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp?rev=190986&r1=190985&r2=190986&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp Wed Sep 18 21:37:36 2013
@@ -179,10 +179,17 @@ public:
// Sections in an executable file on disk should be sector-aligned (512 byte).
_peHeader.FileAlignment = SECTOR_SIZE;
+ // The version number of the resultant executable/DLL. The number is purely
+ // informative, and neither the linker nor the loader won't use it. User can
+ // set the value using /version command line option. Default is 0.0.
+ PECOFFLinkingContext::Version imageVersion = context.getImageVersion();
+ _peHeader.MajorImageVersion = imageVersion.majorVersion;
+ _peHeader.MinorImageVersion = imageVersion.minorVersion;
+
// The required Windows version number. This is the internal version and
// shouldn't be confused with product name. Windows 7 is version 6.1 and
// Windows 8 is 6.2, for example.
- PECOFFLinkingContext::OSVersion minOSVersion = context.getMinOSVersion();
+ PECOFFLinkingContext::Version minOSVersion = context.getMinOSVersion();
_peHeader.MajorOperatingSystemVersion = minOSVersion.majorVersion;
_peHeader.MinorOperatingSystemVersion = minOSVersion.minorVersion;
_peHeader.MajorSubsystemVersion = minOSVersion.majorVersion;
Modified: lld/trunk/test/pecoff/trivial.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/trivial.test?rev=190986&r1=190985&r2=190986&view=diff
==============================================================================
--- lld/trunk/test/pecoff/trivial.test (original)
+++ lld/trunk/test/pecoff/trivial.test Wed Sep 18 21:37:36 2013
@@ -4,8 +4,8 @@
#
# RUN: yaml2obj %p/Inputs/nop.obj.yaml > %t.obj
#
-# RUN: lld -flavor link /out:%t1 /subsystem:console,3.11 /entry:start \
-# RUN: /opt:noref -- %t.obj && llvm-readobj -file-headers %t1 \
+# RUN: lld -flavor link /out:%t1 /subsystem:console,3.11 /version:1.25 \
+# RUN: /entry:start /opt:noref -- %t.obj && llvm-readobj -file-headers %t1 \
# RUN: | FileCheck -check-prefix=FILE %s
#
# RUN: lld -flavor link /out:%t1 /entry:start /opt:noref -- %t.obj \
@@ -40,8 +40,8 @@ FILE: SectionAlignment: 4096
FILE: FileAlignment: 512
FILE: MajorOperatingSystemVersion: 3
FILE: MinorOperatingSystemVersion: 11
-FILE: MajorImageVersion: 0
-FILE: MinorImageVersion: 0
+FILE: MajorImageVersion: 1
+FILE: MinorImageVersion: 25
FILE: MajorSubsystemVersion: 3
FILE: MinorSubsystemVersion: 11
FILE: SizeOfImage: 8192
Modified: lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp?rev=190986&r1=190985&r2=190986&view=diff
==============================================================================
--- lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp (original)
+++ lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp Wed Sep 18 21:37:36 2013
@@ -111,6 +111,18 @@ TEST_F(WinLinkParserTest, MachineX64) {
EXPECT_TRUE(parse("link.exe", "/machine:x64", "a.obj", nullptr));
}
+TEST_F(WinLinkParserTest, MajorImageVersion) {
+ EXPECT_FALSE(parse("link.exe", "/version:7", "foo.o", nullptr));
+ EXPECT_EQ(7, _context.getImageVersion().majorVersion);
+ EXPECT_EQ(0, _context.getImageVersion().minorVersion);
+}
+
+TEST_F(WinLinkParserTest, MajorMinorImageVersion) {
+ EXPECT_FALSE(parse("link.exe", "/version:72.35", "foo.o", nullptr));
+ EXPECT_EQ(72, _context.getImageVersion().majorVersion);
+ EXPECT_EQ(35, _context.getImageVersion().minorVersion);
+}
+
TEST_F(WinLinkParserTest, MinMajorOSVersion) {
EXPECT_FALSE(parse("link.exe", "/subsystem:windows,3", "foo.o", nullptr));
EXPECT_EQ(llvm::COFF::IMAGE_SUBSYSTEM_WINDOWS_GUI, _context.getSubsystem());
More information about the llvm-commits
mailing list