2013-05-31 07:17:58 +08:00
|
|
|
//===- lld/unittest/WinLinkDriverTest.cpp ---------------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
///
|
|
|
|
/// \file
|
|
|
|
/// \brief Windows link.exe driver tests.
|
|
|
|
///
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2013-05-31 10:12:34 +08:00
|
|
|
#include "DriverTest.h"
|
2013-05-31 07:17:58 +08:00
|
|
|
|
2013-08-07 06:31:59 +08:00
|
|
|
#include "lld/ReaderWriter/PECOFFLinkingContext.h"
|
2013-11-06 15:31:55 +08:00
|
|
|
#include "llvm/ADT/Optional.h"
|
2013-05-31 07:17:58 +08:00
|
|
|
#include "llvm/Support/COFF.h"
|
|
|
|
|
2013-12-28 16:11:21 +08:00
|
|
|
#include <set>
|
2013-07-19 09:38:49 +08:00
|
|
|
#include <vector>
|
|
|
|
|
2013-05-31 07:17:58 +08:00
|
|
|
using namespace llvm;
|
|
|
|
using namespace lld;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2013-08-07 06:31:59 +08:00
|
|
|
class WinLinkParserTest
|
|
|
|
: public ParserTest<WinLinkDriver, PECOFFLinkingContext> {
|
2013-05-31 07:17:58 +08:00
|
|
|
protected:
|
2013-08-07 06:31:59 +08:00
|
|
|
virtual const LinkingContext *linkingContext() { return &_context; }
|
2013-05-31 07:17:58 +08:00
|
|
|
};
|
|
|
|
|
2013-05-31 10:12:34 +08:00
|
|
|
TEST_F(WinLinkParserTest, Basic) {
|
2013-09-25 07:26:34 +08:00
|
|
|
EXPECT_TRUE(parse("link.exe", "/subsystem:console", "/out:a.exe",
|
|
|
|
"-entry:start", "a.obj", "b.obj", "c.obj", nullptr));
|
2013-08-07 06:31:59 +08:00
|
|
|
EXPECT_EQ(llvm::COFF::IMAGE_SUBSYSTEM_WINDOWS_CUI, _context.getSubsystem());
|
2013-09-13 03:46:53 +08:00
|
|
|
EXPECT_EQ(llvm::COFF::IMAGE_FILE_MACHINE_I386, _context.getMachineType());
|
2013-08-07 06:31:59 +08:00
|
|
|
EXPECT_EQ("a.exe", _context.outputPath());
|
|
|
|
EXPECT_EQ("_start", _context.entrySymbolName());
|
2013-12-05 21:07:49 +08:00
|
|
|
EXPECT_EQ(4, inputFileCount());
|
2013-07-17 02:45:57 +08:00
|
|
|
EXPECT_EQ("a.obj", inputFile(0));
|
|
|
|
EXPECT_EQ("b.obj", inputFile(1));
|
|
|
|
EXPECT_EQ("c.obj", inputFile(2));
|
2013-08-07 06:31:59 +08:00
|
|
|
EXPECT_TRUE(_context.getInputSearchPaths().empty());
|
2013-07-23 09:29:50 +08:00
|
|
|
|
|
|
|
// Unspecified flags will have default values.
|
2014-01-03 11:29:15 +08:00
|
|
|
EXPECT_EQ(PECOFFLinkingContext::ImageType::exe, _context.getImageType());
|
2013-08-07 06:31:59 +08:00
|
|
|
EXPECT_EQ(6, _context.getMinOSVersion().majorVersion);
|
|
|
|
EXPECT_EQ(0, _context.getMinOSVersion().minorVersion);
|
|
|
|
EXPECT_EQ(0x400000U, _context.getBaseAddress());
|
|
|
|
EXPECT_EQ(1024 * 1024U, _context.getStackReserve());
|
|
|
|
EXPECT_EQ(4096U, _context.getStackCommit());
|
2013-11-07 03:30:14 +08:00
|
|
|
EXPECT_EQ(4096U, _context.getSectionDefaultAlignment());
|
2013-08-07 06:31:59 +08:00
|
|
|
EXPECT_FALSE(_context.allowRemainingUndefines());
|
|
|
|
EXPECT_TRUE(_context.isNxCompat());
|
|
|
|
EXPECT_FALSE(_context.getLargeAddressAware());
|
2013-09-24 04:44:20 +08:00
|
|
|
EXPECT_TRUE(_context.getAllowBind());
|
2013-09-24 05:22:01 +08:00
|
|
|
EXPECT_TRUE(_context.getAllowIsolation());
|
2013-09-24 12:20:37 +08:00
|
|
|
EXPECT_FALSE(_context.getSwapRunFromCD());
|
|
|
|
EXPECT_FALSE(_context.getSwapRunFromNet());
|
2013-08-07 06:31:59 +08:00
|
|
|
EXPECT_TRUE(_context.getBaseRelocationEnabled());
|
|
|
|
EXPECT_TRUE(_context.isTerminalServerAware());
|
2013-08-24 08:39:10 +08:00
|
|
|
EXPECT_TRUE(_context.getDynamicBaseEnabled());
|
2013-10-22 11:49:35 +08:00
|
|
|
EXPECT_TRUE(_context.getCreateManifest());
|
2013-10-23 04:53:07 +08:00
|
|
|
EXPECT_EQ("a.exe.manifest", _context.getManifestOutputPath());
|
2013-10-23 05:39:04 +08:00
|
|
|
EXPECT_EQ("", _context.getManifestDependency());
|
2013-10-22 11:49:35 +08:00
|
|
|
EXPECT_FALSE(_context.getEmbedManifest());
|
|
|
|
EXPECT_EQ(1, _context.getManifestId());
|
|
|
|
EXPECT_EQ("'asInvoker'", _context.getManifestLevel());
|
2013-10-23 01:42:42 +08:00
|
|
|
EXPECT_EQ("'false'", _context.getManifestUiAccess());
|
2013-08-27 11:38:18 +08:00
|
|
|
EXPECT_TRUE(_context.deadStrip());
|
2013-09-27 06:46:04 +08:00
|
|
|
EXPECT_FALSE(_context.logInputFiles());
|
2013-05-31 07:17:58 +08:00
|
|
|
}
|
|
|
|
|
2013-09-24 07:51:31 +08:00
|
|
|
TEST_F(WinLinkParserTest, StartsWithHyphen) {
|
2013-09-25 07:26:34 +08:00
|
|
|
EXPECT_TRUE(
|
|
|
|
parse("link.exe", "-subsystem:console", "-out:a.exe", "a.obj", nullptr));
|
2013-08-07 06:31:59 +08:00
|
|
|
EXPECT_EQ(llvm::COFF::IMAGE_SUBSYSTEM_WINDOWS_CUI, _context.getSubsystem());
|
|
|
|
EXPECT_EQ("a.exe", _context.outputPath());
|
2013-12-05 21:07:49 +08:00
|
|
|
EXPECT_EQ(2, inputFileCount());
|
2013-07-17 02:45:57 +08:00
|
|
|
EXPECT_EQ("a.obj", inputFile(0));
|
2013-05-31 07:29:28 +08:00
|
|
|
}
|
|
|
|
|
2013-08-29 04:27:41 +08:00
|
|
|
TEST_F(WinLinkParserTest, UppercaseOption) {
|
2013-09-25 07:26:34 +08:00
|
|
|
EXPECT_TRUE(
|
|
|
|
parse("link.exe", "/SUBSYSTEM:CONSOLE", "/OUT:a.exe", "a.obj", nullptr));
|
2013-08-29 04:27:41 +08:00
|
|
|
EXPECT_EQ(llvm::COFF::IMAGE_SUBSYSTEM_WINDOWS_CUI, _context.getSubsystem());
|
|
|
|
EXPECT_EQ("a.exe", _context.outputPath());
|
2013-12-05 21:07:49 +08:00
|
|
|
EXPECT_EQ(2, inputFileCount());
|
2013-08-29 04:27:41 +08:00
|
|
|
EXPECT_EQ("a.obj", inputFile(0));
|
|
|
|
}
|
|
|
|
|
2013-07-27 04:54:36 +08:00
|
|
|
TEST_F(WinLinkParserTest, Mllvm) {
|
2013-09-25 07:26:34 +08:00
|
|
|
EXPECT_TRUE(parse("link.exe", "/mllvm:-debug", "a.obj", nullptr));
|
2013-08-07 06:31:59 +08:00
|
|
|
const std::vector<const char *> &options = _context.llvmOptions();
|
2013-07-27 04:54:36 +08:00
|
|
|
EXPECT_EQ(1U, options.size());
|
2013-09-24 08:47:31 +08:00
|
|
|
EXPECT_STREQ("-debug", options[0]);
|
2013-07-27 04:54:36 +08:00
|
|
|
}
|
|
|
|
|
2013-09-24 05:38:03 +08:00
|
|
|
TEST_F(WinLinkParserTest, NoInputFiles) {
|
2013-09-25 07:26:34 +08:00
|
|
|
EXPECT_FALSE(parse("link.exe", nullptr));
|
2013-09-24 05:38:03 +08:00
|
|
|
EXPECT_EQ("No input files\n", errorMessage());
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Tests for implicit file extension interpolation.
|
|
|
|
//
|
|
|
|
|
2013-05-31 10:12:34 +08:00
|
|
|
TEST_F(WinLinkParserTest, NoFileExtension) {
|
2013-09-25 07:26:34 +08:00
|
|
|
EXPECT_TRUE(parse("link.exe", "foo", "bar", nullptr));
|
2013-08-07 06:31:59 +08:00
|
|
|
EXPECT_EQ("foo.exe", _context.outputPath());
|
2013-12-05 21:07:49 +08:00
|
|
|
EXPECT_EQ(3, inputFileCount());
|
2013-07-17 02:45:57 +08:00
|
|
|
EXPECT_EQ("foo.obj", inputFile(0));
|
|
|
|
EXPECT_EQ("bar.obj", inputFile(1));
|
2013-05-31 07:17:58 +08:00
|
|
|
}
|
|
|
|
|
2013-05-31 10:12:34 +08:00
|
|
|
TEST_F(WinLinkParserTest, NonStandardFileExtension) {
|
2013-09-25 07:26:34 +08:00
|
|
|
EXPECT_TRUE(parse("link.exe", "foo.o", nullptr));
|
2013-08-07 06:31:59 +08:00
|
|
|
EXPECT_EQ("foo.exe", _context.outputPath());
|
2013-12-05 21:07:49 +08:00
|
|
|
EXPECT_EQ(2, inputFileCount());
|
2013-07-17 02:45:57 +08:00
|
|
|
EXPECT_EQ("foo.o", inputFile(0));
|
2013-05-31 07:17:58 +08:00
|
|
|
}
|
|
|
|
|
2013-07-19 09:38:49 +08:00
|
|
|
TEST_F(WinLinkParserTest, Libpath) {
|
2013-09-25 07:26:34 +08:00
|
|
|
EXPECT_TRUE(
|
|
|
|
parse("link.exe", "/libpath:dir1", "/libpath:dir2", "a.obj", nullptr));
|
2013-08-07 06:31:59 +08:00
|
|
|
const std::vector<StringRef> &paths = _context.getInputSearchPaths();
|
2013-07-24 01:25:25 +08:00
|
|
|
EXPECT_EQ(2U, paths.size());
|
2013-07-19 09:38:49 +08:00
|
|
|
EXPECT_EQ("dir1", paths[0]);
|
|
|
|
EXPECT_EQ("dir2", paths[1]);
|
|
|
|
}
|
|
|
|
|
2013-11-21 09:08:53 +08:00
|
|
|
//
|
|
|
|
// Tests for input file order
|
|
|
|
//
|
|
|
|
|
|
|
|
TEST_F(WinLinkParserTest, InputOrder) {
|
|
|
|
EXPECT_TRUE(parse("link.exe", "b.lib", "b.obj", "c.obj", "a.lib", "a.obj",
|
|
|
|
nullptr));
|
2013-12-05 21:07:49 +08:00
|
|
|
EXPECT_EQ(6, inputFileCount());
|
2013-11-21 09:08:53 +08:00
|
|
|
EXPECT_EQ("b.obj", inputFile(0));
|
|
|
|
EXPECT_EQ("c.obj", inputFile(1));
|
|
|
|
EXPECT_EQ("a.obj", inputFile(2));
|
|
|
|
EXPECT_EQ("b.lib", inputFile(3));
|
|
|
|
EXPECT_EQ("a.lib", inputFile(4));
|
|
|
|
}
|
|
|
|
|
2013-09-24 05:38:03 +08:00
|
|
|
//
|
|
|
|
// Tests for command line options that take values.
|
|
|
|
//
|
|
|
|
|
2013-12-09 09:47:32 +08:00
|
|
|
TEST_F(WinLinkParserTest, AlternateName) {
|
|
|
|
EXPECT_TRUE(parse("link.exe", "/alternatename:sym1=sym2", "a.out", nullptr));
|
|
|
|
EXPECT_EQ("sym1", _context.getAlternateName("sym2"));
|
|
|
|
EXPECT_EQ("", _context.getAlternateName("foo"));
|
|
|
|
}
|
|
|
|
|
2013-12-12 11:11:26 +08:00
|
|
|
TEST_F(WinLinkParserTest, Export) {
|
2013-12-13 16:42:52 +08:00
|
|
|
EXPECT_TRUE(parse("link.exe", "/export:foo", "a.out", nullptr));
|
2013-12-28 16:11:21 +08:00
|
|
|
const std::set<PECOFFLinkingContext::ExportDesc> &exports =
|
2013-12-13 16:42:52 +08:00
|
|
|
_context.getDllExports();
|
2013-12-25 14:47:40 +08:00
|
|
|
EXPECT_EQ(1U, exports.size());
|
2013-12-28 16:11:21 +08:00
|
|
|
auto it = exports.begin();
|
|
|
|
EXPECT_EQ("_foo", it->name);
|
2013-12-28 16:40:23 +08:00
|
|
|
EXPECT_EQ(-1, it->ordinal);
|
2013-12-28 16:11:21 +08:00
|
|
|
EXPECT_FALSE(it->noname);
|
|
|
|
EXPECT_FALSE(it->isData);
|
2013-12-13 16:42:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WinLinkParserTest, ExportWithOptions) {
|
|
|
|
EXPECT_TRUE(parse("link.exe", "/export:foo,@8,noname,data",
|
|
|
|
"/export:bar,@10,data", "a.out", nullptr));
|
2013-12-28 16:11:21 +08:00
|
|
|
const std::set<PECOFFLinkingContext::ExportDesc> &exports =
|
2013-12-13 16:42:52 +08:00
|
|
|
_context.getDllExports();
|
2013-12-25 14:47:40 +08:00
|
|
|
EXPECT_EQ(2U, exports.size());
|
2013-12-28 16:11:21 +08:00
|
|
|
auto it = exports.begin();
|
|
|
|
EXPECT_EQ("_bar", it->name);
|
|
|
|
EXPECT_EQ(10, it->ordinal);
|
|
|
|
EXPECT_FALSE(it->noname);
|
|
|
|
EXPECT_TRUE(it->isData);
|
|
|
|
++it;
|
|
|
|
EXPECT_EQ("_foo", it->name);
|
|
|
|
EXPECT_EQ(8, it->ordinal);
|
|
|
|
EXPECT_TRUE(it->noname);
|
|
|
|
EXPECT_TRUE(it->isData);
|
2013-12-12 11:11:26 +08:00
|
|
|
}
|
|
|
|
|
2013-12-25 14:46:45 +08:00
|
|
|
TEST_F(WinLinkParserTest, ExportDuplicateExports) {
|
|
|
|
EXPECT_TRUE(
|
|
|
|
parse("link.exe", "/export:foo,@1", "/export:foo,@2", "a.out", nullptr));
|
2013-12-28 16:11:21 +08:00
|
|
|
const std::set<PECOFFLinkingContext::ExportDesc> &exports =
|
2013-12-25 14:46:45 +08:00
|
|
|
_context.getDllExports();
|
|
|
|
EXPECT_EQ(1U, exports.size());
|
2013-12-28 16:11:21 +08:00
|
|
|
auto it = exports.begin();
|
|
|
|
EXPECT_EQ("_foo", it->name);
|
|
|
|
EXPECT_EQ(1, it->ordinal);
|
2013-12-25 14:46:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WinLinkParserTest, ExportDuplicateOrdinals) {
|
2013-12-16 17:15:58 +08:00
|
|
|
EXPECT_FALSE(
|
|
|
|
parse("link.exe", "/export:foo,@1", "/export:bar,@1", "a.out", nullptr));
|
|
|
|
}
|
|
|
|
|
2013-12-16 14:41:06 +08:00
|
|
|
TEST_F(WinLinkParserTest, ExportInvalid1) {
|
|
|
|
EXPECT_FALSE(parse("link.exe", "/export:foo,@0", "a.out", nullptr));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WinLinkParserTest, ExportInvalid2) {
|
|
|
|
EXPECT_FALSE(parse("link.exe", "/export:foo,@65536", "a.out", nullptr));
|
|
|
|
}
|
|
|
|
|
2013-09-24 05:52:01 +08:00
|
|
|
TEST_F(WinLinkParserTest, MachineX86) {
|
2013-09-25 07:26:34 +08:00
|
|
|
EXPECT_TRUE(parse("link.exe", "/machine:x86", "a.obj", nullptr));
|
2013-09-24 05:52:01 +08:00
|
|
|
EXPECT_EQ(llvm::COFF::IMAGE_FILE_MACHINE_I386, _context.getMachineType());
|
|
|
|
}
|
|
|
|
|
2013-09-06 12:17:07 +08:00
|
|
|
TEST_F(WinLinkParserTest, MachineX64) {
|
2013-09-25 07:26:34 +08:00
|
|
|
EXPECT_FALSE(parse("link.exe", "/machine:x64", "a.obj", nullptr));
|
|
|
|
EXPECT_TRUE(StringRef(errorMessage())
|
|
|
|
.startswith("Machine type other than x86 is not supported"));
|
2013-09-06 12:17:07 +08:00
|
|
|
}
|
|
|
|
|
2013-09-19 10:37:36 +08:00
|
|
|
TEST_F(WinLinkParserTest, MajorImageVersion) {
|
2013-09-25 07:26:34 +08:00
|
|
|
EXPECT_TRUE(parse("link.exe", "/version:7", "foo.o", nullptr));
|
2013-09-19 10:37:36 +08:00
|
|
|
EXPECT_EQ(7, _context.getImageVersion().majorVersion);
|
|
|
|
EXPECT_EQ(0, _context.getImageVersion().minorVersion);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WinLinkParserTest, MajorMinorImageVersion) {
|
2013-09-25 07:26:34 +08:00
|
|
|
EXPECT_TRUE(parse("link.exe", "/version:72.35", "foo.o", nullptr));
|
2013-09-19 10:37:36 +08:00
|
|
|
EXPECT_EQ(72, _context.getImageVersion().majorVersion);
|
|
|
|
EXPECT_EQ(35, _context.getImageVersion().minorVersion);
|
|
|
|
}
|
|
|
|
|
2013-05-31 14:30:10 +08:00
|
|
|
TEST_F(WinLinkParserTest, MinMajorOSVersion) {
|
2013-09-25 07:26:34 +08:00
|
|
|
EXPECT_TRUE(parse("link.exe", "/subsystem:windows,3", "foo.o", nullptr));
|
2013-08-07 06:31:59 +08:00
|
|
|
EXPECT_EQ(llvm::COFF::IMAGE_SUBSYSTEM_WINDOWS_GUI, _context.getSubsystem());
|
|
|
|
EXPECT_EQ(3, _context.getMinOSVersion().majorVersion);
|
|
|
|
EXPECT_EQ(0, _context.getMinOSVersion().minorVersion);
|
2013-05-31 14:30:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WinLinkParserTest, MinMajorMinorOSVersion) {
|
2013-09-25 07:26:34 +08:00
|
|
|
EXPECT_TRUE(parse("link.exe", "/subsystem:windows,3.1", "foo.o", nullptr));
|
2013-08-07 06:31:59 +08:00
|
|
|
EXPECT_EQ(llvm::COFF::IMAGE_SUBSYSTEM_WINDOWS_GUI, _context.getSubsystem());
|
|
|
|
EXPECT_EQ(3, _context.getMinOSVersion().majorVersion);
|
|
|
|
EXPECT_EQ(1, _context.getMinOSVersion().minorVersion);
|
2013-05-31 14:30:10 +08:00
|
|
|
}
|
|
|
|
|
2013-07-20 08:45:00 +08:00
|
|
|
TEST_F(WinLinkParserTest, Base) {
|
2013-09-25 07:26:34 +08:00
|
|
|
EXPECT_TRUE(parse("link.exe", "/base:8388608", "a.obj", nullptr));
|
2013-08-07 06:31:59 +08:00
|
|
|
EXPECT_EQ(0x800000U, _context.getBaseAddress());
|
2013-07-20 08:45:00 +08:00
|
|
|
}
|
|
|
|
|
2013-09-24 05:52:01 +08:00
|
|
|
TEST_F(WinLinkParserTest, InvalidBase) {
|
2013-09-25 07:26:34 +08:00
|
|
|
EXPECT_FALSE(parse("link.exe", "/base:1234", "a.obj", nullptr));
|
|
|
|
EXPECT_TRUE(StringRef(errorMessage())
|
|
|
|
.startswith("Base address have to be multiple of 64K"));
|
2013-09-24 05:52:01 +08:00
|
|
|
}
|
|
|
|
|
2013-06-08 11:59:00 +08:00
|
|
|
TEST_F(WinLinkParserTest, StackReserve) {
|
2013-09-25 07:26:34 +08:00
|
|
|
EXPECT_TRUE(parse("link.exe", "/stack:8192", "a.obj", nullptr));
|
2013-08-07 06:31:59 +08:00
|
|
|
EXPECT_EQ(8192U, _context.getStackReserve());
|
|
|
|
EXPECT_EQ(4096U, _context.getStackCommit());
|
2013-06-08 11:59:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WinLinkParserTest, StackReserveAndCommit) {
|
2013-09-25 07:26:34 +08:00
|
|
|
EXPECT_TRUE(parse("link.exe", "/stack:16384,8192", "a.obj", nullptr));
|
2013-08-07 06:31:59 +08:00
|
|
|
EXPECT_EQ(16384U, _context.getStackReserve());
|
|
|
|
EXPECT_EQ(8192U, _context.getStackCommit());
|
2013-06-08 11:59:00 +08:00
|
|
|
}
|
2013-06-09 06:59:10 +08:00
|
|
|
|
2013-09-24 05:52:01 +08:00
|
|
|
TEST_F(WinLinkParserTest, InvalidStackSize) {
|
2013-09-25 07:26:34 +08:00
|
|
|
EXPECT_FALSE(parse("link.exe", "/stack:8192,16384", "a.obj", nullptr));
|
2013-09-24 05:52:01 +08:00
|
|
|
EXPECT_TRUE(StringRef(errorMessage()).startswith("Invalid stack size"));
|
|
|
|
}
|
|
|
|
|
2013-06-09 06:59:10 +08:00
|
|
|
TEST_F(WinLinkParserTest, HeapReserve) {
|
2013-09-25 07:26:34 +08:00
|
|
|
EXPECT_TRUE(parse("link.exe", "/heap:8192", "a.obj", nullptr));
|
2013-08-07 06:31:59 +08:00
|
|
|
EXPECT_EQ(8192U, _context.getHeapReserve());
|
|
|
|
EXPECT_EQ(4096U, _context.getHeapCommit());
|
2013-06-09 06:59:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WinLinkParserTest, HeapReserveAndCommit) {
|
2013-09-25 07:26:34 +08:00
|
|
|
EXPECT_TRUE(parse("link.exe", "/heap:16384,8192", "a.obj", nullptr));
|
2013-08-07 06:31:59 +08:00
|
|
|
EXPECT_EQ(16384U, _context.getHeapReserve());
|
|
|
|
EXPECT_EQ(8192U, _context.getHeapCommit());
|
2013-06-09 06:59:10 +08:00
|
|
|
}
|
2013-06-11 12:52:14 +08:00
|
|
|
|
2013-09-24 05:52:01 +08:00
|
|
|
TEST_F(WinLinkParserTest, InvalidHeapSize) {
|
2013-09-25 07:26:34 +08:00
|
|
|
EXPECT_FALSE(parse("link.exe", "/heap:8192,16384", "a.obj", nullptr));
|
2013-09-24 05:52:01 +08:00
|
|
|
EXPECT_TRUE(StringRef(errorMessage()).startswith("Invalid heap size"));
|
|
|
|
}
|
|
|
|
|
2013-09-24 03:52:35 +08:00
|
|
|
TEST_F(WinLinkParserTest, SectionAlignment) {
|
2013-09-25 07:26:34 +08:00
|
|
|
EXPECT_TRUE(parse("link.exe", "/align:8192", "a.obj", nullptr));
|
2013-11-07 03:30:14 +08:00
|
|
|
EXPECT_EQ(8192U, _context.getSectionDefaultAlignment());
|
2013-09-24 03:52:35 +08:00
|
|
|
}
|
|
|
|
|
2013-11-27 01:57:05 +08:00
|
|
|
TEST_F(WinLinkParserTest, InvalidAlignment) {
|
|
|
|
EXPECT_FALSE(parse("link.exe", "/align:1000", "a.obj", nullptr));
|
|
|
|
EXPECT_EQ("Section alignment must be a power of 2, but got 1000\n",
|
|
|
|
errorMessage());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WinLinkParserTest, Include) {
|
|
|
|
EXPECT_TRUE(parse("link.exe", "/include:foo", "a.out", nullptr));
|
|
|
|
auto symbols = _context.initialUndefinedSymbols();
|
|
|
|
EXPECT_FALSE(symbols.empty());
|
|
|
|
EXPECT_EQ("foo", symbols[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WinLinkParserTest, Merge) {
|
|
|
|
EXPECT_TRUE(parse("link.exe", "/merge:.foo=.bar", "/merge:.bar=.baz",
|
|
|
|
"a.out", nullptr));
|
2013-11-28 02:03:31 +08:00
|
|
|
EXPECT_EQ(".baz", _context.getOutputSectionName(".foo"));
|
|
|
|
EXPECT_EQ(".baz", _context.getOutputSectionName(".bar"));
|
|
|
|
EXPECT_EQ(".abc", _context.getOutputSectionName(".abc"));
|
2013-11-27 01:57:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WinLinkParserTest, Merge_Circular) {
|
|
|
|
EXPECT_FALSE(parse("link.exe", "/merge:.foo=.bar", "/merge:.bar=.foo",
|
|
|
|
"a.out", nullptr));
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Tests for /section
|
|
|
|
//
|
|
|
|
|
2013-11-28 03:07:28 +08:00
|
|
|
namespace {
|
|
|
|
const uint32_t discardable = llvm::COFF::IMAGE_SCN_MEM_DISCARDABLE;
|
|
|
|
const uint32_t not_cached = llvm::COFF::IMAGE_SCN_MEM_NOT_CACHED;
|
|
|
|
const uint32_t not_paged = llvm::COFF::IMAGE_SCN_MEM_NOT_PAGED;
|
|
|
|
const uint32_t shared = llvm::COFF::IMAGE_SCN_MEM_SHARED;
|
|
|
|
const uint32_t execute = llvm::COFF::IMAGE_SCN_MEM_EXECUTE;
|
|
|
|
const uint32_t read = llvm::COFF::IMAGE_SCN_MEM_READ;
|
|
|
|
const uint32_t write = llvm::COFF::IMAGE_SCN_MEM_WRITE;
|
|
|
|
|
2013-11-28 05:34:16 +08:00
|
|
|
#define TEST_SECTION(testname, arg, expect) \
|
|
|
|
TEST_F(WinLinkParserTest, testname) { \
|
|
|
|
EXPECT_TRUE(parse("link.exe", "/section:.text," arg, "a.obj", nullptr)); \
|
|
|
|
EXPECT_EQ(expect, _context.getSectionAttributes(".text", execute | read)); \
|
2013-11-27 01:57:05 +08:00
|
|
|
}
|
|
|
|
|
2013-11-28 05:34:16 +08:00
|
|
|
TEST_SECTION(SectionD, "d", execute | read | discardable);
|
2013-11-28 03:07:28 +08:00
|
|
|
TEST_SECTION(SectionE, "e", execute);
|
2013-11-28 05:34:16 +08:00
|
|
|
TEST_SECTION(SectionK, "k", execute | read | not_cached);
|
|
|
|
TEST_SECTION(SectionP, "p", execute | read | not_paged);
|
2013-11-28 03:07:28 +08:00
|
|
|
TEST_SECTION(SectionR, "r", read);
|
2013-11-28 05:34:16 +08:00
|
|
|
TEST_SECTION(SectionS, "s", execute | read | shared);
|
2013-11-28 03:07:28 +08:00
|
|
|
TEST_SECTION(SectionW, "w", write);
|
2013-11-27 01:57:05 +08:00
|
|
|
|
|
|
|
#undef TEST_SECTION
|
2013-11-28 05:34:16 +08:00
|
|
|
|
|
|
|
TEST_F(WinLinkParserTest, Section) {
|
|
|
|
EXPECT_TRUE(parse("link.exe", "/section:.text,dekprsw",
|
|
|
|
"/section:.text,!dekprsw", "a.obj", nullptr));
|
|
|
|
EXPECT_EQ(0U, _context.getSectionAttributes(".text", execute | read));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WinLinkParserTest, SectionNegate) {
|
|
|
|
EXPECT_TRUE(parse("link.exe", "/section:.text,!e", "a.obj", nullptr));
|
|
|
|
EXPECT_EQ(read, _context.getSectionAttributes(".text", execute | read));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WinLinkParserTest, SectionMultiple) {
|
|
|
|
EXPECT_TRUE(parse("link.exe", "/section:.foo,e", "/section:.foo,rw",
|
|
|
|
"/section:.foo,!d", "a.obj", nullptr));
|
|
|
|
uint32_t flags = execute | read | not_paged | discardable;
|
|
|
|
uint32_t expected = execute | read | write | not_paged;
|
|
|
|
EXPECT_EQ(expected, _context.getSectionAttributes(".foo", flags));
|
|
|
|
}
|
|
|
|
|
2013-11-28 03:07:28 +08:00
|
|
|
} // end anonymous namespace
|
2013-10-26 08:46:57 +08:00
|
|
|
|
2013-09-24 08:16:27 +08:00
|
|
|
//
|
|
|
|
// Tests for /defaultlib and /nodefaultlib.
|
|
|
|
//
|
|
|
|
|
|
|
|
TEST_F(WinLinkParserTest, DefaultLib) {
|
2013-09-25 07:26:34 +08:00
|
|
|
EXPECT_TRUE(parse("link.exe", "/defaultlib:user32.lib",
|
|
|
|
"/defaultlib:kernel32", "a.obj", nullptr));
|
2013-12-05 21:07:49 +08:00
|
|
|
EXPECT_EQ(2, inputFileCount());
|
2013-09-24 08:16:27 +08:00
|
|
|
EXPECT_EQ("a.obj", inputFile(0));
|
2013-12-05 21:07:49 +08:00
|
|
|
EXPECT_EQ("user32.lib", inputFile(1, 0));
|
|
|
|
EXPECT_EQ("kernel32.lib", inputFile(1, 1));
|
2013-09-24 08:16:27 +08:00
|
|
|
}
|
|
|
|
|
2013-11-06 13:13:20 +08:00
|
|
|
TEST_F(WinLinkParserTest, DefaultLibDuplicates) {
|
|
|
|
EXPECT_TRUE(parse("link.exe", "/defaultlib:user32.lib",
|
|
|
|
"/defaultlib:user32.lib", "a.obj", nullptr));
|
2013-12-05 21:07:49 +08:00
|
|
|
EXPECT_EQ(2, inputFileCount());
|
2013-11-06 13:13:20 +08:00
|
|
|
EXPECT_EQ("a.obj", inputFile(0));
|
2013-12-05 21:07:49 +08:00
|
|
|
EXPECT_EQ("user32.lib", inputFile(1, 0));
|
2013-11-06 13:13:20 +08:00
|
|
|
}
|
|
|
|
|
2013-09-24 08:16:27 +08:00
|
|
|
TEST_F(WinLinkParserTest, NoDefaultLib) {
|
2013-09-25 07:26:34 +08:00
|
|
|
EXPECT_TRUE(parse("link.exe", "/defaultlib:user32.lib",
|
|
|
|
"/defaultlib:kernel32", "/nodefaultlib:user32.lib", "a.obj",
|
|
|
|
nullptr));
|
2013-09-24 08:16:27 +08:00
|
|
|
EXPECT_EQ(2, inputFileCount());
|
|
|
|
EXPECT_EQ("a.obj", inputFile(0));
|
2013-12-05 21:07:49 +08:00
|
|
|
EXPECT_EQ("kernel32.lib", inputFile(1, 0));
|
2013-09-24 08:16:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WinLinkParserTest, NoDefaultLibAll) {
|
2013-09-25 07:26:34 +08:00
|
|
|
EXPECT_TRUE(parse("link.exe", "/defaultlib:user32.lib",
|
|
|
|
"/defaultlib:kernel32", "/nodefaultlib", "a.obj", nullptr));
|
2013-12-05 21:07:49 +08:00
|
|
|
EXPECT_EQ(2, inputFileCount());
|
2013-09-24 08:16:27 +08:00
|
|
|
EXPECT_EQ("a.obj", inputFile(0));
|
|
|
|
}
|
|
|
|
|
2013-11-06 13:48:45 +08:00
|
|
|
TEST_F(WinLinkParserTest, DisallowLib) {
|
|
|
|
EXPECT_TRUE(parse("link.exe", "/defaultlib:user32.lib",
|
|
|
|
"/defaultlib:kernel32", "/disallowlib:user32.lib", "a.obj",
|
|
|
|
nullptr));
|
|
|
|
EXPECT_EQ(2, inputFileCount());
|
|
|
|
EXPECT_EQ("a.obj", inputFile(0));
|
2013-12-05 21:07:49 +08:00
|
|
|
EXPECT_EQ("kernel32.lib", inputFile(1, 0));
|
2013-11-06 13:48:45 +08:00
|
|
|
}
|
|
|
|
|
2013-11-23 06:52:15 +08:00
|
|
|
//
|
|
|
|
// Tests for DLL.
|
|
|
|
//
|
|
|
|
|
|
|
|
TEST_F(WinLinkParserTest, NoEntry) {
|
|
|
|
EXPECT_TRUE(parse("link.exe", "/noentry", "/dll", "a.obj", nullptr));
|
2014-01-03 11:29:15 +08:00
|
|
|
EXPECT_EQ(PECOFFLinkingContext::ImageType::dll, _context.getImageType());
|
2013-12-12 11:21:45 +08:00
|
|
|
EXPECT_EQ(0x10000000U, _context.getBaseAddress());
|
2013-11-23 06:52:15 +08:00
|
|
|
EXPECT_EQ("", _context.entrySymbolName());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WinLinkParserTest, NoEntryError) {
|
|
|
|
// /noentry without /dll is an error.
|
|
|
|
EXPECT_FALSE(parse("link.exe", "/noentry", "a.obj", nullptr));
|
|
|
|
EXPECT_EQ("/noentry must be specified with /dll\n", errorMessage());
|
|
|
|
}
|
|
|
|
|
2013-09-24 05:38:03 +08:00
|
|
|
//
|
|
|
|
// Tests for boolean flags.
|
|
|
|
//
|
|
|
|
|
2013-06-11 12:52:14 +08:00
|
|
|
TEST_F(WinLinkParserTest, Force) {
|
2013-09-25 07:26:34 +08:00
|
|
|
EXPECT_TRUE(parse("link.exe", "/force", "a.obj", nullptr));
|
2013-08-07 06:31:59 +08:00
|
|
|
EXPECT_TRUE(_context.allowRemainingUndefines());
|
2013-06-11 12:52:14 +08:00
|
|
|
}
|
|
|
|
|
2013-08-30 05:46:47 +08:00
|
|
|
TEST_F(WinLinkParserTest, ForceUnresolved) {
|
2013-09-25 07:26:34 +08:00
|
|
|
EXPECT_TRUE(parse("link.exe", "/force:unresolved", "a.obj", nullptr));
|
2013-08-30 05:46:47 +08:00
|
|
|
EXPECT_TRUE(_context.allowRemainingUndefines());
|
|
|
|
}
|
|
|
|
|
2013-06-16 11:07:08 +08:00
|
|
|
TEST_F(WinLinkParserTest, NoNxCompat) {
|
2013-09-25 07:26:34 +08:00
|
|
|
EXPECT_TRUE(parse("link.exe", "/nxcompat:no", "a.obj", nullptr));
|
2013-08-07 06:31:59 +08:00
|
|
|
EXPECT_FALSE(_context.isNxCompat());
|
2013-06-16 11:07:08 +08:00
|
|
|
}
|
|
|
|
|
2013-07-17 01:20:38 +08:00
|
|
|
TEST_F(WinLinkParserTest, LargeAddressAware) {
|
2013-09-25 07:26:34 +08:00
|
|
|
EXPECT_TRUE(parse("link.exe", "/largeaddressaware", "a.obj", nullptr));
|
2013-08-07 06:31:59 +08:00
|
|
|
EXPECT_TRUE(_context.getLargeAddressAware());
|
2013-07-17 01:20:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WinLinkParserTest, NoLargeAddressAware) {
|
2013-09-25 07:26:34 +08:00
|
|
|
EXPECT_TRUE(parse("link.exe", "/largeaddressaware:no", "a.obj", nullptr));
|
2013-08-07 06:31:59 +08:00
|
|
|
EXPECT_FALSE(_context.getLargeAddressAware());
|
2013-07-17 01:20:38 +08:00
|
|
|
}
|
|
|
|
|
2013-09-24 04:44:20 +08:00
|
|
|
TEST_F(WinLinkParserTest, AllowBind) {
|
2013-09-25 07:26:34 +08:00
|
|
|
EXPECT_TRUE(parse("link.exe", "/allowbind", "a.obj", nullptr));
|
2013-09-24 04:44:20 +08:00
|
|
|
EXPECT_TRUE(_context.getAllowBind());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WinLinkParserTest, NoAllowBind) {
|
2013-09-25 07:26:34 +08:00
|
|
|
EXPECT_TRUE(parse("link.exe", "/allowbind:no", "a.obj", nullptr));
|
2013-09-24 04:44:20 +08:00
|
|
|
EXPECT_FALSE(_context.getAllowBind());
|
|
|
|
}
|
|
|
|
|
2013-09-24 05:22:01 +08:00
|
|
|
TEST_F(WinLinkParserTest, AllowIsolation) {
|
2013-09-25 07:26:34 +08:00
|
|
|
EXPECT_TRUE(parse("link.exe", "/allowisolation", "a.obj", nullptr));
|
2013-09-24 05:22:01 +08:00
|
|
|
EXPECT_TRUE(_context.getAllowIsolation());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WinLinkParserTest, NoAllowIsolation) {
|
2013-09-25 07:26:34 +08:00
|
|
|
EXPECT_TRUE(parse("link.exe", "/allowisolation:no", "a.obj", nullptr));
|
2013-09-24 05:22:01 +08:00
|
|
|
EXPECT_FALSE(_context.getAllowIsolation());
|
|
|
|
}
|
|
|
|
|
2013-09-24 12:20:37 +08:00
|
|
|
TEST_F(WinLinkParserTest, SwapRunFromCD) {
|
2013-09-25 07:26:34 +08:00
|
|
|
EXPECT_TRUE(parse("link.exe", "/swaprun:cd", "a.obj", nullptr));
|
2013-09-24 12:20:37 +08:00
|
|
|
EXPECT_TRUE(_context.getSwapRunFromCD());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WinLinkParserTest, SwapRunFromNet) {
|
2013-09-25 07:26:34 +08:00
|
|
|
EXPECT_TRUE(parse("link.exe", "/swaprun:net", "a.obj", nullptr));
|
2013-09-24 12:20:37 +08:00
|
|
|
EXPECT_TRUE(_context.getSwapRunFromNet());
|
|
|
|
}
|
|
|
|
|
2013-09-24 11:37:47 +08:00
|
|
|
TEST_F(WinLinkParserTest, Debug) {
|
2013-09-25 07:26:34 +08:00
|
|
|
EXPECT_TRUE(parse("link.exe", "/debug", "a.out", nullptr));
|
2013-09-24 11:37:47 +08:00
|
|
|
EXPECT_FALSE(_context.deadStrip());
|
|
|
|
}
|
|
|
|
|
2013-07-23 09:29:50 +08:00
|
|
|
TEST_F(WinLinkParserTest, Fixed) {
|
2013-09-25 07:26:34 +08:00
|
|
|
EXPECT_TRUE(parse("link.exe", "/fixed", "a.out", nullptr));
|
2013-08-07 06:31:59 +08:00
|
|
|
EXPECT_FALSE(_context.getBaseRelocationEnabled());
|
2013-08-24 08:39:10 +08:00
|
|
|
EXPECT_FALSE(_context.getDynamicBaseEnabled());
|
2013-07-23 09:29:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WinLinkParserTest, NoFixed) {
|
2013-09-25 07:26:34 +08:00
|
|
|
EXPECT_TRUE(parse("link.exe", "/fixed:no", "a.out", nullptr));
|
2013-08-07 06:31:59 +08:00
|
|
|
EXPECT_TRUE(_context.getBaseRelocationEnabled());
|
2013-07-23 09:29:50 +08:00
|
|
|
}
|
2013-07-23 06:17:24 +08:00
|
|
|
|
2013-07-24 01:17:19 +08:00
|
|
|
TEST_F(WinLinkParserTest, TerminalServerAware) {
|
2013-09-25 07:26:34 +08:00
|
|
|
EXPECT_TRUE(parse("link.exe", "/tsaware", "a.out", nullptr));
|
2013-08-07 06:31:59 +08:00
|
|
|
EXPECT_TRUE(_context.isTerminalServerAware());
|
2013-07-24 01:17:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WinLinkParserTest, NoTerminalServerAware) {
|
2013-09-25 07:26:34 +08:00
|
|
|
EXPECT_TRUE(parse("link.exe", "/tsaware:no", "a.out", nullptr));
|
2013-08-07 06:31:59 +08:00
|
|
|
EXPECT_FALSE(_context.isTerminalServerAware());
|
2013-07-24 01:17:19 +08:00
|
|
|
}
|
|
|
|
|
2013-08-24 08:39:10 +08:00
|
|
|
TEST_F(WinLinkParserTest, DynamicBase) {
|
2013-09-25 07:26:34 +08:00
|
|
|
EXPECT_TRUE(parse("link.exe", "/dynamicbase", "a.out", nullptr));
|
2013-08-24 08:39:10 +08:00
|
|
|
EXPECT_TRUE(_context.getDynamicBaseEnabled());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WinLinkParserTest, NoDynamicBase) {
|
2013-09-25 07:26:34 +08:00
|
|
|
EXPECT_TRUE(parse("link.exe", "/dynamicbase:no", "a.out", nullptr));
|
2013-08-24 08:39:10 +08:00
|
|
|
EXPECT_FALSE(_context.getDynamicBaseEnabled());
|
|
|
|
}
|
|
|
|
|
2013-09-24 05:38:03 +08:00
|
|
|
//
|
|
|
|
// Test for /failifmismatch
|
|
|
|
//
|
2013-07-23 06:17:24 +08:00
|
|
|
|
2013-07-25 09:23:50 +08:00
|
|
|
TEST_F(WinLinkParserTest, FailIfMismatch_Match) {
|
2013-09-25 07:26:34 +08:00
|
|
|
EXPECT_TRUE(parse("link.exe", "/failifmismatch:foo=bar",
|
|
|
|
"/failifmismatch:foo=bar", "/failifmismatch:abc=def",
|
|
|
|
"a.out", nullptr));
|
2013-07-25 09:23:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WinLinkParserTest, FailIfMismatch_Mismatch) {
|
2013-09-25 07:26:34 +08:00
|
|
|
EXPECT_FALSE(parse("link.exe", "/failifmismatch:foo=bar",
|
|
|
|
"/failifmismatch:foo=baz", "a.out", nullptr));
|
2013-07-25 09:23:50 +08:00
|
|
|
}
|
|
|
|
|
2013-10-22 11:49:35 +08:00
|
|
|
//
|
2013-10-23 05:39:04 +08:00
|
|
|
// Tests for /manifest, /manifestuac, /manifestfile, and /manifestdependency.
|
2013-10-22 11:49:35 +08:00
|
|
|
//
|
|
|
|
TEST_F(WinLinkParserTest, Manifest_Default) {
|
|
|
|
EXPECT_TRUE(parse("link.exe", "/manifest", "a.out", nullptr));
|
|
|
|
EXPECT_TRUE(_context.getCreateManifest());
|
|
|
|
EXPECT_FALSE(_context.getEmbedManifest());
|
|
|
|
EXPECT_EQ(1, _context.getManifestId());
|
|
|
|
EXPECT_EQ("'asInvoker'", _context.getManifestLevel());
|
2013-10-23 01:42:42 +08:00
|
|
|
EXPECT_EQ("'false'", _context.getManifestUiAccess());
|
2013-10-22 11:49:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WinLinkParserTest, Manifest_No) {
|
|
|
|
EXPECT_TRUE(parse("link.exe", "/manifest:no", "a.out", nullptr));
|
|
|
|
EXPECT_FALSE(_context.getCreateManifest());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WinLinkParserTest, Manifest_Embed) {
|
|
|
|
EXPECT_TRUE(parse("link.exe", "/manifest:embed", "a.out", nullptr));
|
|
|
|
EXPECT_TRUE(_context.getCreateManifest());
|
|
|
|
EXPECT_TRUE(_context.getEmbedManifest());
|
|
|
|
EXPECT_EQ(1, _context.getManifestId());
|
|
|
|
EXPECT_EQ("'asInvoker'", _context.getManifestLevel());
|
2013-10-23 01:42:42 +08:00
|
|
|
EXPECT_EQ("'false'", _context.getManifestUiAccess());
|
2013-10-22 11:49:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WinLinkParserTest, Manifest_Embed_ID42) {
|
|
|
|
EXPECT_TRUE(parse("link.exe", "/manifest:embed,id=42", "a.out", nullptr));
|
|
|
|
EXPECT_TRUE(_context.getCreateManifest());
|
|
|
|
EXPECT_TRUE(_context.getEmbedManifest());
|
|
|
|
EXPECT_EQ(42, _context.getManifestId());
|
|
|
|
EXPECT_EQ("'asInvoker'", _context.getManifestLevel());
|
2013-10-23 01:42:42 +08:00
|
|
|
EXPECT_EQ("'false'", _context.getManifestUiAccess());
|
2013-10-22 11:49:35 +08:00
|
|
|
}
|
|
|
|
|
2013-10-22 12:21:29 +08:00
|
|
|
TEST_F(WinLinkParserTest, Manifestuac_Level) {
|
|
|
|
EXPECT_TRUE(parse("link.exe", "/manifestuac:level='requireAdministrator'",
|
|
|
|
"a.out", nullptr));
|
|
|
|
EXPECT_EQ("'requireAdministrator'", _context.getManifestLevel());
|
2013-10-23 01:42:42 +08:00
|
|
|
EXPECT_EQ("'false'", _context.getManifestUiAccess());
|
2013-10-22 12:21:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WinLinkParserTest, Manifestuac_UiAccess) {
|
2013-10-23 01:42:42 +08:00
|
|
|
EXPECT_TRUE(parse("link.exe", "/manifestuac:uiAccess='true'", "a.out", nullptr));
|
2013-10-22 12:21:29 +08:00
|
|
|
EXPECT_EQ("'asInvoker'", _context.getManifestLevel());
|
2013-10-23 01:42:42 +08:00
|
|
|
EXPECT_EQ("'true'", _context.getManifestUiAccess());
|
2013-10-22 12:21:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WinLinkParserTest, Manifestuac_LevelAndUiAccess) {
|
|
|
|
EXPECT_TRUE(parse("link.exe",
|
2013-10-23 01:42:42 +08:00
|
|
|
"/manifestuac:level='requireAdministrator' uiAccess='true'",
|
2013-10-22 12:21:29 +08:00
|
|
|
"a.out", nullptr));
|
|
|
|
EXPECT_EQ("'requireAdministrator'", _context.getManifestLevel());
|
2013-10-23 01:42:42 +08:00
|
|
|
EXPECT_EQ("'true'", _context.getManifestUiAccess());
|
2013-10-22 12:21:29 +08:00
|
|
|
}
|
|
|
|
|
2013-10-23 04:53:07 +08:00
|
|
|
TEST_F(WinLinkParserTest, Manifestfile) {
|
|
|
|
EXPECT_TRUE(parse("link.exe", "/manifestfile:bar.manifest",
|
|
|
|
"a.out", nullptr));
|
|
|
|
EXPECT_EQ("bar.manifest", _context.getManifestOutputPath());
|
|
|
|
}
|
|
|
|
|
2013-10-23 05:39:04 +08:00
|
|
|
TEST_F(WinLinkParserTest, Manifestdependency) {
|
|
|
|
EXPECT_TRUE(parse("link.exe", "/manifestdependency:foo bar", "a.out",
|
|
|
|
nullptr));
|
|
|
|
EXPECT_EQ("foo bar", _context.getManifestDependency());
|
|
|
|
}
|
|
|
|
|
2013-09-24 05:38:03 +08:00
|
|
|
//
|
|
|
|
// Test for command line flags that are ignored.
|
|
|
|
//
|
|
|
|
|
2013-09-20 06:19:40 +08:00
|
|
|
TEST_F(WinLinkParserTest, Ignore) {
|
|
|
|
// There are some no-op command line options that are recognized for
|
|
|
|
// compatibility with link.exe.
|
2013-09-25 07:26:34 +08:00
|
|
|
EXPECT_TRUE(parse("link.exe", "/nologo", "/errorreport:prompt",
|
|
|
|
"/incremental", "/incremental:no", "/delay:unload",
|
2013-11-06 08:44:10 +08:00
|
|
|
"/disallowlib:foo", "/delayload:user32", "/pdb:foo",
|
|
|
|
"/pdbaltpath:bar", "/verbose", "/verbose:icf", "/wx",
|
2013-11-19 13:55:08 +08:00
|
|
|
"/wx:no", "/tlbid:1", "/tlbout:foo", "/idlout:foo",
|
2013-11-21 05:57:30 +08:00
|
|
|
"/ignoreidl", "/implib:foo", "/safeseh", "/safeseh:no",
|
2013-12-04 16:15:05 +08:00
|
|
|
"/functionpadmin", "a.obj", nullptr));
|
2013-07-26 06:46:49 +08:00
|
|
|
EXPECT_EQ("", errorMessage());
|
2013-12-05 21:07:49 +08:00
|
|
|
EXPECT_EQ(2, inputFileCount());
|
2013-07-26 06:46:49 +08:00
|
|
|
EXPECT_EQ("a.obj", inputFile(0));
|
|
|
|
}
|
|
|
|
|
2013-09-24 05:38:03 +08:00
|
|
|
//
|
|
|
|
// Test for "--"
|
|
|
|
//
|
|
|
|
|
2013-08-14 05:44:44 +08:00
|
|
|
TEST_F(WinLinkParserTest, DashDash) {
|
2013-09-25 07:26:34 +08:00
|
|
|
EXPECT_TRUE(parse("link.exe", "/subsystem:console", "/out:a.exe", "a.obj",
|
|
|
|
"--", "b.obj", "-c.obj", nullptr));
|
2013-08-14 05:44:44 +08:00
|
|
|
EXPECT_EQ(llvm::COFF::IMAGE_SUBSYSTEM_WINDOWS_CUI, _context.getSubsystem());
|
|
|
|
EXPECT_EQ("a.exe", _context.outputPath());
|
2013-12-05 21:07:49 +08:00
|
|
|
EXPECT_EQ(4, inputFileCount());
|
2013-08-14 05:44:44 +08:00
|
|
|
EXPECT_EQ("a.obj", inputFile(0));
|
|
|
|
EXPECT_EQ("b.obj", inputFile(1));
|
|
|
|
EXPECT_EQ("-c.obj", inputFile(2));
|
|
|
|
}
|
|
|
|
|
2013-09-24 05:38:03 +08:00
|
|
|
//
|
|
|
|
// Tests for entry symbol name.
|
|
|
|
//
|
|
|
|
|
2013-08-27 03:55:09 +08:00
|
|
|
TEST_F(WinLinkParserTest, DefEntryNameConsole) {
|
2013-09-25 07:26:34 +08:00
|
|
|
EXPECT_TRUE(parse("link.exe", "/subsystem:console", "a.obj", nullptr));
|
2013-08-27 03:55:09 +08:00
|
|
|
EXPECT_EQ("_mainCRTStartup", _context.entrySymbolName());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WinLinkParserTest, DefEntryNameWindows) {
|
2013-09-25 07:26:34 +08:00
|
|
|
EXPECT_TRUE(parse("link.exe", "/subsystem:windows", "a.obj", nullptr));
|
2013-08-27 03:55:09 +08:00
|
|
|
EXPECT_EQ("_WinMainCRTStartup", _context.entrySymbolName());
|
|
|
|
}
|
|
|
|
|
2013-06-16 11:07:08 +08:00
|
|
|
} // end anonymous namespace
|