2013-06-12 07:07:43 +08:00
|
|
|
//===- lld/unittest/DarwinLdDriverTest.cpp --------------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
///
|
|
|
|
/// \file
|
|
|
|
/// \brief Darwin's ld driver tests.
|
|
|
|
///
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "DriverTest.h"
|
|
|
|
|
2013-08-07 06:31:59 +08:00
|
|
|
#include "lld/ReaderWriter/MachOLinkingContext.h"
|
2013-08-22 06:57:10 +08:00
|
|
|
#include "lld/ReaderWriter/MachOFormat.hpp"
|
2013-06-12 07:07:43 +08:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
using namespace lld;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2013-08-07 06:31:59 +08:00
|
|
|
class DarwinLdParserTest
|
|
|
|
: public ParserTest<DarwinLdDriver, MachOLinkingContext> {
|
2013-06-12 07:07:43 +08:00
|
|
|
protected:
|
2013-08-07 06:31:59 +08:00
|
|
|
virtual const LinkingContext *linkingContext() { return &_context; }
|
2013-06-12 07:07:43 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
TEST_F(DarwinLdParserTest, Basic) {
|
2013-07-17 02:45:57 +08:00
|
|
|
EXPECT_FALSE(parse("ld", "foo.o", "bar.o", nullptr));
|
2013-08-07 06:31:59 +08:00
|
|
|
EXPECT_FALSE(_context.allowRemainingUndefines());
|
|
|
|
EXPECT_FALSE(_context.deadStrip());
|
2013-07-17 02:45:57 +08:00
|
|
|
EXPECT_EQ(2, inputFileCount());
|
|
|
|
EXPECT_EQ("foo.o", inputFile(0));
|
|
|
|
EXPECT_EQ("bar.o", inputFile(1));
|
2013-06-12 07:07:43 +08:00
|
|
|
}
|
|
|
|
|
2013-07-19 07:13:13 +08:00
|
|
|
TEST_F(DarwinLdParserTest, Output) {
|
2013-07-19 07:47:22 +08:00
|
|
|
EXPECT_FALSE(parse("ld", "-o", "my.out", "foo.o", nullptr));
|
2013-08-07 06:31:59 +08:00
|
|
|
EXPECT_EQ("my.out", _context.outputPath());
|
2013-07-19 07:13:13 +08:00
|
|
|
}
|
|
|
|
|
2013-06-12 07:07:43 +08:00
|
|
|
TEST_F(DarwinLdParserTest, Dylib) {
|
2013-07-17 02:45:57 +08:00
|
|
|
EXPECT_FALSE(parse("ld", "-dylib", "foo.o", nullptr));
|
2013-08-07 06:31:59 +08:00
|
|
|
EXPECT_EQ(mach_o::MH_DYLIB, _context.outputFileType());
|
2013-06-12 07:07:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DarwinLdParserTest, Relocatable) {
|
2013-07-17 02:45:57 +08:00
|
|
|
EXPECT_FALSE(parse("ld", "-r", "foo.o", nullptr));
|
2013-08-07 06:31:59 +08:00
|
|
|
EXPECT_EQ(mach_o::MH_OBJECT, _context.outputFileType());
|
2013-06-12 07:07:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DarwinLdParserTest, Bundle) {
|
2013-07-17 02:45:57 +08:00
|
|
|
EXPECT_FALSE(parse("ld", "-bundle", "foo.o", nullptr));
|
2013-08-07 06:31:59 +08:00
|
|
|
EXPECT_EQ(mach_o::MH_BUNDLE, _context.outputFileType());
|
2013-06-12 07:07:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DarwinLdParserTest, Preload) {
|
2013-07-17 02:45:57 +08:00
|
|
|
EXPECT_FALSE(parse("ld", "-preload", "foo.o", nullptr));
|
2013-08-07 06:31:59 +08:00
|
|
|
EXPECT_EQ(mach_o::MH_PRELOAD, _context.outputFileType());
|
2013-06-12 07:07:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DarwinLdParserTest, Static) {
|
2013-07-17 02:45:57 +08:00
|
|
|
EXPECT_FALSE(parse("ld", "-static", "foo.o", nullptr));
|
2013-08-07 06:31:59 +08:00
|
|
|
EXPECT_EQ(mach_o::MH_EXECUTE, _context.outputFileType());
|
2013-06-12 07:07:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DarwinLdParserTest, Entry) {
|
2013-07-17 02:45:57 +08:00
|
|
|
EXPECT_FALSE(parse("ld", "-e", "entryFunc", "foo.o", nullptr));
|
2013-08-07 06:31:59 +08:00
|
|
|
EXPECT_EQ("entryFunc", _context.entrySymbolName());
|
2013-06-12 07:07:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DarwinLdParserTest, OutputPath) {
|
2013-07-17 02:45:57 +08:00
|
|
|
EXPECT_FALSE(parse("ld", "-o", "foo", "foo.o", nullptr));
|
2013-08-07 06:31:59 +08:00
|
|
|
EXPECT_EQ("foo", _context.outputPath());
|
2013-06-12 07:07:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DarwinLdParserTest, DeadStrip) {
|
2013-07-17 02:45:57 +08:00
|
|
|
EXPECT_FALSE(parse("ld", "-dead_strip", "foo.o", nullptr));
|
2013-08-07 06:31:59 +08:00
|
|
|
EXPECT_TRUE(_context.deadStrip());
|
2013-06-12 07:07:43 +08:00
|
|
|
}
|
|
|
|
|
2013-07-19 07:13:13 +08:00
|
|
|
TEST_F(DarwinLdParserTest, DeadStripRootsExe) {
|
2013-07-19 07:47:22 +08:00
|
|
|
EXPECT_FALSE(parse("ld", "-dead_strip", "foo.o", nullptr));
|
2013-08-07 06:31:59 +08:00
|
|
|
EXPECT_FALSE(_context.globalsAreDeadStripRoots());
|
2013-07-19 07:13:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DarwinLdParserTest, DeadStripRootsDylib) {
|
2013-07-19 07:47:22 +08:00
|
|
|
EXPECT_FALSE(parse("ld", "-dylib", "-dead_strip", "foo.o", nullptr));
|
2013-08-07 06:31:59 +08:00
|
|
|
EXPECT_TRUE(_context.globalsAreDeadStripRoots());
|
2013-07-19 07:13:13 +08:00
|
|
|
}
|
|
|
|
|
2013-06-12 07:07:43 +08:00
|
|
|
TEST_F(DarwinLdParserTest, Arch) {
|
2013-07-17 02:45:57 +08:00
|
|
|
EXPECT_FALSE(parse("ld", "-arch", "x86_64", "foo.o", nullptr));
|
2013-08-07 06:31:59 +08:00
|
|
|
EXPECT_EQ(MachOLinkingContext::arch_x86_64, _context.arch());
|
|
|
|
EXPECT_EQ(mach_o::CPU_TYPE_X86_64, _context.getCPUType());
|
|
|
|
EXPECT_EQ(mach_o::CPU_SUBTYPE_X86_64_ALL, _context.getCPUSubType());
|
2013-07-19 07:13:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DarwinLdParserTest, Arch_x86) {
|
2013-07-19 07:47:22 +08:00
|
|
|
EXPECT_FALSE(parse("ld", "-arch", "i386", "foo.o", nullptr));
|
2013-08-07 06:31:59 +08:00
|
|
|
EXPECT_EQ(MachOLinkingContext::arch_x86, _context.arch());
|
|
|
|
EXPECT_EQ(mach_o::CPU_TYPE_I386, _context.getCPUType());
|
|
|
|
EXPECT_EQ(mach_o::CPU_SUBTYPE_X86_ALL, _context.getCPUSubType());
|
2013-07-19 07:13:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DarwinLdParserTest, Arch_armv6) {
|
2013-07-19 07:47:22 +08:00
|
|
|
EXPECT_FALSE(parse("ld", "-arch", "armv6", "foo.o", nullptr));
|
2013-08-07 06:31:59 +08:00
|
|
|
EXPECT_EQ(MachOLinkingContext::arch_armv6, _context.arch());
|
|
|
|
EXPECT_EQ(mach_o::CPU_TYPE_ARM, _context.getCPUType());
|
|
|
|
EXPECT_EQ(mach_o::CPU_SUBTYPE_ARM_V6, _context.getCPUSubType());
|
2013-07-19 07:13:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DarwinLdParserTest, Arch_armv7) {
|
2013-07-19 07:47:22 +08:00
|
|
|
EXPECT_FALSE(parse("ld", "-arch", "armv7", "foo.o", nullptr));
|
2013-08-07 06:31:59 +08:00
|
|
|
EXPECT_EQ(MachOLinkingContext::arch_armv7, _context.arch());
|
|
|
|
EXPECT_EQ(mach_o::CPU_TYPE_ARM, _context.getCPUType());
|
|
|
|
EXPECT_EQ(mach_o::CPU_SUBTYPE_ARM_V7, _context.getCPUSubType());
|
2013-06-12 07:07:43 +08:00
|
|
|
}
|
|
|
|
|
2013-07-19 07:13:13 +08:00
|
|
|
TEST_F(DarwinLdParserTest, Arch_armv7s) {
|
2013-07-19 07:47:22 +08:00
|
|
|
EXPECT_FALSE(parse("ld", "-arch", "armv7s", "foo.o", nullptr));
|
2013-08-07 06:31:59 +08:00
|
|
|
EXPECT_EQ(MachOLinkingContext::arch_armv7s, _context.arch());
|
|
|
|
EXPECT_EQ(mach_o::CPU_TYPE_ARM, _context.getCPUType());
|
|
|
|
EXPECT_EQ(mach_o::CPU_SUBTYPE_ARM_V7S, _context.getCPUSubType());
|
2013-07-19 07:13:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DarwinLdParserTest, MinMacOSX10_7) {
|
2013-07-19 07:47:22 +08:00
|
|
|
EXPECT_FALSE(parse("ld", "-macosx_version_min", "10.7", "foo.o", nullptr));
|
2013-08-07 06:31:59 +08:00
|
|
|
EXPECT_EQ(MachOLinkingContext::OS::macOSX, _context.os());
|
|
|
|
EXPECT_TRUE(_context.minOS("10.7", ""));
|
|
|
|
EXPECT_FALSE(_context.minOS("10.8", ""));
|
2013-07-19 07:13:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DarwinLdParserTest, MinMacOSX10_8) {
|
2013-07-19 07:47:22 +08:00
|
|
|
EXPECT_FALSE(parse("ld", "-macosx_version_min", "10.8.3", "foo.o", nullptr));
|
2013-08-07 06:31:59 +08:00
|
|
|
EXPECT_EQ(MachOLinkingContext::OS::macOSX, _context.os());
|
|
|
|
EXPECT_TRUE(_context.minOS("10.7", ""));
|
|
|
|
EXPECT_TRUE(_context.minOS("10.8", ""));
|
2013-07-19 07:13:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DarwinLdParserTest, iOS5) {
|
2013-07-19 07:47:22 +08:00
|
|
|
EXPECT_FALSE(parse("ld", "-ios_version_min", "5.0", "foo.o", nullptr));
|
2013-08-07 06:31:59 +08:00
|
|
|
EXPECT_EQ(MachOLinkingContext::OS::iOS, _context.os());
|
|
|
|
EXPECT_TRUE(_context.minOS("", "5.0"));
|
|
|
|
EXPECT_FALSE(_context.minOS("", "6.0"));
|
2013-07-19 07:13:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DarwinLdParserTest, iOS6) {
|
2013-07-19 07:47:22 +08:00
|
|
|
EXPECT_FALSE(parse("ld", "-ios_version_min", "6.0", "foo.o", nullptr));
|
2013-08-07 06:31:59 +08:00
|
|
|
EXPECT_EQ(MachOLinkingContext::OS::iOS, _context.os());
|
|
|
|
EXPECT_TRUE(_context.minOS("", "5.0"));
|
|
|
|
EXPECT_TRUE(_context.minOS("", "6.0"));
|
2013-07-19 07:13:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DarwinLdParserTest, iOS_Simulator5) {
|
2013-07-19 07:47:22 +08:00
|
|
|
EXPECT_FALSE(parse("ld", "-ios_simulator_version_min", "5.0", "a.o", nullptr));
|
2013-08-07 06:31:59 +08:00
|
|
|
EXPECT_EQ(MachOLinkingContext::OS::iOS_simulator, _context.os());
|
|
|
|
EXPECT_TRUE(_context.minOS("", "5.0"));
|
|
|
|
EXPECT_FALSE(_context.minOS("", "6.0"));
|
2013-07-19 07:13:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DarwinLdParserTest, iOS_Simulator6) {
|
2013-07-19 07:47:22 +08:00
|
|
|
EXPECT_FALSE(parse("ld", "-ios_simulator_version_min", "6.0", "a.o", nullptr));
|
2013-08-07 06:31:59 +08:00
|
|
|
EXPECT_EQ(MachOLinkingContext::OS::iOS_simulator, _context.os());
|
|
|
|
EXPECT_TRUE(_context.minOS("", "5.0"));
|
|
|
|
EXPECT_TRUE(_context.minOS("", "6.0"));
|
2013-07-19 07:13:13 +08:00
|
|
|
}
|
|
|
|
|
2013-06-12 07:07:43 +08:00
|
|
|
} // end anonymous namespace
|