diff options
author | Rui Ueyama <ruiu@google.com> | 2015-04-10 21:40:59 +0000 |
---|---|---|
committer | Rui Ueyama <ruiu@google.com> | 2015-04-10 21:40:59 +0000 |
commit | aabd7ca452ec652d34b98e428545a9cc55d0db60 (patch) | |
tree | 14d4ae869befb41641a7de4e537d2a19baebab2d /lld/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp | |
parent | 08d9520f890f71065c4bb088bf5f568491ae8da7 (diff) | |
download | bcm5719-llvm-aabd7ca452ec652d34b98e428545a9cc55d0db60.tar.gz bcm5719-llvm-aabd7ca452ec652d34b98e428545a9cc55d0db60.zip |
Do s/_context/_ctx/g globally.
I believe this patch eliminates all remaining uses of _context
or _linkingContext variable names. Consistent naming improves
readability.
llvm-svn: 234645
Diffstat (limited to 'lld/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp')
-rw-r--r-- | lld/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp | 94 |
1 files changed, 45 insertions, 49 deletions
diff --git a/lld/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp b/lld/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp index 0f02f76dd66..d6efc67e627 100644 --- a/lld/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp +++ b/lld/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp @@ -94,7 +94,7 @@ SegmentInfo::SegmentInfo(StringRef n) class Util { public: Util(const MachOLinkingContext &ctxt) - : _context(ctxt), _archHandler(ctxt.archHandler()), _entryAtom(nullptr) {} + : _ctx(ctxt), _archHandler(ctxt.archHandler()), _entryAtom(nullptr) {} ~Util(); void assignAtomsToSections(const lld::File &atomFile); @@ -156,7 +156,7 @@ private: static unsigned weight(const SectionInfo *); }; - const MachOLinkingContext &_context; + const MachOLinkingContext &_ctx; mach_o::ArchHandler &_archHandler; llvm::BumpPtrAllocator _allocator; std::vector<SectionInfo*> _sectionInfos; @@ -205,9 +205,8 @@ SectionInfo *Util::getRelocatableSection(DefinedAtom::ContentType type) { } } // Otherwise allocate new SectionInfo object. - SectionInfo *sect = new (_allocator) SectionInfo(segmentName, sectionName, - sectionType, _context, - sectionAttrs); + SectionInfo *sect = new (_allocator) + SectionInfo(segmentName, sectionName, sectionType, _ctx, sectionAttrs); _sectionInfos.push_back(sect); _sectionMap[type] = sect; return sect; @@ -276,11 +275,8 @@ SectionInfo *Util::getFinalSection(DefinedAtom::ContentType atomType) { } } // Otherwise allocate new SectionInfo object. - SectionInfo *sect = new (_allocator) SectionInfo(p.segmentName, - p.sectionName, - p.sectionType, - _context, - sectionAttrs); + SectionInfo *sect = new (_allocator) SectionInfo( + p.segmentName, p.sectionName, p.sectionType, _ctx, sectionAttrs); _sectionInfos.push_back(sect); _sectionMap[atomType] = sect; return sect; @@ -297,7 +293,7 @@ SectionInfo *Util::sectionForAtom(const DefinedAtom *atom) { auto pos = _sectionMap.find(type); if ( pos != _sectionMap.end() ) return pos->second; - bool rMode = (_context.outputMachOType() == llvm::MachO::MH_OBJECT); + bool rMode = (_ctx.outputMachOType() == llvm::MachO::MH_OBJECT); return rMode ? getRelocatableSection(type) : getFinalSection(type); } else { // This atom needs to be in a custom section. @@ -314,8 +310,8 @@ SectionInfo *Util::sectionForAtom(const DefinedAtom *atom) { assert(seperatorIndex != StringRef::npos); StringRef segName = customName.slice(0, seperatorIndex); StringRef sectName = customName.drop_front(seperatorIndex + 1); - SectionInfo *sect = new (_allocator) SectionInfo(segName, sectName, - S_REGULAR, _context); + SectionInfo *sect = + new (_allocator) SectionInfo(segName, sectName, S_REGULAR, _ctx); _customSections.push_back(sect); _sectionInfos.push_back(sect); return sect; @@ -403,14 +399,14 @@ bool Util::TextSectionSorter::operator()(const SectionInfo *left, void Util::organizeSections() { - if (_context.outputMachOType() == llvm::MachO::MH_OBJECT) { + if (_ctx.outputMachOType() == llvm::MachO::MH_OBJECT) { // Leave sections ordered as normalized file specified. uint32_t sectionIndex = 1; for (SectionInfo *si : _sectionInfos) { si->finalSectionIndex = sectionIndex++; } } else { - switch (_context.outputMachOType()){ + switch (_ctx.outputMachOType()) { case llvm::MachO::MH_EXECUTE: // Main executables, need a zero-page segment segmentForName("__PAGEZERO"); @@ -459,7 +455,7 @@ void Util::layoutSectionsInSegment(SegmentInfo *seg, uint64_t &addr) { sect->address = llvm::RoundUpToAlignment(addr, sect->alignment); addr = sect->address + sect->size; } - seg->size = llvm::RoundUpToAlignment(addr - seg->address,_context.pageSize()); + seg->size = llvm::RoundUpToAlignment(addr - seg->address, _ctx.pageSize()); } @@ -476,35 +472,35 @@ void Util::layoutSectionsInTextSegment(size_t hlcSize, SegmentInfo *seg, } int64_t padding = taddr - hlcSize; while (padding < 0) - padding += _context.pageSize(); + padding += _ctx.pageSize(); // Start assigning section address starting at padded offset. addr += (padding + hlcSize); for (SectionInfo *sect : seg->sections) { sect->address = llvm::RoundUpToAlignment(addr, sect->alignment); addr = sect->address + sect->size; } - seg->size = llvm::RoundUpToAlignment(addr - seg->address,_context.pageSize()); + seg->size = llvm::RoundUpToAlignment(addr - seg->address, _ctx.pageSize()); } void Util::assignAddressesToSections(const NormalizedFile &file) { size_t hlcSize = headerAndLoadCommandsSize(file); uint64_t address = 0; - if (_context.outputMachOType() != llvm::MachO::MH_OBJECT) { + if (_ctx.outputMachOType() != llvm::MachO::MH_OBJECT) { for (SegmentInfo *seg : _segmentInfos) { if (seg->name.equals("__PAGEZERO")) { - seg->size = _context.pageZeroSize(); + seg->size = _ctx.pageZeroSize(); address += seg->size; } else if (seg->name.equals("__TEXT")) { - // _context.baseAddress() == 0 implies it was either unspecified or + // _ctx.baseAddress() == 0 implies it was either unspecified or // pageZeroSize is also 0. In either case resetting address is safe. - address = _context.baseAddress() ? _context.baseAddress() : address; + address = _ctx.baseAddress() ? _ctx.baseAddress() : address; layoutSectionsInTextSegment(hlcSize, seg, address); } else layoutSectionsInSegment(seg, address); - address = llvm::RoundUpToAlignment(address, _context.pageSize()); + address = llvm::RoundUpToAlignment(address, _ctx.pageSize()); } DEBUG_WITH_TYPE("WriterMachO-norm", llvm::dbgs() << "assignAddressesToSections()\n"; @@ -567,7 +563,7 @@ void Util::appendSection(SectionInfo *si, NormalizedFile &file) { } void Util::copySectionContent(NormalizedFile &file) { - const bool r = (_context.outputMachOType() == llvm::MachO::MH_OBJECT); + const bool r = (_ctx.outputMachOType() == llvm::MachO::MH_OBJECT); // Utility function for ArchHandler to find address of atom in output file. auto addrForAtom = [&] (const Atom &atom) -> uint64_t { @@ -598,8 +594,8 @@ void Util::copySectionContent(NormalizedFile &file) { uint8_t *atomContent = reinterpret_cast<uint8_t*> (§ionContent[ai.offsetInSection]); _archHandler.generateAtomContent(*ai.atom, r, addrForAtom, - sectionAddrForAtom, - _context.baseAddress(), atomContent); + sectionAddrForAtom, _ctx.baseAddress(), + atomContent); } } } @@ -608,7 +604,7 @@ void Util::copySectionContent(NormalizedFile &file) { void Util::copySectionInfo(NormalizedFile &file) { file.sections.reserve(_sectionInfos.size()); // For final linked images, write sections grouped by segment. - if (_context.outputMachOType() != llvm::MachO::MH_OBJECT) { + if (_ctx.outputMachOType() != llvm::MachO::MH_OBJECT) { for (SegmentInfo *sgi : _segmentInfos) { for (SectionInfo *si : sgi->sections) { appendSection(si, file); @@ -624,7 +620,7 @@ void Util::copySectionInfo(NormalizedFile &file) { void Util::updateSectionInfo(NormalizedFile &file) { file.sections.reserve(_sectionInfos.size()); - if (_context.outputMachOType() != llvm::MachO::MH_OBJECT) { + if (_ctx.outputMachOType() != llvm::MachO::MH_OBJECT) { // For final linked images, sections grouped by segment. for (SegmentInfo *sgi : _segmentInfos) { Segment *normSeg = &file.segments[sgi->normalizedSegmentIndex]; @@ -645,7 +641,7 @@ void Util::updateSectionInfo(NormalizedFile &file) { } void Util::copyEntryPointAddress(NormalizedFile &nFile) { - if (_context.outputTypeHasEntry()) { + if (_ctx.outputTypeHasEntry()) { if (_archHandler.isThumbFunction(*_entryAtom)) nFile.entryAddress = (_atomToAddress[_entryAtom] | 1); else @@ -656,13 +652,13 @@ void Util::copyEntryPointAddress(NormalizedFile &nFile) { void Util::buildAtomToAddressMap() { DEBUG_WITH_TYPE("WriterMachO-address", llvm::dbgs() << "assign atom addresses:\n"); - const bool lookForEntry = _context.outputTypeHasEntry(); + const bool lookForEntry = _ctx.outputTypeHasEntry(); for (SectionInfo *sect : _sectionInfos) { for (const AtomInfo &info : sect->atomsAndOffsets) { _atomToAddress[info.atom] = sect->address + info.offsetInSection; if (lookForEntry && (info.atom->contentType() == DefinedAtom::typeCode) && (info.atom->size() != 0) && - info.atom->name() == _context.entrySymbolName()) { + info.atom->name() == _ctx.entrySymbolName()) { _entryAtom = info.atom; } DEBUG_WITH_TYPE("WriterMachO-address", llvm::dbgs() @@ -673,7 +669,7 @@ void Util::buildAtomToAddressMap() { } } for (const Atom *atom : _machHeaderAliasAtoms) { - _atomToAddress[atom] = _context.baseAddress(); + _atomToAddress[atom] = _ctx.baseAddress(); DEBUG_WITH_TYPE("WriterMachO-address", llvm::dbgs() << " address=" << llvm::format("0x%016X", _atomToAddress[atom]) @@ -720,20 +716,20 @@ bool Util::AtomSorter::operator()(const AtomAndIndex &left, std::error_code Util::getSymbolTableRegion(const DefinedAtom* atom, bool &inGlobalsRegion, SymbolScope &scope) { - bool rMode = (_context.outputMachOType() == llvm::MachO::MH_OBJECT); + bool rMode = (_ctx.outputMachOType() == llvm::MachO::MH_OBJECT); switch (atom->scope()) { case Atom::scopeTranslationUnit: scope = 0; inGlobalsRegion = false; return std::error_code(); case Atom::scopeLinkageUnit: - if ((_context.exportMode() == MachOLinkingContext::ExportMode::whiteList) - && _context.exportSymbolNamed(atom->name())) { + if ((_ctx.exportMode() == MachOLinkingContext::ExportMode::whiteList) && + _ctx.exportSymbolNamed(atom->name())) { return make_dynamic_error_code(Twine("cannot export hidden symbol ") + atom->name()); } if (rMode) { - if (_context.keepPrivateExterns()) { + if (_ctx.keepPrivateExterns()) { // -keep_private_externs means keep in globals region as N_PEXT. scope = N_PEXT | N_EXT; inGlobalsRegion = true; @@ -745,8 +741,8 @@ std::error_code Util::getSymbolTableRegion(const DefinedAtom* atom, inGlobalsRegion = false; return std::error_code(); case Atom::scopeGlobal: - if (_context.exportRestrictMode()) { - if (_context.exportSymbolNamed(atom->name())) { + if (_ctx.exportRestrictMode()) { + if (_ctx.exportSymbolNamed(atom->name())) { scope = N_EXT; inGlobalsRegion = true; return std::error_code(); @@ -767,7 +763,7 @@ std::error_code Util::getSymbolTableRegion(const DefinedAtom* atom, std::error_code Util::addSymbols(const lld::File &atomFile, NormalizedFile &file) { - bool rMode = (_context.outputMachOType() == llvm::MachO::MH_OBJECT); + bool rMode = (_ctx.outputMachOType() == llvm::MachO::MH_OBJECT); // Mach-O symbol table has three regions: locals, globals, undefs. // Add all local (non-global) symbols in address order @@ -953,8 +949,8 @@ void Util::addDependentDylibs(const lld::File &atomFile,NormalizedFile &nFile) { DependentDylib depInfo; depInfo.path = loadPath; depInfo.kind = llvm::MachO::LC_LOAD_DYLIB; - depInfo.currentVersion = _context.dylibCurrentVersion(loadPath); - depInfo.compatVersion = _context.dylibCompatVersion(loadPath); + depInfo.currentVersion = _ctx.dylibCurrentVersion(loadPath); + depInfo.compatVersion = _ctx.dylibCompatVersion(loadPath); nFile.dependentDylibs.push_back(depInfo); } else { if ( slAtom->canBeNullAtRuntime() ) @@ -968,7 +964,7 @@ void Util::addDependentDylibs(const lld::File &atomFile,NormalizedFile &nFile) { DylibInfo &info = _dylibInfo[dep.path]; if (info.hasWeak && !info.hasNonWeak) dep.kind = llvm::MachO::LC_LOAD_WEAK_DYLIB; - else if (_context.isUpwardDylib(dep.path)) + else if (_ctx.isUpwardDylib(dep.path)) dep.kind = llvm::MachO::LC_LOAD_UPWARD_DYLIB; } } @@ -1005,7 +1001,7 @@ uint32_t Util::sectionIndexForAtom(const Atom *atom) { } void Util::addSectionRelocs(const lld::File &, NormalizedFile &file) { - if (_context.outputMachOType() != llvm::MachO::MH_OBJECT) + if (_ctx.outputMachOType() != llvm::MachO::MH_OBJECT) return; @@ -1085,7 +1081,7 @@ void Util::buildDataInCodeArray(const lld::File &, NormalizedFile &file) { void Util::addRebaseAndBindingInfo(const lld::File &atomFile, NormalizedFile &nFile) { - if (_context.outputMachOType() == llvm::MachO::MH_OBJECT) + if (_ctx.outputMachOType() == llvm::MachO::MH_OBJECT) return; uint8_t segmentIndex; @@ -1141,7 +1137,7 @@ void Util::addRebaseAndBindingInfo(const lld::File &atomFile, } void Util::addExportInfo(const lld::File &atomFile, NormalizedFile &nFile) { - if (_context.outputMachOType() == llvm::MachO::MH_OBJECT) + if (_ctx.outputMachOType() == llvm::MachO::MH_OBJECT) return; for (SectionInfo *sect : _sectionInfos) { @@ -1149,8 +1145,8 @@ void Util::addExportInfo(const lld::File &atomFile, NormalizedFile &nFile) { const DefinedAtom *atom = info.atom; if (atom->scope() != Atom::scopeGlobal) continue; - if (_context.exportRestrictMode()) { - if (!_context.exportSymbolNamed(atom->name())) + if (_ctx.exportRestrictMode()) { + if (!_ctx.exportSymbolNamed(atom->name())) continue; } Export exprt; @@ -1170,10 +1166,10 @@ void Util::addExportInfo(const lld::File &atomFile, NormalizedFile &nFile) { uint32_t Util::fileFlags() { // FIXME: these need to determined at runtime. - if (_context.outputMachOType() == MH_OBJECT) { + if (_ctx.outputMachOType() == MH_OBJECT) { return MH_SUBSECTIONS_VIA_SYMBOLS; } else { - if ((_context.outputMachOType() == MH_EXECUTE) && _context.PIE()) + if ((_ctx.outputMachOType() == MH_EXECUTE) && _ctx.PIE()) return MH_DYLDLINK | MH_NOUNDEFS | MH_TWOLEVEL | MH_PIE; else return MH_DYLDLINK | MH_NOUNDEFS | MH_TWOLEVEL; |