diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2015-12-30 11:57:38 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2015-12-30 11:57:38 +0000 |
commit | 5a5c549fe9a3fef595297bd21d36bed8409dc37d (patch) | |
tree | a964c8f5ac85b7b641cac022c5f9bf4eed3d2b9b /unittests | |
parent | fb911942f1434f3d1750f83f25f5e42c80e60638 (diff) | |
download | src-5a5c549fe9a3fef595297bd21d36bed8409dc37d.tar.gz src-5a5c549fe9a3fef595297bd21d36bed8409dc37d.zip |
Vendor import of lld trunk r256633:vendor/lld/lld-trunk-r256633
Notes
Notes:
svn path=/vendor/lld/dist/; revision=292934
svn path=/vendor/lld/lld-trunk-r256633/; revision=292935; tag=vendor/lld/lld-trunk-r256633
Diffstat (limited to 'unittests')
-rw-r--r-- | unittests/CoreTests/Makefile | 14 | ||||
-rw-r--r-- | unittests/DriverTests/CMakeLists.txt | 4 | ||||
-rw-r--r-- | unittests/DriverTests/DarwinLdDriverTest.cpp | 6 | ||||
-rw-r--r-- | unittests/DriverTests/DriverTest.h | 2 | ||||
-rw-r--r-- | unittests/DriverTests/GnuLdDriverTest.cpp | 21 | ||||
-rw-r--r-- | unittests/DriverTests/Makefile | 20 | ||||
-rw-r--r-- | unittests/DriverTests/UniversalDriverTest.cpp | 4 | ||||
-rw-r--r-- | unittests/DriverTests/WinLinkDriverTest.cpp | 728 | ||||
-rw-r--r-- | unittests/DriverTests/WinLinkModuleDefTest.cpp | 155 | ||||
-rw-r--r-- | unittests/MachOTests/MachONormalizedFileBinaryReaderTests.cpp | 16 | ||||
-rw-r--r-- | unittests/MachOTests/MachONormalizedFileBinaryWriterTests.cpp | 17 | ||||
-rw-r--r-- | unittests/MachOTests/MachONormalizedFileToAtomsTests.cpp | 2 | ||||
-rw-r--r-- | unittests/MachOTests/MachONormalizedFileYAMLTests.cpp | 36 | ||||
-rw-r--r-- | unittests/Makefile | 31 |
14 files changed, 60 insertions, 996 deletions
diff --git a/unittests/CoreTests/Makefile b/unittests/CoreTests/Makefile deleted file mode 100644 index 366df01a08cc..000000000000 --- a/unittests/CoreTests/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -##===- unittests/CoreTests/Makefile ----------------------------*- Makefile -*-===## -# -# The LLVM Compiler Infrastructure -# -# This file is distributed under the University of Illinois Open Source -# License. See LICENSE.TXT for details. -# -##===----------------------------------------------------------------------===## - -LLD_LEVEL = ../.. -TESTNAME = CoreTest -LLVMLIBS = gtest.a LLVMOption.a LLVMSupport.a - -include $(LLD_LEVEL)/unittests/Makefile diff --git a/unittests/DriverTests/CMakeLists.txt b/unittests/DriverTests/CMakeLists.txt index 59d56d459582..0378e6164429 100644 --- a/unittests/DriverTests/CMakeLists.txt +++ b/unittests/DriverTests/CMakeLists.txt @@ -2,13 +2,11 @@ add_lld_unittest(DriverTests UniversalDriverTest.cpp GnuLdDriverTest.cpp DarwinLdDriverTest.cpp - WinLinkDriverTest.cpp - WinLinkModuleDefTest.cpp ) target_link_libraries(DriverTests lldDriver + lldCOFF lldCore - lldPECOFF lldMachO ) diff --git a/unittests/DriverTests/DarwinLdDriverTest.cpp b/unittests/DriverTests/DarwinLdDriverTest.cpp index 1c77a05f5856..e2809c44984d 100644 --- a/unittests/DriverTests/DarwinLdDriverTest.cpp +++ b/unittests/DriverTests/DarwinLdDriverTest.cpp @@ -231,10 +231,10 @@ TEST_F(DarwinLdParserTest, deadStrippableDylibInvalidType) { } TEST_F(DarwinLdParserTest, llvmOptions) { - EXPECT_TRUE(parse("ld", "-mllvm", "-debug-only", "-mllvm", "foo", "a.o", + 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],"-debug-only"), 0); - EXPECT_EQ(strcmp(options[1],"foo"), 0); + EXPECT_EQ(strcmp(options[0],"-enable-tbaa"), 0); + EXPECT_EQ(strcmp(options[1],"-enable-misched"), 0); } diff --git a/unittests/DriverTests/DriverTest.h b/unittests/DriverTests/DriverTest.h index 2349132ee2ce..65af7cac3139 100644 --- a/unittests/DriverTests/DriverTest.h +++ b/unittests/DriverTests/DriverTest.h @@ -51,7 +51,7 @@ protected: // Call the parser. raw_string_ostream os(_errorMessage); - return D::parse(vec.size(), &vec[0], _ctx, os); + return D::parse(vec, _ctx, os); } T _ctx; diff --git a/unittests/DriverTests/GnuLdDriverTest.cpp b/unittests/DriverTests/GnuLdDriverTest.cpp index 92eb920f0180..13d20a4411a1 100644 --- a/unittests/DriverTests/GnuLdDriverTest.cpp +++ b/unittests/DriverTests/GnuLdDriverTest.cpp @@ -31,7 +31,7 @@ class LinkerScriptTest : public testing::Test { protected: void SetUp() override { llvm::Triple triple(llvm::sys::getDefaultTargetTriple()); - _ctx = std::move(GnuLdDriver::createELFLinkingContext(triple)); + _ctx = GnuLdDriver::createELFLinkingContext(triple); } void parse(StringRef script, bool nostdlib = false) { @@ -42,7 +42,7 @@ protected: std::error_code ec = GnuLdDriver::evalLinkerScript(*_ctx, std::move(mb), out, nostdlib); EXPECT_FALSE(ec); - }; + } std::unique_ptr<ELFLinkingContext> _ctx; }; @@ -199,6 +199,22 @@ TEST_F(GnuLdParserTest, 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) { @@ -281,4 +297,3 @@ TEST_F(LinkerScriptTest, ExprEval) { EXPECT_EQ(0x14000, result); EXPECT_EQ(0, sa2->symbol().compare(StringRef("."))); } - diff --git a/unittests/DriverTests/Makefile b/unittests/DriverTests/Makefile deleted file mode 100644 index ae97fb01adbf..000000000000 --- a/unittests/DriverTests/Makefile +++ /dev/null @@ -1,20 +0,0 @@ -##===---- unittests/DriverTests/Makefile ----------------*- Makefile -*-===## -# -# The LLVM Compiler Infrastructure -# -# This file is distributed under the University of Illinois Open Source -# License. See LICENSE.TXT for details. -# -##===-------------------------------------------------------------------===## - -LLD_LEVEL = ../.. -TESTNAME = DriverTests -USEDLIBS = lldDriver.a lldConfig.a \ - lldELF.a lldMachO.a lldPECOFF.a \ - lldCore.a lldNative.a lldReaderWriter.a \ - lldHexagonELFTarget.a lldMipsELFTarget.a \ - lldX86ELFTarget.a lldExampleSubTarget.a lldX86_64ELFTarget.a \ - lldYAML.a lldAArch64ELFTarget.a lldARMELFTarget.a \ - LLVMObject.a LLVMMCParser.a LLVMMC.a LLVMBitReader.a \ - LLVMCore.a LLVMOption.a LLVMSupport.a -include $(LLD_LEVEL)/unittests/Makefile diff --git a/unittests/DriverTests/UniversalDriverTest.cpp b/unittests/DriverTests/UniversalDriverTest.cpp index 8e90ca4d5867..0a464d3038c6 100644 --- a/unittests/DriverTests/UniversalDriverTest.cpp +++ b/unittests/DriverTests/UniversalDriverTest.cpp @@ -21,11 +21,11 @@ using namespace llvm; using namespace lld; TEST(UniversalDriver, flavor) { - const char *args[] = { "gnu-ld" }; + const char *args[] = {"ld", "-flavor", "old-gnu"}; std::string diags; raw_string_ostream os(diags); - UniversalDriver::link(array_lengthof(args), args, os); + 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"), diff --git a/unittests/DriverTests/WinLinkDriverTest.cpp b/unittests/DriverTests/WinLinkDriverTest.cpp deleted file mode 100644 index c2bc455aa81f..000000000000 --- a/unittests/DriverTests/WinLinkDriverTest.cpp +++ /dev/null @@ -1,728 +0,0 @@ -//===- 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/PECOFFLinkingContext.h" -#include "llvm/ADT/Optional.h" -#include "llvm/Support/COFF.h" -#include <set> -#include <vector> - -using namespace llvm; -using namespace lld; - -namespace { -class WinLinkParserTest - : public ParserTest<WinLinkDriver, PECOFFLinkingContext> { -protected: - const LinkingContext *linkingContext() override { return &_ctx; } -}; -} - -TEST_F(WinLinkParserTest, Basic) { - EXPECT_TRUE(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, _ctx.getSubsystem()); - EXPECT_EQ(llvm::COFF::IMAGE_FILE_MACHINE_I386, _ctx.getMachineType()); - EXPECT_EQ("a.exe", _ctx.outputPath()); - EXPECT_EQ("start", _ctx.getEntrySymbolName()); - EXPECT_EQ(4, inputFileCount()); - EXPECT_EQ("a.obj", inputFile(0)); - EXPECT_EQ("b.obj", inputFile(1)); - EXPECT_EQ("c.obj", inputFile(2)); - EXPECT_TRUE(_ctx.getInputSearchPaths().empty()); - - // Unspecified flags will have default values. - EXPECT_FALSE(_ctx.isDll()); - EXPECT_EQ(6, _ctx.getMinOSVersion().majorVersion); - EXPECT_EQ(0, _ctx.getMinOSVersion().minorVersion); - EXPECT_EQ(0x400000U, _ctx.getBaseAddress()); - EXPECT_EQ(1024 * 1024U, _ctx.getStackReserve()); - EXPECT_EQ(4096U, _ctx.getStackCommit()); - EXPECT_EQ(4096U, _ctx.getSectionDefaultAlignment()); - EXPECT_FALSE(_ctx.allowRemainingUndefines()); - EXPECT_TRUE(_ctx.isNxCompat()); - EXPECT_FALSE(_ctx.getLargeAddressAware()); - EXPECT_TRUE(_ctx.getAllowBind()); - EXPECT_TRUE(_ctx.getAllowIsolation()); - EXPECT_FALSE(_ctx.getSwapRunFromCD()); - EXPECT_FALSE(_ctx.getSwapRunFromNet()); - EXPECT_TRUE(_ctx.getBaseRelocationEnabled()); - EXPECT_TRUE(_ctx.isTerminalServerAware()); - EXPECT_TRUE(_ctx.getDynamicBaseEnabled()); - EXPECT_TRUE(_ctx.getCreateManifest()); - EXPECT_EQ("", _ctx.getManifestDependency()); - EXPECT_FALSE(_ctx.getEmbedManifest()); - EXPECT_EQ(1, _ctx.getManifestId()); - EXPECT_TRUE(_ctx.getManifestUAC()); - EXPECT_EQ("'asInvoker'", _ctx.getManifestLevel()); - EXPECT_EQ("'false'", _ctx.getManifestUiAccess()); - EXPECT_TRUE(_ctx.deadStrip()); - EXPECT_FALSE(_ctx.logInputFiles()); -} - -TEST_F(WinLinkParserTest, StartsWithHyphen) { - EXPECT_TRUE( - parse("link.exe", "-subsystem:console", "-out:a.exe", "a.obj", nullptr)); - EXPECT_EQ(llvm::COFF::IMAGE_SUBSYSTEM_WINDOWS_CUI, _ctx.getSubsystem()); - EXPECT_EQ("a.exe", _ctx.outputPath()); - EXPECT_EQ(2, inputFileCount()); - EXPECT_EQ("a.obj", inputFile(0)); -} - -TEST_F(WinLinkParserTest, UppercaseOption) { - EXPECT_TRUE( - parse("link.exe", "/SUBSYSTEM:CONSOLE", "/OUT:a.exe", "a.obj", nullptr)); - EXPECT_EQ(llvm::COFF::IMAGE_SUBSYSTEM_WINDOWS_CUI, _ctx.getSubsystem()); - EXPECT_EQ("a.exe", _ctx.outputPath()); - EXPECT_EQ(2, inputFileCount()); - EXPECT_EQ("a.obj", inputFile(0)); -} - -TEST_F(WinLinkParserTest, Mllvm) { - EXPECT_TRUE(parse("link.exe", "/mllvm:-debug", "a.obj", nullptr)); - const std::vector<const char *> &options = _ctx.llvmOptions(); - EXPECT_EQ(1U, options.size()); - EXPECT_STREQ("-debug", options[0]); -} - -TEST_F(WinLinkParserTest, NoInputFiles) { - EXPECT_FALSE(parse("link.exe", nullptr)); - EXPECT_EQ("No input files\n", errorMessage()); -} - -// -// Tests for implicit file extension interpolation. -// - -TEST_F(WinLinkParserTest, NoFileExtension) { - EXPECT_TRUE(parse("link.exe", "foo", "bar", nullptr)); - EXPECT_EQ("foo.exe", _ctx.outputPath()); - EXPECT_EQ(3, inputFileCount()); - EXPECT_EQ("foo.obj", inputFile(0)); - EXPECT_EQ("bar.obj", inputFile(1)); -} - -TEST_F(WinLinkParserTest, NonStandardFileExtension) { - EXPECT_TRUE(parse("link.exe", "foo.o", nullptr)); - EXPECT_EQ("foo.exe", _ctx.outputPath()); - EXPECT_EQ(2, inputFileCount()); - EXPECT_EQ("foo.o", inputFile(0)); -} - -TEST_F(WinLinkParserTest, Libpath) { - EXPECT_TRUE( - parse("link.exe", "/libpath:dir1", "/libpath:dir2", "a.obj", nullptr)); - const std::vector<StringRef> &paths = _ctx.getInputSearchPaths(); - EXPECT_EQ(2U, paths.size()); - EXPECT_EQ("dir1", paths[0]); - EXPECT_EQ("dir2", paths[1]); -} - -// -// Tests for input file order -// - -TEST_F(WinLinkParserTest, InputOrder) { - EXPECT_TRUE(parse("link.exe", "a.lib", "b.obj", "c.obj", "a.lib", "d.obj", - nullptr)); - EXPECT_EQ(5, inputFileCount()); - EXPECT_EQ("b.obj", inputFile(0)); - EXPECT_EQ("c.obj", inputFile(1)); - EXPECT_EQ("d.obj", inputFile(2)); - EXPECT_EQ("a.lib", inputFile(3)); -} - -// -// Tests for command line options that take values. -// - -TEST_F(WinLinkParserTest, AlternateName) { - EXPECT_TRUE(parse("link.exe", "/alternatename:sym1=sym", - "/alternatename:sym2=sym", "a.out", nullptr)); - const std::set<std::string> &aliases = _ctx.getAlternateNames("sym"); - EXPECT_EQ(2U, aliases.size()); - auto it = aliases.begin(); - EXPECT_EQ("sym1", *it++); - EXPECT_EQ("sym2", *it++); -} - -TEST_F(WinLinkParserTest, Export) { - EXPECT_TRUE(parse("link.exe", "/export:foo", "a.out", nullptr)); - const std::vector<PECOFFLinkingContext::ExportDesc> &exports = - _ctx.getDllExports(); - EXPECT_EQ(1U, exports.size()); - EXPECT_EQ("_foo", exports[0].name); - EXPECT_EQ(-1, exports[0].ordinal); - EXPECT_FALSE(exports[0].noname); - EXPECT_FALSE(exports[0].isData); -} - -TEST_F(WinLinkParserTest, ExportWithOptions) { - EXPECT_TRUE(parse("link.exe", "/export:foo,@8,noname,data", - "/export:bar,@10,data", "a.out", nullptr)); - const std::vector<PECOFFLinkingContext::ExportDesc> &exports = - _ctx.getDllExports(); - EXPECT_EQ(2U, exports.size()); - EXPECT_EQ("_foo", exports[0].name); - EXPECT_EQ(8, exports[0].ordinal); - EXPECT_TRUE(exports[0].noname); - EXPECT_TRUE(exports[0].isData); - EXPECT_EQ("_bar", exports[1].name); - EXPECT_EQ(10, exports[1].ordinal); - EXPECT_FALSE(exports[1].noname); - EXPECT_TRUE(exports[1].isData); -} - -TEST_F(WinLinkParserTest, ExportDuplicateExports) { - EXPECT_TRUE( - parse("link.exe", "/export:foo", "/export:foo,@2", "a.out", nullptr)); - const std::vector<PECOFFLinkingContext::ExportDesc> &exports = - _ctx.getDllExports(); - EXPECT_EQ(1U, exports.size()); - EXPECT_EQ("_foo", exports[0].name); - EXPECT_EQ(-1, exports[0].ordinal); -} - -TEST_F(WinLinkParserTest, ExportDuplicateOrdinals) { - EXPECT_FALSE( - parse("link.exe", "/export:foo,@1", "/export:bar,@1", "a.out", nullptr)); -} - -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)); -} - -TEST_F(WinLinkParserTest, MachineX86) { - EXPECT_TRUE(parse("link.exe", "/machine:x86", "a.obj", nullptr)); - EXPECT_EQ(llvm::COFF::IMAGE_FILE_MACHINE_I386, _ctx.getMachineType()); -} - -TEST_F(WinLinkParserTest, MachineX64) { - EXPECT_TRUE(parse("link.exe", "/machine:x64", "a.obj", nullptr)); - EXPECT_EQ(llvm::COFF::IMAGE_FILE_MACHINE_AMD64, _ctx.getMachineType()); -} - -TEST_F(WinLinkParserTest, MachineArm) { - EXPECT_TRUE(parse("link.exe", "/machine:arm", "a.obj", nullptr)); - EXPECT_EQ(llvm::COFF::IMAGE_FILE_MACHINE_ARMNT, _ctx.getMachineType()); -} - -TEST_F(WinLinkParserTest, MachineUnknown) { - EXPECT_FALSE(parse("link.exe", "/machine:nosucharch", "a.obj", nullptr)); - EXPECT_EQ("error: unknown machine type: nosucharch\n", errorMessage()); -} - -TEST_F(WinLinkParserTest, MajorImageVersion) { - EXPECT_TRUE(parse("link.exe", "/version:7", "foo.o", nullptr)); - EXPECT_EQ(7, _ctx.getImageVersion().majorVersion); - EXPECT_EQ(0, _ctx.getImageVersion().minorVersion); -} - -TEST_F(WinLinkParserTest, MajorMinorImageVersion) { - EXPECT_TRUE(parse("link.exe", "/version:72.35", "foo.o", nullptr)); - EXPECT_EQ(72, _ctx.getImageVersion().majorVersion); - EXPECT_EQ(35, _ctx.getImageVersion().minorVersion); -} - -TEST_F(WinLinkParserTest, MinMajorOSVersion) { - EXPECT_TRUE(parse("link.exe", "/subsystem:windows,3", "foo.o", nullptr)); - EXPECT_EQ(llvm::COFF::IMAGE_SUBSYSTEM_WINDOWS_GUI, _ctx.getSubsystem()); - EXPECT_EQ(3, _ctx.getMinOSVersion().majorVersion); - EXPECT_EQ(0, _ctx.getMinOSVersion().minorVersion); -} - -TEST_F(WinLinkParserTest, MinMajorMinorOSVersion) { - EXPECT_TRUE(parse("link.exe", "/subsystem:windows,3.1", "foo.o", nullptr)); - EXPECT_EQ(llvm::COFF::IMAGE_SUBSYSTEM_WINDOWS_GUI, _ctx.getSubsystem()); - EXPECT_EQ(3, _ctx.getMinOSVersion().majorVersion); - EXPECT_EQ(1, _ctx.getMinOSVersion().minorVersion); -} - -TEST_F(WinLinkParserTest, Base) { - EXPECT_TRUE(parse("link.exe", "/base:8388608", "a.obj", nullptr)); - EXPECT_EQ(0x800000U, _ctx.getBaseAddress()); -} - -TEST_F(WinLinkParserTest, InvalidBase) { - EXPECT_FALSE(parse("link.exe", "/base:1234", "a.obj", nullptr)); - EXPECT_TRUE(StringRef(errorMessage()) - .startswith("Base address have to be multiple of 64K")); -} - -TEST_F(WinLinkParserTest, StackReserve) { - EXPECT_TRUE(parse("link.exe", "/stack:8192", "a.obj", nullptr)); - EXPECT_EQ(8192U, _ctx.getStackReserve()); - EXPECT_EQ(4096U, _ctx.getStackCommit()); -} - -TEST_F(WinLinkParserTest, StackReserveAndCommit) { - EXPECT_TRUE(parse("link.exe", "/stack:16384,8192", "a.obj", nullptr)); - EXPECT_EQ(16384U, _ctx.getStackReserve()); - EXPECT_EQ(8192U, _ctx.getStackCommit()); -} - -TEST_F(WinLinkParserTest, InvalidStackSize) { - EXPECT_FALSE(parse("link.exe", "/stack:8192,16384", "a.obj", nullptr)); - EXPECT_TRUE(StringRef(errorMessage()).startswith("Invalid stack size")); -} - -TEST_F(WinLinkParserTest, HeapReserve) { - EXPECT_TRUE(parse("link.exe", "/heap:8192", "a.obj", nullptr)); - EXPECT_EQ(8192U, _ctx.getHeapReserve()); - EXPECT_EQ(4096U, _ctx.getHeapCommit()); -} - -TEST_F(WinLinkParserTest, HeapReserveAndCommit) { - EXPECT_TRUE(parse("link.exe", "/heap:16384,8192", "a.obj", nullptr)); - EXPECT_EQ(16384U, _ctx.getHeapReserve()); - EXPECT_EQ(8192U, _ctx.getHeapCommit()); -} - -TEST_F(WinLinkParserTest, InvalidHeapSize) { - EXPECT_FALSE(parse("link.exe", "/heap:8192,16384", "a.obj", nullptr)); - EXPECT_TRUE(StringRef(errorMessage()).startswith("Invalid heap size")); -} - -TEST_F(WinLinkParserTest, SectionAlignment) { - EXPECT_TRUE(parse("link.exe", "/align:8192", "a.obj", nullptr)); - EXPECT_EQ(8192U, _ctx.getSectionDefaultAlignment()); -} - -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 = _ctx.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)); - EXPECT_EQ(".baz", _ctx.getOutputSectionName(".foo")); - EXPECT_EQ(".baz", _ctx.getOutputSectionName(".bar")); - EXPECT_EQ(".abc", _ctx.getOutputSectionName(".abc")); -} - -TEST_F(WinLinkParserTest, Merge_Circular) { - EXPECT_FALSE(parse("link.exe", "/merge:.foo=.bar", "/merge:.bar=.foo", - "a.out", nullptr)); -} - -TEST_F(WinLinkParserTest, Implib) { - EXPECT_TRUE(parse("link.exe", "/implib:foo.dll.lib", "a.out", nullptr)); - EXPECT_EQ("foo.dll.lib", _ctx.getOutputImportLibraryPath()); -} - -TEST_F(WinLinkParserTest, ImplibDefault) { - EXPECT_TRUE(parse("link.exe", "/out:foobar.dll", "a.out", nullptr)); - EXPECT_EQ("foobar.lib", _ctx.getOutputImportLibraryPath()); -} - -// -// Tests for /section -// - -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; - -#define TEST_SECTION(testname, arg, expect) \ - TEST_F(WinLinkParserTest, testname) { \ - EXPECT_TRUE(parse("link.exe", "/section:.text," arg, "a.obj", nullptr)); \ - EXPECT_EQ(expect, _ctx.getSectionAttributes(".text", execute | read)); \ - } - -TEST_SECTION(SectionD, "d", execute | read | discardable) -TEST_SECTION(SectionE, "e", execute) -TEST_SECTION(SectionK, "k", execute | read | not_cached) -TEST_SECTION(SectionP, "p", execute | read | not_paged) -TEST_SECTION(SectionR, "r", read) -TEST_SECTION(SectionS, "s", execute | read | shared) -TEST_SECTION(SectionW, "w", write) - -#undef TEST_SECTION - -TEST_F(WinLinkParserTest, Section) { - EXPECT_TRUE(parse("link.exe", "/section:.text,dekprsw", - "/section:.text,!dekprsw", "a.obj", nullptr)); - EXPECT_EQ(0U, _ctx.getSectionAttributes(".text", execute | read)); -} - -TEST_F(WinLinkParserTest, SectionNegate) { - EXPECT_TRUE(parse("link.exe", "/section:.text,!e", "a.obj", nullptr)); - EXPECT_EQ(read, _ctx.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, _ctx.getSectionAttributes(".foo", flags)); -} - -} // end anonymous namespace - -// -// Tests for /defaultlib and /nodefaultlib. -// - -TEST_F(WinLinkParserTest, DefaultLib) { - EXPECT_TRUE(parse("link.exe", "/defaultlib:user32.lib", - "/defaultlib:kernel32", "a.obj", nullptr)); - EXPECT_EQ(4, inputFileCount()); - EXPECT_EQ("a.obj", inputFile(0)); - EXPECT_EQ("user32.lib", inputFile(1)); - EXPECT_EQ("kernel32.lib", inputFile(2)); -} - -TEST_F(WinLinkParserTest, DefaultLibDuplicates) { - EXPECT_TRUE(parse("link.exe", "/defaultlib:user32.lib", - "/defaultlib:user32.lib", "a.obj", nullptr)); - EXPECT_EQ(3, inputFileCount()); - EXPECT_EQ("a.obj", inputFile(0)); - EXPECT_EQ("user32.lib", inputFile(1)); -} - -TEST_F(WinLinkParserTest, NoDefaultLib) { - EXPECT_TRUE(parse("link.exe", "/defaultlib:user32.lib", - "/defaultlib:kernel32", "/nodefaultlib:user32.lib", "a.obj", - nullptr)); - EXPECT_EQ(3, inputFileCount()); - EXPECT_EQ("a.obj", inputFile(0)); - EXPECT_EQ("kernel32.lib", inputFile(1)); -} - -TEST_F(WinLinkParserTest, NoDefaultLibCase) { - EXPECT_TRUE(parse("link.exe", "/defaultlib:user32", - "/defaultlib:kernel32", "/nodefaultlib:USER32.LIB", "a.obj", - nullptr)); - EXPECT_EQ(3, inputFileCount()); - EXPECT_EQ("a.obj", inputFile(0)); - EXPECT_EQ("kernel32.lib", inputFile(1)); -} - -TEST_F(WinLinkParserTest, NoDefaultLibAll) { - EXPECT_TRUE(parse("link.exe", "/defaultlib:user32.lib", - "/defaultlib:kernel32", "/nodefaultlib", "a.obj", nullptr)); - EXPECT_EQ(2, inputFileCount()); - EXPECT_EQ("a.obj", inputFile(0)); -} - -TEST_F(WinLinkParserTest, DisallowLib) { - EXPECT_TRUE(parse("link.exe", "/defaultlib:user32.lib", - "/defaultlib:kernel32", "/disallowlib:user32.lib", "a.obj", - nullptr)); - EXPECT_EQ(3, inputFileCount()); - EXPECT_EQ("a.obj", inputFile(0)); - EXPECT_EQ("kernel32.lib", inputFile(1)); -} - -// -// Tests for DLL. -// - -TEST_F(WinLinkParserTest, NoEntry) { - EXPECT_TRUE(parse("link.exe", "/noentry", "/dll", "a.obj", nullptr)); - EXPECT_TRUE(_ctx.isDll()); - EXPECT_EQ(0x10000000U, _ctx.getBaseAddress()); - EXPECT_EQ("", _ctx.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()); -} - -// -// Tests for DELAYLOAD. -// - -TEST_F(WinLinkParserTest, DelayLoad) { - EXPECT_TRUE(parse("link.exe", "/delayload:abc.dll", "/delayload:def.dll", - "a.obj", nullptr)); - EXPECT_TRUE(_ctx.isDelayLoadDLL("abc.dll")); - EXPECT_TRUE(_ctx.isDelayLoadDLL("DEF.DLL")); - EXPECT_FALSE(_ctx.isDelayLoadDLL("xyz.dll")); -} - -// -// Tests for SEH. -// - -TEST_F(WinLinkParserTest, SafeSEH) { - EXPECT_TRUE(parse("link.exe", "/safeseh", "a.obj", nullptr)); - EXPECT_TRUE(_ctx.requireSEH()); - EXPECT_FALSE(_ctx.noSEH()); -} - -TEST_F(WinLinkParserTest, NoSafeSEH) { - EXPECT_TRUE(parse("link.exe", "/safeseh:no", "a.obj", nullptr)); - EXPECT_FALSE(_ctx.requireSEH()); - EXPECT_TRUE(_ctx.noSEH()); -} - -// -// Tests for boolean flags. -// - -TEST_F(WinLinkParserTest, Force) { - EXPECT_TRUE(parse("link.exe", "/force", "a.obj", nullptr)); - EXPECT_TRUE(_ctx.allowRemainingUndefines()); -} - -TEST_F(WinLinkParserTest, ForceUnresolved) { - EXPECT_TRUE(parse("link.exe", "/force:unresolved", "a.obj", nullptr)); - EXPECT_TRUE(_ctx.allowRemainingUndefines()); -} - -TEST_F(WinLinkParserTest, NoNxCompat) { - EXPECT_TRUE(parse("link.exe", "/nxcompat:no", "a.obj", nullptr)); - EXPECT_FALSE(_ctx.isNxCompat()); -} - -TEST_F(WinLinkParserTest, LargeAddressAware) { - EXPECT_TRUE(parse("link.exe", "/largeaddressaware", "a.obj", nullptr)); - EXPECT_TRUE(_ctx.getLargeAddressAware()); -} - -TEST_F(WinLinkParserTest, NoLargeAddressAware) { - EXPECT_TRUE(parse("link.exe", "/largeaddressaware:no", "a.obj", nullptr)); - EXPECT_FALSE(_ctx.getLargeAddressAware()); -} - -TEST_F(WinLinkParserTest, AllowBind) { - EXPECT_TRUE(parse("link.exe", "/allowbind", "a.obj", nullptr)); - EXPECT_TRUE(_ctx.getAllowBind()); -} - -TEST_F(WinLinkParserTest, NoAllowBind) { - EXPECT_TRUE(parse("link.exe", "/allowbind:no", "a.obj", nullptr)); - EXPECT_FALSE(_ctx.getAllowBind()); -} - -TEST_F(WinLinkParserTest, AllowIsolation) { - EXPECT_TRUE(parse("link.exe", "/allowisolation", "a.obj", nullptr)); - EXPECT_TRUE(_ctx.getAllowIsolation()); -} - -TEST_F(WinLinkParserTest, NoAllowIsolation) { - EXPECT_TRUE(parse("link.exe", "/allowisolation:no", "a.obj", nullptr)); - EXPECT_FALSE(_ctx.getAllowIsolation()); -} - -TEST_F(WinLinkParserTest, SwapRunFromCD) { - EXPECT_TRUE(parse("link.exe", "/swaprun:cd", "a.obj", nullptr)); - EXPECT_TRUE(_ctx.getSwapRunFromCD()); -} - -TEST_F(WinLinkParserTest, SwapRunFromNet) { - EXPECT_TRUE(parse("link.exe", "/swaprun:net", "a.obj", nullptr)); - EXPECT_TRUE(_ctx.getSwapRunFromNet()); -} - -TEST_F(WinLinkParserTest, Debug) { - EXPECT_TRUE(parse("link.exe", "/debug", "a.obj", nullptr)); - EXPECT_TRUE(_ctx.deadStrip()); - EXPECT_TRUE(_ctx.getDebug()); - EXPECT_EQ("a.pdb", _ctx.getPDBFilePath()); -} - -TEST_F(WinLinkParserTest, PDB) { - EXPECT_TRUE(parse("link.exe", "/debug", "/pdb:foo.pdb", "a.obj", nullptr)); - EXPECT_TRUE(_ctx.getDebug()); - EXPECT_EQ("foo.pdb", _ctx.getPDBFilePath()); -} - -TEST_F(WinLinkParserTest, Fixed) { - EXPECT_TRUE(parse("link.exe", "/fixed", "a.out", nullptr)); - EXPECT_FALSE(_ctx.getBaseRelocationEnabled()); - EXPECT_FALSE(_ctx.getDynamicBaseEnabled()); -} - -TEST_F(WinLinkParserTest, NoFixed) { - EXPECT_TRUE(parse("link.exe", "/fixed:no", "a.out", nullptr)); - EXPECT_TRUE(_ctx.getBaseRelocationEnabled()); -} - -TEST_F(WinLinkParserTest, TerminalServerAware) { - EXPECT_TRUE(parse("link.exe", "/tsaware", "a.out", nullptr)); - EXPECT_TRUE(_ctx.isTerminalServerAware()); -} - -TEST_F(WinLinkParserTest, NoTerminalServerAware) { - EXPECT_TRUE(parse("link.exe", "/tsaware:no", "a.out", nullptr)); - EXPECT_FALSE(_ctx.isTerminalServerAware()); -} - -TEST_F(WinLinkParserTest, DynamicBase) { - EXPECT_TRUE(parse("link.exe", "/dynamicbase", "a.out", nullptr)); - EXPECT_TRUE(_ctx.getDynamicBaseEnabled()); -} - -TEST_F(WinLinkParserTest, NoDynamicBase) { - EXPECT_TRUE(parse("link.exe", "/dynamicbase:no", "a.out", nullptr)); - EXPECT_FALSE(_ctx.getDynamicBaseEnabled()); -} - -// -// Test for /failifmismatch -// - -TEST_F(WinLinkParserTest, FailIfMismatch_Match) { - EXPECT_TRUE(parse("link.exe", "/failifmismatch:foo=bar", - "/failifmismatch:foo=bar", "/failifmismatch:abc=def", - "a.out", nullptr)); -} - -TEST_F(WinLinkParserTest, FailIfMismatch_Mismatch) { - EXPECT_FALSE(parse("link.exe", "/failifmismatch:foo=bar", - "/failifmismatch:foo=baz", "a.out", nullptr)); -} - -// -// Tests for /manifest, /manifestuac, /manifestfile, and /manifestdependency. -// -TEST_F(WinLinkParserTest, Manifest_Default) { - EXPECT_TRUE(parse("link.exe", "/manifest", "a.out", nullptr)); - EXPECT_TRUE(_ctx.getCreateManifest()); - EXPECT_FALSE(_ctx.getEmbedManifest()); - EXPECT_EQ(1, _ctx.getManifestId()); - EXPECT_EQ("'asInvoker'", _ctx.getManifestLevel()); - EXPECT_EQ("'false'", _ctx.getManifestUiAccess()); -} - -TEST_F(WinLinkParserTest, Manifest_No) { - EXPECT_TRUE(parse("link.exe", "/manifest:no", "a.out", nullptr)); - EXPECT_FALSE(_ctx.getCreateManifest()); -} - -TEST_F(WinLinkParserTest, Manifestuac_no) { - EXPECT_TRUE(parse("link.exe", "/manifestuac:NO", "a.out", nullptr)); - EXPECT_FALSE(_ctx.getManifestUAC()); -} - -TEST_F(WinLinkParserTest, Manifestuac_Level) { - EXPECT_TRUE(parse("link.exe", "/manifestuac:level='requireAdministrator'", - "a.out", nullptr)); - EXPECT_EQ("'requireAdministrator'", _ctx.getManifestLevel()); - EXPECT_EQ("'false'", _ctx.getManifestUiAccess()); -} - -TEST_F(WinLinkParserTest, Manifestuac_UiAccess) { - EXPECT_TRUE(parse("link.exe", "/manifestuac:uiAccess='true'", "a.out", nullptr)); - EXPECT_EQ("'asInvoker'", _ctx.getManifestLevel()); - EXPECT_EQ("'true'", _ctx.getManifestUiAccess()); -} - -TEST_F(WinLinkParserTest, Manifestuac_LevelAndUiAccess) { - EXPECT_TRUE(parse("link.exe", - "/manifestuac:level='requireAdministrator' uiAccess='true'", - "a.out", nullptr)); - EXPECT_EQ("'requireAdministrator'", _ctx.getManifestLevel()); - EXPECT_EQ("'true'", _ctx.getManifestUiAccess()); -} - -TEST_F(WinLinkParserTest, Manifestfile) { - EXPECT_TRUE(parse("link.exe", "/manifestfile:bar.manifest", - "a.out", nullptr)); - EXPECT_EQ("bar.manifest", _ctx.getManifestOutputPath()); -} - -TEST_F(WinLinkParserTest, Manifestdependency) { - EXPECT_TRUE(parse("link.exe", "/manifestdependency:foo bar", "a.out", - nullptr)); - EXPECT_EQ("foo bar", _ctx.getManifestDependency()); -} - -// -// Test for /OPT -// - -TEST_F(WinLinkParserTest, OptNoRef) { - EXPECT_TRUE(parse("link.exe", "/opt:noref", "a.obj", nullptr)); - EXPECT_FALSE(_ctx.deadStrip()); -} - -TEST_F(WinLinkParserTest, OptIgnore) { - EXPECT_TRUE(parse("link.exe", "/opt:ref", "/opt:icf", "/opt:noicf", - "/opt:icf=foo", "/opt:lbr", "/opt:nolbr", "a.obj", - nullptr)); -} - -TEST_F(WinLinkParserTest, OptUnknown) { - EXPECT_FALSE(parse("link.exe", "/opt:foo", "a.obj", nullptr)); -} - -// -// Test for /PROFILE -// - -TEST_F(WinLinkParserTest, Profile) { - EXPECT_TRUE(parse("link.exe", "/profile", "a.obj", nullptr)); - EXPECT_TRUE(_ctx.deadStrip()); - EXPECT_TRUE(_ctx.getBaseRelocationEnabled()); - EXPECT_TRUE(_ctx.getDynamicBaseEnabled()); -} - -// -// Test for command line flags that are ignored. -// - -TEST_F(WinLinkParserTest, Ignore) { - // There are some no-op command line options that are recognized for - // compatibility with link.exe. - EXPECT_TRUE(parse("link.exe", "/nologo", "/errorreport:prompt", - "/incremental", "/incremental:no", "/delay:unload", - "/disallowlib:foo", "/pdbaltpath:bar", - "/wx", "/wx:no", "/tlbid:1", "/tlbout:foo", "/idlout:foo", - "/ignore:4000", "/ignoreidl", "/implib:foo", "/safeseh", - "/safeseh:no", "/functionpadmin", "/maxilksize:1024", - "a.obj", nullptr)); - EXPECT_EQ("", errorMessage()); - EXPECT_EQ(2, inputFileCount()); - EXPECT_EQ("a.obj", inputFile(0)); -} - -// -// Test for "--" -// - -TEST_F(WinLinkParserTest, DashDash) { - EXPECT_TRUE(parse("link.exe", "/subsystem:console", "/out:a.exe", "a.obj", - "--", "b.obj", "-c.obj", nullptr)); - EXPECT_EQ(llvm::COFF::IMAGE_SUBSYSTEM_WINDOWS_CUI, _ctx.getSubsystem()); - EXPECT_EQ("a.exe", _ctx.outputPath()); - EXPECT_EQ(4, inputFileCount()); - EXPECT_EQ("a.obj", inputFile(0)); - EXPECT_EQ("b.obj", inputFile(1)); - EXPECT_EQ("-c.obj", inputFile(2)); -} diff --git a/unittests/DriverTests/WinLinkModuleDefTest.cpp b/unittests/DriverTests/WinLinkModuleDefTest.cpp deleted file mode 100644 index 6762fd4b2ea6..000000000000 --- a/unittests/DriverTests/WinLinkModuleDefTest.cpp +++ /dev/null @@ -1,155 +0,0 @@ -//===- lld/unittest/WinLinkModuleDefTest.cpp ------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#include "gtest/gtest.h" -#include "lld/Driver/WinLinkModuleDef.h" -#include "llvm/Support/MemoryBuffer.h" -#include <memory> - -using namespace llvm; -using namespace lld; - -class ParserTest : public testing::Test { -protected: - std::vector<moduledef::Directive *> _dirs; - - void parse(const char *contents) { - auto membuf = - std::unique_ptr<MemoryBuffer>(MemoryBuffer::getMemBuffer(contents)); - moduledef::Lexer lexer(std::move(membuf)); - moduledef::Parser parser(lexer, _alloc); - EXPECT_TRUE(parser.parse(_dirs)); - EXPECT_TRUE(!_dirs.empty()); - } - - void verifyExportDesc(const PECOFFLinkingContext::ExportDesc &exp, - StringRef sym, int ordinal, bool noname, bool isData) { - EXPECT_EQ(sym, exp.name); - EXPECT_EQ(ordinal, exp.ordinal); - EXPECT_EQ(noname, exp.noname); - EXPECT_EQ(isData, exp.isData); - } - -private: - llvm::BumpPtrAllocator _alloc; -}; - -TEST_F(ParserTest, Exports) { - parse("EXPORTS\n" - " sym1\n" - " sym2 @5\n" - " sym3 @8 NONAME\n" - " sym4 DATA\n" - " sym5 @10 NONAME DATA\n"); - EXPECT_EQ(1U, _dirs.size()); - const std::vector<PECOFFLinkingContext::ExportDesc> &exports = - cast<moduledef::Exports>(_dirs[0])->getExports(); - EXPECT_EQ(5U, exports.size()); - verifyExportDesc(exports[0], "sym1", -1, false, false); - verifyExportDesc(exports[1], "sym2", 5, false, false); - verifyExportDesc(exports[2], "sym3", 8, true, false); - verifyExportDesc(exports[3], "sym4", -1, false, true); - verifyExportDesc(exports[4], "sym5", 10, true, true); -} - -TEST_F(ParserTest, Heapsize) { - parse("HEAPSIZE 65536"); - EXPECT_EQ(1U, _dirs.size()); - auto *heapsize = cast<moduledef::Heapsize>(_dirs[0]); - EXPECT_EQ(65536U, heapsize->getReserve()); - EXPECT_EQ(0U, heapsize->getCommit()); -} - -TEST_F(ParserTest, HeapsizeWithCommit) { - parse("HEAPSIZE 65536, 8192"); - EXPECT_EQ(1U, _dirs.size()); - auto *heapsize = cast<moduledef::Heapsize>(_dirs[0]); - EXPECT_EQ(65536U, heapsize->getReserve()); - EXPECT_EQ(8192U, heapsize->getCommit()); -} - -TEST_F(ParserTest, StacksizeBasic) { - parse("STACKSIZE 65536"); - EXPECT_EQ(1U, _dirs.size()); - auto *stacksize = cast<moduledef::Stacksize>(_dirs[0]); - EXPECT_EQ(65536U, stacksize->getReserve()); - EXPECT_EQ(0U, stacksize->getCommit()); -} - -TEST_F(ParserTest, StacksizeWithCommit) { - parse("STACKSIZE 65536, 8192"); - EXPECT_EQ(1U, _dirs.size()); - auto *stacksize = cast<moduledef::Stacksize>(_dirs[0]); - EXPECT_EQ(65536U, stacksize->getReserve()); - EXPECT_EQ(8192U, stacksize->getCommit()); -} - -TEST_F(ParserTest, Library) { - parse("LIBRARY foo.dll"); - EXPECT_EQ(1U, _dirs.size()); - auto *lib = cast<moduledef::Library>(_dirs[0]); - EXPECT_EQ("foo.dll", lib->getName()); -} - -TEST_F(ParserTest, NameBasic) { - parse("NAME foo.exe"); - EXPECT_EQ(1U, _dirs.size()); - auto *name = cast<moduledef::Name>(_dirs[0]); - EXPECT_EQ("foo.exe", name->getOutputPath()); - EXPECT_EQ(0U, name->getBaseAddress()); -} - -TEST_F(ParserTest, NameWithBase) { - parse("NAME foo.exe BASE=4096"); - EXPECT_EQ(1U, _dirs.size()); - auto *name = cast<moduledef::Name>(_dirs[0]); - EXPECT_EQ("foo.exe", name->getOutputPath()); - EXPECT_EQ(4096U, name->getBaseAddress()); -} - -TEST_F(ParserTest, NameLongFileName) { - parse("NAME \"a long file name.exe\""); - EXPECT_EQ(1U, _dirs.size()); - auto *name = cast<moduledef::Name>(_dirs[0]); - EXPECT_EQ("a long file name.exe", name->getOutputPath()); - EXPECT_EQ(0U, name->getBaseAddress()); -} - -TEST_F(ParserTest, VersionMajor) { - parse("VERSION 12"); - EXPECT_EQ(1U, _dirs.size()); - auto *ver = cast<moduledef::Version>(_dirs[0]); - EXPECT_EQ(12, ver->getMajorVersion()); - EXPECT_EQ(0, ver->getMinorVersion()); -} - -TEST_F(ParserTest, VersionMajorMinor) { - parse("VERSION 12.34"); - EXPECT_EQ(1U, _dirs.size()); - auto *ver = cast<moduledef::Version>(_dirs[0]); - EXPECT_EQ(12, ver->getMajorVersion()); - EXPECT_EQ(34, ver->getMinorVersion()); -} - -TEST_F(ParserTest, Multiple) { - parse("LIBRARY foo\n" - "EXPORTS sym\n" - "VERSION 12"); - EXPECT_EQ(3U, _dirs.size()); - auto *lib = cast<moduledef::Library>(_dirs[0]); - EXPECT_EQ("foo.dll", lib->getName()); - - const std::vector<PECOFFLinkingContext::ExportDesc> &exports = - cast<moduledef::Exports>(_dirs[1])->getExports(); - EXPECT_EQ(1U, exports.size()); - verifyExportDesc(exports[0], "sym", -1, false, false); - - auto *ver = cast<moduledef::Version>(_dirs[2]); - EXPECT_EQ(12, ver->getMajorVersion()); -} diff --git a/unittests/MachOTests/MachONormalizedFileBinaryReaderTests.cpp b/unittests/MachOTests/MachONormalizedFileBinaryReaderTests.cpp index 22ed3f15b3e6..6827a732fbd8 100644 --- a/unittests/MachOTests/MachONormalizedFileBinaryReaderTests.cpp +++ b/unittests/MachOTests/MachONormalizedFileBinaryReaderTests.cpp @@ -273,7 +273,7 @@ TEST(BinaryReaderTest, hello_obj_x86_64) { EXPECT_EQ(text.type, S_REGULAR); EXPECT_EQ(text.attributes,SectionAttr(S_ATTR_PURE_INSTRUCTIONS | S_ATTR_SOME_INSTRUCTIONS)); - EXPECT_EQ(text.alignment, 4U); + EXPECT_EQ((uint16_t)text.alignment, 16U); EXPECT_EQ(text.address, Hex64(0x0)); EXPECT_EQ(text.content.size(), 45UL); EXPECT_EQ((int)(text.content[0]), 0x55); @@ -298,7 +298,7 @@ TEST(BinaryReaderTest, hello_obj_x86_64) { EXPECT_TRUE(cstring.sectionName.equals("__cstring")); EXPECT_EQ(cstring.type, S_CSTRING_LITERALS); EXPECT_EQ(cstring.attributes, SectionAttr(0)); - EXPECT_EQ(cstring.alignment, 0U); + EXPECT_EQ((uint16_t)cstring.alignment, 1U); EXPECT_EQ(cstring.address, Hex64(0x02D)); EXPECT_EQ(cstring.content.size(), 7UL); EXPECT_EQ((int)(cstring.content[0]), 0x68); @@ -399,7 +399,7 @@ TEST(BinaryReaderTest, hello_obj_x86) { EXPECT_EQ(text.type, S_REGULAR); EXPECT_EQ(text.attributes,SectionAttr(S_ATTR_PURE_INSTRUCTIONS | S_ATTR_SOME_INSTRUCTIONS)); - EXPECT_EQ(text.alignment, 4U); + EXPECT_EQ((uint16_t)text.alignment, 16U); EXPECT_EQ(text.address, Hex64(0x0)); EXPECT_EQ(text.content.size(), 48UL); EXPECT_EQ((int)(text.content[0]), 0x55); @@ -434,7 +434,7 @@ TEST(BinaryReaderTest, hello_obj_x86) { EXPECT_TRUE(cstring.sectionName.equals("__cstring")); EXPECT_EQ(cstring.type, S_CSTRING_LITERALS); EXPECT_EQ(cstring.attributes, SectionAttr(0)); - EXPECT_EQ(cstring.alignment, 0U); + EXPECT_EQ((uint16_t)cstring.alignment, 1U); EXPECT_EQ(cstring.address, Hex64(0x030)); EXPECT_EQ(cstring.content.size(), 7UL); EXPECT_EQ((int)(cstring.content[0]), 0x68); @@ -532,7 +532,7 @@ TEST(BinaryReaderTest, hello_obj_armv7) { EXPECT_EQ(text.type, S_REGULAR); EXPECT_EQ(text.attributes,SectionAttr(S_ATTR_PURE_INSTRUCTIONS | S_ATTR_SOME_INSTRUCTIONS)); - EXPECT_EQ(text.alignment, 2U); + EXPECT_EQ((uint16_t)text.alignment, 4U); EXPECT_EQ(text.address, Hex64(0x0)); EXPECT_EQ(text.content.size(), 42UL); EXPECT_EQ((int)(text.content[0]), 0x80); @@ -576,7 +576,7 @@ TEST(BinaryReaderTest, hello_obj_armv7) { EXPECT_TRUE(cstring.sectionName.equals("__cstring")); EXPECT_EQ(cstring.type, S_CSTRING_LITERALS); EXPECT_EQ(cstring.attributes, SectionAttr(0)); - EXPECT_EQ(cstring.alignment, 0U); + EXPECT_EQ((uint16_t)cstring.alignment, 1U); EXPECT_EQ(cstring.address, Hex64(0x02A)); EXPECT_EQ(cstring.content.size(), 7UL); EXPECT_EQ((int)(cstring.content[0]), 0x68); @@ -677,7 +677,7 @@ TEST(BinaryReaderTest, hello_obj_ppc) { EXPECT_EQ(text.type, S_REGULAR); EXPECT_EQ(text.attributes,SectionAttr(S_ATTR_PURE_INSTRUCTIONS | S_ATTR_SOME_INSTRUCTIONS)); - EXPECT_EQ(text.alignment, 2U); + EXPECT_EQ((uint16_t)text.alignment, 4U); EXPECT_EQ(text.address, Hex64(0x0)); EXPECT_EQ(text.content.size(), 68UL); EXPECT_EQ((int)(text.content[0]), 0x7C); @@ -720,7 +720,7 @@ TEST(BinaryReaderTest, hello_obj_ppc) { EXPECT_TRUE(cstring.sectionName.equals("__cstring")); EXPECT_EQ(cstring.type, S_CSTRING_LITERALS); EXPECT_EQ(cstring.attributes, SectionAttr(0)); - EXPECT_EQ(cstring.alignment, 2U); + EXPECT_EQ((uint16_t)cstring.alignment, 4U); EXPECT_EQ(cstring.address, Hex64(0x044)); EXPECT_EQ(cstring.content.size(), 7UL); EXPECT_EQ((int)(cstring.content[0]), 0x68); diff --git a/unittests/MachOTests/MachONormalizedFileBinaryWriterTests.cpp b/unittests/MachOTests/MachONormalizedFileBinaryWriterTests.cpp index d79c6d62a847..87c527233cb1 100644 --- a/unittests/MachOTests/MachONormalizedFileBinaryWriterTests.cpp +++ b/unittests/MachOTests/MachONormalizedFileBinaryWriterTests.cpp @@ -123,7 +123,7 @@ TEST(BinaryWriterTest, obj_relocs_x86_64) { text.type = S_REGULAR; text.attributes = SectionAttr(S_ATTR_PURE_INSTRUCTIONS | S_ATTR_SOME_INSTRUCTIONS); - text.alignment = 4; + text.alignment = 16; text.address = 0; const uint8_t textBytes[] = { 0xe8, 0x00, 0x00, 0x00, 0x00, 0x48, 0x8b, 0x05, @@ -179,7 +179,7 @@ TEST(BinaryWriterTest, obj_relocs_x86_64) { EXPECT_EQ(S_REGULAR, text.type); EXPECT_EQ(text.attributes,SectionAttr(S_ATTR_PURE_INSTRUCTIONS | S_ATTR_SOME_INSTRUCTIONS)); - EXPECT_EQ(text.alignment, 4U); + EXPECT_EQ((uint16_t)text.alignment, 16U); EXPECT_EQ(text.address, Hex64(0x0)); EXPECT_EQ(48UL, text.content.size()); const Relocation& call = text.relocations[0]; @@ -240,7 +240,7 @@ TEST(BinaryWriterTest, obj_relocs_x86) { text.type = S_REGULAR; text.attributes = SectionAttr(S_ATTR_PURE_INSTRUCTIONS | S_ATTR_SOME_INSTRUCTIONS); - text.alignment = 4; + text.alignment = 16; text.address = 0; const uint8_t textBytes[] = { 0xe8, 0xfb, 0xff, 0xff, 0xff, 0xa1, 0x00, 0x00, @@ -290,7 +290,7 @@ TEST(BinaryWriterTest, obj_relocs_x86) { EXPECT_EQ(S_REGULAR, text.type); EXPECT_EQ(text.attributes,SectionAttr(S_ATTR_PURE_INSTRUCTIONS | S_ATTR_SOME_INSTRUCTIONS)); - EXPECT_EQ(text.alignment, 4U); + EXPECT_EQ((uint16_t)text.alignment, 16U); EXPECT_EQ(text.address, Hex64(0x0)); EXPECT_EQ(22UL, text.content.size()); const Relocation& call = text.relocations[0]; @@ -350,7 +350,7 @@ TEST(BinaryWriterTest, obj_relocs_armv7) { text.type = S_REGULAR; text.attributes = SectionAttr(S_ATTR_PURE_INSTRUCTIONS | S_ATTR_SOME_INSTRUCTIONS); - text.alignment = 2; + text.alignment = 4; text.address = 0; const uint8_t textBytes[] = { 0xff, 0xf7, 0xfe, 0xef, 0x40, 0xf2, 0x05, 0x01, @@ -415,7 +415,7 @@ TEST(BinaryWriterTest, obj_relocs_armv7) { EXPECT_EQ(S_REGULAR, text.type); EXPECT_EQ(text.attributes,SectionAttr(S_ATTR_PURE_INSTRUCTIONS | S_ATTR_SOME_INSTRUCTIONS)); - EXPECT_EQ(text.alignment, 2U); + EXPECT_EQ((uint16_t)text.alignment, 4U); EXPECT_EQ(text.address, Hex64(0x0)); EXPECT_EQ(18UL, text.content.size()); const Relocation& blx = text.relocations[0]; @@ -479,7 +479,7 @@ TEST(BinaryWriterTest, obj_relocs_ppc) { text.type = S_REGULAR; text.attributes = SectionAttr(S_ATTR_PURE_INSTRUCTIONS | S_ATTR_SOME_INSTRUCTIONS); - text.alignment = 2; + text.alignment = 4; text.address = 0; const uint8_t textBytes[] = { 0x48, 0x00, 0x00, 0x01, 0x40, 0x82, 0xff, 0xfc, @@ -571,7 +571,7 @@ TEST(BinaryWriterTest, obj_relocs_ppc) { EXPECT_EQ(S_REGULAR, text.type); EXPECT_EQ(text.attributes,SectionAttr(S_ATTR_PURE_INSTRUCTIONS | S_ATTR_SOME_INSTRUCTIONS)); - EXPECT_EQ(text.alignment, 2U); + EXPECT_EQ((uint16_t)text.alignment, 4U); EXPECT_EQ(text.address, Hex64(0x0)); EXPECT_EQ(44UL, text.content.size()); const Relocation& br24 = text.relocations[0]; @@ -690,4 +690,3 @@ TEST(BinaryWriterTest, obj_relocs_ppc) { std::error_code ec = llvm::sys::fs::remove(Twine(tmpFl)); EXPECT_FALSE(ec); } - diff --git a/unittests/MachOTests/MachONormalizedFileToAtomsTests.cpp b/unittests/MachOTests/MachONormalizedFileToAtomsTests.cpp index 16ef88aa4a40..7def86c87929 100644 --- a/unittests/MachOTests/MachONormalizedFileToAtomsTests.cpp +++ b/unittests/MachOTests/MachONormalizedFileToAtomsTests.cpp @@ -66,7 +66,7 @@ TEST(ToAtomsTest, basic_obj_x86_64) { EXPECT_FALSE(!atom_f); const lld::File &file = **atom_f; EXPECT_EQ(3U, file.defined().size()); - lld::File::defined_iterator it = file.defined().begin(); + auto it = file.defined().begin(); const lld::DefinedAtom *atom1 = *it; ++it; const lld::DefinedAtom *atom2 = *it; diff --git a/unittests/MachOTests/MachONormalizedFileYAMLTests.cpp b/unittests/MachOTests/MachONormalizedFileYAMLTests.cpp index 562dae60049d..d13e360b41a5 100644 --- a/unittests/MachOTests/MachONormalizedFileYAMLTests.cpp +++ b/unittests/MachOTests/MachONormalizedFileYAMLTests.cpp @@ -197,7 +197,7 @@ TEST(ObjectFileYAML, oneSection) { " section: __text\n" " type: S_REGULAR\n" " attributes: [ S_ATTR_PURE_INSTRUCTIONS ]\n" - " alignment: 1\n" + " alignment: 2\n" " address: 0x12345678\n" " content: [ 0x90, 0x90 ]\n" "...\n"); @@ -213,7 +213,7 @@ TEST(ObjectFileYAML, oneSection) { EXPECT_EQ((uint32_t)(sect.type), (uint32_t)(llvm::MachO::S_REGULAR)); EXPECT_EQ((uint32_t)(sect.attributes), (uint32_t)(llvm::MachO::S_ATTR_PURE_INSTRUCTIONS)); - EXPECT_EQ(sect.alignment, 1U); + EXPECT_EQ((uint16_t)sect.alignment, 2U); EXPECT_EQ((uint64_t)sect.address, 0x12345678ULL); EXPECT_EQ(sect.content.size(), 2UL); EXPECT_EQ((int)(sect.content[0]), 0x90); @@ -232,7 +232,7 @@ TEST(ObjectFileYAML, hello_x86_64) { " section: __text\n" " type: S_REGULAR\n" " attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS]\n" - " alignment: 0\n" + " alignment: 1\n" " address: 0x0000\n" " content: [ 0x55, 0x48, 0x89, 0xe5, 0x48, 0x8d, 0x3d, 0x00,\n" " 0x00, 0x00, 0x00, 0x30, 0xc0, 0xe8, 0x00, 0x00,\n" @@ -254,7 +254,7 @@ TEST(ObjectFileYAML, hello_x86_64) { " section: __cstring\n" " type: S_CSTRING_LITERALS\n" " attributes: [ ]\n" - " alignment: 0\n" + " alignment: 1\n" " address: 0x0016\n" " content: [ 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x0a, 0x00 ]\n" "global-symbols:\n" @@ -286,7 +286,7 @@ TEST(ObjectFileYAML, hello_x86_64) { EXPECT_EQ((uint32_t)(sect1.attributes), (uint32_t)(llvm::MachO::S_ATTR_PURE_INSTRUCTIONS | llvm::MachO::S_ATTR_SOME_INSTRUCTIONS)); - EXPECT_EQ(sect1.alignment, 0U); + EXPECT_EQ((uint16_t)sect1.alignment, 1U); EXPECT_EQ((uint64_t)sect1.address, 0x0ULL); EXPECT_EQ(sect1.content.size(), 22UL); EXPECT_EQ((int)(sect1.content[0]), 0x55); @@ -316,7 +316,7 @@ TEST(ObjectFileYAML, hello_x86_64) { EXPECT_TRUE(sect2.sectionName.equals("__cstring")); EXPECT_EQ((uint32_t)(sect2.type), (uint32_t)(llvm::MachO::S_CSTRING_LITERALS)); EXPECT_EQ((uint32_t)(sect2.attributes), 0U); - EXPECT_EQ(sect2.alignment, 0U); + EXPECT_EQ((uint16_t)sect2.alignment, 1U); EXPECT_EQ((uint64_t)sect2.address, 0x016ULL); EXPECT_EQ(sect2.content.size(), 7UL); EXPECT_EQ((int)(sect2.content[0]), 0x68); @@ -361,7 +361,7 @@ TEST(ObjectFileYAML, hello_x86) { " section: __text\n" " type: S_REGULAR\n" " attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS]\n" - " alignment: 0\n" + " alignment: 1\n" " address: 0x0000\n" " content: [ 0x55, 0x89, 0xe5, 0x83, 0xec, 0x08, 0xe8, 0x00,\n" " 0x00, 0x00, 0x00, 0x58, 0x8d, 0x80, 0x16, 0x00,\n" @@ -391,7 +391,7 @@ TEST(ObjectFileYAML, hello_x86) { " section: __cstring\n" " type: S_CSTRING_LITERALS\n" " attributes: [ ]\n" - " alignment: 0\n" + " alignment: 1\n" " address: 0x0021\n" " content: [ 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x0a, 0x00 ]\n" "global-symbols:\n" @@ -417,7 +417,7 @@ TEST(ObjectFileYAML, hello_x86) { EXPECT_EQ((uint32_t)(sect1.attributes), (uint32_t)(llvm::MachO::S_ATTR_PURE_INSTRUCTIONS | llvm::MachO::S_ATTR_SOME_INSTRUCTIONS)); - EXPECT_EQ(sect1.alignment, 0U); + EXPECT_EQ((uint16_t)sect1.alignment, 1U); EXPECT_EQ((uint64_t)sect1.address, 0x0ULL); EXPECT_EQ(sect1.content.size(), 33UL); EXPECT_EQ((int)(sect1.content[0]), 0x55); @@ -454,7 +454,7 @@ TEST(ObjectFileYAML, hello_x86) { EXPECT_TRUE(sect2.sectionName.equals("__cstring")); EXPECT_EQ((uint32_t)(sect2.type), (uint32_t)(llvm::MachO::S_CSTRING_LITERALS)); EXPECT_EQ((uint32_t)(sect2.attributes), 0U); - EXPECT_EQ(sect2.alignment, 0U); + EXPECT_EQ((uint16_t)sect2.alignment, 1U); EXPECT_EQ((uint64_t)sect2.address, 0x021ULL); EXPECT_EQ(sect2.content.size(), 7UL); EXPECT_EQ((int)(sect2.content[0]), 0x68); @@ -490,7 +490,7 @@ TEST(ObjectFileYAML, hello_armv6) { " section: __text\n" " type: S_REGULAR\n" " attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS]\n" - " alignment: 2\n" + " alignment: 4\n" " address: 0x0000\n" " content: [ 0x80, 0x40, 0x2d, 0xe9, 0x10, 0x00, 0x9f, 0xe5,\n" " 0x0d, 0x70, 0xa0, 0xe1, 0x00, 0x00, 0x8f, 0xe0,\n" @@ -519,7 +519,7 @@ TEST(ObjectFileYAML, hello_armv6) { " section: __cstring\n" " type: S_CSTRING_LITERALS\n" " attributes: [ ]\n" - " alignment: 0\n" + " alignment: 1\n" " address: 0x0020\n" " content: [ 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x0a, 0x00 ]\n" "global-symbols:\n" @@ -545,7 +545,7 @@ TEST(ObjectFileYAML, hello_armv6) { EXPECT_EQ((uint32_t)(sect1.attributes), (uint32_t)(llvm::MachO::S_ATTR_PURE_INSTRUCTIONS | llvm::MachO::S_ATTR_SOME_INSTRUCTIONS)); - EXPECT_EQ(sect1.alignment, 2U); + EXPECT_EQ((uint16_t)sect1.alignment, 4U); EXPECT_EQ((uint64_t)sect1.address, 0x0ULL); EXPECT_EQ(sect1.content.size(), 32UL); EXPECT_EQ((int)(sect1.content[0]), 0x80); @@ -582,7 +582,7 @@ TEST(ObjectFileYAML, hello_armv6) { EXPECT_TRUE(sect2.sectionName.equals("__cstring")); EXPECT_EQ((uint32_t)(sect2.type), (uint32_t)(llvm::MachO::S_CSTRING_LITERALS)); EXPECT_EQ((uint32_t)(sect2.attributes), 0U); - EXPECT_EQ(sect2.alignment, 0U); + EXPECT_EQ((uint16_t)sect2.alignment, 1U); EXPECT_EQ((uint64_t)sect2.address, 0x020ULL); EXPECT_EQ(sect2.content.size(), 7UL); EXPECT_EQ((int)(sect2.content[0]), 0x68); @@ -620,7 +620,7 @@ TEST(ObjectFileYAML, hello_armv7) { " section: __text\n" " type: S_REGULAR\n" " attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS]\n" - " alignment: 1\n" + " alignment: 2\n" " address: 0x0000\n" " content: [ 0x80, 0xb5, 0x40, 0xf2, 0x06, 0x00, 0x6f, 0x46,\n" " 0xc0, 0xf2, 0x00, 0x00, 0x78, 0x44, 0xff, 0xf7,\n" @@ -660,7 +660,7 @@ TEST(ObjectFileYAML, hello_armv7) { " section: __cstring\n" " type: S_CSTRING_LITERALS\n" " attributes: [ ]\n" - " alignment: 0\n" + " alignment: 1\n" " address: 0x0016\n" " content: [ 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x0a, 0x00 ]\n" "global-symbols:\n" @@ -687,7 +687,7 @@ TEST(ObjectFileYAML, hello_armv7) { EXPECT_EQ((uint32_t)(sect1.attributes), (uint32_t)(llvm::MachO::S_ATTR_PURE_INSTRUCTIONS | llvm::MachO::S_ATTR_SOME_INSTRUCTIONS)); - EXPECT_EQ(sect1.alignment, 1U); + EXPECT_EQ((uint16_t)sect1.alignment, 2U); EXPECT_EQ((uint64_t)sect1.address, 0x0ULL); EXPECT_EQ(sect1.content.size(), 22UL); EXPECT_EQ((int)(sect1.content[0]), 0x80); @@ -740,7 +740,7 @@ TEST(ObjectFileYAML, hello_armv7) { EXPECT_TRUE(sect2.sectionName.equals("__cstring")); EXPECT_EQ((uint32_t)(sect2.type), (uint32_t)(llvm::MachO::S_CSTRING_LITERALS)); EXPECT_EQ((uint32_t)(sect2.attributes), 0U); - EXPECT_EQ(sect2.alignment, 0U); + EXPECT_EQ((uint16_t)sect2.alignment, 1U); EXPECT_EQ((uint64_t)sect2.address, 0x016ULL); EXPECT_EQ(sect2.content.size(), 7UL); EXPECT_EQ((int)(sect2.content[0]), 0x68); diff --git a/unittests/Makefile b/unittests/Makefile deleted file mode 100644 index 0fbb17d48289..000000000000 --- a/unittests/Makefile +++ /dev/null @@ -1,31 +0,0 @@ -##===- unittests/Makefile ----------------------------------*- Makefile -*-===## -# -# The LLVM Compiler Infrastructure -# -# This file is distributed under the University of Illinois Open Source -# License. See LICENSE.TXT for details. -# -##===----------------------------------------------------------------------===## - -# If LLD_LEVEL is not set, then we are the top-level Makefile. Otherwise, we -# are being included from a subdirectory makefile. - -ifndef LLD_LEVEL - -IS_UNITTEST_LEVEL := 1 -LLD_LEVEL := .. - -PARALLEL_DIRS = CoreTests DriverTests - -include $(LLD_LEVEL)/../../Makefile.config - -endif # LLD_LEVEL - -include $(LLD_LEVEL)/Makefile - -ifndef IS_UNITTEST_LEVEL - -MAKEFILE_UNITTEST_NO_INCLUDE_COMMON := 1 -include $(LLVM_SRC_ROOT)/unittests/Makefile.unittest - -endif # IS_UNITTEST_LEVEL |