1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
//===- 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.
///
//===----------------------------------------------------------------------===//
#include "DriverTest.h"
#include "lld/ReaderWriter/PECOFFTargetInfo.h"
#include "llvm/Support/COFF.h"
#include <vector>
using namespace llvm;
using namespace lld;
namespace {
class WinLinkParserTest : public ParserTest<WinLinkDriver, PECOFFTargetInfo> {
protected:
virtual const TargetInfo *targetInfo() {
return &_info;
}
};
TEST_F(WinLinkParserTest, Basic) {
EXPECT_FALSE(parse("link.exe", "-subsystem", "console", "-out", "a.exe",
"-entry", "_start", "a.obj", "b.obj", "c.obj", nullptr));
EXPECT_EQ(llvm::COFF::IMAGE_SUBSYSTEM_WINDOWS_CUI, _info.getSubsystem());
EXPECT_EQ("a.exe", _info.outputPath());
EXPECT_EQ("_start", _info.entrySymbolName());
EXPECT_EQ(3, inputFileCount());
EXPECT_EQ("a.obj", inputFile(0));
EXPECT_EQ("b.obj", inputFile(1));
EXPECT_EQ("c.obj", inputFile(2));
EXPECT_TRUE(_info.getInputSearchPaths().empty());
EXPECT_EQ(6, _info.getMinOSVersion().majorVersion);
EXPECT_EQ(0, _info.getMinOSVersion().minorVersion);
EXPECT_EQ((uint64_t)0x400000, _info.getBaseAddress());
EXPECT_EQ(1024 * 1024ULL, _info.getStackReserve());
EXPECT_EQ(4096ULL, _info.getStackCommit());
EXPECT_FALSE(_info.allowRemainingUndefines());
EXPECT_TRUE(_info.getNxCompat());
EXPECT_FALSE(_info.getLargeAddressAware());
}
TEST_F(WinLinkParserTest, WindowsStyleOption) {
EXPECT_FALSE(parse("link.exe", "/subsystem:console", "/out:a.exe", "a.obj",
nullptr));
EXPECT_EQ(llvm::COFF::IMAGE_SUBSYSTEM_WINDOWS_CUI, _info.getSubsystem());
EXPECT_EQ("a.exe", _info.outputPath());
EXPECT_EQ(1, inputFileCount());
EXPECT_EQ("a.obj", inputFile(0));
}
TEST_F(WinLinkParserTest, NoFileExtension) {
EXPECT_FALSE(parse("link.exe", "foo", "bar", nullptr));
EXPECT_EQ("foo.exe", _info.outputPath());
EXPECT_EQ(2, inputFileCount());
EXPECT_EQ("foo.obj", inputFile(0));
EXPECT_EQ("bar.obj", inputFile(1));
}
TEST_F(WinLinkParserTest, NonStandardFileExtension) {
EXPECT_FALSE(parse("link.exe", "foo.o", nullptr));
EXPECT_EQ("foo.exe", _info.outputPath());
EXPECT_EQ(1, inputFileCount());
EXPECT_EQ("foo.o", inputFile(0));
}
TEST_F(WinLinkParserTest, Libpath) {
EXPECT_FALSE(parse("link.exe", "-libpath", "dir1", "-libpath", "dir2",
"a.obj", nullptr));
const std::vector<StringRef> &paths = _info.getInputSearchPaths();
EXPECT_EQ((size_t)2, paths.size());
EXPECT_EQ("dir1", paths[0]);
EXPECT_EQ("dir2", paths[1]);
}
TEST_F(WinLinkParserTest, MinMajorOSVersion) {
EXPECT_FALSE(parse("link.exe", "-subsystem", "windows,3", "foo.o", nullptr));
EXPECT_EQ(llvm::COFF::IMAGE_SUBSYSTEM_WINDOWS_GUI, _info.getSubsystem());
EXPECT_EQ(3, _info.getMinOSVersion().majorVersion);
EXPECT_EQ(0, _info.getMinOSVersion().minorVersion);
}
TEST_F(WinLinkParserTest, MinMajorMinorOSVersion) {
EXPECT_FALSE(parse("link.exe", "-subsystem", "windows,3.1", "foo.o", nullptr));
EXPECT_EQ(llvm::COFF::IMAGE_SUBSYSTEM_WINDOWS_GUI, _info.getSubsystem());
EXPECT_EQ(3, _info.getMinOSVersion().majorVersion);
EXPECT_EQ(1, _info.getMinOSVersion().minorVersion);
}
TEST_F(WinLinkParserTest, Base) {
EXPECT_FALSE(parse("link.exe", "-base", "8388608", "a.obj", nullptr));
EXPECT_EQ((uint64_t)0x800000, _info.getBaseAddress());
}
TEST_F(WinLinkParserTest, StackReserve) {
EXPECT_FALSE(parse("link.exe", "-stack", "8192", "a.obj", nullptr));
EXPECT_EQ(8192ULL, _info.getStackReserve());
EXPECT_EQ(4096ULL, _info.getStackCommit());
}
TEST_F(WinLinkParserTest, StackReserveAndCommit) {
EXPECT_FALSE(parse("link.exe", "-stack", "16384,8192", "a.obj", nullptr));
EXPECT_EQ(16384ULL, _info.getStackReserve());
EXPECT_EQ(8192ULL, _info.getStackCommit());
}
TEST_F(WinLinkParserTest, HeapReserve) {
EXPECT_FALSE(parse("link.exe", "-heap", "8192", "a.obj", nullptr));
EXPECT_EQ(8192ULL, _info.getHeapReserve());
EXPECT_EQ(4096ULL, _info.getHeapCommit());
}
TEST_F(WinLinkParserTest, HeapReserveAndCommit) {
EXPECT_FALSE(parse("link.exe", "-heap", "16384,8192", "a.obj", nullptr));
EXPECT_EQ(16384ULL, _info.getHeapReserve());
EXPECT_EQ(8192ULL, _info.getHeapCommit());
}
TEST_F(WinLinkParserTest, Force) {
EXPECT_FALSE(parse("link.exe", "-force", "a.obj", nullptr));
EXPECT_TRUE(_info.allowRemainingUndefines());
}
TEST_F(WinLinkParserTest, NoNxCompat) {
EXPECT_FALSE(parse("link.exe", "-nxcompat:no", "a.obj", nullptr));
EXPECT_FALSE(_info.getNxCompat());
}
TEST_F(WinLinkParserTest, LargeAddressAware) {
EXPECT_FALSE(parse("link.exe", "-largeaddressaware", "a.obj", nullptr));
EXPECT_TRUE(_info.getLargeAddressAware());
}
TEST_F(WinLinkParserTest, NoLargeAddressAware) {
EXPECT_FALSE(parse("link.exe", "-largeaddressaware:no", "a.obj", nullptr));
EXPECT_FALSE(_info.getLargeAddressAware());
}
TEST_F(WinLinkParserTest, NoInputFiles) {
EXPECT_TRUE(parse("link.exe", nullptr));
EXPECT_EQ("No input files\n", errorMessage());
}
} // end anonymous namespace
|