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"
|
|
|
|
|
|
|
|
#include "lld/ReaderWriter/MachOTargetInfo.h"
|
|
|
|
#include "../../lib/ReaderWriter/MachO/MachOFormat.hpp"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
using namespace lld;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class DarwinLdParserTest : public ParserTest<DarwinLdDriver, MachOTargetInfo> {
|
|
|
|
protected:
|
2013-07-17 02:45:57 +08:00
|
|
|
virtual const TargetInfo *targetInfo() {
|
|
|
|
return &_info;
|
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));
|
|
|
|
EXPECT_FALSE(_info.allowRemainingUndefines());
|
|
|
|
EXPECT_FALSE(_info.deadStrip());
|
|
|
|
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-07-19 07:13:13 +08:00
|
|
|
EXPECT_EQ("my.out", _info.outputPath());
|
|
|
|
}
|
|
|
|
|
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));
|
|
|
|
EXPECT_EQ(mach_o::MH_DYLIB, _info.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));
|
|
|
|
EXPECT_EQ(mach_o::MH_OBJECT, _info.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));
|
|
|
|
EXPECT_EQ(mach_o::MH_BUNDLE, _info.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));
|
|
|
|
EXPECT_EQ(mach_o::MH_PRELOAD, _info.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));
|
|
|
|
EXPECT_EQ(mach_o::MH_EXECUTE, _info.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));
|
|
|
|
EXPECT_EQ("entryFunc", _info.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));
|
|
|
|
EXPECT_EQ("foo", _info.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));
|
|
|
|
EXPECT_TRUE(_info.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-07-19 07:13:13 +08:00
|
|
|
EXPECT_FALSE(_info.globalsAreDeadStripRoots());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DarwinLdParserTest, DeadStripRootsDylib) {
|
2013-07-19 07:47:22 +08:00
|
|
|
EXPECT_FALSE(parse("ld", "-dylib", "-dead_strip", "foo.o", nullptr));
|
2013-07-19 07:13:13 +08:00
|
|
|
EXPECT_TRUE(_info.globalsAreDeadStripRoots());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DarwinLdParserTest, ForceLoadArchive) {
|
2013-07-19 07:47:22 +08:00
|
|
|
EXPECT_FALSE(parse("ld","-all_load", "foo.o", nullptr));
|
2013-07-19 07:13:13 +08:00
|
|
|
EXPECT_TRUE(_info.forceLoadAllArchives());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DarwinLdParserTest, NoForceLoadArchive) {
|
2013-07-19 07:47:22 +08:00
|
|
|
EXPECT_FALSE(parse("ld", "foo.o", nullptr));
|
2013-07-19 07:13:13 +08:00
|
|
|
EXPECT_FALSE(_info.forceLoadAllArchives());
|
|
|
|
}
|
|
|
|
|
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));
|
|
|
|
EXPECT_EQ(MachOTargetInfo::arch_x86_64, _info.arch());
|
2013-07-19 07:13:13 +08:00
|
|
|
EXPECT_EQ(mach_o::CPU_TYPE_X86_64, _info.getCPUType());
|
|
|
|
EXPECT_EQ(mach_o::CPU_SUBTYPE_X86_64_ALL, _info.getCPUSubType());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DarwinLdParserTest, Arch_x86) {
|
2013-07-19 07:47:22 +08:00
|
|
|
EXPECT_FALSE(parse("ld", "-arch", "i386", "foo.o", nullptr));
|
2013-07-19 07:13:13 +08:00
|
|
|
EXPECT_EQ(MachOTargetInfo::arch_x86, _info.arch());
|
|
|
|
EXPECT_EQ(mach_o::CPU_TYPE_I386, _info.getCPUType());
|
|
|
|
EXPECT_EQ(mach_o::CPU_SUBTYPE_X86_ALL, _info.getCPUSubType());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DarwinLdParserTest, Arch_armv6) {
|
2013-07-19 07:47:22 +08:00
|
|
|
EXPECT_FALSE(parse("ld", "-arch", "armv6", "foo.o", nullptr));
|
2013-07-19 07:13:13 +08:00
|
|
|
EXPECT_EQ(MachOTargetInfo::arch_armv6, _info.arch());
|
|
|
|
EXPECT_EQ(mach_o::CPU_TYPE_ARM, _info.getCPUType());
|
|
|
|
EXPECT_EQ(mach_o::CPU_SUBTYPE_ARM_V6, _info.getCPUSubType());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DarwinLdParserTest, Arch_armv7) {
|
2013-07-19 07:47:22 +08:00
|
|
|
EXPECT_FALSE(parse("ld", "-arch", "armv7", "foo.o", nullptr));
|
2013-07-19 07:13:13 +08:00
|
|
|
EXPECT_EQ(MachOTargetInfo::arch_armv7, _info.arch());
|
|
|
|
EXPECT_EQ(mach_o::CPU_TYPE_ARM, _info.getCPUType());
|
|
|
|
EXPECT_EQ(mach_o::CPU_SUBTYPE_ARM_V7, _info.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-07-19 07:13:13 +08:00
|
|
|
EXPECT_EQ(MachOTargetInfo::arch_armv7s, _info.arch());
|
|
|
|
EXPECT_EQ(mach_o::CPU_TYPE_ARM, _info.getCPUType());
|
|
|
|
EXPECT_EQ(mach_o::CPU_SUBTYPE_ARM_V7S, _info.getCPUSubType());
|
|
|
|
}
|
|
|
|
|
|
|
|
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-07-19 07:13:13 +08:00
|
|
|
EXPECT_EQ(MachOTargetInfo::OS::macOSX, _info.os());
|
|
|
|
EXPECT_TRUE(_info.minOS("10.7", ""));
|
|
|
|
EXPECT_FALSE(_info.minOS("10.8", ""));
|
|
|
|
}
|
|
|
|
|
|
|
|
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-07-19 07:13:13 +08:00
|
|
|
EXPECT_EQ(MachOTargetInfo::OS::macOSX, _info.os());
|
|
|
|
EXPECT_TRUE(_info.minOS("10.7", ""));
|
|
|
|
EXPECT_TRUE(_info.minOS("10.8", ""));
|
|
|
|
}
|
|
|
|
|
|
|
|
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-07-19 07:13:13 +08:00
|
|
|
EXPECT_EQ(MachOTargetInfo::OS::iOS, _info.os());
|
|
|
|
EXPECT_TRUE(_info.minOS("", "5.0"));
|
|
|
|
EXPECT_FALSE(_info.minOS("", "6.0"));
|
|
|
|
}
|
|
|
|
|
|
|
|
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-07-19 07:13:13 +08:00
|
|
|
EXPECT_EQ(MachOTargetInfo::OS::iOS, _info.os());
|
|
|
|
EXPECT_TRUE(_info.minOS("", "5.0"));
|
|
|
|
EXPECT_TRUE(_info.minOS("", "6.0"));
|
|
|
|
}
|
|
|
|
|
|
|
|
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-07-19 07:13:13 +08:00
|
|
|
EXPECT_EQ(MachOTargetInfo::OS::iOS_simulator, _info.os());
|
|
|
|
EXPECT_TRUE(_info.minOS("", "5.0"));
|
|
|
|
EXPECT_FALSE(_info.minOS("", "6.0"));
|
|
|
|
}
|
|
|
|
|
|
|
|
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-07-19 07:13:13 +08:00
|
|
|
EXPECT_EQ(MachOTargetInfo::OS::iOS_simulator, _info.os());
|
|
|
|
EXPECT_TRUE(_info.minOS("", "5.0"));
|
|
|
|
EXPECT_TRUE(_info.minOS("", "6.0"));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-06-12 07:07:43 +08:00
|
|
|
} // end anonymous namespace
|