diff --git a/lld/ELF/AArch64ErrataFix.cpp b/lld/ELF/AArch64ErrataFix.cpp --- a/lld/ELF/AArch64ErrataFix.cpp +++ b/lld/ELF/AArch64ErrataFix.cpp @@ -44,9 +44,8 @@ using namespace llvm::object; using namespace llvm::support; using namespace llvm::support::endian; - -namespace lld { -namespace elf { +using namespace lld; +using namespace lld::elf; // Helper functions to identify instructions and conditions needed to trigger // the Cortex-A53-843419 erratum. @@ -371,7 +370,7 @@ return patchOff; } -class Patch843419Section : public SyntheticSection { +class elf::Patch843419Section : public SyntheticSection { public: Patch843419Section(InputSection *p, uint64_t off); @@ -645,5 +644,3 @@ } return addressesChanged; } -} // namespace elf -} // namespace lld diff --git a/lld/ELF/ARMErrataFix.cpp b/lld/ELF/ARMErrataFix.cpp --- a/lld/ELF/ARMErrataFix.cpp +++ b/lld/ELF/ARMErrataFix.cpp @@ -33,9 +33,8 @@ using namespace llvm::object; using namespace llvm::support; using namespace llvm::support::endian; - -namespace lld { -namespace elf { +using namespace lld; +using namespace lld::elf; // The documented title for Erratum 657417 is: // "A 32bit branch instruction that spans two 4K regions can result in an @@ -71,7 +70,7 @@ // 00001002 2 - bytes padding // 00001004 __CortexA8657417_00000FFE: B.w func -class Patch657417Section : public SyntheticSection { +class elf::Patch657417Section : public SyntheticSection { public: Patch657417Section(InputSection *p, uint64_t off, uint32_t instr, bool isARM); @@ -527,6 +526,3 @@ } return addressesChanged; } - -} // namespace elf -} // namespace lld diff --git a/lld/ELF/Arch/AArch64.cpp b/lld/ELF/Arch/AArch64.cpp --- a/lld/ELF/Arch/AArch64.cpp +++ b/lld/ELF/Arch/AArch64.cpp @@ -17,14 +17,13 @@ using namespace llvm; using namespace llvm::support::endian; using namespace llvm::ELF; - -namespace lld { -namespace elf { +using namespace lld; +using namespace lld::elf; // Page(Expr) is the page address of the expression Expr, defined // as (Expr & ~0xFFF). (This applies even if the machine page size // supported by the platform has a different value.) -uint64_t getAArch64Page(uint64_t expr) { +uint64_t elf::getAArch64Page(uint64_t expr) { return expr & ~static_cast(0xFFF); } @@ -698,7 +697,4 @@ return &t; } -TargetInfo *getAArch64TargetInfo() { return getTargetInfo(); } - -} // namespace elf -} // namespace lld +TargetInfo *elf::getAArch64TargetInfo() { return getTargetInfo(); } diff --git a/lld/ELF/Arch/AMDGPU.cpp b/lld/ELF/Arch/AMDGPU.cpp --- a/lld/ELF/Arch/AMDGPU.cpp +++ b/lld/ELF/Arch/AMDGPU.cpp @@ -17,9 +17,8 @@ using namespace llvm::object; using namespace llvm::support::endian; using namespace llvm::ELF; - -namespace lld { -namespace elf { +using namespace lld; +using namespace lld::elf; namespace { class AMDGPU final : public TargetInfo { @@ -109,10 +108,7 @@ return R_AMDGPU_NONE; } -TargetInfo *getAMDGPUTargetInfo() { +TargetInfo *elf::getAMDGPUTargetInfo() { static AMDGPU target; return ⌖ } - -} // namespace elf -} // namespace lld diff --git a/lld/ELF/Arch/ARM.cpp b/lld/ELF/Arch/ARM.cpp --- a/lld/ELF/Arch/ARM.cpp +++ b/lld/ELF/Arch/ARM.cpp @@ -18,9 +18,8 @@ using namespace llvm; using namespace llvm::support::endian; using namespace llvm::ELF; - -namespace lld { -namespace elf { +using namespace lld; +using namespace lld::elf; namespace { class ARM final : public TargetInfo { @@ -845,10 +844,7 @@ } } -TargetInfo *getARMTargetInfo() { +TargetInfo *elf::getARMTargetInfo() { static ARM target; return ⌖ } - -} // namespace elf -} // namespace lld diff --git a/lld/ELF/Arch/AVR.cpp b/lld/ELF/Arch/AVR.cpp --- a/lld/ELF/Arch/AVR.cpp +++ b/lld/ELF/Arch/AVR.cpp @@ -36,9 +36,8 @@ using namespace llvm::object; using namespace llvm::support::endian; using namespace llvm::ELF; - -namespace lld { -namespace elf { +using namespace lld; +using namespace lld::elf; namespace { class AVR final : public TargetInfo { @@ -73,10 +72,7 @@ } } -TargetInfo *getAVRTargetInfo() { +TargetInfo *elf::getAVRTargetInfo() { static AVR target; return ⌖ } - -} // namespace elf -} // namespace lld diff --git a/lld/ELF/Arch/Hexagon.cpp b/lld/ELF/Arch/Hexagon.cpp --- a/lld/ELF/Arch/Hexagon.cpp +++ b/lld/ELF/Arch/Hexagon.cpp @@ -19,9 +19,8 @@ using namespace llvm::object; using namespace llvm::support::endian; using namespace llvm::ELF; - -namespace lld { -namespace elf { +using namespace lld; +using namespace lld::elf; namespace { class Hexagon final : public TargetInfo { @@ -386,10 +385,7 @@ return R_HEX_NONE; } -TargetInfo *getHexagonTargetInfo() { +TargetInfo *elf::getHexagonTargetInfo() { static Hexagon target; return ⌖ } - -} // namespace elf -} // namespace lld diff --git a/lld/ELF/Arch/MSP430.cpp b/lld/ELF/Arch/MSP430.cpp --- a/lld/ELF/Arch/MSP430.cpp +++ b/lld/ELF/Arch/MSP430.cpp @@ -26,9 +26,8 @@ using namespace llvm::object; using namespace llvm::support::endian; using namespace llvm::ELF; - -namespace lld { -namespace elf { +using namespace lld; +using namespace lld::elf; namespace { class MSP430 final : public TargetInfo { @@ -90,10 +89,7 @@ } } -TargetInfo *getMSP430TargetInfo() { +TargetInfo *elf::getMSP430TargetInfo() { static MSP430 target; return ⌖ } - -} // namespace elf -} // namespace lld diff --git a/lld/ELF/Arch/Mips.cpp b/lld/ELF/Arch/Mips.cpp --- a/lld/ELF/Arch/Mips.cpp +++ b/lld/ELF/Arch/Mips.cpp @@ -18,9 +18,9 @@ using namespace llvm; using namespace llvm::object; using namespace llvm::ELF; +using namespace lld; +using namespace lld::elf; -namespace lld { -namespace elf { namespace { template class MIPS final : public TargetInfo { public: @@ -734,7 +734,7 @@ } // Return true if the symbol is a PIC function. -template bool isMipsPIC(const Defined *sym) { +template bool elf::isMipsPIC(const Defined *sym) { if (!sym->isFunc()) return false; @@ -752,20 +752,17 @@ return file->getObj().getHeader()->e_flags & EF_MIPS_PIC; } -template TargetInfo *getMipsTargetInfo() { +template TargetInfo *elf::getMipsTargetInfo() { static MIPS target; return ⌖ } -template TargetInfo *getMipsTargetInfo(); -template TargetInfo *getMipsTargetInfo(); -template TargetInfo *getMipsTargetInfo(); -template TargetInfo *getMipsTargetInfo(); +template TargetInfo *elf::getMipsTargetInfo(); +template TargetInfo *elf::getMipsTargetInfo(); +template TargetInfo *elf::getMipsTargetInfo(); +template TargetInfo *elf::getMipsTargetInfo(); -template bool isMipsPIC(const Defined *); -template bool isMipsPIC(const Defined *); -template bool isMipsPIC(const Defined *); -template bool isMipsPIC(const Defined *); - -} // namespace elf -} // namespace lld +template bool elf::isMipsPIC(const Defined *); +template bool elf::isMipsPIC(const Defined *); +template bool elf::isMipsPIC(const Defined *); +template bool elf::isMipsPIC(const Defined *); diff --git a/lld/ELF/Arch/MipsArchTree.cpp b/lld/ELF/Arch/MipsArchTree.cpp --- a/lld/ELF/Arch/MipsArchTree.cpp +++ b/lld/ELF/Arch/MipsArchTree.cpp @@ -23,8 +23,8 @@ using namespace llvm::object; using namespace llvm::ELF; -namespace lld { -namespace elf { +using namespace lld; +using namespace lld::elf; namespace { struct ArchTreeEdge { @@ -294,7 +294,7 @@ return ret; } -template uint32_t calcMipsEFlags() { +template uint32_t elf::calcMipsEFlags() { std::vector v; for (InputFile *f : objectFiles) v.push_back({f, cast>(f)->getObj().getHeader()->e_flags}); @@ -350,7 +350,8 @@ } } -uint8_t getMipsFpAbiFlag(uint8_t oldFlag, uint8_t newFlag, StringRef fileName) { +uint8_t elf::getMipsFpAbiFlag(uint8_t oldFlag, uint8_t newFlag, + StringRef fileName) { if (compareMipsFpAbi(newFlag, oldFlag) >= 0) return newFlag; if (compareMipsFpAbi(oldFlag, newFlag) < 0) @@ -366,7 +367,7 @@ return false; } -bool isMipsN32Abi(const InputFile *f) { +bool elf::isMipsN32Abi(const InputFile *f) { switch (config->ekind) { case ELF32LEKind: return isN32Abi(f); @@ -381,17 +382,14 @@ } } -bool isMicroMips() { return config->eflags & EF_MIPS_MICROMIPS; } +bool elf::isMicroMips() { return config->eflags & EF_MIPS_MICROMIPS; } -bool isMipsR6() { +bool elf::isMipsR6() { uint32_t arch = config->eflags & EF_MIPS_ARCH; return arch == EF_MIPS_ARCH_32R6 || arch == EF_MIPS_ARCH_64R6; } -template uint32_t calcMipsEFlags(); -template uint32_t calcMipsEFlags(); -template uint32_t calcMipsEFlags(); -template uint32_t calcMipsEFlags(); - -} // namespace elf -} // namespace lld +template uint32_t elf::calcMipsEFlags(); +template uint32_t elf::calcMipsEFlags(); +template uint32_t elf::calcMipsEFlags(); +template uint32_t elf::calcMipsEFlags(); diff --git a/lld/ELF/Arch/PPC.cpp b/lld/ELF/Arch/PPC.cpp --- a/lld/ELF/Arch/PPC.cpp +++ b/lld/ELF/Arch/PPC.cpp @@ -17,9 +17,8 @@ using namespace llvm; using namespace llvm::support::endian; using namespace llvm::ELF; - -namespace lld { -namespace elf { +using namespace lld; +using namespace lld::elf; namespace { class PPC final : public TargetInfo { @@ -71,7 +70,7 @@ write32(config->isLE ? loc : loc - 2, insn); } -void writePPC32GlinkSection(uint8_t *buf, size_t numEntries) { +void elf::writePPC32GlinkSection(uint8_t *buf, size_t numEntries) { // Create canonical PLT entries for non-PIE code. Compilers don't generate // non-GOT-non-PLT relocations referencing external functions for -fpie/-fPIE. uint32_t glink = in.plt->getVA(); // VA of .glink @@ -468,10 +467,7 @@ } } -TargetInfo *getPPCTargetInfo() { +TargetInfo *elf::getPPCTargetInfo() { static PPC target; return ⌖ } - -} // namespace elf -} // namespace lld diff --git a/lld/ELF/Arch/PPC64.cpp b/lld/ELF/Arch/PPC64.cpp --- a/lld/ELF/Arch/PPC64.cpp +++ b/lld/ELF/Arch/PPC64.cpp @@ -17,9 +17,8 @@ using namespace llvm::object; using namespace llvm::support::endian; using namespace llvm::ELF; - -namespace lld { -namespace elf { +using namespace lld; +using namespace lld::elf; static uint64_t ppc64TocOffset = 0x8000; static uint64_t dynamicThreadPointerOffset = 0x8000; @@ -61,7 +60,7 @@ ADDI = 14 }; -uint64_t getPPC64TocBase() { +uint64_t elf::getPPC64TocBase() { // The TOC consists of sections .got, .toc, .tocbss, .plt in that order. The // TOC starts where the first of these sections starts. We always create a // .got when we see a relocation that uses it, so for us the start is always @@ -75,7 +74,7 @@ return tocVA + ppc64TocOffset; } -unsigned getPPC64GlobalEntryToLocalEntryOffset(uint8_t stOther) { +unsigned elf::getPPC64GlobalEntryToLocalEntryOffset(uint8_t stOther) { // The offset is encoded into the 3 most significant bits of the st_other // field, with some special values described in section 3.4.1 of the ABI: // 0 --> Zero offset between the GEP and LEP, and the function does NOT use @@ -100,7 +99,7 @@ return 0; } -bool isPPC64SmallCodeModelTocReloc(RelType type) { +bool elf::isPPC64SmallCodeModelTocReloc(RelType type) { // The only small code model relocations that access the .toc section. return type == R_PPC64_TOC16 || type == R_PPC64_TOC16_DS; } @@ -155,7 +154,7 @@ // ld/lwa 3, 0(3) # load the value from the address // // Returns true if the relaxation is performed. -bool tryRelaxPPC64TocIndirection(const Relocation &rel, uint8_t *bufLoc) { +bool elf::tryRelaxPPC64TocIndirection(const Relocation &rel, uint8_t *bufLoc) { assert(config->tocOptimize); if (rel.addend < 0) return false; @@ -472,7 +471,7 @@ } } -unsigned getPPCDFormOp(unsigned secondaryOp) { +unsigned elf::getPPCDFormOp(unsigned secondaryOp) { switch (secondaryOp) { case LBZX: return LBZ; @@ -1110,10 +1109,7 @@ return true; } -TargetInfo *getPPC64TargetInfo() { +TargetInfo *elf::getPPC64TargetInfo() { static PPC64 target; return ⌖ } - -} // namespace elf -} // namespace lld diff --git a/lld/ELF/Arch/RISCV.cpp b/lld/ELF/Arch/RISCV.cpp --- a/lld/ELF/Arch/RISCV.cpp +++ b/lld/ELF/Arch/RISCV.cpp @@ -15,9 +15,8 @@ using namespace llvm::object; using namespace llvm::support::endian; using namespace llvm::ELF; - -namespace lld { -namespace elf { +using namespace lld; +using namespace lld::elf; namespace { @@ -446,10 +445,7 @@ } } -TargetInfo *getRISCVTargetInfo() { +TargetInfo *elf::getRISCVTargetInfo() { static RISCV target; return ⌖ } - -} // namespace elf -} // namespace lld diff --git a/lld/ELF/Arch/SPARCV9.cpp b/lld/ELF/Arch/SPARCV9.cpp --- a/lld/ELF/Arch/SPARCV9.cpp +++ b/lld/ELF/Arch/SPARCV9.cpp @@ -16,9 +16,8 @@ using namespace llvm; using namespace llvm::support::endian; using namespace llvm::ELF; - -namespace lld { -namespace elf { +using namespace lld; +using namespace lld::elf; namespace { class SPARCV9 final : public TargetInfo { @@ -196,10 +195,7 @@ relocateNoSym(buf + 4, R_SPARC_WDISP19, -(off + 4 - pltEntrySize)); } -TargetInfo *getSPARCV9TargetInfo() { +TargetInfo *elf::getSPARCV9TargetInfo() { static SPARCV9 target; return ⌖ } - -} // namespace elf -} // namespace lld diff --git a/lld/ELF/Arch/X86.cpp b/lld/ELF/Arch/X86.cpp --- a/lld/ELF/Arch/X86.cpp +++ b/lld/ELF/Arch/X86.cpp @@ -16,9 +16,8 @@ using namespace llvm; using namespace llvm::support::endian; using namespace llvm::ELF; - -namespace lld { -namespace elf { +using namespace lld; +using namespace lld::elf; namespace { class X86 : public TargetInfo { @@ -615,7 +614,7 @@ write32le(buf + 22, -off - 26); } -TargetInfo *getX86TargetInfo() { +TargetInfo *elf::getX86TargetInfo() { if (config->zRetpolineplt) { if (config->isPic) { static RetpolinePic t; @@ -633,6 +632,3 @@ static X86 t; return &t; } - -} // namespace elf -} // namespace lld diff --git a/lld/ELF/Arch/X86_64.cpp b/lld/ELF/Arch/X86_64.cpp --- a/lld/ELF/Arch/X86_64.cpp +++ b/lld/ELF/Arch/X86_64.cpp @@ -19,9 +19,8 @@ using namespace llvm::object; using namespace llvm::support::endian; using namespace llvm::ELF; - -namespace lld { -namespace elf { +using namespace lld; +using namespace lld::elf; namespace { class X86_64 : public TargetInfo { @@ -1086,7 +1085,4 @@ return &t; } -TargetInfo *getX86_64TargetInfo() { return getTargetInfo(); } - -} // namespace elf -} // namespace lld +TargetInfo *elf::getX86_64TargetInfo() { return getTargetInfo(); } diff --git a/lld/ELF/CallGraphSort.cpp b/lld/ELF/CallGraphSort.cpp --- a/lld/ELF/CallGraphSort.cpp +++ b/lld/ELF/CallGraphSort.cpp @@ -48,9 +48,8 @@ #include using namespace llvm; - -namespace lld { -namespace elf { +using namespace lld; +using namespace lld::elf; namespace { struct Edge { @@ -265,9 +264,6 @@ // This first builds a call graph based on the profile data then merges sections // according to the C³ heuristic. All clusters are then sorted by a density // metric to further improve locality. -DenseMap computeCallGraphProfileOrder() { +DenseMap elf::computeCallGraphProfileOrder() { return CallGraphSort().run(); } - -} // namespace elf -} // namespace lld diff --git a/lld/ELF/DWARF.cpp b/lld/ELF/DWARF.cpp --- a/lld/ELF/DWARF.cpp +++ b/lld/ELF/DWARF.cpp @@ -22,9 +22,9 @@ using namespace llvm; using namespace llvm::object; +using namespace lld; +using namespace lld::elf; -namespace lld { -namespace elf { template LLDDwarfObj::LLDDwarfObj(ObjFile *obj) { for (InputSectionBase *sec : obj->getSections()) { if (!sec) @@ -119,10 +119,7 @@ return findAux(*sec.sec, pos, sec.sec->template rels()); } -template class LLDDwarfObj; -template class LLDDwarfObj; -template class LLDDwarfObj; -template class LLDDwarfObj; - -} // namespace elf -} // namespace lld +template class elf::LLDDwarfObj; +template class elf::LLDDwarfObj; +template class elf::LLDDwarfObj; +template class elf::LLDDwarfObj; diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -66,18 +66,17 @@ using namespace llvm::object; using namespace llvm::sys; using namespace llvm::support; +using namespace lld; +using namespace lld::elf; -namespace lld { -namespace elf { - -Configuration *config; -LinkerDriver *driver; +Configuration *elf::config; +LinkerDriver *elf::driver; static void setConfigs(opt::InputArgList &args); static void readConfigs(opt::InputArgList &args); -bool link(ArrayRef args, bool canExitEarly, raw_ostream &stdoutOS, - raw_ostream &stderrOS) { +bool elf::link(ArrayRef args, bool canExitEarly, + raw_ostream &stdoutOS, raw_ostream &stderrOS) { lld::stdoutOS = &stdoutOS; lld::stderrOS = &stderrOS; @@ -2096,6 +2095,3 @@ // Write the result to the file. writeResult(); } - -} // namespace elf -} // namespace lld diff --git a/lld/ELF/DriverUtils.cpp b/lld/ELF/DriverUtils.cpp --- a/lld/ELF/DriverUtils.cpp +++ b/lld/ELF/DriverUtils.cpp @@ -30,9 +30,8 @@ using namespace llvm; using namespace llvm::sys; using namespace llvm::opt; - -namespace lld { -namespace elf { +using namespace lld; +using namespace lld::elf; // Create OptTable @@ -144,7 +143,7 @@ return args; } -void printHelp() { +void elf::printHelp() { ELFOptTable().PrintHelp( lld::outs(), (config->progName + " [options] file...").str().c_str(), "lld", false /*ShowHidden*/, true /*ShowAllAliases*/); @@ -166,7 +165,7 @@ // Reconstructs command line arguments so that so that you can re-run // the same command with the same inputs. This is for --reproduce. -std::string createResponseFile(const opt::InputArgList &args) { +std::string elf::createResponseFile(const opt::InputArgList &args) { SmallString<0> data; raw_svector_ostream os(data); os << "--chroot .\n"; @@ -217,7 +216,7 @@ return None; } -Optional findFromSearchPaths(StringRef path) { +Optional elf::findFromSearchPaths(StringRef path) { for (StringRef dir : config->searchPaths) if (Optional s = findFile(dir, path)) return s; @@ -226,7 +225,7 @@ // This is for -l. We'll look for lib.so or lib.a from // search paths. -Optional searchLibraryBaseName(StringRef name) { +Optional elf::searchLibraryBaseName(StringRef name) { for (StringRef dir : config->searchPaths) { if (!config->isStatic) if (Optional s = findFile(dir, "lib" + name + ".so")) @@ -238,7 +237,7 @@ } // This is for -l. -Optional searchLibrary(StringRef name) { +Optional elf::searchLibrary(StringRef name) { if (name.startswith(":")) return findFromSearchPaths(name.substr(1)); return searchLibraryBaseName(name); @@ -247,11 +246,8 @@ // If a linker/version script doesn't exist in the current directory, we also // look for the script in the '-L' search paths. This matches the behaviour of // '-T', --version-script=, and linker script INPUT() command in ld.bfd. -Optional searchScript(StringRef name) { +Optional elf::searchScript(StringRef name) { if (fs::exists(name)) return name.str(); return findFromSearchPaths(name); } - -} // namespace elf -} // namespace lld diff --git a/lld/ELF/EhFrame.cpp b/lld/ELF/EhFrame.cpp --- a/lld/ELF/EhFrame.cpp +++ b/lld/ELF/EhFrame.cpp @@ -29,9 +29,9 @@ using namespace llvm::ELF; using namespace llvm::dwarf; using namespace llvm::object; +using namespace lld; +using namespace lld::elf; -namespace lld { -namespace elf { namespace { class EhReader { public: @@ -56,7 +56,7 @@ }; } -size_t readEhRecordSize(InputSectionBase *s, size_t off) { +size_t elf::readEhRecordSize(InputSectionBase *s, size_t off) { return EhReader(s, s->data().slice(off)).readEhRecordSize(); } @@ -148,7 +148,7 @@ d = d.slice(size); } -uint8_t getFdeEncoding(EhSectionPiece *p) { +uint8_t elf::getFdeEncoding(EhSectionPiece *p) { return EhReader(p->sec, p->data()).getFdeEncoding(); } @@ -194,6 +194,3 @@ } return DW_EH_PE_absptr; } - -} // namespace elf -} // namespace lld diff --git a/lld/ELF/ICF.cpp b/lld/ELF/ICF.cpp --- a/lld/ELF/ICF.cpp +++ b/lld/ELF/ICF.cpp @@ -92,9 +92,9 @@ using namespace llvm; using namespace llvm::ELF; using namespace llvm::object; +using namespace lld; +using namespace lld::elf; -namespace lld { -namespace elf { namespace { template class ICF { public: @@ -525,15 +525,12 @@ } // ICF entry point function. -template void doIcf() { +template void elf::doIcf() { llvm::TimeTraceScope timeScope("ICF"); ICF().run(); } -template void doIcf(); -template void doIcf(); -template void doIcf(); -template void doIcf(); - -} // namespace elf -} // namespace lld +template void elf::doIcf(); +template void elf::doIcf(); +template void elf::doIcf(); +template void elf::doIcf(); diff --git a/lld/ELF/InputFiles.h b/lld/ELF/InputFiles.h --- a/lld/ELF/InputFiles.h +++ b/lld/ELF/InputFiles.h @@ -38,8 +38,6 @@ std::string toString(const elf::InputFile *f); namespace elf { -class InputFile; -class InputSectionBase; using llvm::object::Archive; diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp --- a/lld/ELF/InputFiles.cpp +++ b/lld/ELF/InputFiles.cpp @@ -36,10 +36,23 @@ using namespace llvm::sys; using namespace llvm::sys::fs; using namespace llvm::support::endian; +using namespace lld; +using namespace lld::elf; + +bool InputFile::isInGroup; +uint32_t InputFile::nextGroupId; + +std::vector elf::archiveFiles; +std::vector elf::binaryFiles; +std::vector elf::bitcodeFiles; +std::vector elf::lazyObjFiles; +std::vector elf::objectFiles; +std::vector elf::sharedFiles; + +std::unique_ptr elf::tar; -namespace lld { // Returns "", "foo.a(bar.o)" or "baz.o". -std::string toString(const elf::InputFile *f) { +std::string lld::toString(const InputFile *f) { if (!f) return ""; @@ -52,18 +65,6 @@ return f->toStringCache; } -namespace elf { -bool InputFile::isInGroup; -uint32_t InputFile::nextGroupId; -std::vector archiveFiles; -std::vector binaryFiles; -std::vector bitcodeFiles; -std::vector lazyObjFiles; -std::vector objectFiles; -std::vector sharedFiles; - -std::unique_ptr tar; - static ELFKind getELFKind(MemoryBufferRef mb, StringRef archiveName) { unsigned char size; unsigned char endian; @@ -102,7 +103,7 @@ ++nextGroupId; } -Optional readFile(StringRef path) { +Optional elf::readFile(StringRef path) { // The --chroot option changes our virtual root directory. // This is useful when you are dealing with files created by --reproduce. if (!config->chroot.empty() && path.startswith("/")) @@ -208,7 +209,7 @@ } // Add symbols in File to the symbol table. -void parseFile(InputFile *file) { +void elf::parseFile(InputFile *file) { switch (config->ekind) { case ELF32LEKind: doParseFile(file); @@ -1542,8 +1543,8 @@ STV_DEFAULT, STT_OBJECT, data.size(), 0, nullptr}); } -InputFile *createObjectFile(MemoryBufferRef mb, StringRef archiveName, - uint64_t offsetInArchive) { +InputFile *elf::createObjectFile(MemoryBufferRef mb, StringRef archiveName, + uint64_t offsetInArchive) { if (isBitcode(mb)) return make(mb, archiveName, offsetInArchive); @@ -1634,7 +1635,7 @@ } } -std::string replaceThinLTOSuffix(StringRef path) { +std::string elf::replaceThinLTOSuffix(StringRef path) { StringRef suffix = config->thinLTOObjectSuffixReplace.first; StringRef repl = config->thinLTOObjectSuffixReplace.second; @@ -1653,15 +1654,12 @@ template void LazyObjFile::parse(); template void LazyObjFile::parse(); -template class ObjFile; -template class ObjFile; -template class ObjFile; -template class ObjFile; +template class elf::ObjFile; +template class elf::ObjFile; +template class elf::ObjFile; +template class elf::ObjFile; template void SharedFile::parse(); template void SharedFile::parse(); template void SharedFile::parse(); template void SharedFile::parse(); - -} // namespace elf -} // namespace lld diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp --- a/lld/ELF/InputSection.cpp +++ b/lld/ELF/InputSection.cpp @@ -36,17 +36,17 @@ using namespace llvm::support; using namespace llvm::support::endian; using namespace llvm::sys; +using namespace lld; +using namespace lld::elf; + +std::vector elf::inputSections; +DenseSet> elf::ppc64noTocRelax; -namespace lld { // Returns a string to construct an error message. -std::string toString(const elf::InputSectionBase *sec) { +std::string lld::toString(const InputSectionBase *sec) { return (toString(sec->file) + ":(" + sec->name + ")").str(); } -namespace elf { -std::vector inputSections; -DenseSet> ppc64noTocRelax; - template static ArrayRef getSectionContents(ObjFile &file, const typename ELFT::Shdr &hdr) { @@ -1137,7 +1137,7 @@ end, f->stOther)) continue; if (!getFile()->someNoSplitStack) - error(toString(this) + ": " + f->getName() + + error(lld::toString(this) + ": " + f->getName() + " (with -fsplit-stack) calls " + rel.sym->getName() + " (without -fsplit-stack), but couldn't adjust its prologue"); } @@ -1400,6 +1400,3 @@ template void EhInputSection::split(); template void EhInputSection::split(); template void EhInputSection::split(); - -} // namespace elf -} // namespace lld diff --git a/lld/ELF/LTO.cpp b/lld/ELF/LTO.cpp --- a/lld/ELF/LTO.cpp +++ b/lld/ELF/LTO.cpp @@ -41,9 +41,8 @@ using namespace llvm; using namespace llvm::object; using namespace llvm::ELF; - -namespace lld { -namespace elf { +using namespace lld; +using namespace lld::elf; // Creates an empty file to store a list of object files for final // linking of distributed ThinLTO. @@ -351,6 +350,3 @@ ret.push_back(createObjectFile(*file)); return ret; } - -} // namespace elf -} // namespace lld diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp --- a/lld/ELF/LinkerScript.cpp +++ b/lld/ELF/LinkerScript.cpp @@ -43,10 +43,10 @@ using namespace llvm::ELF; using namespace llvm::object; using namespace llvm::support::endian; +using namespace lld; +using namespace lld::elf; -namespace lld { -namespace elf { -LinkerScript *script; +LinkerScript *elf::script; static uint64_t getOutputSectionVA(SectionBase *sec) { OutputSection *os = sec->getOutputSection(); @@ -1247,6 +1247,3 @@ } return ret; } - -} // namespace elf -} // namespace lld diff --git a/lld/ELF/MapFile.cpp b/lld/ELF/MapFile.cpp --- a/lld/ELF/MapFile.cpp +++ b/lld/ELF/MapFile.cpp @@ -33,9 +33,9 @@ using namespace llvm; using namespace llvm::object; +using namespace lld; +using namespace lld::elf; -namespace lld { -namespace elf { using SymbolMapTy = DenseMap>; static constexpr char indent8[] = " "; // 8 spaces @@ -138,7 +138,7 @@ } } -void writeMapFile() { +void elf::writeMapFile() { if (config->mapFile.empty()) return; @@ -227,7 +227,7 @@ // // In this case, strlen is defined by libc.so.6 and used by other two // files. -void writeCrossReferenceTable() { +void elf::writeCrossReferenceTable() { if (!config->cref) return; @@ -259,7 +259,7 @@ } } -void writeArchiveStats() { +void elf::writeArchiveStats() { if (config->printArchiveStats.empty()) return; @@ -276,6 +276,3 @@ os << f->getMemberCount() << '\t' << f->getFetchedMemberCount() << '\t' << f->getName() << '\n'; } - -} // namespace elf -} // namespace lld diff --git a/lld/ELF/MarkLive.cpp b/lld/ELF/MarkLive.cpp --- a/lld/ELF/MarkLive.cpp +++ b/lld/ELF/MarkLive.cpp @@ -38,11 +38,10 @@ using namespace llvm; using namespace llvm::ELF; using namespace llvm::object; +using namespace llvm::support::endian; +using namespace lld; +using namespace lld::elf; -namespace endian = llvm::support::endian; - -namespace lld { -namespace elf { namespace { template class MarkLive { public: @@ -142,7 +141,7 @@ if (firstRelI == (unsigned)-1) continue; - if (endian::read32(piece.data().data() + 4) == 0) { + if (read32(piece.data().data() + 4) == 0) { // This is a CIE, we only need to worry about the first relocation. It is // known to point to the personality function. resolveReloc(eh, rels[firstRelI], false); @@ -323,7 +322,7 @@ // Before calling this function, Live bits are off for all // input sections. This function make some or all of them on // so that they are emitted to the output file. -template void markLive() { +template void elf::markLive() { llvm::TimeTraceScope timeScope("markLive"); // If -gc-sections is not given, no sections are removed. if (!config->gcSections) { @@ -392,10 +391,7 @@ message("removing unused section " + toString(sec)); } -template void markLive(); -template void markLive(); -template void markLive(); -template void markLive(); - -} // namespace elf -} // namespace lld +template void elf::markLive(); +template void elf::markLive(); +template void elf::markLive(); +template void elf::markLive(); diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp --- a/lld/ELF/OutputSections.cpp +++ b/lld/ELF/OutputSections.cpp @@ -27,9 +27,9 @@ using namespace llvm::object; using namespace llvm::support::endian; using namespace llvm::ELF; +using namespace lld; +using namespace lld::elf; -namespace lld { -namespace elf { uint8_t *Out::bufferStart; uint8_t Out::first; PhdrEntry *Out::tlsPhdr; @@ -39,7 +39,7 @@ OutputSection *Out::initArray; OutputSection *Out::finiArray; -std::vector outputSections; +std::vector elf::outputSections; uint32_t OutputSection::getPhdrFlags() const { uint32_t ret = 0; @@ -225,7 +225,7 @@ in[i] = v[i].second; } -uint64_t getHeaderSize() { +uint64_t elf::getHeaderSize() { if (config->oFormatBinary) return 0; return Out::elfHeader->size + Out::programHeaders->size; @@ -478,7 +478,7 @@ // If an input string is in the form of "foo.N" where N is a number, // return N. Otherwise, returns 65536, which is one greater than the // lowest priority. -int getPriority(StringRef s) { +int elf::getPriority(StringRef s) { size_t pos = s.rfind('.'); if (pos == StringRef::npos) return 65536; @@ -488,7 +488,7 @@ return v; } -InputSection *getFirstInputSection(const OutputSection *os) { +InputSection *elf::getFirstInputSection(const OutputSection *os) { for (BaseCommand *base : os->sectionCommands) if (auto *isd = dyn_cast(base)) if (!isd->sections.empty()) @@ -496,7 +496,7 @@ return nullptr; } -std::vector getInputSections(const OutputSection *os) { +std::vector elf::getInputSections(const OutputSection *os) { std::vector ret; for (BaseCommand *base : os->sectionCommands) if (auto *isd = dyn_cast(base)) @@ -537,6 +537,3 @@ template void OutputSection::maybeCompress(); template void OutputSection::maybeCompress(); template void OutputSection::maybeCompress(); - -} // namespace elf -} // namespace lld diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp --- a/lld/ELF/Relocations.cpp +++ b/lld/ELF/Relocations.cpp @@ -62,9 +62,9 @@ using namespace llvm::ELF; using namespace llvm::object; using namespace llvm::support::endian; +using namespace lld; +using namespace lld::elf; -namespace lld { -namespace elf { static Optional getLinkerScriptLocation(const Symbol &sym) { for (BaseCommand *base : script->sectionCommands) if (auto *cmd = dyn_cast(base)) @@ -96,8 +96,8 @@ return msg + s.getObjMsg(off); } -void reportRangeError(uint8_t *loc, const Relocation &rel, const Twine &v, - int64_t min, uint64_t max) { +void elf::reportRangeError(uint8_t *loc, const Relocation &rel, const Twine &v, + int64_t min, uint64_t max) { ErrorPlace errPlace = getErrorPlace(loc); std::string hint; if (rel.sym && !rel.sym->isLocal()) @@ -911,7 +911,7 @@ error(msg); } -template void reportUndefinedSymbols() { +template void elf::reportUndefinedSymbols() { // Find the first "undefined symbol" diagnostic for each diagnostic, and // collect all "referenced from" lines at the first diagnostic. DenseMap firstRef; @@ -1514,7 +1514,7 @@ }); } -template void scanRelocations(InputSectionBase &s) { +template void elf::scanRelocations(InputSectionBase &s) { if (s.areRelocsRela) scanRelocs(s, s.relas()); else @@ -1999,7 +1999,7 @@ // hexagonNeedsTLSSymbol scans for relocations would require a call to // __tls_get_addr. // hexagonTLSSymbolUpdate rebinds the relocation to __tls_get_addr. -bool hexagonNeedsTLSSymbol(ArrayRef outputSections) { +bool elf::hexagonNeedsTLSSymbol(ArrayRef outputSections) { bool needTlsSymbol = false; forEachInputSectionDescription( outputSections, [&](OutputSection *os, InputSectionDescription *isd) { @@ -2013,7 +2013,7 @@ return needTlsSymbol; } -void hexagonTLSSymbolUpdate(ArrayRef outputSections) { +void elf::hexagonTLSSymbolUpdate(ArrayRef outputSections) { Symbol *sym = symtab->find("__tls_get_addr"); if (!sym) return; @@ -2033,14 +2033,11 @@ }); } -template void scanRelocations(InputSectionBase &); -template void scanRelocations(InputSectionBase &); -template void scanRelocations(InputSectionBase &); -template void scanRelocations(InputSectionBase &); -template void reportUndefinedSymbols(); -template void reportUndefinedSymbols(); -template void reportUndefinedSymbols(); -template void reportUndefinedSymbols(); - -} // namespace elf -} // namespace lld +template void elf::scanRelocations(InputSectionBase &); +template void elf::scanRelocations(InputSectionBase &); +template void elf::scanRelocations(InputSectionBase &); +template void elf::scanRelocations(InputSectionBase &); +template void elf::reportUndefinedSymbols(); +template void elf::reportUndefinedSymbols(); +template void elf::reportUndefinedSymbols(); +template void elf::reportUndefinedSymbols(); diff --git a/lld/ELF/ScriptLexer.cpp b/lld/ELF/ScriptLexer.cpp --- a/lld/ELF/ScriptLexer.cpp +++ b/lld/ELF/ScriptLexer.cpp @@ -36,9 +36,9 @@ #include "llvm/ADT/Twine.h" using namespace llvm; +using namespace lld; +using namespace lld::elf; -namespace lld { -namespace elf { // Returns a whole line containing the current token. StringRef ScriptLexer::getLine() { StringRef s = getCurrentMB().getBuffer(); @@ -298,6 +298,3 @@ return mb; llvm_unreachable("getCurrentMB: failed to find a token"); } - -} // namespace elf -} // namespace lld diff --git a/lld/ELF/ScriptParser.cpp b/lld/ELF/ScriptParser.cpp --- a/lld/ELF/ScriptParser.cpp +++ b/lld/ELF/ScriptParser.cpp @@ -38,9 +38,9 @@ using namespace llvm; using namespace llvm::ELF; using namespace llvm::support::endian; +using namespace lld; +using namespace lld::elf; -namespace lld { -namespace elf { namespace { class ScriptParser final : ScriptLexer { public: @@ -1365,7 +1365,7 @@ return [=] { return cmd->size; }; } if (tok == "SIZEOF_HEADERS") - return [=] { return getHeaderSize(); }; + return [=] { return elf::getHeaderSize(); }; // Tok is the dot. if (tok == ".") @@ -1607,19 +1607,18 @@ return {flags, negFlags}; } -void readLinkerScript(MemoryBufferRef mb) { +void elf::readLinkerScript(MemoryBufferRef mb) { ScriptParser(mb).readLinkerScript(); } -void readVersionScript(MemoryBufferRef mb) { +void elf::readVersionScript(MemoryBufferRef mb) { ScriptParser(mb).readVersionScript(); } -void readDynamicList(MemoryBufferRef mb) { ScriptParser(mb).readDynamicList(); } +void elf::readDynamicList(MemoryBufferRef mb) { + ScriptParser(mb).readDynamicList(); +} -void readDefsym(StringRef name, MemoryBufferRef mb) { +void elf::readDefsym(StringRef name, MemoryBufferRef mb) { ScriptParser(mb).readDefsym(name); } - -} // namespace elf -} // namespace lld diff --git a/lld/ELF/SymbolTable.cpp b/lld/ELF/SymbolTable.cpp --- a/lld/ELF/SymbolTable.cpp +++ b/lld/ELF/SymbolTable.cpp @@ -26,10 +26,10 @@ using namespace llvm; using namespace llvm::object; using namespace llvm::ELF; +using namespace lld; +using namespace lld::elf; -namespace lld { -namespace elf { -SymbolTable *symtab; +SymbolTable *elf::symtab; void SymbolTable::wrap(Symbol *sym, Symbol *real, Symbol *wrap) { // Swap symbols as instructed by -wrap. @@ -269,6 +269,3 @@ // --dynamic-list. handleDynamicList(); } - -} // namespace elf -} // namespace lld diff --git a/lld/ELF/Symbols.cpp b/lld/ELF/Symbols.cpp --- a/lld/ELF/Symbols.cpp +++ b/lld/ELF/Symbols.cpp @@ -23,8 +23,9 @@ using namespace llvm; using namespace llvm::object; using namespace llvm::ELF; +using namespace lld; +using namespace lld::elf; -namespace lld { // Returns a symbol for an error message. static std::string demangle(StringRef symName) { if (elf::config->demangle) @@ -32,7 +33,7 @@ return std::string(symName); } -std::string toString(const elf::Symbol &sym) { +std::string lld::toString(const elf::Symbol &sym) { StringRef name = sym.getName(); std::string ret = demangle(name); @@ -44,11 +45,10 @@ return ret; } -std::string toELFString(const Archive::Symbol &b) { +std::string lld::toELFString(const Archive::Symbol &b) { return demangle(b.getName()); } -namespace elf { Defined *ElfSym::bss; Defined *ElfSym::etext1; Defined *ElfSym::etext2; @@ -64,7 +64,7 @@ Defined *ElfSym::relaIpltEnd; Defined *ElfSym::riscvGlobalPointer; Defined *ElfSym::tlsModuleBase; -DenseMap backwardReferences; +DenseMap elf::backwardReferences; static uint64_t getSymVA(const Symbol &sym, int64_t &addend) { switch (sym.kind()) { @@ -301,7 +301,7 @@ } // Print out a log message for --trace-symbol. -void printTraceSymbol(const Symbol *sym) { +void elf::printTraceSymbol(const Symbol *sym) { std::string s; if (sym->isUndefined()) s = ": reference to "; @@ -317,7 +317,7 @@ message(toString(sym->file) + s + sym->getName()); } -void maybeWarnUnorderableSymbol(const Symbol *sym) { +void elf::maybeWarnUnorderableSymbol(const Symbol *sym) { if (!config->warnSymbolOrdering) return; @@ -349,7 +349,7 @@ // Returns true if a symbol can be replaced at load-time by a symbol // with the same name defined in other ELF executable or DSO. -bool computeIsPreemptible(const Symbol &sym) { +bool elf::computeIsPreemptible(const Symbol &sym) { assert(!sym.isLocal()); // Only symbols with default visibility that appear in dynsym can be @@ -375,7 +375,7 @@ return true; } -void reportBackrefs() { +void elf::reportBackrefs() { for (auto &it : backwardReferences) { const Symbol &sym = *it.first; warn("backward reference detected: " + sym.getName() + " in " + @@ -728,6 +728,3 @@ binding = bind; } } - -} // namespace elf -} // namespace lld diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp --- a/lld/ELF/SyntheticSections.cpp +++ b/lld/ELF/SyntheticSections.cpp @@ -46,13 +46,13 @@ using namespace llvm::ELF; using namespace llvm::object; using namespace llvm::support; +using namespace lld; +using namespace lld::elf; using llvm::support::endian::read32le; using llvm::support::endian::write32le; using llvm::support::endian::write64le; -namespace lld { -namespace elf { constexpr size_t MergeNoTailSection::numShards; static uint64_t readUint(uint8_t *buf) { @@ -83,7 +83,7 @@ // With this feature, you can identify LLD-generated binaries easily // by "readelf --string-dump .comment ". // The returned object is a mergeable string section. -MergeInputSection *createCommentSection() { +MergeInputSection *elf::createCommentSection() { return make(SHF_MERGE | SHF_STRINGS, SHT_PROGBITS, 1, getVersion(), ".comment"); } @@ -139,7 +139,7 @@ flags.ases |= s->ases; flags.flags1 |= s->flags1; flags.flags2 |= s->flags2; - flags.fp_abi = getMipsFpAbiFlag(flags.fp_abi, s->fp_abi, filename); + flags.fp_abi = elf::getMipsFpAbiFlag(flags.fp_abi, s->fp_abi, filename); }; if (create) @@ -253,7 +253,7 @@ return make>(reginfo); } -InputSection *createInterpSection() { +InputSection *elf::createInterpSection() { // StringSaver guarantees that the returned string ends with '\0'. StringRef s = saver.save(config->dynamicLinker); ArrayRef contents = {(const uint8_t *)s.data(), s.size() + 1}; @@ -262,8 +262,8 @@ ".interp"); } -Defined *addSyntheticLocal(StringRef name, uint8_t type, uint64_t value, - uint64_t size, InputSectionBase §ion) { +Defined *elf::addSyntheticLocal(StringRef name, uint8_t type, uint64_t value, + uint64_t size, InputSectionBase §ion) { auto *s = make(section.file, name, STB_LOCAL, STV_DEFAULT, type, value, size, §ion); if (in.symTab) @@ -1275,7 +1275,7 @@ // Add remaining entries to complete .dynamic contents. template void DynamicSection::finalizeContents() { - Partition &part = getPartition(); + elf::Partition &part = getPartition(); bool isMain = part.name.empty(); for (StringRef s : config->filterList) @@ -3049,7 +3049,7 @@ (getPartition().verDef || getPartition().verNeed->isNeeded()); } -void addVerneed(Symbol *ss) { +void elf::addVerneed(Symbol *ss) { auto &file = cast(*ss->file); if (ss->verdefIndex == VER_NDX_GLOBAL) { ss->versionId = VER_NDX_GLOBAL; @@ -3232,16 +3232,16 @@ }); } -MergeSyntheticSection *createMergeSynthetic(StringRef name, uint32_t type, - uint64_t flags, - uint32_t alignment) { +MergeSyntheticSection *elf::createMergeSynthetic(StringRef name, uint32_t type, + uint64_t flags, + uint32_t alignment) { bool shouldTailMerge = (flags & SHF_STRINGS) && config->optimize >= 2; if (shouldTailMerge) return make(name, type, flags, alignment); return make(name, type, flags, alignment); } -template void splitSections() { +template void elf::splitSections() { llvm::TimeTraceScope timeScope("Split sections"); // splitIntoPieces needs to be called on each MergeInputSection // before calling finalizeContents(). @@ -3627,7 +3627,7 @@ return 0; } -template void writeEhdr(uint8_t *buf, Partition &part) { +template void elf::writeEhdr(uint8_t *buf, Partition &part) { // For executable segments, the trap instructions are written before writing // the header. Setting Elf header bytes to zero ensures that any unused bytes // in header are zero-cleared, instead of having trap instructions. @@ -3653,7 +3653,7 @@ } } -template void writePhdrs(uint8_t *buf, Partition &part) { +template void elf::writePhdrs(uint8_t *buf, Partition &part) { // Write the program header table. auto *hBuf = reinterpret_cast(buf); for (PhdrEntry *p : part.phdrs) { @@ -3728,85 +3728,82 @@ } } -InStruct in; +InStruct elf::in; -std::vector partitions; -Partition *mainPart; +std::vector elf::partitions; +Partition *elf::mainPart; template GdbIndexSection *GdbIndexSection::create(); template GdbIndexSection *GdbIndexSection::create(); template GdbIndexSection *GdbIndexSection::create(); template GdbIndexSection *GdbIndexSection::create(); -template void splitSections(); -template void splitSections(); -template void splitSections(); -template void splitSections(); - -template class MipsAbiFlagsSection; -template class MipsAbiFlagsSection; -template class MipsAbiFlagsSection; -template class MipsAbiFlagsSection; - -template class MipsOptionsSection; -template class MipsOptionsSection; -template class MipsOptionsSection; -template class MipsOptionsSection; - -template class MipsReginfoSection; -template class MipsReginfoSection; -template class MipsReginfoSection; -template class MipsReginfoSection; - -template class DynamicSection; -template class DynamicSection; -template class DynamicSection; -template class DynamicSection; - -template class RelocationSection; -template class RelocationSection; -template class RelocationSection; -template class RelocationSection; - -template class AndroidPackedRelocationSection; -template class AndroidPackedRelocationSection; -template class AndroidPackedRelocationSection; -template class AndroidPackedRelocationSection; - -template class RelrSection; -template class RelrSection; -template class RelrSection; -template class RelrSection; - -template class SymbolTableSection; -template class SymbolTableSection; -template class SymbolTableSection; -template class SymbolTableSection; - -template class VersionNeedSection; -template class VersionNeedSection; -template class VersionNeedSection; -template class VersionNeedSection; - -template void writeEhdr(uint8_t *Buf, Partition &Part); -template void writeEhdr(uint8_t *Buf, Partition &Part); -template void writeEhdr(uint8_t *Buf, Partition &Part); -template void writeEhdr(uint8_t *Buf, Partition &Part); - -template void writePhdrs(uint8_t *Buf, Partition &Part); -template void writePhdrs(uint8_t *Buf, Partition &Part); -template void writePhdrs(uint8_t *Buf, Partition &Part); -template void writePhdrs(uint8_t *Buf, Partition &Part); - -template class PartitionElfHeaderSection; -template class PartitionElfHeaderSection; -template class PartitionElfHeaderSection; -template class PartitionElfHeaderSection; - -template class PartitionProgramHeadersSection; -template class PartitionProgramHeadersSection; -template class PartitionProgramHeadersSection; -template class PartitionProgramHeadersSection; - -} // namespace elf -} // namespace lld +template void elf::splitSections(); +template void elf::splitSections(); +template void elf::splitSections(); +template void elf::splitSections(); + +template class elf::MipsAbiFlagsSection; +template class elf::MipsAbiFlagsSection; +template class elf::MipsAbiFlagsSection; +template class elf::MipsAbiFlagsSection; + +template class elf::MipsOptionsSection; +template class elf::MipsOptionsSection; +template class elf::MipsOptionsSection; +template class elf::MipsOptionsSection; + +template class elf::MipsReginfoSection; +template class elf::MipsReginfoSection; +template class elf::MipsReginfoSection; +template class elf::MipsReginfoSection; + +template class elf::DynamicSection; +template class elf::DynamicSection; +template class elf::DynamicSection; +template class elf::DynamicSection; + +template class elf::RelocationSection; +template class elf::RelocationSection; +template class elf::RelocationSection; +template class elf::RelocationSection; + +template class elf::AndroidPackedRelocationSection; +template class elf::AndroidPackedRelocationSection; +template class elf::AndroidPackedRelocationSection; +template class elf::AndroidPackedRelocationSection; + +template class elf::RelrSection; +template class elf::RelrSection; +template class elf::RelrSection; +template class elf::RelrSection; + +template class elf::SymbolTableSection; +template class elf::SymbolTableSection; +template class elf::SymbolTableSection; +template class elf::SymbolTableSection; + +template class elf::VersionNeedSection; +template class elf::VersionNeedSection; +template class elf::VersionNeedSection; +template class elf::VersionNeedSection; + +template void elf::writeEhdr(uint8_t *Buf, Partition &Part); +template void elf::writeEhdr(uint8_t *Buf, Partition &Part); +template void elf::writeEhdr(uint8_t *Buf, Partition &Part); +template void elf::writeEhdr(uint8_t *Buf, Partition &Part); + +template void elf::writePhdrs(uint8_t *Buf, Partition &Part); +template void elf::writePhdrs(uint8_t *Buf, Partition &Part); +template void elf::writePhdrs(uint8_t *Buf, Partition &Part); +template void elf::writePhdrs(uint8_t *Buf, Partition &Part); + +template class elf::PartitionElfHeaderSection; +template class elf::PartitionElfHeaderSection; +template class elf::PartitionElfHeaderSection; +template class elf::PartitionElfHeaderSection; + +template class elf::PartitionProgramHeadersSection; +template class elf::PartitionProgramHeadersSection; +template class elf::PartitionProgramHeadersSection; +template class elf::PartitionProgramHeadersSection; diff --git a/lld/ELF/Target.cpp b/lld/ELF/Target.cpp --- a/lld/ELF/Target.cpp +++ b/lld/ELF/Target.cpp @@ -35,19 +35,19 @@ using namespace llvm; using namespace llvm::object; using namespace llvm::ELF; +using namespace lld; +using namespace lld::elf; -namespace lld { -std::string toString(elf::RelType type) { +const TargetInfo *elf::target; + +std::string lld::toString(RelType type) { StringRef s = getELFRelocationTypeName(elf::config->emachine, type); if (s == "Unknown") return ("Unknown (" + Twine(type) + ")").str(); return std::string(s); } -namespace elf { -const TargetInfo *target; - -TargetInfo *getTarget() { +TargetInfo *elf::getTarget() { switch (config->emachine) { case EM_386: case EM_IAMCU: @@ -112,7 +112,7 @@ return {}; } -ErrorPlace getErrorPlace(const uint8_t *loc) { +ErrorPlace elf::getErrorPlace(const uint8_t *loc) { switch (config->ekind) { case ELF32LEKind: return getErrPlace(loc); @@ -186,6 +186,3 @@ return *config->imageBase; return config->isPic ? 0 : defaultImageBase; } - -} // namespace elf -} // namespace lld diff --git a/lld/ELF/Thunks.cpp b/lld/ELF/Thunks.cpp --- a/lld/ELF/Thunks.cpp +++ b/lld/ELF/Thunks.cpp @@ -40,9 +40,8 @@ using namespace llvm; using namespace llvm::object; using namespace llvm::ELF; - -namespace lld { -namespace elf { +using namespace lld; +using namespace lld::elf; namespace { @@ -714,8 +713,8 @@ return dyn_cast(dr.section); } -void writePPC32PltCallStub(uint8_t *buf, uint64_t gotPltVA, - const InputFile *file, int64_t addend) { +void elf::writePPC32PltCallStub(uint8_t *buf, uint64_t gotPltVA, + const InputFile *file, int64_t addend) { if (!config->isPic) { write32(buf + 0, 0x3d600000 | (gotPltVA + 0x8000) >> 16); // lis r11,ha write32(buf + 4, 0x816b0000 | (uint16_t)gotPltVA); // lwz r11,l(r11) @@ -799,7 +798,7 @@ write32(buf + 4, 0x4e800420); // bctr } -void writePPC64LoadAndBranch(uint8_t *buf, int64_t offset) { +void elf::writePPC64LoadAndBranch(uint8_t *buf, int64_t offset) { uint16_t offHa = (offset + 0x8000) >> 16; uint16_t offLo = offset & 0xffff; @@ -956,7 +955,7 @@ return make(s, a); } -Thunk *addThunk(const InputSection &isec, Relocation &rel) { +Thunk *elf::addThunk(const InputSection &isec, Relocation &rel) { Symbol &s = *rel.sym; int64_t a = rel.addend; @@ -977,6 +976,3 @@ llvm_unreachable("add Thunk only supported for ARM, Mips and PowerPC"); } - -} // end namespace elf -} // end namespace lld diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -38,9 +38,9 @@ using namespace llvm::object; using namespace llvm::support; using namespace llvm::support::endian; +using namespace lld; +using namespace lld::elf; -namespace lld { -namespace elf { namespace { // The writer writes a SymbolTable result to a file. template class Writer { @@ -95,7 +95,7 @@ return name.startswith(prefix) || name == prefix.drop_back(); } -StringRef getOutputSectionName(const InputSectionBase *s) { +StringRef elf::getOutputSectionName(const InputSectionBase *s) { if (config->relocatable) return s->name; @@ -152,7 +152,7 @@ !config->dynamicLinker.empty() && script->needsInterpSection(); } -template void writeResult() { +template void elf::writeResult() { llvm::TimeTraceScope timeScope("Write output file"); Writer().run(); } @@ -177,7 +177,7 @@ phdrs.erase(it, phdrs.end()); } -void copySectionsIntoPartitions() { +void elf::copySectionsIntoPartitions() { std::vector newSections; for (unsigned part = 2; part != partitions.size() + 1; ++part) { for (InputSectionBase *s : inputSections) { @@ -199,7 +199,7 @@ newSections.end()); } -void combineEhSections() { +void elf::combineEhSections() { for (InputSectionBase *&s : inputSections) { // Ignore dead sections and the partition end marker (.part.end), // whose partition number is out of bounds. @@ -240,7 +240,7 @@ // The linker is expected to define some symbols depending on // the linking result. This function defines such symbols. -void addReservedSymbols() { +void elf::addReservedSymbols() { if (config->emachine == EM_MIPS) { // Define _gp for MIPS. st_value of _gp symbol will be updated by Writer // so that it points to an absolute address which by default is relative @@ -333,7 +333,7 @@ return nullptr; } -template void createSyntheticSections() { +template void elf::createSyntheticSections() { // Initialize all pointers with NULL. This is needed because // you can call lld::elf::main more than once as a library. memset(&Out::first, 0, sizeof(Out)); @@ -2960,15 +2960,12 @@ part.buildId->writeBuildId(buildId); } -template void createSyntheticSections(); -template void createSyntheticSections(); -template void createSyntheticSections(); -template void createSyntheticSections(); +template void elf::createSyntheticSections(); +template void elf::createSyntheticSections(); +template void elf::createSyntheticSections(); +template void elf::createSyntheticSections(); -template void writeResult(); -template void writeResult(); -template void writeResult(); -template void writeResult(); - -} // namespace elf -} // namespace lld +template void elf::writeResult(); +template void elf::writeResult(); +template void elf::writeResult(); +template void elf::writeResult();