aboutsummaryrefslogtreecommitdiffstats
path: root/unittests
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2016-07-23 20:48:50 +0000
committerDimitry Andric <dim@FreeBSD.org>2016-07-23 20:48:50 +0000
commit1c98619801a5705c688e683be3ef9d70169a0686 (patch)
tree8422105cd1a94c368315f2db16b9ac746cf7c000 /unittests
parentf4f3ce4613680903220815690ad79fc7ba0a2e26 (diff)
downloadsrc-1c98619801a5705c688e683be3ef9d70169a0686.tar.gz
src-1c98619801a5705c688e683be3ef9d70169a0686.zip
Vendor import of lld release_39 branch r276489:vendor/lld/lld-release_39-r276489
Notes
Notes: svn path=/vendor/lld/dist/; revision=303239 svn path=/vendor/lld/lld-release_39-r276489/; revision=303240; tag=vendor/lld/lld-release_39-r276489
Diffstat (limited to 'unittests')
-rw-r--r--unittests/CoreTests/CMakeLists.txt5
-rw-r--r--unittests/CoreTests/RangeTest.cpp240
-rw-r--r--unittests/DriverTests/CMakeLists.txt4
-rw-r--r--unittests/DriverTests/DarwinLdDriverTest.cpp153
-rw-r--r--unittests/DriverTests/DriverTest.h61
-rw-r--r--unittests/DriverTests/GnuLdDriverTest.cpp299
-rw-r--r--unittests/DriverTests/UniversalDriverTest.cpp33
-rw-r--r--unittests/MachOTests/MachONormalizedFileBinaryReaderTests.cpp25
-rw-r--r--unittests/MachOTests/MachONormalizedFileBinaryWriterTests.cpp18
-rw-r--r--unittests/MachOTests/MachONormalizedFileToAtomsTests.cpp18
-rw-r--r--unittests/MachOTests/MachONormalizedFileYAMLTests.cpp23
11 files changed, 138 insertions, 741 deletions
diff --git a/unittests/CoreTests/CMakeLists.txt b/unittests/CoreTests/CMakeLists.txt
index aa85617916b4..98405d5c73a1 100644
--- a/unittests/CoreTests/CMakeLists.txt
+++ b/unittests/CoreTests/CMakeLists.txt
@@ -1,4 +1,7 @@
add_lld_unittest(CoreTests
ParallelTest.cpp
- RangeTest.cpp
+ )
+
+target_link_libraries(CoreTests
+ ${PTHREAD_LIB}
)
diff --git a/unittests/CoreTests/RangeTest.cpp b/unittests/CoreTests/RangeTest.cpp
deleted file mode 100644
index 2b2fcd5f7875..000000000000
--- a/unittests/CoreTests/RangeTest.cpp
+++ /dev/null
@@ -1,240 +0,0 @@
-//===- lld/unittest/RangeTest.cpp -----------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-///
-/// \file
-/// \brief range.h unit tests.
-///
-//===----------------------------------------------------------------------===//
-
-#include "gtest/gtest.h"
-#include "lld/Core/range.h"
-#include <array>
-#include <assert.h>
-#include <deque>
-#include <forward_list>
-#include <iterator>
-#include <list>
-#include <numeric>
-#include <sstream>
-#include <vector>
-
-template <typename T, typename U> struct AssertTypesSame;
-template <typename T> struct AssertTypesSame<T, T> {};
-#define ASSERT_TYPES_SAME(T, U) AssertTypesSame<T, U>()
-
-struct no_begin {};
-struct member_begin {
- int *begin();
-};
-struct free_begin {};
-int *begin(free_begin);
-
-template <typename T>
-auto type_of_forward(T &&t) -> decltype(std::forward<T>(t)) {
- return std::forward<T>(t);
-}
-
-template <typename To> To implicit_cast(To val) { return val; }
-
-void test_traits() {
- using namespace lld::detail;
- ASSERT_TYPES_SAME(begin_result<no_begin>::type, undefined);
- // This causes clang to segfault.
-#if 0
- ASSERT_TYPES_SAME(
- begin_result<decltype(type_of_forward(member_begin()))>::type, int *);
-#endif
- ASSERT_TYPES_SAME(begin_result<free_begin>::type, int *);
-}
-
-TEST(Range, constructors) {
- std::vector<int> v(5);
- std::iota(v.begin(), v.end(), 0);
- lld::range<std::vector<int>::iterator> r = v;
- EXPECT_EQ(v.begin(), r.begin());
- EXPECT_EQ(v.end(), r.end());
-
- int arr[] = { 1, 2, 3, 4, 5 };
- std::begin(arr);
- lld::range<int *> r2 = arr;
- EXPECT_EQ(5, r2.back());
-}
-
-TEST(Range, conversion_to_pointer_range) {
- std::vector<int> v(5);
- std::iota(v.begin(), v.end(), 0);
- lld::range<int *> r = v;
- EXPECT_EQ(&*v.begin(), r.begin());
- EXPECT_EQ(2, r[2]);
-}
-
-template <typename Iter> void takes_range(lld::range<Iter> r) {
- int expected = 0;
- for (int val : r) {
- EXPECT_EQ(expected++, val);
- }
-}
-
-void takes_ptr_range(lld::range<const int *> r) {
- int expected = 0;
- for (int val : r) {
- EXPECT_EQ(expected++, val);
- }
-}
-
-TEST(Range, passing) {
- using lld::make_range;
- using lld::make_ptr_range;
- std::list<int> l(5);
- std::iota(l.begin(), l.end(), 0);
- takes_range(make_range(l));
- takes_range(make_range(implicit_cast<const std::list<int> &>(l)));
- std::deque<int> d(5);
- std::iota(d.begin(), d.end(), 0);
- takes_range(make_range(d));
- takes_range(make_range(implicit_cast<const std::deque<int> &>(d)));
- std::vector<int> v(5);
- std::iota(v.begin(), v.end(), 0);
- takes_range(make_range(v));
- takes_range(make_range(implicit_cast<const std::vector<int> &>(v)));
- static_assert(
- std::is_same<decltype(make_ptr_range(v)), lld::range<int *>>::value,
- "make_ptr_range should return a range of pointers");
- takes_range(make_ptr_range(v));
- takes_range(make_ptr_range(implicit_cast<const std::vector<int> &>(v)));
- int arr[] = { 0, 1, 2, 3, 4 };
- takes_range(make_range(arr));
- const int carr[] = { 0, 1, 2, 3, 4 };
- takes_range(make_range(carr));
-
- takes_ptr_range(v);
- takes_ptr_range(implicit_cast<const std::vector<int> &>(v));
- takes_ptr_range(arr);
- takes_ptr_range(carr);
-}
-
-TEST(Range, access) {
- std::array<int, 5> a = { { 1, 2, 3, 4, 5 } };
- lld::range<decltype(a.begin())> r = a;
- EXPECT_EQ(4, r[3]);
- EXPECT_EQ(4, r[-2]);
-}
-
-template <bool b> struct CompileAssert;
-template <> struct CompileAssert<true> {};
-
-#if __has_feature(cxx_constexpr)
-constexpr int arr[] = { 1, 2, 3, 4, 5 };
-TEST(Range, constexpr) {
- constexpr lld::range<const int *> r(arr, arr + 5);
- CompileAssert<r.front() == 1>();
- CompileAssert<r.size() == 5>();
- CompileAssert<r[4] == 5>();
-}
-#endif
-
-template <typename Container> void test_slice() {
- Container cont(10);
- std::iota(cont.begin(), cont.end(), 0);
- lld::range<decltype(cont.begin())> r = cont;
-
- // One argument.
- EXPECT_EQ(10, r.slice(0).size());
- EXPECT_EQ(8, r.slice(2).size());
- EXPECT_EQ(2, r.slice(2).front());
- EXPECT_EQ(1, r.slice(-1).size());
- EXPECT_EQ(9, r.slice(-1).front());
-
- // Two positive arguments.
- EXPECT_TRUE(r.slice(5, 2).empty());
- EXPECT_EQ(next(cont.begin(), 5), r.slice(5, 2).begin());
- EXPECT_EQ(1, r.slice(1, 2).size());
- EXPECT_EQ(1, r.slice(1, 2).front());
-
- // Two negative arguments.
- EXPECT_TRUE(r.slice(-2, -5).empty());
- EXPECT_EQ(next(cont.begin(), 8), r.slice(-2, -5).begin());
- EXPECT_EQ(1, r.slice(-2, -1).size());
- EXPECT_EQ(8, r.slice(-2, -1).front());
-
- // Positive start, negative stop.
- EXPECT_EQ(1, r.slice(6, -3).size());
- EXPECT_EQ(6, r.slice(6, -3).front());
- EXPECT_TRUE(r.slice(6, -5).empty());
- EXPECT_EQ(next(cont.begin(), 6), r.slice(6, -5).begin());
-
- // Negative start, positive stop.
- EXPECT_TRUE(r.slice(-3, 6).empty());
- EXPECT_EQ(next(cont.begin(), 7), r.slice(-3, 6).begin());
- EXPECT_EQ(1, r.slice(-5, 6).size());
- EXPECT_EQ(5, r.slice(-5, 6).front());
-}
-
-TEST(Range, slice) {
- // -fsanitize=undefined complains about this, but only if optimizations are
- // enabled.
-#if 0
- test_slice<std::forward_list<int>>();
-#endif
- test_slice<std::list<int>>();
-// This doesn't build with libstdc++ 4.7
-#if 0
- test_slice<std::deque<int>>();
-#endif
-}
-
-// This test is flaky and I've yet to pin down why. Changing between
-// EXPECT_EQ(1, input.front()) and EXPECT_TRUE(input.front() == 1) makes it work
-// with VS 2012 in Debug mode. Clang on Linux seems to fail with -03 and -02 -g
-// -fsanitize=undefined.
-#if 0
-TEST(Range, istream_range) {
- std::istringstream stream("1 2 3 4 5");
- // MSVC interprets input as a function declaration if you don't declare start
- // and instead directly pass std::istream_iterator<int>(stream).
- auto start = std::istream_iterator<int>(stream);
- lld::range<std::istream_iterator<int>> input(
- start, std::istream_iterator<int>());
- EXPECT_TRUE(input.front() == 1);
- input.pop_front();
- EXPECT_TRUE(input.front() == 2);
- input.pop_front(2);
- EXPECT_TRUE(input.front() == 4);
- input.pop_front_upto(7);
- EXPECT_TRUE(input.empty());
-}
-#endif
-
-//! [algorithm using range]
-template <typename T> void partial_sum(T &container) {
- using lld::make_range;
- auto range = make_range(container);
- typename T::value_type sum = 0;
- // One would actually use a range-based for loop
- // in this case, but you get the idea:
- for (; !range.empty(); range.pop_front()) {
- sum += range.front();
- range.front() = sum;
- }
-}
-
-TEST(Range, user1) {
- std::vector<int> v(5, 2);
- partial_sum(v);
- EXPECT_EQ(8, v[3]);
-}
-//! [algorithm using range]
-
-//! [algorithm using ptr_range]
-void my_write(int fd, lld::range<const char *> buffer) {}
-
-TEST(Range, user2) {
- std::string s("Hello world");
- my_write(1, s);
-}
diff --git a/unittests/DriverTests/CMakeLists.txt b/unittests/DriverTests/CMakeLists.txt
index 0378e6164429..91d22ca19d72 100644
--- a/unittests/DriverTests/CMakeLists.txt
+++ b/unittests/DriverTests/CMakeLists.txt
@@ -1,12 +1,8 @@
add_lld_unittest(DriverTests
- UniversalDriverTest.cpp
- GnuLdDriverTest.cpp
DarwinLdDriverTest.cpp
)
target_link_libraries(DriverTests
lldDriver
- lldCOFF
- lldCore
lldMachO
)
diff --git a/unittests/DriverTests/DarwinLdDriverTest.cpp b/unittests/DriverTests/DarwinLdDriverTest.cpp
index e2809c44984d..ea7fcc7eafcb 100644
--- a/unittests/DriverTests/DarwinLdDriverTest.cpp
+++ b/unittests/DriverTests/DarwinLdDriverTest.cpp
@@ -12,23 +12,47 @@
///
//===----------------------------------------------------------------------===//
-#include "DriverTest.h"
+#include "lld/Driver/Driver.h"
#include "lld/ReaderWriter/MachOLinkingContext.h"
#include "llvm/Support/MachO.h"
+#include "llvm/Support/raw_ostream.h"
+#include "gtest/gtest.h"
using namespace llvm;
using namespace lld;
+namespace lld {
+namespace mach_o {
+bool parse(llvm::ArrayRef<const char *> args, MachOLinkingContext &ctx,
+ raw_ostream &diagnostics);
+}
+}
+
namespace {
-class DarwinLdParserTest
- : public ParserTest<DarwinLdDriver, MachOLinkingContext> {
+class DarwinLdParserTest : public testing::Test {
protected:
- const LinkingContext *linkingContext() override { return &_ctx; }
+ int inputFileCount() { return _ctx.getNodes().size(); }
+
+ std::string inputFile(int index) {
+ Node &node = *_ctx.getNodes()[index];
+ if (node.kind() == Node::Kind::File)
+ return cast<FileNode>(&node)->getFile()->path();
+ llvm_unreachable("not handling other types of input files");
+ }
+
+ bool parse(std::vector<const char *> args) {
+ args.insert(args.begin(), "ld");
+ std::string errorMessage;
+ raw_string_ostream os(errorMessage);
+ return mach_o::parse(args, _ctx, os);
+ }
+
+ MachOLinkingContext _ctx;
};
}
TEST_F(DarwinLdParserTest, Basic) {
- EXPECT_TRUE(parse("ld", "foo.o", "bar.o", "-arch", "i386", nullptr));
+ EXPECT_TRUE(parse({"foo.o", "bar.o", "-arch", "i386"}));
EXPECT_FALSE(_ctx.allowRemainingUndefines());
EXPECT_FALSE(_ctx.deadStrip());
EXPECT_EQ(2, inputFileCount());
@@ -37,204 +61,207 @@ TEST_F(DarwinLdParserTest, Basic) {
}
TEST_F(DarwinLdParserTest, Output) {
- EXPECT_TRUE(parse("ld", "-o", "my.out", "foo.o", "-arch", "i386", nullptr));
+ EXPECT_TRUE(parse({"-o", "my.out", "foo.o", "-arch", "i386"}));
EXPECT_EQ("my.out", _ctx.outputPath());
}
TEST_F(DarwinLdParserTest, Dylib) {
- EXPECT_TRUE(parse("ld", "-dylib", "foo.o", "-arch", "i386", nullptr));
+ EXPECT_TRUE(parse({"-dylib", "foo.o", "-arch", "i386"}));
EXPECT_EQ(llvm::MachO::MH_DYLIB, _ctx.outputMachOType());
}
TEST_F(DarwinLdParserTest, Relocatable) {
- EXPECT_TRUE(parse("ld", "-r", "foo.o", "-arch", "i386", nullptr));
+ EXPECT_TRUE(parse({"-r", "foo.o", "-arch", "i386"}));
EXPECT_EQ(llvm::MachO::MH_OBJECT, _ctx.outputMachOType());
}
TEST_F(DarwinLdParserTest, Bundle) {
- EXPECT_TRUE(parse("ld", "-bundle", "foo.o", "-arch", "i386", nullptr));
+ EXPECT_TRUE(parse({"-bundle", "foo.o", "-arch", "i386"}));
EXPECT_EQ(llvm::MachO::MH_BUNDLE, _ctx.outputMachOType());
}
TEST_F(DarwinLdParserTest, Preload) {
- EXPECT_TRUE(parse("ld", "-preload", "foo.o", "-arch", "i386", nullptr));
+ EXPECT_TRUE(parse({"-preload", "foo.o", "-arch", "i386"}));
EXPECT_EQ(llvm::MachO::MH_PRELOAD, _ctx.outputMachOType());
}
TEST_F(DarwinLdParserTest, Static) {
- EXPECT_TRUE(parse("ld", "-static", "foo.o", "-arch", "i386", nullptr));
+ EXPECT_TRUE(parse({"-static", "foo.o", "-arch", "i386"}));
EXPECT_EQ(llvm::MachO::MH_EXECUTE, _ctx.outputMachOType());
}
TEST_F(DarwinLdParserTest, Entry) {
- EXPECT_TRUE(parse("ld", "-e", "entryFunc", "foo.o", "-arch", "i386",nullptr));
+ EXPECT_TRUE(parse({"-e", "entryFunc", "foo.o", "-arch", "i386"}));
EXPECT_EQ("entryFunc", _ctx.entrySymbolName());
}
TEST_F(DarwinLdParserTest, DeadStrip) {
- EXPECT_TRUE(parse("ld", "-arch", "x86_64", "-dead_strip", "foo.o", nullptr));
+ EXPECT_TRUE(parse({"-arch", "x86_64", "-dead_strip", "foo.o"}));
EXPECT_TRUE(_ctx.deadStrip());
}
TEST_F(DarwinLdParserTest, DeadStripRootsExe) {
- EXPECT_TRUE(parse("ld", "-arch", "x86_64", "-dead_strip", "foo.o", nullptr));
+ EXPECT_TRUE(parse({"-arch", "x86_64", "-dead_strip", "foo.o"}));
EXPECT_FALSE(_ctx.globalsAreDeadStripRoots());
}
TEST_F(DarwinLdParserTest, DeadStripRootsDylib) {
- EXPECT_TRUE(parse("ld", "-arch", "x86_64", "-dylib", "-dead_strip", "foo.o",
- nullptr));
+ EXPECT_TRUE(parse({"-arch", "x86_64", "-dylib", "-dead_strip", "foo.o"}));
+ EXPECT_FALSE(_ctx.globalsAreDeadStripRoots());
+}
+
+TEST_F(DarwinLdParserTest, DeadStripRootsRelocatable) {
+ EXPECT_TRUE(parse({"-arch", "x86_64", "-r", "-dead_strip", "foo.o"}));
+ EXPECT_FALSE(_ctx.globalsAreDeadStripRoots());
+}
+
+TEST_F(DarwinLdParserTest, DeadStripRootsExportDynamicExe) {
+ EXPECT_TRUE(
+ parse({"-arch", "x86_64", "-dead_strip", "-export_dynamic", "foo.o"}));
EXPECT_TRUE(_ctx.globalsAreDeadStripRoots());
}
+TEST_F(DarwinLdParserTest, DeadStripRootsExportDynamicDylib) {
+ EXPECT_TRUE(parse({"-arch", "x86_64", "-dylib", "-dead_strip",
+ "-export_dynamic", "foo.o"}));
+ EXPECT_TRUE(_ctx.globalsAreDeadStripRoots());
+}
+
+TEST_F(DarwinLdParserTest, DeadStripRootsExportDynamicRelocatable) {
+ EXPECT_TRUE(parse(
+ {"-arch", "x86_64", "-r", "-dead_strip", "-export_dynamic", "foo.o"}));
+ EXPECT_FALSE(_ctx.globalsAreDeadStripRoots());
+}
+
TEST_F(DarwinLdParserTest, Arch) {
- EXPECT_TRUE(parse("ld", "-arch", "x86_64", "foo.o", nullptr));
+ EXPECT_TRUE(parse({"-arch", "x86_64", "foo.o"}));
EXPECT_EQ(MachOLinkingContext::arch_x86_64, _ctx.arch());
EXPECT_EQ((uint32_t)llvm::MachO::CPU_TYPE_X86_64, _ctx.getCPUType());
EXPECT_EQ(llvm::MachO::CPU_SUBTYPE_X86_64_ALL, _ctx.getCPUSubType());
}
TEST_F(DarwinLdParserTest, Arch_x86) {
- EXPECT_TRUE(parse("ld", "-arch", "i386", "foo.o", nullptr));
+ EXPECT_TRUE(parse({"-arch", "i386", "foo.o"}));
EXPECT_EQ(MachOLinkingContext::arch_x86, _ctx.arch());
EXPECT_EQ((uint32_t)llvm::MachO::CPU_TYPE_I386, _ctx.getCPUType());
EXPECT_EQ(llvm::MachO::CPU_SUBTYPE_X86_ALL, _ctx.getCPUSubType());
}
TEST_F(DarwinLdParserTest, Arch_armv6) {
- EXPECT_TRUE(parse("ld", "-arch", "armv6", "foo.o", nullptr));
+ EXPECT_TRUE(parse({"-arch", "armv6", "foo.o"}));
EXPECT_EQ(MachOLinkingContext::arch_armv6, _ctx.arch());
EXPECT_EQ((uint32_t)llvm::MachO::CPU_TYPE_ARM, _ctx.getCPUType());
EXPECT_EQ(llvm::MachO::CPU_SUBTYPE_ARM_V6, _ctx.getCPUSubType());
}
TEST_F(DarwinLdParserTest, Arch_armv7) {
- EXPECT_TRUE(parse("ld", "-arch", "armv7", "foo.o", nullptr));
+ EXPECT_TRUE(parse({"-arch", "armv7", "foo.o"}));
EXPECT_EQ(MachOLinkingContext::arch_armv7, _ctx.arch());
EXPECT_EQ((uint32_t)llvm::MachO::CPU_TYPE_ARM, _ctx.getCPUType());
EXPECT_EQ(llvm::MachO::CPU_SUBTYPE_ARM_V7, _ctx.getCPUSubType());
}
TEST_F(DarwinLdParserTest, Arch_armv7s) {
- EXPECT_TRUE(parse("ld", "-arch", "armv7s", "foo.o", nullptr));
+ EXPECT_TRUE(parse({"-arch", "armv7s", "foo.o"}));
EXPECT_EQ(MachOLinkingContext::arch_armv7s, _ctx.arch());
EXPECT_EQ((uint32_t)llvm::MachO::CPU_TYPE_ARM, _ctx.getCPUType());
EXPECT_EQ(llvm::MachO::CPU_SUBTYPE_ARM_V7S, _ctx.getCPUSubType());
}
TEST_F(DarwinLdParserTest, MinMacOSX10_7) {
- EXPECT_TRUE(parse("ld", "-macosx_version_min", "10.7", "foo.o",
- "-arch", "x86_64", nullptr));
+ EXPECT_TRUE(
+ parse({"-macosx_version_min", "10.7", "foo.o", "-arch", "x86_64"}));
EXPECT_EQ(MachOLinkingContext::OS::macOSX, _ctx.os());
EXPECT_TRUE(_ctx.minOS("10.7", ""));
EXPECT_FALSE(_ctx.minOS("10.8", ""));
}
TEST_F(DarwinLdParserTest, MinMacOSX10_8) {
- EXPECT_TRUE(parse("ld", "-macosx_version_min", "10.8.3", "foo.o",
- "-arch", "x86_64", nullptr));
+ EXPECT_TRUE(
+ parse({"-macosx_version_min", "10.8.3", "foo.o", "-arch", "x86_64"}));
EXPECT_EQ(MachOLinkingContext::OS::macOSX, _ctx.os());
EXPECT_TRUE(_ctx.minOS("10.7", ""));
EXPECT_TRUE(_ctx.minOS("10.8", ""));
}
TEST_F(DarwinLdParserTest, iOS5) {
- EXPECT_TRUE(parse("ld", "-ios_version_min", "5.0", "foo.o",
- "-arch", "armv7", nullptr));
+ EXPECT_TRUE(parse({"-ios_version_min", "5.0", "foo.o", "-arch", "armv7"}));
EXPECT_EQ(MachOLinkingContext::OS::iOS, _ctx.os());
EXPECT_TRUE(_ctx.minOS("", "5.0"));
EXPECT_FALSE(_ctx.minOS("", "6.0"));
}
TEST_F(DarwinLdParserTest, iOS6) {
- EXPECT_TRUE(parse("ld", "-ios_version_min", "6.0", "foo.o", "-arch", "armv7",
- nullptr));
+ EXPECT_TRUE(parse({"-ios_version_min", "6.0", "foo.o", "-arch", "armv7"}));
EXPECT_EQ(MachOLinkingContext::OS::iOS, _ctx.os());
EXPECT_TRUE(_ctx.minOS("", "5.0"));
EXPECT_TRUE(_ctx.minOS("", "6.0"));
}
TEST_F(DarwinLdParserTest, iOS_Simulator5) {
- EXPECT_TRUE(parse("ld", "-ios_simulator_version_min", "5.0", "a.o",
- "-arch", "i386", nullptr));
+ EXPECT_TRUE(
+ parse({"-ios_simulator_version_min", "5.0", "a.o", "-arch", "i386"}));
EXPECT_EQ(MachOLinkingContext::OS::iOS_simulator, _ctx.os());
EXPECT_TRUE(_ctx.minOS("", "5.0"));
EXPECT_FALSE(_ctx.minOS("", "6.0"));
}
TEST_F(DarwinLdParserTest, iOS_Simulator6) {
- EXPECT_TRUE(parse("ld", "-ios_simulator_version_min", "6.0", "a.o",
- "-arch", "i386", nullptr));
+ EXPECT_TRUE(
+ parse({"-ios_simulator_version_min", "6.0", "a.o", "-arch", "i386"}));
EXPECT_EQ(MachOLinkingContext::OS::iOS_simulator, _ctx.os());
EXPECT_TRUE(_ctx.minOS("", "5.0"));
EXPECT_TRUE(_ctx.minOS("", "6.0"));
}
TEST_F(DarwinLdParserTest, compatibilityVersion) {
- EXPECT_TRUE(
- parse("ld", "-dylib", "-compatibility_version", "1.2.3", "a.o",
- "-arch", "i386",nullptr));
+ EXPECT_TRUE(parse(
+ {"-dylib", "-compatibility_version", "1.2.3", "a.o", "-arch", "i386"}));
EXPECT_EQ(_ctx.compatibilityVersion(), 0x10203U);
}
TEST_F(DarwinLdParserTest, compatibilityVersionInvalidType) {
- EXPECT_FALSE(parse("ld", "-bundle", "-compatibility_version", "1.2.3", "a.o",
- "-arch", "i386",nullptr));
+ EXPECT_FALSE(parse(
+ {"-bundle", "-compatibility_version", "1.2.3", "a.o", "-arch", "i386"}));
}
TEST_F(DarwinLdParserTest, compatibilityVersionInvalidValue) {
- EXPECT_FALSE(parse("ld", "-bundle", "-compatibility_version", "1,2,3", "a.o",
- "-arch", "i386", nullptr));
+ EXPECT_FALSE(parse(
+ {"-bundle", "-compatibility_version", "1,2,3", "a.o", "-arch", "i386"}));
}
TEST_F(DarwinLdParserTest, currentVersion) {
EXPECT_TRUE(
- parse("ld", "-dylib", "-current_version", "1.2.3", "a.o", "-arch", "i386",
- nullptr));
+ parse({"-dylib", "-current_version", "1.2.3", "a.o", "-arch", "i386"}));
EXPECT_EQ(_ctx.currentVersion(), 0x10203U);
}
TEST_F(DarwinLdParserTest, currentVersionInvalidType) {
EXPECT_FALSE(
- parse("ld", "-bundle", "-current_version", "1.2.3", "a.o",
- "-arch", "i386", nullptr));
+ parse({"-bundle", "-current_version", "1.2.3", "a.o", "-arch", "i386"}));
}
TEST_F(DarwinLdParserTest, currentVersionInvalidValue) {
EXPECT_FALSE(
- parse("ld", "-bundle", "-current_version", "1,2,3", "a.o",
- "-arch", "i386", nullptr));
+ parse({"-bundle", "-current_version", "1,2,3", "a.o", "-arch", "i386"}));
}
TEST_F(DarwinLdParserTest, bundleLoader) {
EXPECT_TRUE(
- parse("ld", "-bundle", "-bundle_loader", "/bin/ls", "a.o",
- "-arch", "i386", nullptr));
+ parse({"-bundle", "-bundle_loader", "/bin/ls", "a.o", "-arch", "i386"}));
EXPECT_EQ(_ctx.bundleLoader(), "/bin/ls");
}
TEST_F(DarwinLdParserTest, bundleLoaderInvalidType) {
- EXPECT_FALSE(parse("ld", "-bundle_loader", "/bin/ls", "a.o", "-arch", "i386",
- nullptr));
+ EXPECT_FALSE(parse({"-bundle_loader", "/bin/ls", "a.o", "-arch", "i386"}));
}
TEST_F(DarwinLdParserTest, deadStrippableDylib) {
EXPECT_TRUE(
- parse("ld", "-dylib", "-mark_dead_strippable_dylib", "a.o",
- "-arch", "i386", nullptr));
+ parse({"-dylib", "-mark_dead_strippable_dylib", "a.o", "-arch", "i386"}));
EXPECT_EQ(true, _ctx.deadStrippableDylib());
}
TEST_F(DarwinLdParserTest, deadStrippableDylibInvalidType) {
- EXPECT_FALSE(parse("ld", "-mark_dead_strippable_dylib", "a.o",
- "-arch", "i386", nullptr));
-}
-
-TEST_F(DarwinLdParserTest, llvmOptions) {
- EXPECT_TRUE(parse("ld", "-mllvm", "-enable-tbaa", "-mllvm", "-enable-misched", "a.o",
- "-arch", "i386", nullptr));
- const std::vector<const char *> &options = _ctx.llvmOptions();
- EXPECT_EQ(options.size(), 2UL);
- EXPECT_EQ(strcmp(options[0],"-enable-tbaa"), 0);
- EXPECT_EQ(strcmp(options[1],"-enable-misched"), 0);
+ EXPECT_FALSE(parse({"-mark_dead_strippable_dylib", "a.o", "-arch", "i386"}));
}
diff --git a/unittests/DriverTests/DriverTest.h b/unittests/DriverTests/DriverTest.h
deleted file mode 100644
index 65af7cac3139..000000000000
--- a/unittests/DriverTests/DriverTest.h
+++ /dev/null
@@ -1,61 +0,0 @@
-//===- lld/unittest/DriverTest.h ------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "lld/Driver/Driver.h"
-#include "llvm/Support/raw_ostream.h"
-#include "gtest/gtest.h"
-#include <stdarg.h>
-
-namespace {
-
-using namespace llvm;
-using namespace lld;
-
-template<typename D, typename T>
-class ParserTest : public testing::Test {
-protected:
-
- virtual const LinkingContext *linkingContext() = 0;
-
- std::string &errorMessage() { return _errorMessage; }
-
- // Convenience method for getting number of input files.
- int inputFileCount() {
- return linkingContext()->getNodes().size();
- }
-
- // Convenience method for getting i'th input files name.
- std::string inputFile(int index) {
- Node &node = *linkingContext()->getNodes()[index];
- if (node.kind() == Node::Kind::File)
- return cast<FileNode>(&node)->getFile()->path();
- llvm_unreachable("not handling other types of input files");
- }
-
- // For unit tests to call driver with various command lines.
- bool parse(const char *args, ...) {
- // Construct command line options from varargs.
- std::vector<const char *> vec;
- vec.push_back(args);
- va_list ap;
- va_start(ap, args);
- while (const char *arg = va_arg(ap, const char *))
- vec.push_back(arg);
- va_end(ap);
-
- // Call the parser.
- raw_string_ostream os(_errorMessage);
- return D::parse(vec, _ctx, os);
- }
-
- T _ctx;
- std::string _errorMessage;
-};
-
-}
diff --git a/unittests/DriverTests/GnuLdDriverTest.cpp b/unittests/DriverTests/GnuLdDriverTest.cpp
deleted file mode 100644
index 13d20a4411a1..000000000000
--- a/unittests/DriverTests/GnuLdDriverTest.cpp
+++ /dev/null
@@ -1,299 +0,0 @@
-//===- 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"
-#include "llvm/Support/MemoryBuffer.h"
-
-using namespace llvm;
-using namespace lld;
-
-namespace {
-
-class GnuLdParserTest
- : public ParserTest<GnuLdDriver, std::unique_ptr<ELFLinkingContext>> {
-protected:
- const LinkingContext *linkingContext() override { return _ctx.get(); }
-};
-
-class LinkerScriptTest : public testing::Test {
-protected:
- void SetUp() override {
- llvm::Triple triple(llvm::sys::getDefaultTargetTriple());
- _ctx = GnuLdDriver::createELFLinkingContext(triple);
- }
-
- void parse(StringRef script, bool nostdlib = false) {
- std::unique_ptr<MemoryBuffer> mb = MemoryBuffer::getMemBuffer(
- script, "foo.so");
- std::string s;
- raw_string_ostream out(s);
- std::error_code ec =
- GnuLdDriver::evalLinkerScript(*_ctx, std::move(mb), out, nostdlib);
- EXPECT_FALSE(ec);
- }
-
- std::unique_ptr<ELFLinkingContext> _ctx;
-};
-
-} // anonymous namespace
-
-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", "a.o", "-o", "foo", nullptr));
- EXPECT_EQ("foo", _ctx->outputPath());
-}
-
-TEST_F(GnuLdParserTest, OutputDefault) {
- EXPECT_TRUE(parse("ld", "abc.o", nullptr));
- EXPECT_EQ("a.out", _ctx->outputPath());
-}
-
-// --noinhibit-exec
-
-TEST_F(GnuLdParserTest, NoinhibitExec) {
- EXPECT_TRUE(parse("ld", "a.o", "--noinhibit-exec", nullptr));
- EXPECT_TRUE(_ctx->allowRemainingUndefines());
-}
-
-// --entry
-
-TEST_F(GnuLdParserTest, Entry) {
- EXPECT_TRUE(parse("ld", "a.o", "--entry", "foo", nullptr));
- EXPECT_EQ("foo", _ctx->entrySymbolName());
-}
-
-TEST_F(GnuLdParserTest, EntryShort) {
- EXPECT_TRUE(parse("ld", "a.o", "-e", "foo", nullptr));
- EXPECT_EQ("foo", _ctx->entrySymbolName());
-}
-
-TEST_F(GnuLdParserTest, EntryJoined) {
- EXPECT_TRUE(parse("ld", "a.o", "--entry=foo", nullptr));
- EXPECT_EQ("foo", _ctx->entrySymbolName());
-}
-
-// --export-dynamic
-
-TEST_F(GnuLdParserTest, ExportDynamic) {
- EXPECT_TRUE(parse("ld", "a.o", "--export-dynamic", nullptr));
- EXPECT_TRUE(_ctx->shouldExportDynamic());
-}
-
-TEST_F(GnuLdParserTest, NoExportDynamic) {
- EXPECT_TRUE(parse("ld", "a.o", "--no-export-dynamic", nullptr));
- EXPECT_FALSE(_ctx->shouldExportDynamic());
-}
-
-// --init
-
-TEST_F(GnuLdParserTest, Init) {
- EXPECT_TRUE(parse("ld", "a.o", "-init", "foo", "-init", "bar", nullptr));
- EXPECT_EQ("bar", _ctx->initFunction());
-}
-
-TEST_F(GnuLdParserTest, InitJoined) {
- EXPECT_TRUE(parse("ld", "a.o", "-init=foo", nullptr));
- EXPECT_EQ("foo", _ctx->initFunction());
-}
-
-// --soname
-
-TEST_F(GnuLdParserTest, SOName) {
- EXPECT_TRUE(parse("ld", "a.o", "--soname=foo", nullptr));
- EXPECT_EQ("foo", _ctx->sharedObjectName());
-}
-
-TEST_F(GnuLdParserTest, SONameSingleDash) {
- EXPECT_TRUE(parse("ld", "a.o", "-soname=foo", nullptr));
- EXPECT_EQ("foo", _ctx->sharedObjectName());
-}
-
-TEST_F(GnuLdParserTest, SONameH) {
- EXPECT_TRUE(parse("ld", "a.o", "-h", "foo", nullptr));
- EXPECT_EQ("foo", _ctx->sharedObjectName());
-}
-
-// -rpath
-
-TEST_F(GnuLdParserTest, Rpath) {
- EXPECT_TRUE(parse("ld", "a.o", "-rpath", "foo:bar", nullptr));
- EXPECT_EQ(2, _ctx->getRpathList().size());
- EXPECT_EQ("foo", _ctx->getRpathList()[0]);
- EXPECT_EQ("bar", _ctx->getRpathList()[1]);
-}
-
-TEST_F(GnuLdParserTest, RpathEq) {
- EXPECT_TRUE(parse("ld", "a.o", "-rpath=foo", nullptr));
- EXPECT_EQ(1, _ctx->getRpathList().size());
- EXPECT_EQ("foo", _ctx->getRpathList()[0]);
-}
-
-// --defsym
-
-TEST_F(GnuLdParserTest, DefsymDecimal) {
- EXPECT_TRUE(parse("ld", "a.o", "--defsym=sym=1000", nullptr));
- assert(_ctx.get());
- auto map = _ctx->getAbsoluteSymbols();
- EXPECT_EQ((size_t)1, map.size());
- EXPECT_EQ((uint64_t)1000, map["sym"]);
-}
-
-TEST_F(GnuLdParserTest, DefsymHexadecimal) {
- EXPECT_TRUE(parse("ld", "a.o", "--defsym=sym=0x1000", nullptr));
- auto map = _ctx->getAbsoluteSymbols();
- EXPECT_EQ((size_t)1, map.size());
- EXPECT_EQ((uint64_t)0x1000, map["sym"]);
-}
-
-TEST_F(GnuLdParserTest, DefsymAlias) {
- EXPECT_TRUE(parse("ld", "a.o", "--defsym=sym=abc", nullptr));
- auto map = _ctx->getAliases();
- EXPECT_EQ((size_t)1, map.size());
- EXPECT_EQ("abc", map["sym"]);
-}
-
-TEST_F(GnuLdParserTest, DefsymOctal) {
- EXPECT_TRUE(parse("ld", "a.o", "--defsym=sym=0777", nullptr));
- auto map = _ctx->getAbsoluteSymbols();
- EXPECT_EQ((size_t)1, map.size());
- EXPECT_EQ((uint64_t)0777, map["sym"]);
-}
-
-TEST_F(GnuLdParserTest, DefsymMisssingSymbol) {
- EXPECT_FALSE(parse("ld", "a.o", "--defsym==0", nullptr));
-}
-
-TEST_F(GnuLdParserTest, DefsymMisssingValue) {
- EXPECT_FALSE(parse("ld", "a.o", "--defsym=sym=", nullptr));
-}
-
-// --as-needed
-
-TEST_F(GnuLdParserTest, AsNeeded) {
- EXPECT_TRUE(parse("ld", "a.o", "--as-needed", "b.o", "c.o",
- "--no-as-needed", "d.o", nullptr));
- std::vector<std::unique_ptr<Node>> &nodes = _ctx->getNodes();
- EXPECT_EQ((size_t)4, nodes.size());
- EXPECT_FALSE(cast<FileNode>(nodes[0].get())->asNeeded());
- EXPECT_TRUE(cast<FileNode>(nodes[1].get())->asNeeded());
- EXPECT_TRUE(cast<FileNode>(nodes[2].get())->asNeeded());
- EXPECT_FALSE(cast<FileNode>(nodes[3].get())->asNeeded());
-}
-
-// Emulation
-
-TEST_F(GnuLdParserTest, Emulation) {
- EXPECT_TRUE(parse("mips-linux-gnu-ld", "a.o", "-m", "elf64ltsmip", nullptr));
- EXPECT_EQ(Triple::mips64el, _ctx->getTriple().getArch());
- EXPECT_TRUE(
- parse("mips64el-linux-gnu-ld", "a.o", "-m", "elf32btsmip", nullptr));
- EXPECT_EQ(Triple::mips, _ctx->getTriple().getArch());
- EXPECT_TRUE(
- parse("mipsel-linux-gnu-ld", "a.o", "-m", "elf32btsmipn32", nullptr));
- EXPECT_EQ(Triple::mips, _ctx->getTriple().getArch());
- EXPECT_TRUE(
- parse("mips-linux-gnu-ld", "a.o", "-m", "elf32ltsmipn32", nullptr));
- EXPECT_EQ(Triple::mipsel, _ctx->getTriple().getArch());
-}
-
-// Linker script
-
-TEST_F(LinkerScriptTest, Input) {
- parse("INPUT(/x /y)");
- std::vector<std::unique_ptr<Node>> &nodes = _ctx->getNodes();
- EXPECT_EQ((size_t)2, nodes.size());
- EXPECT_EQ("/x", cast<FileNode>(nodes[0].get())->getFile()->path());
- EXPECT_EQ("/y", cast<FileNode>(nodes[1].get())->getFile()->path());
-}
-
-TEST_F(LinkerScriptTest, Group) {
- parse("GROUP(/x /y)");
- std::vector<std::unique_ptr<Node>> &nodes = _ctx->getNodes();
- EXPECT_EQ((size_t)3, nodes.size());
- EXPECT_EQ("/x", cast<FileNode>(nodes[0].get())->getFile()->path());
- EXPECT_EQ("/y", cast<FileNode>(nodes[1].get())->getFile()->path());
- EXPECT_EQ(2, cast<GroupEnd>(nodes[2].get())->getSize());
-}
-
-TEST_F(LinkerScriptTest, SearchDir) {
- parse("SEARCH_DIR(\"/foo/bar\")");
- std::vector<StringRef> paths = _ctx->getSearchPaths();
- EXPECT_EQ((size_t)1, paths.size());
- EXPECT_EQ("/foo/bar", paths[0]);
-}
-
-TEST_F(LinkerScriptTest, Entry) {
- parse("ENTRY(blah)");
- EXPECT_EQ("blah", _ctx->entrySymbolName());
-}
-
-TEST_F(LinkerScriptTest, Output) {
- parse("OUTPUT(\"/path/to/output\")");
- EXPECT_EQ("/path/to/output", _ctx->outputPath());
-}
-
-// Test that search paths are ignored when nostdlib is set.
-TEST_F(LinkerScriptTest, IgnoreSearchDirNoStdLib) {
- parse("SEARCH_DIR(\"/foo/bar\")", true /*nostdlib*/);
- std::vector<StringRef> paths = _ctx->getSearchPaths();
- EXPECT_EQ((size_t)0, paths.size());
-}
-
-TEST_F(LinkerScriptTest, ExprEval) {
- parse("SECTIONS { symbol = 0x4000 + 0x40; \n"
- ". = (symbol >= 0x4040)? (0x5001 * 2 & 0xFFF0) << 1 : 0}");
-
- EXPECT_EQ((size_t)1, _ctx->linkerScriptSema().getLinkerScripts().size());
-
- script::LinkerScript *ls =
- _ctx->linkerScriptSema().getLinkerScripts()[0]->get();
- EXPECT_EQ((size_t)1, ls->_commands.size());
-
- auto *secs = dyn_cast<const script::Sections>(*ls->_commands.begin());
- EXPECT_TRUE(secs != nullptr);
- EXPECT_EQ(2, secs->end() - secs->begin());
-
- auto command = secs->begin();
- auto *sa1 = dyn_cast<const script::SymbolAssignment>(*command);
- EXPECT_TRUE(sa1 != nullptr);
- EXPECT_EQ(script::SymbolAssignment::Simple, sa1->assignmentKind());
- EXPECT_EQ(script::SymbolAssignment::Default, sa1->assignmentVisibility());
-
- ++command;
- auto *sa2 = dyn_cast<const script::SymbolAssignment>(*command);
- EXPECT_TRUE(sa2 != nullptr);
- EXPECT_EQ(script::SymbolAssignment::Simple, sa2->assignmentKind());
- EXPECT_EQ(script::SymbolAssignment::Default, sa2->assignmentVisibility());
-
- script::Expression::SymbolTableTy mySymbolTable;
- auto ans = sa1->expr()->evalExpr(mySymbolTable);
- EXPECT_FALSE(ans.getError());
- int64_t result = *ans;
- EXPECT_EQ(0x4040, result);
- mySymbolTable[sa1->symbol()] = result;
-
- auto ans2 = sa2->expr()->evalExpr(mySymbolTable);
- EXPECT_FALSE(ans2.getError());
- result = *ans2;
- EXPECT_EQ(0x14000, result);
- EXPECT_EQ(0, sa2->symbol().compare(StringRef(".")));
-}
diff --git a/unittests/DriverTests/UniversalDriverTest.cpp b/unittests/DriverTests/UniversalDriverTest.cpp
deleted file mode 100644
index 0a464d3038c6..000000000000
--- a/unittests/DriverTests/UniversalDriverTest.cpp
+++ /dev/null
@@ -1,33 +0,0 @@
-//===- lld/unittest/UniversalDriverTest.cpp -------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-///
-/// \file
-/// \brief Universal driver tests that depend on the value of argv[0].
-///
-//===----------------------------------------------------------------------===//
-
-#include "gtest/gtest.h"
-#include "lld/Driver/Driver.h"
-#include "llvm/ADT/STLExtras.h"
-#include "llvm/Support/raw_ostream.h"
-
-using namespace llvm;
-using namespace lld;
-
-TEST(UniversalDriver, flavor) {
- const char *args[] = {"ld", "-flavor", "old-gnu"};
-
- std::string diags;
- raw_string_ostream os(diags);
- UniversalDriver::link(args, os);
- EXPECT_EQ(os.str().find("failed to determine driver flavor"),
- std::string::npos);
- EXPECT_NE(os.str().find("No input files"),
- std::string::npos);
-}
diff --git a/unittests/MachOTests/MachONormalizedFileBinaryReaderTests.cpp b/unittests/MachOTests/MachONormalizedFileBinaryReaderTests.cpp
index 6827a732fbd8..a3c445a93619 100644
--- a/unittests/MachOTests/MachONormalizedFileBinaryReaderTests.cpp
+++ b/unittests/MachOTests/MachONormalizedFileBinaryReaderTests.cpp
@@ -9,13 +9,17 @@
#include "gtest/gtest.h"
#include "../../lib/ReaderWriter/MachO/MachONormalizedFile.h"
+#include "lld/ReaderWriter/MachOLinkingContext.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Error.h"
#include "llvm/Support/MachO.h"
-#include <assert.h>
-#include <vector>
+#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/YAMLTraits.h"
+#include <cstdint>
+#include <memory>
using llvm::StringRef;
using llvm::MemoryBuffer;
-using llvm::ErrorOr;
using namespace lld::mach_o::normalized;
using namespace llvm::MachO;
@@ -24,7 +28,7 @@ static std::unique_ptr<NormalizedFile>
fromBinary(const uint8_t bytes[], unsigned length, StringRef archStr) {
StringRef sr((const char*)bytes, length);
std::unique_ptr<MemoryBuffer> mb(MemoryBuffer::getMemBuffer(sr, "", false));
- ErrorOr<std::unique_ptr<NormalizedFile>> r =
+ llvm::Expected<std::unique_ptr<NormalizedFile>> r =
lld::mach_o::normalized::readBinary(
mb, lld::MachOLinkingContext::archFromName(archStr));
EXPECT_FALSE(!r);
@@ -75,7 +79,6 @@ TEST(BinaryReaderTest, empty_obj_x86_64) {
EXPECT_TRUE(f->undefinedSymbols.empty());
}
-
TEST(BinaryReaderTest, empty_obj_x86) {
FILEBYTES = {
0xce, 0xfa, 0xed, 0xfe, 0x07, 0x00, 0x00, 0x00,
@@ -107,7 +110,6 @@ TEST(BinaryReaderTest, empty_obj_x86) {
EXPECT_TRUE(f->undefinedSymbols.empty());
}
-
TEST(BinaryReaderTest, empty_obj_ppc) {
FILEBYTES = {
0xfe, 0xed, 0xfa, 0xce, 0x00, 0x00, 0x00, 0x12,
@@ -139,7 +141,6 @@ TEST(BinaryReaderTest, empty_obj_ppc) {
EXPECT_TRUE(f->undefinedSymbols.empty());
}
-
TEST(BinaryReaderTest, empty_obj_armv7) {
FILEBYTES = {
0xce, 0xfa, 0xed, 0xfe, 0x0c, 0x00, 0x00, 0x00,
@@ -326,7 +327,6 @@ TEST(BinaryReaderTest, hello_obj_x86_64) {
EXPECT_EQ(printfLabel.scope, SymbolScope(N_EXT));
}
-
TEST(BinaryReaderTest, hello_obj_x86) {
FILEBYTES = {
0xCE, 0xFA, 0xED, 0xFE, 0x07, 0x00, 0x00, 0x00,
@@ -458,7 +458,6 @@ TEST(BinaryReaderTest, hello_obj_x86) {
EXPECT_EQ(printfLabel.scope, SymbolScope(N_EXT));
}
-
TEST(BinaryReaderTest, hello_obj_armv7) {
FILEBYTES = {
0xCE, 0xFA, 0xED, 0xFE, 0x0C, 0x00, 0x00, 0x00,
@@ -600,7 +599,6 @@ TEST(BinaryReaderTest, hello_obj_armv7) {
EXPECT_EQ(printfLabel.scope, SymbolScope(N_EXT));
}
-
TEST(BinaryReaderTest, hello_obj_ppc) {
FILEBYTES = {
0xFE, 0xED, 0xFA, 0xCE, 0x00, 0x00, 0x00, 0x12,
@@ -743,6 +741,9 @@ TEST(BinaryReaderTest, hello_obj_ppc) {
EXPECT_EQ(printfLabel.type, N_UNDF);
EXPECT_EQ(printfLabel.scope, SymbolScope(N_EXT));
- writeBinary(*f, "/tmp/foo.o");
-
+ auto ec = writeBinary(*f, "/tmp/foo.o");
+ // FIXME: We want to do EXPECT_FALSE(ec) but that fails on some Windows bots,
+ // probably due to /tmp not being available.
+ // For now just consume the error without checking it.
+ consumeError(std::move(ec));
}
diff --git a/unittests/MachOTests/MachONormalizedFileBinaryWriterTests.cpp b/unittests/MachOTests/MachONormalizedFileBinaryWriterTests.cpp
index 87c527233cb1..f44950a8d5ab 100644
--- a/unittests/MachOTests/MachONormalizedFileBinaryWriterTests.cpp
+++ b/unittests/MachOTests/MachONormalizedFileBinaryWriterTests.cpp
@@ -35,7 +35,7 @@ static void fromBinary(StringRef path, std::unique_ptr<MemoryBuffer> &mb,
EXPECT_FALSE(ec);
mb = std::move(mbOrErr.get());
- ErrorOr<std::unique_ptr<NormalizedFile>> r =
+ llvm::Expected<std::unique_ptr<NormalizedFile>> r =
lld::mach_o::normalized::readBinary(
mb, lld::MachOLinkingContext::archFromName(archStr));
EXPECT_FALSE(!r);
@@ -148,8 +148,8 @@ TEST(BinaryWriterTest, obj_relocs_x86_64) {
std::error_code ec =
llvm::sys::fs::createTemporaryFile(Twine("xx"), "o", tmpFl);
EXPECT_FALSE(ec);
- ec = writeBinary(f, tmpFl);
- EXPECT_FALSE(ec);
+ llvm::Error ec2 = writeBinary(f, tmpFl);
+ EXPECT_FALSE(ec2);
}
std::unique_ptr<MemoryBuffer> bufferOwner;
@@ -260,8 +260,8 @@ TEST(BinaryWriterTest, obj_relocs_x86) {
std::error_code ec =
llvm::sys::fs::createTemporaryFile(Twine("xx"), "o", tmpFl);
EXPECT_FALSE(ec);
- ec = writeBinary(f, tmpFl);
- EXPECT_FALSE(ec);
+ llvm::Error ec2 = writeBinary(f, tmpFl);
+ EXPECT_FALSE(ec2);
}
std::unique_ptr<MemoryBuffer> bufferOwner;
std::unique_ptr<NormalizedFile> f2;
@@ -378,8 +378,8 @@ TEST(BinaryWriterTest, obj_relocs_armv7) {
std::error_code ec =
llvm::sys::fs::createTemporaryFile(Twine("xx"), "o", tmpFl);
EXPECT_FALSE(ec);
- ec = writeBinary(f, tmpFl);
- EXPECT_FALSE(ec);
+ llvm::Error ec2 = writeBinary(f, tmpFl);
+ EXPECT_FALSE(ec2);
}
std::unique_ptr<MemoryBuffer> bufferOwner;
std::unique_ptr<NormalizedFile> f2;
@@ -534,8 +534,8 @@ TEST(BinaryWriterTest, obj_relocs_ppc) {
std::error_code ec =
llvm::sys::fs::createTemporaryFile(Twine("xx"), "o", tmpFl);
EXPECT_FALSE(ec);
- ec = writeBinary(f, tmpFl);
- EXPECT_FALSE(ec);
+ llvm::Error ec2 = writeBinary(f, tmpFl);
+ EXPECT_FALSE(ec2);
}
std::unique_ptr<MemoryBuffer> bufferOwner;
std::unique_ptr<NormalizedFile> f2;
diff --git a/unittests/MachOTests/MachONormalizedFileToAtomsTests.cpp b/unittests/MachOTests/MachONormalizedFileToAtomsTests.cpp
index 7def86c87929..8205ea97520a 100644
--- a/unittests/MachOTests/MachONormalizedFileToAtomsTests.cpp
+++ b/unittests/MachOTests/MachONormalizedFileToAtomsTests.cpp
@@ -9,11 +9,17 @@
#include "gtest/gtest.h"
#include "../../lib/ReaderWriter/MachO/MachONormalizedFile.h"
+#include "lld/Core/Atom.h"
+#include "lld/Core/DefinedAtom.h"
+#include "lld/Core/File.h"
+#include "lld/Core/UndefinedAtom.h"
+#include "lld/ReaderWriter/MachOLinkingContext.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/Support/Error.h"
#include "llvm/Support/MachO.h"
-#include <assert.h>
-#include <vector>
-
-using llvm::ErrorOr;
+#include "llvm/Support/YAMLTraits.h"
+#include <cstdint>
+#include <memory>
using namespace lld::mach_o::normalized;
using namespace llvm::MachO;
@@ -21,7 +27,7 @@ using namespace llvm::MachO;
TEST(ToAtomsTest, empty_obj_x86_64) {
NormalizedFile f;
f.arch = lld::MachOLinkingContext::arch_x86_64;
- ErrorOr<std::unique_ptr<const lld::File>> atom_f =
+ llvm::Expected<std::unique_ptr<const lld::File>> atom_f =
normalizedToAtoms(f, "", false);
EXPECT_FALSE(!atom_f);
EXPECT_EQ(0U, (*atom_f)->defined().size());
@@ -61,7 +67,7 @@ TEST(ToAtomsTest, basic_obj_x86_64) {
bazSymbol.value = 3;
f.localSymbols.push_back(bazSymbol);
- ErrorOr<std::unique_ptr<const lld::File>> atom_f =
+ llvm::Expected<std::unique_ptr<const lld::File>> atom_f =
normalizedToAtoms(f, "", false);
EXPECT_FALSE(!atom_f);
const lld::File &file = **atom_f;
diff --git a/unittests/MachOTests/MachONormalizedFileYAMLTests.cpp b/unittests/MachOTests/MachONormalizedFileYAMLTests.cpp
index d13e360b41a5..e41b7ecd801c 100644
--- a/unittests/MachOTests/MachONormalizedFileYAMLTests.cpp
+++ b/unittests/MachOTests/MachONormalizedFileYAMLTests.cpp
@@ -9,22 +9,27 @@
#include "gtest/gtest.h"
#include "../../lib/ReaderWriter/MachO/MachONormalizedFile.h"
+#include "lld/ReaderWriter/MachOLinkingContext.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Error.h"
#include "llvm/Support/MachO.h"
-#include <assert.h>
-#include <vector>
+#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/raw_ostream.h"
+#include <cstdint>
+#include <memory>
+#include <system_error>
+#include <string>
using llvm::StringRef;
using llvm::MemoryBuffer;
-using llvm::ErrorOr;
using lld::mach_o::normalized::NormalizedFile;
using lld::mach_o::normalized::Symbol;
using lld::mach_o::normalized::Section;
using lld::mach_o::normalized::Relocation;
-
static std::unique_ptr<NormalizedFile> fromYAML(StringRef str) {
std::unique_ptr<MemoryBuffer> mb(MemoryBuffer::getMemBuffer(str));
- ErrorOr<std::unique_ptr<NormalizedFile>> r
+ llvm::Expected<std::unique_ptr<NormalizedFile>> r
= lld::mach_o::normalized::readYaml(mb);
EXPECT_FALSE(!r);
return std::move(*r);
@@ -36,7 +41,6 @@ static void toYAML(const NormalizedFile &f, std::string &out) {
EXPECT_TRUE(!ec);
}
-
// ppc is no longer supported, but it is here to test endianness handling.
TEST(ObjectFileYAML, empty_ppc) {
std::unique_ptr<NormalizedFile> f = fromYAML(
@@ -134,7 +138,6 @@ TEST(ObjectFileYAML, empty_armv7s) {
EXPECT_TRUE(f->undefinedSymbols.empty());
}
-
TEST(ObjectFileYAML, roundTrip) {
std::string intermediate;
{
@@ -157,7 +160,6 @@ TEST(ObjectFileYAML, roundTrip) {
}
}
-
TEST(ObjectFileYAML, oneSymbol) {
std::unique_ptr<NormalizedFile> f = fromYAML(
"---\n"
@@ -186,7 +188,6 @@ TEST(ObjectFileYAML, oneSymbol) {
EXPECT_EQ((uint64_t)sym.value, 0x100ULL);
}
-
TEST(ObjectFileYAML, oneSection) {
std::unique_ptr<NormalizedFile> f = fromYAML(
"---\n"
@@ -220,7 +221,6 @@ TEST(ObjectFileYAML, oneSection) {
EXPECT_EQ((int)(sect.content[1]), 0x90);
}
-
TEST(ObjectFileYAML, hello_x86_64) {
std::unique_ptr<NormalizedFile> f = fromYAML(
"---\n"
@@ -349,7 +349,6 @@ TEST(ObjectFileYAML, hello_x86_64) {
EXPECT_EQ((uint64_t)sym3.value, 0x0ULL);
}
-
TEST(ObjectFileYAML, hello_x86) {
std::unique_ptr<NormalizedFile> f = fromYAML(
"---\n"
@@ -607,8 +606,6 @@ TEST(ObjectFileYAML, hello_armv6) {
EXPECT_EQ((uint64_t)sym2.value, 0x0ULL);
}
-
-
TEST(ObjectFileYAML, hello_armv7) {
std::unique_ptr<NormalizedFile> f = fromYAML(
"---\n"