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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
//===- lld/unittest/GnuLdDriverTest.cpp -----------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
///
/// \file
/// \brief GNU ld driver tests.
///
//===----------------------------------------------------------------------===//
#include "DriverTest.h"
#include "lld/ReaderWriter/ELFLinkingContext.h"
using namespace llvm;
using namespace lld;
namespace {
class GnuLdParserTest
: public ParserTest<GnuLdDriver, std::unique_ptr<ELFLinkingContext>> {
protected:
const LinkingContext *linkingContext() override { return _context.get(); }
};
}
// All calls of parse() in this file has empty "--start-group" and "--end-group"
// options. This is a workaround for the current GNU-compatible driver. The
// driver complains if no input file is given, but if we give a file, it tries
// to read it to get magic bytes. It's not suitable for unit tests.
//
// TODO: Modify the driver to make it more test friendly.
TEST_F(GnuLdParserTest, Empty) {
EXPECT_FALSE(parse("ld", nullptr));
EXPECT_EQ(linkingContext(), nullptr);
EXPECT_EQ("No input files\n", errorMessage());
}
// -o
TEST_F(GnuLdParserTest, Output) {
EXPECT_TRUE(parse("ld", "--start-group", "--end-group", "-o", "foo",
nullptr));
EXPECT_EQ("foo", _context->outputPath());
}
// --noinhibit-exec
TEST_F(GnuLdParserTest, NoinhibitExec) {
EXPECT_TRUE(parse("ld", "--start-group", "--end-group", "--noinhibit-exec",
nullptr));
EXPECT_TRUE(_context->allowRemainingUndefines());
}
// --entry
TEST_F(GnuLdParserTest, Entry) {
EXPECT_TRUE(parse("ld", "--start-group", "--end-group", "--entry", "foo",
nullptr));
EXPECT_EQ("foo", _context->entrySymbolName());
}
TEST_F(GnuLdParserTest, EntryShort) {
EXPECT_TRUE(parse("ld", "--start-group", "--end-group", "-e", "foo",
nullptr));
EXPECT_EQ("foo", _context->entrySymbolName());
}
TEST_F(GnuLdParserTest, EntryJoined) {
EXPECT_TRUE(parse("ld", "--start-group", "--end-group", "--entry=foo",
nullptr));
EXPECT_EQ("foo", _context->entrySymbolName());
}
// --init
TEST_F(GnuLdParserTest, Init) {
EXPECT_TRUE(parse("ld", "--start-group", "--end-group", "-init", "foo",
"-init", "bar", nullptr));
EXPECT_EQ(2, _context->initFunctions().size());
EXPECT_EQ("foo", _context->initFunctions()[0]);
EXPECT_EQ("bar", _context->initFunctions()[1]);
}
TEST_F(GnuLdParserTest, InitJoined) {
EXPECT_TRUE(parse("ld", "--start-group", "--end-group", "-init=foo",
nullptr));
EXPECT_EQ(1, _context->initFunctions().size());
EXPECT_EQ("foo", _context->initFunctions()[0]);
}
// --soname
TEST_F(GnuLdParserTest, SOName) {
EXPECT_TRUE(parse("ld", "--start-group", "--end-group", "--soname=foo",
nullptr));
EXPECT_EQ("foo", _context->sharedObjectName());
}
TEST_F(GnuLdParserTest, SONameSingleDash) {
EXPECT_TRUE(parse("ld", "--start-group", "--end-group", "-soname=foo",
nullptr));
EXPECT_EQ("foo", _context->sharedObjectName());
}
TEST_F(GnuLdParserTest, SONameH) {
EXPECT_TRUE(parse("ld", "--start-group", "--end-group", "-h", "foo",
nullptr));
EXPECT_EQ("foo", _context->sharedObjectName());
}
// -rpath
TEST_F(GnuLdParserTest, Rpath) {
EXPECT_TRUE(parse("ld", "--start-group", "--end-group", "-rpath", "foo:bar",
nullptr));
EXPECT_EQ(2, _context->getRpathList().size());
EXPECT_EQ("foo", _context->getRpathList()[0]);
EXPECT_EQ("bar", _context->getRpathList()[1]);
}
TEST_F(GnuLdParserTest, RpathEq) {
EXPECT_TRUE(parse("ld", "--start-group", "--end-group", "-rpath=foo",
nullptr));
EXPECT_EQ(1, _context->getRpathList().size());
EXPECT_EQ("foo", _context->getRpathList()[0]);
}
// --defsym
TEST_F(GnuLdParserTest, DefsymDecimal) {
EXPECT_TRUE(parse("ld", "--start-group", "--end-group", "--defsym=sym=1000",
nullptr));
assert(_context.get());
auto map = _context->getAbsoluteSymbols();
EXPECT_EQ((size_t)1, map.size());
EXPECT_EQ((uint64_t)1000, map["sym"]);
}
TEST_F(GnuLdParserTest, DefsymHexadecimal) {
EXPECT_TRUE(parse("ld", "--start-group", "--end-group", "--defsym=sym=0x1000",
nullptr));
auto map = _context->getAbsoluteSymbols();
EXPECT_EQ((size_t)1, map.size());
EXPECT_EQ((uint64_t)0x1000, map["sym"]);
}
TEST_F(GnuLdParserTest, DefsymAlias) {
EXPECT_TRUE(
parse("ld", "--start-group", "--end-group", "--defsym=sym=abc", nullptr));
auto map = _context->getAliases();
EXPECT_EQ((size_t)1, map.size());
EXPECT_EQ("abc", map["sym"]);
}
TEST_F(GnuLdParserTest, DefsymOctal) {
EXPECT_TRUE(parse("ld", "--start-group", "--end-group", "--defsym=sym=0777",
nullptr));
auto map = _context->getAbsoluteSymbols();
EXPECT_EQ((size_t)1, map.size());
EXPECT_EQ((uint64_t)0777, map["sym"]);
}
TEST_F(GnuLdParserTest, DefsymMisssingSymbol) {
EXPECT_FALSE(
parse("ld", "--start-group", "--end-group", "--defsym==0", nullptr));
}
TEST_F(GnuLdParserTest, DefsymMisssingValue) {
EXPECT_FALSE(
parse("ld", "--start-group", "--end-group", "--defsym=sym=", nullptr));
}
|