diff --git a/lld/lib/Driver/DarwinLdDriver.cpp b/lld/lib/Driver/DarwinLdDriver.cpp index 82fc078ac944..d41bba05ffa3 100644 --- a/lld/lib/Driver/DarwinLdDriver.cpp +++ b/lld/lib/Driver/DarwinLdDriver.cpp @@ -16,7 +16,6 @@ #include "lld/Driver/Driver.h" #include "lld/Driver/DarwinInputGraph.h" #include "lld/ReaderWriter/MachOLinkingContext.h" -#include "lld/ReaderWriter/MachOFormat.hpp" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/Triple.h" @@ -25,6 +24,7 @@ #include "llvm/Support/CommandLine.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/Host.h" +#include "llvm/Support/MachO.h" #include "llvm/Support/ManagedStatic.h" #include "llvm/Support/Path.h" #include "llvm/Support/PrettyStackTrace.h" @@ -117,22 +117,22 @@ bool DarwinLdDriver::parse(int argc, const char *argv[], OPT_bundle, OPT_static, OPT_preload)) { switch (kind->getOption().getID()) { case OPT_dylib: - ctx.setOutputFileType(mach_o::MH_DYLIB); + ctx.setOutputFileType(llvm::MachO::MH_DYLIB); ctx.setGlobalsAreDeadStripRoots(true); break; case OPT_relocatable: ctx.setPrintRemainingUndefines(false); ctx.setAllowRemainingUndefines(true); - ctx.setOutputFileType(mach_o::MH_OBJECT); + ctx.setOutputFileType(llvm::MachO::MH_OBJECT); break; case OPT_bundle: - ctx.setOutputFileType(mach_o::MH_BUNDLE); + ctx.setOutputFileType(llvm::MachO::MH_BUNDLE); break; case OPT_static: - ctx.setOutputFileType(mach_o::MH_EXECUTE); + ctx.setOutputFileType(llvm::MachO::MH_EXECUTE); break; case OPT_preload: - ctx.setOutputFileType(mach_o::MH_PRELOAD); + ctx.setOutputFileType(llvm::MachO::MH_PRELOAD); break; } } @@ -164,7 +164,7 @@ bool DarwinLdDriver::parse(int argc, const char *argv[], // Handle -compatibility_version and -current_version if (llvm::opt::Arg *vers = parsedArgs->getLastArg(OPT_compatibility_version)) { - if (ctx.outputFileType() != mach_o::MH_DYLIB) { + if (ctx.outputFileType() != llvm::MachO::MH_DYLIB) { diagnostics << "error: -compatibility_version can only be used with -dylib\n"; return false; @@ -178,7 +178,7 @@ bool DarwinLdDriver::parse(int argc, const char *argv[], } if (llvm::opt::Arg *vers = parsedArgs->getLastArg(OPT_current_version)) { - if (ctx.outputFileType() != mach_o::MH_DYLIB) { + if (ctx.outputFileType() != llvm::MachO::MH_DYLIB) { diagnostics << "-current_version can only be used with -dylib\n"; return false; } diff --git a/lld/lib/ReaderWriter/MachO/ExecutableAtoms.hpp b/lld/lib/ReaderWriter/MachO/ExecutableAtoms.hpp index ee375a5a89ff..b144d8abacec 100644 --- a/lld/lib/ReaderWriter/MachO/ExecutableAtoms.hpp +++ b/lld/lib/ReaderWriter/MachO/ExecutableAtoms.hpp @@ -10,6 +10,7 @@ #ifndef LLD_READER_WRITER_MACHO_EXECUTABLE_ATOM_H_ #define LLD_READER_WRITER_MACHO_EXECUTABLE_ATOM_H_ +#include "llvm/Support/MachO.h" #include "lld/Core/DefinedAtom.h" #include "lld/Core/UndefinedAtom.h" @@ -32,7 +33,7 @@ public: : SimpleFile(context, "C runtime"), _undefMain(*this, context.entrySymbolName()) { // only main executables need _main - if (context.outputFileType() == MH_EXECUTE) { + if (context.outputFileType() == llvm::MachO::MH_EXECUTE) { this->addAtom(_undefMain); } } diff --git a/lld/lib/ReaderWriter/MachO/MachOLinkingContext.cpp b/lld/lib/ReaderWriter/MachO/MachOLinkingContext.cpp index b8f7b4e55d9d..6b9c81650a9c 100644 --- a/lld/lib/ReaderWriter/MachO/MachOLinkingContext.cpp +++ b/lld/lib/ReaderWriter/MachO/MachOLinkingContext.cpp @@ -8,7 +8,6 @@ //===----------------------------------------------------------------------===// #include "lld/ReaderWriter/MachOLinkingContext.h" -#include "lld/ReaderWriter/MachOFormat.hpp" #include "GOTPass.hpp" #include "StubsPass.hpp" #include "ReferenceKinds.h" @@ -20,6 +19,7 @@ #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/Triple.h" +#include "llvm/Support/MachO.h" using lld::mach_o::KindHandler; @@ -68,16 +68,16 @@ struct ArchInfo { }; static ArchInfo archInfos[] = { - { "x86_64", MachOLinkingContext::arch_x86_64, mach_o::CPU_TYPE_X86_64, - mach_o::CPU_SUBTYPE_X86_64_ALL }, - { "i386", MachOLinkingContext::arch_x86, mach_o::CPU_TYPE_I386, - mach_o::CPU_SUBTYPE_X86_ALL }, - { "armv6", MachOLinkingContext::arch_armv6, mach_o::CPU_TYPE_ARM, - mach_o::CPU_SUBTYPE_ARM_V6 }, - { "armv7", MachOLinkingContext::arch_armv7, mach_o::CPU_TYPE_ARM, - mach_o::CPU_SUBTYPE_ARM_V7 }, - { "armv7s", MachOLinkingContext::arch_armv7s, mach_o::CPU_TYPE_ARM, - mach_o::CPU_SUBTYPE_ARM_V7S }, + { "x86_64", MachOLinkingContext::arch_x86_64, llvm::MachO::CPU_TYPE_X86_64, + llvm::MachO::CPU_SUBTYPE_X86_64_ALL }, + { "i386", MachOLinkingContext::arch_x86, llvm::MachO::CPU_TYPE_I386, + llvm::MachO::CPU_SUBTYPE_X86_ALL }, + { "armv6", MachOLinkingContext::arch_armv6, llvm::MachO::CPU_TYPE_ARM, + llvm::MachO::CPU_SUBTYPE_ARM_V6 }, + { "armv7", MachOLinkingContext::arch_armv7, llvm::MachO::CPU_TYPE_ARM, + llvm::MachO::CPU_SUBTYPE_ARM_V7 }, + { "armv7s", MachOLinkingContext::arch_armv7s, llvm::MachO::CPU_TYPE_ARM, + llvm::MachO::CPU_SUBTYPE_ARM_V7S }, { StringRef(), MachOLinkingContext::arch_unknown, 0, 0 } }; @@ -122,7 +122,7 @@ uint32_t MachOLinkingContext::cpuSubtypeFromArch(Arch arch) { } MachOLinkingContext::MachOLinkingContext() - : _outputFileType(mach_o::MH_EXECUTE), _outputFileTypeStatic(false), + : _outputFileType(llvm::MachO::MH_EXECUTE), _outputFileTypeStatic(false), _doNothing(false), _arch(arch_unknown), _os(OS::macOSX), _osMinVersion(0), _pageZeroSize(0x1000), _compatibilityVersion(0), _currentVersion(0), _deadStrippableDylib(false), _kindHandler(nullptr) {} @@ -139,9 +139,9 @@ uint32_t MachOLinkingContext::getCPUSubType() const { bool MachOLinkingContext::outputTypeHasEntry() const { switch (_outputFileType) { - case mach_o::MH_EXECUTE: - case mach_o::MH_DYLINKER: - case mach_o::MH_PRELOAD: + case llvm::MachO::MH_EXECUTE: + case llvm::MachO::MH_DYLINKER: + case llvm::MachO::MH_PRELOAD: return true; default: return false; @@ -168,7 +168,7 @@ bool MachOLinkingContext::minOS(StringRef mac, StringRef iOS) const { } bool MachOLinkingContext::addEntryPointLoadCommand() const { - if ((_outputFileType == mach_o::MH_EXECUTE) && !_outputFileTypeStatic) { + if ((_outputFileType == llvm::MachO::MH_EXECUTE) && !_outputFileTypeStatic) { return minOS("10.8", "6.0"); } return false; @@ -176,14 +176,14 @@ bool MachOLinkingContext::addEntryPointLoadCommand() const { bool MachOLinkingContext::addUnixThreadLoadCommand() const { switch (_outputFileType) { - case mach_o::MH_EXECUTE: + case llvm::MachO::MH_EXECUTE: if (_outputFileTypeStatic) return true; else return !minOS("10.8", "6.0"); break; - case mach_o::MH_DYLINKER: - case mach_o::MH_PRELOAD: + case llvm::MachO::MH_DYLINKER: + case llvm::MachO::MH_PRELOAD: return true; default: return false; @@ -191,7 +191,7 @@ bool MachOLinkingContext::addUnixThreadLoadCommand() const { } bool MachOLinkingContext::validateImpl(raw_ostream &diagnostics) { - if ((_outputFileType == mach_o::MH_EXECUTE) && _entrySymbolName.empty()) { + if ((_outputFileType == llvm::MachO::MH_EXECUTE) && _entrySymbolName.empty()){ if (_outputFileTypeStatic) { _entrySymbolName = "start"; } else { @@ -205,24 +205,24 @@ bool MachOLinkingContext::validateImpl(raw_ostream &diagnostics) { } } - if (_currentVersion && _outputFileType != mach_o::MH_DYLIB) { + if (_currentVersion && _outputFileType != llvm::MachO::MH_DYLIB) { diagnostics << "error: -current_version can only be used with dylibs\n"; return false; } - if (_compatibilityVersion && _outputFileType != mach_o::MH_DYLIB) { + if (_compatibilityVersion && _outputFileType != llvm::MachO::MH_DYLIB) { diagnostics << "error: -compatibility_version can only be used with dylibs\n"; return false; } - if (_deadStrippableDylib && _outputFileType != mach_o::MH_DYLIB) { + if (_deadStrippableDylib && _outputFileType != llvm::MachO::MH_DYLIB) { diagnostics << "error: -mark_dead_strippable_dylib can only be used with dylibs.\n"; return false; } - if (!_bundleLoader.empty() && outputFileType() != mach_o::MH_BUNDLE) { + if (!_bundleLoader.empty() && outputFileType() != llvm::MachO::MH_BUNDLE) { diagnostics << "error: -bundle_loader can only be used with Mach-O bundles\n"; return false; diff --git a/lld/unittests/DriverTests/DarwinLdDriverTest.cpp b/lld/unittests/DriverTests/DarwinLdDriverTest.cpp index 1af1a34fad5c..d9b6764e01ce 100644 --- a/lld/unittests/DriverTests/DarwinLdDriverTest.cpp +++ b/lld/unittests/DriverTests/DarwinLdDriverTest.cpp @@ -14,8 +14,9 @@ #include "DriverTest.h" +#include "llvm/Support/MachO.h" + #include "lld/ReaderWriter/MachOLinkingContext.h" -#include "lld/ReaderWriter/MachOFormat.hpp" using namespace llvm; using namespace lld; @@ -44,27 +45,27 @@ TEST_F(DarwinLdParserTest, Output) { TEST_F(DarwinLdParserTest, Dylib) { EXPECT_TRUE(parse("ld", "-dylib", "foo.o", nullptr)); - EXPECT_EQ(mach_o::MH_DYLIB, _context.outputFileType()); + EXPECT_EQ(llvm::MachO::MH_DYLIB, _context.outputFileType()); } TEST_F(DarwinLdParserTest, Relocatable) { EXPECT_TRUE(parse("ld", "-r", "foo.o", nullptr)); - EXPECT_EQ(mach_o::MH_OBJECT, _context.outputFileType()); + EXPECT_EQ(llvm::MachO::MH_OBJECT, _context.outputFileType()); } TEST_F(DarwinLdParserTest, Bundle) { EXPECT_TRUE(parse("ld", "-bundle", "foo.o", nullptr)); - EXPECT_EQ(mach_o::MH_BUNDLE, _context.outputFileType()); + EXPECT_EQ(llvm::MachO::MH_BUNDLE, _context.outputFileType()); } TEST_F(DarwinLdParserTest, Preload) { EXPECT_TRUE(parse("ld", "-preload", "foo.o", nullptr)); - EXPECT_EQ(mach_o::MH_PRELOAD, _context.outputFileType()); + EXPECT_EQ(llvm::MachO::MH_PRELOAD, _context.outputFileType()); } TEST_F(DarwinLdParserTest, Static) { EXPECT_TRUE(parse("ld", "-static", "foo.o", nullptr)); - EXPECT_EQ(mach_o::MH_EXECUTE, _context.outputFileType()); + EXPECT_EQ(llvm::MachO::MH_EXECUTE, _context.outputFileType()); } TEST_F(DarwinLdParserTest, Entry) { @@ -95,36 +96,36 @@ TEST_F(DarwinLdParserTest, DeadStripRootsDylib) { TEST_F(DarwinLdParserTest, Arch) { EXPECT_TRUE(parse("ld", "-arch", "x86_64", "foo.o", nullptr)); 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()); + EXPECT_EQ((uint32_t)llvm::MachO::CPU_TYPE_X86_64, _context.getCPUType()); + EXPECT_EQ(llvm::MachO::CPU_SUBTYPE_X86_64_ALL, _context.getCPUSubType()); } TEST_F(DarwinLdParserTest, Arch_x86) { EXPECT_TRUE(parse("ld", "-arch", "i386", "foo.o", nullptr)); 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()); + EXPECT_EQ((uint32_t)llvm::MachO::CPU_TYPE_I386, _context.getCPUType()); + EXPECT_EQ(llvm::MachO::CPU_SUBTYPE_X86_ALL, _context.getCPUSubType()); } TEST_F(DarwinLdParserTest, Arch_armv6) { EXPECT_TRUE(parse("ld", "-arch", "armv6", "foo.o", nullptr)); 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()); + EXPECT_EQ((uint32_t)llvm::MachO::CPU_TYPE_ARM, _context.getCPUType()); + EXPECT_EQ(llvm::MachO::CPU_SUBTYPE_ARM_V6, _context.getCPUSubType()); } TEST_F(DarwinLdParserTest, Arch_armv7) { EXPECT_TRUE(parse("ld", "-arch", "armv7", "foo.o", nullptr)); 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()); + EXPECT_EQ((uint32_t)llvm::MachO::CPU_TYPE_ARM, _context.getCPUType()); + EXPECT_EQ(llvm::MachO::CPU_SUBTYPE_ARM_V7, _context.getCPUSubType()); } TEST_F(DarwinLdParserTest, Arch_armv7s) { EXPECT_TRUE(parse("ld", "-arch", "armv7s", "foo.o", nullptr)); 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()); + EXPECT_EQ((uint32_t)llvm::MachO::CPU_TYPE_ARM, _context.getCPUType()); + EXPECT_EQ(llvm::MachO::CPU_SUBTYPE_ARM_V7S, _context.getCPUSubType()); } TEST_F(DarwinLdParserTest, MinMacOSX10_7) {