From ce039266c11a521f6702f413e04875c29d340822 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Fri, 6 Jan 2017 10:04:08 +0000 Subject: [PATCH] Merge elf::toString and coff::toString. The two overloaded functions hid each other. This patch merges them. llvm-svn: 291222 --- lld/COFF/InputFiles.cpp | 7 +++---- lld/COFF/InputFiles.h | 5 ++--- lld/COFF/Symbols.cpp | 7 +++---- lld/COFF/Symbols.h | 5 ++--- lld/ELF/InputFiles.cpp | 2 +- lld/ELF/InputFiles.h | 11 +++++++---- lld/ELF/InputSection.cpp | 10 +++++----- lld/ELF/InputSection.h | 5 ++--- lld/ELF/Symbols.cpp | 2 +- lld/ELF/Symbols.h | 5 ++--- lld/ELF/Target.cpp | 8 ++++---- lld/ELF/Target.h | 3 ++- 12 files changed, 34 insertions(+), 36 deletions(-) diff --git a/lld/COFF/InputFiles.cpp b/lld/COFF/InputFiles.cpp index 0a97c2185f89..cde355cd3f34 100644 --- a/lld/COFF/InputFiles.cpp +++ b/lld/COFF/InputFiles.cpp @@ -372,6 +372,8 @@ MachineTypes BitcodeFile::getMachineType() { return IMAGE_FILE_MACHINE_UNKNOWN; } } +} // namespace coff +} // namespace lld // Returns the last element of a path, which is supposed to be a filename. static StringRef getBasename(StringRef Path) { @@ -382,7 +384,7 @@ static StringRef getBasename(StringRef Path) { } // Returns a string in the format of "foo.obj" or "foo.obj(bar.lib)". -std::string toString(InputFile *File) { +std::string lld::toString(coff::InputFile *File) { if (!File) return "(internal)"; if (File->ParentName.empty()) @@ -393,6 +395,3 @@ std::string toString(InputFile *File) { .str(); return StringRef(Res).lower(); } - -} // namespace coff -} // namespace lld diff --git a/lld/COFF/InputFiles.h b/lld/COFF/InputFiles.h index 498a1743e985..1b5d42939cca 100644 --- a/lld/COFF/InputFiles.h +++ b/lld/COFF/InputFiles.h @@ -202,10 +202,9 @@ private: llvm::BumpPtrAllocator Alloc; std::unique_ptr M; }; - -std::string toString(InputFile *File); - } // namespace coff + +std::string toString(coff::InputFile *File); } // namespace lld #endif diff --git a/lld/COFF/Symbols.cpp b/lld/COFF/Symbols.cpp index 6de85d581f49..b940bebf36ab 100644 --- a/lld/COFF/Symbols.cpp +++ b/lld/COFF/Symbols.cpp @@ -73,13 +73,12 @@ Defined *Undefined::getWeakAlias() { return D; return nullptr; } +} // namespace coff // Returns a symbol name for an error message. -std::string toString(SymbolBody &B) { - if (Optional S = demangle(B.getName())) +std::string lld::toString(coff::SymbolBody &B) { + if (Optional S = coff::demangle(B.getName())) return ("\"" + *S + "\" (" + B.getName() + ")").str(); return B.getName(); } - -} // namespace coff } // namespace lld diff --git a/lld/COFF/Symbols.h b/lld/COFF/Symbols.h index bc9ad4aa8aff..1ca7366364d7 100644 --- a/lld/COFF/Symbols.h +++ b/lld/COFF/Symbols.h @@ -428,10 +428,9 @@ inline Symbol *SymbolBody::symbol() { return reinterpret_cast(reinterpret_cast(this) - offsetof(Symbol, Body)); } - -std::string toString(SymbolBody &B); - } // namespace coff + +std::string toString(coff::SymbolBody &B); } // namespace lld #endif diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp index 522f9603b5eb..bd9f25873c87 100644 --- a/lld/ELF/InputFiles.cpp +++ b/lld/ELF/InputFiles.cpp @@ -96,7 +96,7 @@ std::string elf::ObjectFile::getLineInfo(InputSectionBase *S, } // Returns "(internal)", "foo.a(bar.o)" or "baz.o". -std::string elf::toString(const InputFile *F) { +std::string lld::toString(const InputFile *F) { if (!F) return "(internal)"; if (!F->ArchiveName.empty()) diff --git a/lld/ELF/InputFiles.h b/lld/ELF/InputFiles.h index aba1d71379b0..8b188348199f 100644 --- a/lld/ELF/InputFiles.h +++ b/lld/ELF/InputFiles.h @@ -35,11 +35,17 @@ class InputFile; } namespace lld { +namespace elf { +class InputFile; +} + +// Returns "(internal)", "foo.a(bar.o)" or "baz.o". +std::string toString(const elf::InputFile *F); + namespace elf { using llvm::object::Archive; -class InputFile; class Lazy; class SymbolBody; @@ -84,9 +90,6 @@ private: const Kind FileKind; }; -// Returns "(internal)", "foo.a(bar.o)" or "baz.o". -std::string toString(const InputFile *F); - template class ELFFileBase : public InputFile { public: typedef typename ELFT::Shdr Elf_Shdr; diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp index 805e51dab507..e87d92aa207c 100644 --- a/lld/ELF/InputSection.cpp +++ b/lld/ELF/InputSection.cpp @@ -34,7 +34,7 @@ using namespace lld::elf; // Returns a string to construct an error message. template -std::string elf::toString(const InputSectionBase *Sec) { +std::string lld::toString(const InputSectionBase *Sec) { return (Sec->getFile()->getName() + ":(" + Sec->Name + ")").str(); } @@ -844,7 +844,7 @@ template class elf::MergeInputSection; template class elf::MergeInputSection; template class elf::MergeInputSection; -template std::string elf::toString(const InputSectionBase *); -template std::string elf::toString(const InputSectionBase *); -template std::string elf::toString(const InputSectionBase *); -template std::string elf::toString(const InputSectionBase *); +template std::string lld::toString(const InputSectionBase *); +template std::string lld::toString(const InputSectionBase *); +template std::string lld::toString(const InputSectionBase *); +template std::string lld::toString(const InputSectionBase *); diff --git a/lld/ELF/InputSection.h b/lld/ELF/InputSection.h index adbc1e1e3829..fc7a7fb60973 100644 --- a/lld/ELF/InputSection.h +++ b/lld/ELF/InputSection.h @@ -318,10 +318,9 @@ private: }; template InputSection InputSection::Discarded; - -template std::string toString(const InputSectionBase *); - } // namespace elf + +template std::string toString(const elf::InputSectionBase *); } // namespace lld #endif diff --git a/lld/ELF/Symbols.cpp b/lld/ELF/Symbols.cpp index f168d37bdf0a..72bcff4e0f4d 100644 --- a/lld/ELF/Symbols.cpp +++ b/lld/ELF/Symbols.cpp @@ -305,7 +305,7 @@ void elf::printTraceSymbol(Symbol *Sym) { } // Returns a symbol for an error message. -std::string elf::toString(const SymbolBody &B) { +std::string lld::toString(const SymbolBody &B) { if (Config->Demangle) if (Optional S = demangle(B.getName())) return *S; diff --git a/lld/ELF/Symbols.h b/lld/ELF/Symbols.h index cbf8fa81a138..38889571679c 100644 --- a/lld/ELF/Symbols.h +++ b/lld/ELF/Symbols.h @@ -453,10 +453,9 @@ inline Symbol *SymbolBody::symbol() { return reinterpret_cast(reinterpret_cast(this) - offsetof(Symbol, Body)); } - -std::string toString(const SymbolBody &B); - } // namespace elf + +std::string toString(const elf::SymbolBody &B); } // namespace lld #endif diff --git a/lld/ELF/Target.cpp b/lld/ELF/Target.cpp index d82e654b9c4c..cb2b178fa849 100644 --- a/lld/ELF/Target.cpp +++ b/lld/ELF/Target.cpp @@ -44,6 +44,10 @@ using namespace llvm::object; using namespace llvm::support::endian; using namespace llvm::ELF; +std::string lld::toString(uint32_t Type) { + return getELFRelocationTypeName(elf::Config->EMachine, Type); +} + namespace lld { namespace elf { @@ -52,10 +56,6 @@ TargetInfo *Target; static void or32le(uint8_t *P, int32_t V) { write32le(P, read32le(P) | V); } static void or32be(uint8_t *P, int32_t V) { write32be(P, read32be(P) | V); } -std::string toString(uint32_t Type) { - return getELFRelocationTypeName(Config->EMachine, Type); -} - template static std::string getErrorLoc(uint8_t *Loc) { for (InputSectionData *D : Symtab::X->Sections) { auto *IS = dyn_cast_or_null>(D); diff --git a/lld/ELF/Target.h b/lld/ELF/Target.h index 156a2c023230..752f9cd5ee4e 100644 --- a/lld/ELF/Target.h +++ b/lld/ELF/Target.h @@ -104,13 +104,14 @@ public: virtual void relaxTlsLdToLe(uint8_t *Loc, uint32_t Type, uint64_t Val) const; }; -std::string toString(uint32_t RelType); uint64_t getPPC64TocBase(); uint64_t getAArch64Page(uint64_t Expr); extern TargetInfo *Target; TargetInfo *createTarget(); } + +std::string toString(uint32_t RelType); } #endif