[llvm] r240780 - Implement elf_section_iterator and getELFType().
Rafael Espindola
rafael.espindola at gmail.com
Fri Jun 26 06:11:16 PDT 2015
Author: rafael
Date: Fri Jun 26 08:11:15 2015
New Revision: 240780
URL: http://llvm.org/viewvc/llvm-project?rev=240780&view=rev
Log:
Implement elf_section_iterator and getELFType().
And with those, simplify getSymbolNMTypeChar.
Modified:
llvm/trunk/include/llvm/Object/ELFObjectFile.h
llvm/trunk/tools/llvm-nm/llvm-nm.cpp
Modified: llvm/trunk/include/llvm/Object/ELFObjectFile.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/ELFObjectFile.h?rev=240780&r1=240779&r2=240780&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/ELFObjectFile.h (original)
+++ llvm/trunk/include/llvm/Object/ELFObjectFile.h Fri Jun 26 08:11:15 2015
@@ -47,6 +47,8 @@ protected:
virtual uint64_t getSymbolSize(DataRefImpl Symb) const = 0;
virtual uint8_t getSymbolOther(DataRefImpl Symb) const = 0;
+ virtual uint8_t getSymbolELFType(DataRefImpl Symb) const = 0;
+
virtual uint32_t getSectionType(DataRefImpl Sec) const = 0;
virtual uint64_t getSectionFlags(DataRefImpl Sec) const = 0;
@@ -84,6 +86,21 @@ public:
}
};
+class elf_section_iterator : public section_iterator {
+public:
+ elf_section_iterator(const section_iterator &B) : section_iterator(B) {
+ assert(isa<ELFObjectFileBase>(B->getObject()));
+ }
+
+ const ELFSectionRef *operator->() const {
+ return static_cast<const ELFSectionRef *>(section_iterator::operator->());
+ }
+
+ const ELFSectionRef &operator*() const {
+ return static_cast<const ELFSectionRef &>(section_iterator::operator*());
+ }
+};
+
class ELFSymbolRef : public SymbolRef {
public:
ELFSymbolRef(const SymbolRef &B) : SymbolRef(B) {
@@ -101,6 +118,10 @@ public:
uint8_t getOther() const {
return getObject()->getSymbolOther(getRawDataRefImpl());
}
+
+ uint8_t getELFType() const {
+ return getObject()->getSymbolELFType(getRawDataRefImpl());
+ }
};
class elf_symbol_iterator : public symbol_iterator {
@@ -155,6 +176,7 @@ protected:
uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override;
uint32_t getSymbolFlags(DataRefImpl Symb) const override;
uint8_t getSymbolOther(DataRefImpl Symb) const override;
+ uint8_t getSymbolELFType(DataRefImpl Symb) const override;
SymbolRef::Type getSymbolType(DataRefImpl Symb) const override;
section_iterator getSymbolSection(const Elf_Sym *Symb) const;
std::error_code getSymbolSection(DataRefImpl Symb,
@@ -405,6 +427,11 @@ uint8_t ELFObjectFile<ELFT>::getSymbolOt
}
template <class ELFT>
+uint8_t ELFObjectFile<ELFT>::getSymbolELFType(DataRefImpl Symb) const {
+ return toELFSymIter(Symb)->getType();
+}
+
+template <class ELFT>
SymbolRef::Type ELFObjectFile<ELFT>::getSymbolType(DataRefImpl Symb) const {
const Elf_Sym *ESym = getSymbol(Symb);
Modified: llvm/trunk/tools/llvm-nm/llvm-nm.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-nm/llvm-nm.cpp?rev=240780&r1=240779&r2=240780&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-nm/llvm-nm.cpp (original)
+++ llvm/trunk/tools/llvm-nm/llvm-nm.cpp Fri Jun 26 08:11:15 2015
@@ -630,25 +630,20 @@ static void sortAndPrintSymbolList(Symbo
SymbolList.clear();
}
-template <class ELFT>
-static char getSymbolNMTypeChar(ELFObjectFile<ELFT> &Obj,
+static char getSymbolNMTypeChar(ELFObjectFileBase &Obj,
basic_symbol_iterator I) {
- typedef typename ELFObjectFile<ELFT>::Elf_Sym Elf_Sym;
- typedef typename ELFObjectFile<ELFT>::Elf_Shdr Elf_Shdr;
-
// OK, this is ELF
- symbol_iterator SymI(I);
+ elf_symbol_iterator SymI(I);
- DataRefImpl Symb = I->getRawDataRefImpl();
- const Elf_Sym *ESym = Obj.getSymbol(Symb);
- const ELFFile<ELFT> &EF = *Obj.getELFFile();
- const Elf_Shdr *ESec = EF.getSection(ESym);
+ elf_section_iterator SecI = Obj.section_end();
+ if (error(SymI->getSection(SecI)))
+ return '?';
- if (ESec) {
- switch (ESec->sh_type) {
+ if (SecI != Obj.section_end()) {
+ switch (SecI->getType()) {
case ELF::SHT_PROGBITS:
case ELF::SHT_DYNAMIC:
- switch (ESec->sh_flags) {
+ switch (SecI->getFlags()) {
case (ELF::SHF_ALLOC | ELF::SHF_EXECINSTR):
return 't';
case (ELF::SHF_TLS | ELF::SHF_ALLOC | ELF::SHF_WRITE):
@@ -665,7 +660,7 @@ static char getSymbolNMTypeChar(ELFObjec
}
}
- if (ESym->getType() == ELF::STT_SECTION) {
+ if (SymI->getELFType() == ELF::STT_SECTION) {
StringRef Name;
if (error(SymI->getName(Name)))
return '?';
@@ -828,14 +823,8 @@ static char getNMTypeChar(SymbolicFile &
Ret = getSymbolNMTypeChar(*COFF, I);
else if (MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(&Obj))
Ret = getSymbolNMTypeChar(*MachO, I);
- else if (ELF32LEObjectFile *ELF = dyn_cast<ELF32LEObjectFile>(&Obj))
- Ret = getSymbolNMTypeChar(*ELF, I);
- else if (ELF64LEObjectFile *ELF = dyn_cast<ELF64LEObjectFile>(&Obj))
- Ret = getSymbolNMTypeChar(*ELF, I);
- else if (ELF32BEObjectFile *ELF = dyn_cast<ELF32BEObjectFile>(&Obj))
- Ret = getSymbolNMTypeChar(*ELF, I);
else
- Ret = getSymbolNMTypeChar(cast<ELF64BEObjectFile>(Obj), I);
+ Ret = getSymbolNMTypeChar(cast<ELFObjectFileBase>(Obj), I);
if (Symflags & object::SymbolRef::SF_Global)
Ret = toupper(Ret);
More information about the llvm-commits
mailing list