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
|
//===- lld/unittest/DarwinLdDriverTest.cpp --------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
///
/// \file
/// \brief Darwin's ld driver tests.
///
//===----------------------------------------------------------------------===//
#include "DriverTest.h"
#include "lld/ReaderWriter/MachOTargetInfo.h"
#include "../../lib/ReaderWriter/MachO/MachOFormat.hpp"
using namespace llvm;
using namespace lld;
namespace {
class DarwinLdParserTest : public ParserTest<DarwinLdDriver, MachOTargetInfo> {
protected:
virtual const TargetInfo *targetInfo() {
return &_info;
}
};
TEST_F(DarwinLdParserTest, Basic) {
EXPECT_FALSE(parse("ld", "foo.o", "bar.o", nullptr));
EXPECT_FALSE(_info.allowRemainingUndefines());
EXPECT_FALSE(_info.deadStrip());
EXPECT_EQ(2, inputFileCount());
EXPECT_EQ("foo.o", inputFile(0));
EXPECT_EQ("bar.o", inputFile(1));
}
TEST_F(DarwinLdParserTest, Dylib) {
EXPECT_FALSE(parse("ld", "-dylib", "foo.o", nullptr));
EXPECT_EQ(mach_o::MH_DYLIB, _info.outputFileType());
}
TEST_F(DarwinLdParserTest, Relocatable) {
EXPECT_FALSE(parse("ld", "-r", "foo.o", nullptr));
EXPECT_EQ(mach_o::MH_OBJECT, _info.outputFileType());
}
TEST_F(DarwinLdParserTest, Bundle) {
EXPECT_FALSE(parse("ld", "-bundle", "foo.o", nullptr));
EXPECT_EQ(mach_o::MH_BUNDLE, _info.outputFileType());
}
TEST_F(DarwinLdParserTest, Preload) {
EXPECT_FALSE(parse("ld", "-preload", "foo.o", nullptr));
EXPECT_EQ(mach_o::MH_PRELOAD, _info.outputFileType());
}
TEST_F(DarwinLdParserTest, Static) {
EXPECT_FALSE(parse("ld", "-static", "foo.o", nullptr));
EXPECT_EQ(mach_o::MH_EXECUTE, _info.outputFileType());
}
TEST_F(DarwinLdParserTest, Entry) {
EXPECT_FALSE(parse("ld", "-e", "entryFunc", "foo.o", nullptr));
EXPECT_EQ("entryFunc", _info.entrySymbolName());
}
TEST_F(DarwinLdParserTest, OutputPath) {
EXPECT_FALSE(parse("ld", "-o", "foo", "foo.o", nullptr));
EXPECT_EQ("foo", _info.outputPath());
}
TEST_F(DarwinLdParserTest, DeadStrip) {
EXPECT_FALSE(parse("ld", "-dead_strip", "foo.o", nullptr));
EXPECT_TRUE(_info.deadStrip());
}
TEST_F(DarwinLdParserTest, Arch) {
EXPECT_FALSE(parse("ld", "-arch", "x86_64", "foo.o", nullptr));
EXPECT_EQ(MachOTargetInfo::arch_x86_64, _info.arch());
}
} // end anonymous namespace
|