[llvm] r240777 - Simplify getSymbolType.
Rafael Espindola
rafael.espindola at gmail.com
Fri Jun 26 05:18:50 PDT 2015
Author: rafael
Date: Fri Jun 26 07:18:49 2015
New Revision: 240777
URL: http://llvm.org/viewvc/llvm-project?rev=240777&view=rev
Log:
Simplify getSymbolType.
This is still a really odd function. Most calls are in object format specific
contexts and should probably be replaced with a more direct query, but at least
now this is not too obnoxious to use.
Modified:
llvm/trunk/include/llvm/Object/COFF.h
llvm/trunk/include/llvm/Object/ELFObjectFile.h
llvm/trunk/include/llvm/Object/MachO.h
llvm/trunk/include/llvm/Object/ObjectFile.h
llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
llvm/trunk/lib/Object/COFFObjectFile.cpp
llvm/trunk/lib/Object/MachOObjectFile.cpp
llvm/trunk/tools/dsymutil/MachODebugMapParser.cpp
llvm/trunk/tools/llvm-objdump/MachODump.cpp
llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp
llvm/trunk/tools/llvm-readobj/ARMWinEHPrinter.cpp
llvm/trunk/tools/llvm-rtdyld/llvm-rtdyld.cpp
llvm/trunk/tools/llvm-symbolizer/LLVMSymbolize.cpp
Modified: llvm/trunk/include/llvm/Object/COFF.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/COFF.h?rev=240777&r1=240776&r2=240777&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/COFF.h (original)
+++ llvm/trunk/include/llvm/Object/COFF.h Fri Jun 26 07:18:49 2015
@@ -639,8 +639,7 @@ protected:
uint64_t getSymbolValue(DataRefImpl Symb) const override;
uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override;
uint32_t getSymbolFlags(DataRefImpl Symb) const override;
- std::error_code getSymbolType(DataRefImpl Symb,
- SymbolRef::Type &Res) const override;
+ SymbolRef::Type getSymbolType(DataRefImpl Symb) const override;
std::error_code getSymbolSection(DataRefImpl Symb,
section_iterator &Res) const override;
void moveSectionNext(DataRefImpl &Sec) const override;
Modified: llvm/trunk/include/llvm/Object/ELFObjectFile.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/ELFObjectFile.h?rev=240777&r1=240776&r2=240777&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/ELFObjectFile.h (original)
+++ llvm/trunk/include/llvm/Object/ELFObjectFile.h Fri Jun 26 07:18:49 2015
@@ -136,8 +136,7 @@ protected:
uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override;
uint32_t getSymbolFlags(DataRefImpl Symb) const override;
uint8_t getSymbolOther(DataRefImpl Symb) const override;
- std::error_code getSymbolType(DataRefImpl Symb,
- SymbolRef::Type &Res) const override;
+ SymbolRef::Type getSymbolType(DataRefImpl Symb) const override;
section_iterator getSymbolSection(const Elf_Sym *Symb) const;
std::error_code getSymbolSection(DataRefImpl Symb,
section_iterator &Res) const override;
@@ -390,34 +389,25 @@ uint8_t ELFObjectFile<ELFT>::getSymbolOt
}
template <class ELFT>
-std::error_code
-ELFObjectFile<ELFT>::getSymbolType(DataRefImpl Symb,
- SymbolRef::Type &Result) const {
+SymbolRef::Type ELFObjectFile<ELFT>::getSymbolType(DataRefImpl Symb) const {
const Elf_Sym *ESym = getSymbol(Symb);
switch (ESym->getType()) {
case ELF::STT_NOTYPE:
- Result = SymbolRef::ST_Unknown;
- break;
+ return SymbolRef::ST_Unknown;
case ELF::STT_SECTION:
- Result = SymbolRef::ST_Debug;
- break;
+ return SymbolRef::ST_Debug;
case ELF::STT_FILE:
- Result = SymbolRef::ST_File;
- break;
+ return SymbolRef::ST_File;
case ELF::STT_FUNC:
- Result = SymbolRef::ST_Function;
- break;
+ return SymbolRef::ST_Function;
case ELF::STT_OBJECT:
case ELF::STT_COMMON:
case ELF::STT_TLS:
- Result = SymbolRef::ST_Data;
- break;
+ return SymbolRef::ST_Data;
default:
- Result = SymbolRef::ST_Other;
- break;
+ return SymbolRef::ST_Other;
}
- return std::error_code();
}
template <class ELFT>
Modified: llvm/trunk/include/llvm/Object/MachO.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/MachO.h?rev=240777&r1=240776&r2=240777&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/MachO.h (original)
+++ llvm/trunk/include/llvm/Object/MachO.h Fri Jun 26 07:18:49 2015
@@ -211,8 +211,7 @@ public:
uint64_t getSymbolValue(DataRefImpl Symb) const override;
uint32_t getSymbolAlignment(DataRefImpl Symb) const override;
uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override;
- std::error_code getSymbolType(DataRefImpl Symb,
- SymbolRef::Type &Res) const override;
+ SymbolRef::Type getSymbolType(DataRefImpl Symb) const override;
uint32_t getSymbolFlags(DataRefImpl Symb) const override;
std::error_code getSymbolSection(DataRefImpl Symb,
section_iterator &Res) const override;
Modified: llvm/trunk/include/llvm/Object/ObjectFile.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/ObjectFile.h?rev=240777&r1=240776&r2=240777&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/ObjectFile.h (original)
+++ llvm/trunk/include/llvm/Object/ObjectFile.h Fri Jun 26 07:18:49 2015
@@ -150,7 +150,7 @@ public:
/// @brief Get the alignment of this symbol as the actual value (not log 2).
uint32_t getAlignment() const;
uint64_t getCommonSize() const;
- std::error_code getType(SymbolRef::Type &Result) const;
+ SymbolRef::Type getType() const;
/// @brief Get section this symbol is defined in reference to. Result is
/// end_sections() if it is undefined or is an absolute symbol.
@@ -210,8 +210,7 @@ protected:
virtual uint64_t getSymbolValue(DataRefImpl Symb) const = 0;
virtual uint32_t getSymbolAlignment(DataRefImpl Symb) const;
virtual uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const = 0;
- virtual std::error_code getSymbolType(DataRefImpl Symb,
- SymbolRef::Type &Res) const = 0;
+ virtual SymbolRef::Type getSymbolType(DataRefImpl Symb) const = 0;
virtual std::error_code getSymbolSection(DataRefImpl Symb,
section_iterator &Res) const = 0;
@@ -347,8 +346,8 @@ inline std::error_code SymbolRef::getSec
return getObject()->getSymbolSection(getRawDataRefImpl(), Result);
}
-inline std::error_code SymbolRef::getType(SymbolRef::Type &Result) const {
- return getObject()->getSymbolType(getRawDataRefImpl(), Result);
+inline SymbolRef::Type SymbolRef::getType() const {
+ return getObject()->getSymbolType(getRawDataRefImpl());
}
inline const ObjectFile *SymbolRef::getObject() const {
Modified: llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp?rev=240777&r1=240776&r2=240777&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp Fri Jun 26 07:18:49 2015
@@ -175,8 +175,7 @@ RuntimeDyldImpl::loadObjectImpl(const ob
if (IsCommon)
CommonSymbols.push_back(*I);
else {
- object::SymbolRef::Type SymType;
- Check(I->getType(SymType));
+ object::SymbolRef::Type SymType = I->getType();
if (SymType == object::SymbolRef::ST_Function ||
SymType == object::SymbolRef::ST_Data ||
Modified: llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp?rev=240777&r1=240776&r2=240777&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp Fri Jun 26 07:18:49 2015
@@ -1082,7 +1082,7 @@ relocation_iterator RuntimeDyldELF::proc
RTDyldSymbolTable::const_iterator gsi = GlobalSymbolTable.end();
if (Symbol != Obj.symbol_end()) {
gsi = GlobalSymbolTable.find(TargetName.data());
- Symbol->getType(SymType);
+ SymType = Symbol->getType();
}
if (gsi != GlobalSymbolTable.end()) {
const auto &SymInfo = gsi->second;
Modified: llvm/trunk/lib/Object/COFFObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/COFFObjectFile.cpp?rev=240777&r1=240776&r2=240777&view=diff
==============================================================================
--- llvm/trunk/lib/Object/COFFObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/COFFObjectFile.cpp Fri Jun 26 07:18:49 2015
@@ -177,36 +177,27 @@ std::error_code COFFObjectFile::getSymbo
return std::error_code();
}
-std::error_code COFFObjectFile::getSymbolType(DataRefImpl Ref,
- SymbolRef::Type &Result) const {
+SymbolRef::Type COFFObjectFile::getSymbolType(DataRefImpl Ref) const {
COFFSymbolRef Symb = getCOFFSymbol(Ref);
int32_t SectionNumber = Symb.getSectionNumber();
- Result = SymbolRef::ST_Other;
- if (Symb.isAnyUndefined()) {
- Result = SymbolRef::ST_Unknown;
- } else if (Symb.isFunctionDefinition()) {
- Result = SymbolRef::ST_Function;
- } else if (Symb.isCommon()) {
- Result = SymbolRef::ST_Data;
- } else if (Symb.isFileRecord()) {
- Result = SymbolRef::ST_File;
- } else if (SectionNumber == COFF::IMAGE_SYM_DEBUG ||
- Symb.isSectionDefinition()) {
- // TODO: perhaps we need a new symbol type ST_Section.
- Result = SymbolRef::ST_Debug;
- } else if (!COFF::isReservedSectionNumber(SectionNumber)) {
- const coff_section *Section = nullptr;
- if (std::error_code EC = getSection(SectionNumber, Section))
- return EC;
- uint32_t Characteristics = Section->Characteristics;
- if (Characteristics & COFF::IMAGE_SCN_CNT_CODE)
- Result = SymbolRef::ST_Function;
- else if (Characteristics & (COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
- COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA))
- Result = SymbolRef::ST_Data;
- }
- return std::error_code();
+ if (Symb.isAnyUndefined())
+ return SymbolRef::ST_Unknown;
+ if (Symb.isFunctionDefinition())
+ return SymbolRef::ST_Function;
+ if (Symb.isCommon())
+ return SymbolRef::ST_Data;
+ if (Symb.isFileRecord())
+ return SymbolRef::ST_File;
+
+ // TODO: perhaps we need a new symbol type ST_Section.
+ if (SectionNumber == COFF::IMAGE_SYM_DEBUG || Symb.isSectionDefinition())
+ return SymbolRef::ST_Debug;
+
+ if (!COFF::isReservedSectionNumber(SectionNumber))
+ return SymbolRef::ST_Data;
+
+ return SymbolRef::ST_Other;
}
uint32_t COFFObjectFile::getSymbolFlags(DataRefImpl Ref) const {
Modified: llvm/trunk/lib/Object/MachOObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/MachOObjectFile.cpp?rev=240777&r1=240776&r2=240777&view=diff
==============================================================================
--- llvm/trunk/lib/Object/MachOObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/MachOObjectFile.cpp Fri Jun 26 07:18:49 2015
@@ -399,28 +399,21 @@ uint64_t MachOObjectFile::getCommonSymbo
return Value;
}
-std::error_code MachOObjectFile::getSymbolType(DataRefImpl Symb,
- SymbolRef::Type &Res) const {
+SymbolRef::Type MachOObjectFile::getSymbolType(DataRefImpl Symb) const {
MachO::nlist_base Entry = getSymbolTableEntryBase(this, Symb);
uint8_t n_type = Entry.n_type;
- Res = SymbolRef::ST_Other;
-
// If this is a STAB debugging symbol, we can do nothing more.
- if (n_type & MachO::N_STAB) {
- Res = SymbolRef::ST_Debug;
- return std::error_code();
- }
+ if (n_type & MachO::N_STAB)
+ return SymbolRef::ST_Debug;
switch (n_type & MachO::N_TYPE) {
case MachO::N_UNDF :
- Res = SymbolRef::ST_Unknown;
- break;
+ return SymbolRef::ST_Unknown;
case MachO::N_SECT :
- Res = SymbolRef::ST_Function;
- break;
+ return SymbolRef::ST_Function;
}
- return std::error_code();
+ return SymbolRef::ST_Other;
}
uint32_t MachOObjectFile::getSymbolFlags(DataRefImpl DRI) const {
@@ -576,8 +569,7 @@ bool MachOObjectFile::isSectionVirtual(D
bool MachOObjectFile::sectionContainsSymbol(DataRefImpl Sec,
DataRefImpl Symb) const {
- SymbolRef::Type ST;
- this->getSymbolType(Symb, ST);
+ SymbolRef::Type ST = getSymbolType(Symb);
if (ST == SymbolRef::ST_Unknown)
return false;
Modified: llvm/trunk/tools/dsymutil/MachODebugMapParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/dsymutil/MachODebugMapParser.cpp?rev=240777&r1=240776&r2=240777&view=diff
==============================================================================
--- llvm/trunk/tools/dsymutil/MachODebugMapParser.cpp (original)
+++ llvm/trunk/tools/dsymutil/MachODebugMapParser.cpp Fri Jun 26 07:18:49 2015
@@ -221,10 +221,9 @@ void MachODebugMapParser::loadMainBinary
const MachOObjectFile &MainBinary = MainBinaryHolder.GetAs<MachOObjectFile>();
section_iterator Section = MainBinary.section_end();
for (const auto &Sym : MainBinary.symbols()) {
- SymbolRef::Type Type;
+ SymbolRef::Type Type = Sym.getType();
// Skip undefined and STAB entries.
- if (Sym.getType(Type) || (Type & SymbolRef::ST_Debug) ||
- (Type & SymbolRef::ST_Unknown))
+ if ((Type & SymbolRef::ST_Debug) || (Type & SymbolRef::ST_Unknown))
continue;
StringRef Name;
uint64_t Addr;
Modified: llvm/trunk/tools/llvm-objdump/MachODump.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objdump/MachODump.cpp?rev=240777&r1=240776&r2=240777&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objdump/MachODump.cpp (original)
+++ llvm/trunk/tools/llvm-objdump/MachODump.cpp Fri Jun 26 07:18:49 2015
@@ -178,9 +178,8 @@ static const Target *GetTarget(const Mac
struct SymbolSorter {
bool operator()(const SymbolRef &A, const SymbolRef &B) {
- SymbolRef::Type AType, BType;
- A.getType(AType);
- B.getType(BType);
+ SymbolRef::Type AType = A.getType();
+ SymbolRef::Type BType = B.getType();
uint64_t AAddr, BAddr;
if (AType != SymbolRef::ST_Function)
@@ -588,8 +587,7 @@ static void CreateSymbolAddressMap(MachO
SymbolAddressMap *AddrMap) {
// Create a map of symbol addresses to symbol names.
for (const SymbolRef &Symbol : O->symbols()) {
- SymbolRef::Type ST;
- Symbol.getType(ST);
+ SymbolRef::Type ST = Symbol.getType();
if (ST == SymbolRef::ST_Function || ST == SymbolRef::ST_Data ||
ST == SymbolRef::ST_Other) {
uint64_t Address;
@@ -6124,8 +6122,7 @@ static void DisassembleMachO(StringRef F
SymbolAddressMap AddrMap;
bool DisSymNameFound = false;
for (const SymbolRef &Symbol : MachOOF->symbols()) {
- SymbolRef::Type ST;
- Symbol.getType(ST);
+ SymbolRef::Type ST = Symbol.getType();
if (ST == SymbolRef::ST_Function || ST == SymbolRef::ST_Data ||
ST == SymbolRef::ST_Other) {
uint64_t Address;
@@ -6173,8 +6170,7 @@ static void DisassembleMachO(StringRef F
StringRef SymName;
Symbols[SymIdx].getName(SymName);
- SymbolRef::Type ST;
- Symbols[SymIdx].getType(ST);
+ SymbolRef::Type ST = Symbols[SymIdx].getType();
if (ST != SymbolRef::ST_Function)
continue;
@@ -6199,8 +6195,7 @@ static void DisassembleMachO(StringRef F
uint64_t NextSym = 0;
uint64_t NextSymIdx = SymIdx + 1;
while (Symbols.size() > NextSymIdx) {
- SymbolRef::Type NextSymType;
- Symbols[NextSymIdx].getType(NextSymType);
+ SymbolRef::Type NextSymType = Symbols[NextSymIdx].getType();
if (NextSymType == SymbolRef::ST_Function) {
containsNextSym =
Sections[SectIdx].containsSymbol(Symbols[NextSymIdx]);
Modified: llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp?rev=240777&r1=240776&r2=240777&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp (original)
+++ llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp Fri Jun 26 07:18:49 2015
@@ -1078,13 +1078,11 @@ void llvm::PrintSymbolTable(const Object
}
for (const SymbolRef &Symbol : o->symbols()) {
uint64_t Address;
- SymbolRef::Type Type;
+ SymbolRef::Type Type = Symbol.getType();
uint32_t Flags = Symbol.getFlags();
section_iterator Section = o->section_end();
if (error(Symbol.getAddress(Address)))
continue;
- if (error(Symbol.getType(Type)))
- continue;
if (error(Symbol.getSection(Section)))
continue;
StringRef Name;
Modified: llvm/trunk/tools/llvm-readobj/ARMWinEHPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/ARMWinEHPrinter.cpp?rev=240777&r1=240776&r2=240777&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/ARMWinEHPrinter.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/ARMWinEHPrinter.cpp Fri Jun 26 07:18:49 2015
@@ -198,13 +198,8 @@ Decoder::getSectionContaining(const COFF
ErrorOr<object::SymbolRef> Decoder::getSymbol(const COFFObjectFile &COFF,
uint64_t VA, bool FunctionOnly) {
for (const auto &Symbol : COFF.symbols()) {
- if (FunctionOnly) {
- SymbolRef::Type Type;
- if (std::error_code EC = Symbol.getType(Type))
- return EC;
- if (Type != SymbolRef::ST_Function)
- continue;
- }
+ if (FunctionOnly && Symbol.getType() != SymbolRef::ST_Function)
+ continue;
uint64_t Address;
if (std::error_code EC = Symbol.getAddress(Address))
Modified: llvm/trunk/tools/llvm-rtdyld/llvm-rtdyld.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-rtdyld/llvm-rtdyld.cpp?rev=240777&r1=240776&r2=240777&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-rtdyld/llvm-rtdyld.cpp (original)
+++ llvm/trunk/tools/llvm-rtdyld/llvm-rtdyld.cpp Fri Jun 26 07:18:49 2015
@@ -265,10 +265,7 @@ static int printLineInfoForInput(bool Lo
// Use symbol info to iterate functions in the object.
for (const auto &P : SymAddr) {
object::SymbolRef Sym = P.first;
- object::SymbolRef::Type SymType;
- if (Sym.getType(SymType))
- continue;
- if (SymType == object::SymbolRef::ST_Function) {
+ if (Sym.getType() == object::SymbolRef::ST_Function) {
StringRef Name;
uint64_t Addr;
if (Sym.getName(Name))
Modified: llvm/trunk/tools/llvm-symbolizer/LLVMSymbolize.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-symbolizer/LLVMSymbolize.cpp?rev=240777&r1=240776&r2=240777&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-symbolizer/LLVMSymbolize.cpp (original)
+++ llvm/trunk/tools/llvm-symbolizer/LLVMSymbolize.cpp Fri Jun 26 07:18:49 2015
@@ -80,9 +80,7 @@ ModuleInfo::ModuleInfo(ObjectFile *Obj,
void ModuleInfo::addSymbol(const SymbolRef &Symbol, uint64_t SymbolSize,
DataExtractor *OpdExtractor, uint64_t OpdAddress) {
- SymbolRef::Type SymbolType;
- if (error(Symbol.getType(SymbolType)))
- return;
+ SymbolRef::Type SymbolType = Symbol.getType();
if (SymbolType != SymbolRef::ST_Function && SymbolType != SymbolRef::ST_Data)
return;
uint64_t SymbolAddress;
More information about the llvm-commits
mailing list