From d30a1f2cb2a5e60eb130b461337cdf9f4d63a606 Mon Sep 17 00:00:00 2001 From: Tim Northover Date: Fri, 20 Jun 2014 15:59:00 +0000 Subject: [PATCH] MachO: rename _outputFileType to avoid shadowing parent field. llvm-svn: 211367 --- lld/include/lld/ReaderWriter/MachOLinkingContext.h | 6 ++--- lld/lib/Driver/DarwinLdDriver.cpp | 4 ++-- lld/lib/ReaderWriter/MachO/ExecutableAtoms.hpp | 2 +- lld/lib/ReaderWriter/MachO/MachOLinkingContext.cpp | 27 +++++++++++----------- .../MachO/MachONormalizedFileFromAtoms.cpp | 18 +++++++-------- lld/lib/ReaderWriter/MachO/WriterMachO.cpp | 2 +- lld/unittests/DriverTests/DarwinLdDriverTest.cpp | 10 ++++---- 7 files changed, 34 insertions(+), 35 deletions(-) diff --git a/lld/include/lld/ReaderWriter/MachOLinkingContext.h b/lld/include/lld/ReaderWriter/MachOLinkingContext.h index 8bac0ba..036fe8b 100644 --- a/lld/include/lld/ReaderWriter/MachOLinkingContext.h +++ b/lld/include/lld/ReaderWriter/MachOLinkingContext.h @@ -68,7 +68,7 @@ public: mach_o::KindHandler &kindHandler() const; - HeaderFileType outputFileType() const { return _outputFileType; } + HeaderFileType outputMachOType() const { return _outputMachOType; } Arch arch() const { return _arch; } StringRef archName() const { return nameFromArch(_arch); } @@ -153,8 +153,8 @@ private: static ArchInfo _s_archInfos[]; - HeaderFileType _outputFileType; // e.g MH_EXECUTE - bool _outputFileTypeStatic; // Disambiguate static vs dynamic prog + HeaderFileType _outputMachOType; // e.g MH_EXECUTE + bool _outputMachOTypeStatic; // Disambiguate static vs dynamic prog bool _doNothing; // for -help and -v which just print info Arch _arch; OS _os; diff --git a/lld/lib/Driver/DarwinLdDriver.cpp b/lld/lib/Driver/DarwinLdDriver.cpp index 069ff35..c667840 100644 --- a/lld/lib/Driver/DarwinLdDriver.cpp +++ b/lld/lib/Driver/DarwinLdDriver.cpp @@ -211,7 +211,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() != llvm::MachO::MH_DYLIB) { + if (ctx.outputMachOType() != llvm::MachO::MH_DYLIB) { diagnostics << "error: -compatibility_version can only be used with -dylib\n"; return false; @@ -225,7 +225,7 @@ bool DarwinLdDriver::parse(int argc, const char *argv[], } if (llvm::opt::Arg *vers = parsedArgs->getLastArg(OPT_current_version)) { - if (ctx.outputFileType() != llvm::MachO::MH_DYLIB) { + if (ctx.outputMachOType() != 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 e212f48..94d4fad 100644 --- a/lld/lib/ReaderWriter/MachO/ExecutableAtoms.hpp +++ b/lld/lib/ReaderWriter/MachO/ExecutableAtoms.hpp @@ -33,7 +33,7 @@ public: CRuntimeFile(const MachOLinkingContext &context) : SimpleFile("C runtime"), _undefMain(*this, context.entrySymbolName()) { // only main executables need _main - if (context.outputFileType() == llvm::MachO::MH_EXECUTE) { + if (context.outputMachOType() == llvm::MachO::MH_EXECUTE) { this->addAtom(_undefMain); } } diff --git a/lld/lib/ReaderWriter/MachO/MachOLinkingContext.cpp b/lld/lib/ReaderWriter/MachO/MachOLinkingContext.cpp index 8be2d76..b1e2929 100644 --- a/lld/lib/ReaderWriter/MachO/MachOLinkingContext.cpp +++ b/lld/lib/ReaderWriter/MachO/MachOLinkingContext.cpp @@ -119,7 +119,7 @@ uint32_t MachOLinkingContext::cpuSubtypeFromArch(Arch arch) { } MachOLinkingContext::MachOLinkingContext() - : _outputFileType(MH_EXECUTE), _outputFileTypeStatic(false), + : _outputMachOType(MH_EXECUTE), _outputMachOTypeStatic(false), _doNothing(false), _arch(arch_unknown), _os(OS::macOSX), _osMinVersion(0), _pageZeroSize(0), _pageSize(4096), _compatibilityVersion(0), _currentVersion(0), _deadStrippableDylib(false), _printAtoms(false), @@ -129,12 +129,12 @@ MachOLinkingContext::~MachOLinkingContext() {} void MachOLinkingContext::configure(HeaderFileType type, Arch arch, OS os, uint32_t minOSVersion) { - _outputFileType = type; + _outputMachOType = type; _arch = arch; _os = os; _osMinVersion = minOSVersion; - switch (_outputFileType) { + switch (_outputMachOType) { case llvm::MachO::MH_EXECUTE: // If targeting newer OS, use _main if (minOS("10.8", "6.0")) { @@ -211,7 +211,7 @@ bool MachOLinkingContext::is64Bit() const { } bool MachOLinkingContext::outputTypeHasEntry() const { - switch (_outputFileType) { + switch (_outputMachOType) { case MH_EXECUTE: case MH_DYLINKER: case MH_PRELOAD: @@ -240,16 +240,16 @@ bool MachOLinkingContext::minOS(StringRef mac, StringRef iOS) const { } bool MachOLinkingContext::addEntryPointLoadCommand() const { - if ((_outputFileType == MH_EXECUTE) && !_outputFileTypeStatic) { + if ((_outputMachOType == MH_EXECUTE) && !_outputMachOTypeStatic) { return minOS("10.8", "6.0"); } return false; } bool MachOLinkingContext::addUnixThreadLoadCommand() const { - switch (_outputFileType) { + switch (_outputMachOType) { case MH_EXECUTE: - if (_outputFileTypeStatic) + if (_outputMachOTypeStatic) return true; else return !minOS("10.8", "6.0"); @@ -265,24 +265,24 @@ bool MachOLinkingContext::addUnixThreadLoadCommand() const { bool MachOLinkingContext::validateImpl(raw_ostream &diagnostics) { // TODO: if -arch not specified, look at arch of first .o file. - if (_currentVersion && _outputFileType != MH_DYLIB) { + if (_currentVersion && _outputMachOType != MH_DYLIB) { diagnostics << "error: -current_version can only be used with dylibs\n"; return false; } - if (_compatibilityVersion && _outputFileType != MH_DYLIB) { + if (_compatibilityVersion && _outputMachOType != MH_DYLIB) { diagnostics << "error: -compatibility_version can only be used with dylibs\n"; return false; } - if (_deadStrippableDylib && _outputFileType != MH_DYLIB) { + if (_deadStrippableDylib && _outputMachOType != MH_DYLIB) { diagnostics << "error: -mark_dead_strippable_dylib can only be used with dylibs.\n"; return false; } - if (!_bundleLoader.empty() && outputFileType() != MH_BUNDLE) { + if (!_bundleLoader.empty() && outputMachOType() != MH_BUNDLE) { diagnostics << "error: -bundle_loader can only be used with Mach-O bundles\n"; return false; @@ -292,7 +292,7 @@ bool MachOLinkingContext::validateImpl(raw_ostream &diagnostics) { } void MachOLinkingContext::addPasses(PassManager &pm) { - if (outputFileType() != MH_OBJECT) { + if (outputMachOType() != MH_OBJECT) { pm.add(std::unique_ptr(new mach_o::GOTPass)); pm.add(std::unique_ptr(new mach_o::StubsPass(*this))); } @@ -300,9 +300,8 @@ void MachOLinkingContext::addPasses(PassManager &pm) { } Writer &MachOLinkingContext::writer() const { - if (!_writer) { + if (!_writer) _writer = createWriterMachO(*this); - } return *_writer; } diff --git a/lld/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp b/lld/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp index e441b9b..726092c 100644 --- a/lld/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp +++ b/lld/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp @@ -263,7 +263,7 @@ SectionInfo *Util::sectionForAtom(const DefinedAtom *atom) { auto pos = _sectionMap.find(type); if ( pos != _sectionMap.end() ) return pos->second; - bool rMode = (_context.outputFileType() == llvm::MachO::MH_OBJECT); + bool rMode = (_context.outputMachOType() == llvm::MachO::MH_OBJECT); return rMode ? getRelocatableSection(type) : getFinalSection(type); } else { // This atom needs to be in a custom section. @@ -365,7 +365,7 @@ bool Util::TextSectionSorter::operator()(const SectionInfo *left, void Util::organizeSections() { - if (_context.outputFileType() == llvm::MachO::MH_OBJECT) { + if (_context.outputMachOType() == llvm::MachO::MH_OBJECT) { // Leave sections ordered as normalized file specified. uint32_t sectionIndex = 1; for (SectionInfo *si : _sectionInfos) { @@ -373,7 +373,7 @@ void Util::organizeSections() { } } else { // Main executables, need a zero-page segment - if (_context.outputFileType() == llvm::MachO::MH_EXECUTE) + if (_context.outputMachOType() == llvm::MachO::MH_EXECUTE) segmentForName("__PAGEZERO"); // Group sections into segments. for (SectionInfo *si : _sectionInfos) { @@ -442,7 +442,7 @@ void Util::layoutSectionsInTextSegment(SegmentInfo *seg, uint64_t &addr) { void Util::assignAddressesToSections() { uint64_t address = 0; // FIXME - if (_context.outputFileType() != llvm::MachO::MH_OBJECT) { + if (_context.outputMachOType() != llvm::MachO::MH_OBJECT) { for (SegmentInfo *seg : _segmentInfos) { if (seg->name.equals("__PAGEZERO")) { seg->size = _context.pageZeroSize(); @@ -538,7 +538,7 @@ void Util::appendSection(SectionInfo *si, NormalizedFile &file) { void Util::copySections(NormalizedFile &file) { file.sections.reserve(_sectionInfos.size()); // For final linked images, write sections grouped by segment. - if (_context.outputFileType() != llvm::MachO::MH_OBJECT) { + if (_context.outputMachOType() != llvm::MachO::MH_OBJECT) { for (SegmentInfo *sgi : _segmentInfos) { for (SectionInfo *si : sgi->sections) { appendSection(si, file); @@ -622,7 +622,7 @@ bool Util::AtomSorter::operator()(const AtomAndIndex &left, bool Util::belongsInGlobalSymbolsSection(const DefinedAtom* atom) { // ScopeLinkageUnit symbols are in globals area of symbol table // in object files, but in locals area for final linked images. - if (_context.outputFileType() == llvm::MachO::MH_OBJECT) + if (_context.outputMachOType() == llvm::MachO::MH_OBJECT) return (atom->scope() != Atom::scopeTranslationUnit); else return (atom->scope() == Atom::scopeGlobal); @@ -826,7 +826,7 @@ void Util::appendReloc(const DefinedAtom *atom, const Reference *ref, } void Util::addSectionRelocs(const lld::File &, NormalizedFile &file) { - if (_context.outputFileType() != llvm::MachO::MH_OBJECT) + if (_context.outputMachOType() != llvm::MachO::MH_OBJECT) return; for (SectionInfo *si : _sectionInfos) { @@ -842,7 +842,7 @@ void Util::addSectionRelocs(const lld::File &, NormalizedFile &file) { void Util::addRebaseAndBindingInfo(const lld::File &atomFile, NormalizedFile &nFile) { - if (_context.outputFileType() == llvm::MachO::MH_OBJECT) + if (_context.outputMachOType() == llvm::MachO::MH_OBJECT) return; uint8_t segmentIndex; @@ -918,7 +918,7 @@ normalizedFromAtoms(const lld::File &atomFile, std::unique_ptr f(new NormalizedFile()); NormalizedFile &normFile = *f.get(); f->arch = context.arch(); - f->fileType = context.outputFileType(); + f->fileType = context.outputMachOType(); f->flags = util.fileFlags(); util.copySegmentInfo(normFile); util.copySections(normFile); diff --git a/lld/lib/ReaderWriter/MachO/WriterMachO.cpp b/lld/lib/ReaderWriter/MachO/WriterMachO.cpp index 90eff17..f76bfff 100644 --- a/lld/lib/ReaderWriter/MachO/WriterMachO.cpp +++ b/lld/lib/ReaderWriter/MachO/WriterMachO.cpp @@ -46,7 +46,7 @@ public: } bool createImplicitFiles(std::vector > &r) override { - if (_context.outputFileType() == llvm::MachO::MH_EXECUTE) { + if (_context.outputMachOType() == llvm::MachO::MH_EXECUTE) { // When building main executables, add _main as required entry point. r.emplace_back(new CRuntimeFile(_context)); } diff --git a/lld/unittests/DriverTests/DarwinLdDriverTest.cpp b/lld/unittests/DriverTests/DarwinLdDriverTest.cpp index 761face..3c17ca9 100644 --- a/lld/unittests/DriverTests/DarwinLdDriverTest.cpp +++ b/lld/unittests/DriverTests/DarwinLdDriverTest.cpp @@ -45,27 +45,27 @@ TEST_F(DarwinLdParserTest, Output) { TEST_F(DarwinLdParserTest, Dylib) { EXPECT_TRUE(parse("ld", "-dylib", "foo.o", nullptr)); - EXPECT_EQ(llvm::MachO::MH_DYLIB, _context.outputFileType()); + EXPECT_EQ(llvm::MachO::MH_DYLIB, _context.outputMachOType()); } TEST_F(DarwinLdParserTest, Relocatable) { EXPECT_TRUE(parse("ld", "-r", "foo.o", nullptr)); - EXPECT_EQ(llvm::MachO::MH_OBJECT, _context.outputFileType()); + EXPECT_EQ(llvm::MachO::MH_OBJECT, _context.outputMachOType()); } TEST_F(DarwinLdParserTest, Bundle) { EXPECT_TRUE(parse("ld", "-bundle", "foo.o", nullptr)); - EXPECT_EQ(llvm::MachO::MH_BUNDLE, _context.outputFileType()); + EXPECT_EQ(llvm::MachO::MH_BUNDLE, _context.outputMachOType()); } TEST_F(DarwinLdParserTest, Preload) { EXPECT_TRUE(parse("ld", "-preload", "foo.o", nullptr)); - EXPECT_EQ(llvm::MachO::MH_PRELOAD, _context.outputFileType()); + EXPECT_EQ(llvm::MachO::MH_PRELOAD, _context.outputMachOType()); } TEST_F(DarwinLdParserTest, Static) { EXPECT_TRUE(parse("ld", "-static", "foo.o", nullptr)); - EXPECT_EQ(llvm::MachO::MH_EXECUTE, _context.outputFileType()); + EXPECT_EQ(llvm::MachO::MH_EXECUTE, _context.outputMachOType()); } TEST_F(DarwinLdParserTest, Entry) { -- 2.7.4