Skip to content

Commit

Permalink
Implement containsSymbol with other lower level methods.
Browse files Browse the repository at this point in the history
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241112 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
espindola committed Jun 30, 2015
1 parent ce77289 commit d231306
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 44 deletions.
1 change: 0 additions & 1 deletion include/llvm/Object/COFF.h
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,6 @@ class COFFObjectFile : public ObjectFile {
bool isSectionData(DataRefImpl Sec) const override;
bool isSectionBSS(DataRefImpl Sec) const override;
bool isSectionVirtual(DataRefImpl Sec) const override;
bool sectionContainsSymbol(DataRefImpl Sec, DataRefImpl Symb) const override;
relocation_iterator section_rel_begin(DataRefImpl Sec) const override;
relocation_iterator section_rel_end(DataRefImpl Sec) const override;

Expand Down
12 changes: 0 additions & 12 deletions include/llvm/Object/ELFObjectFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ template <class ELFT> class ELFObjectFile : public ELFObjectFileBase {
bool isSectionData(DataRefImpl Sec) const override;
bool isSectionBSS(DataRefImpl Sec) const override;
bool isSectionVirtual(DataRefImpl Sec) const override;
bool sectionContainsSymbol(DataRefImpl Sec, DataRefImpl Symb) const override;
relocation_iterator section_rel_begin(DataRefImpl Sec) const override;
relocation_iterator section_rel_end(DataRefImpl Sec) const override;
section_iterator getRelocatedSection(DataRefImpl Sec) const override;
Expand Down Expand Up @@ -595,17 +594,6 @@ bool ELFObjectFile<ELFT>::isSectionVirtual(DataRefImpl Sec) const {
return toELFShdrIter(Sec)->sh_type == ELF::SHT_NOBITS;
}

template <class ELFT>
bool ELFObjectFile<ELFT>::sectionContainsSymbol(DataRefImpl Sec,
DataRefImpl Symb) const {
const Elf_Sym *ESym = toELFSymIter(Symb);

uintX_t Index = ESym->st_shndx;
bool Reserved = Index >= ELF::SHN_LORESERVE && Index <= ELF::SHN_HIRESERVE;

return !Reserved && (&*toELFShdrIter(Sec) == EF.getSection(ESym->st_shndx));
}

template <class ELFT>
relocation_iterator
ELFObjectFile<ELFT>::section_rel_begin(DataRefImpl Sec) const {
Expand Down
1 change: 0 additions & 1 deletion include/llvm/Object/MachO.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ class MachOObjectFile : public ObjectFile {
bool isSectionData(DataRefImpl Sec) const override;
bool isSectionBSS(DataRefImpl Sec) const override;
bool isSectionVirtual(DataRefImpl Sec) const override;
bool sectionContainsSymbol(DataRefImpl Sec, DataRefImpl Symb) const override;
relocation_iterator section_rel_begin(DataRefImpl Sec) const override;
relocation_iterator section_rel_end(DataRefImpl Sec) const override;

Expand Down
7 changes: 0 additions & 7 deletions include/llvm/Object/ObjectFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,6 @@ class ObjectFile : public SymbolicFile {
virtual bool isSectionBSS(DataRefImpl Sec) const = 0;
// A section is 'virtual' if its contents aren't present in the object image.
virtual bool isSectionVirtual(DataRefImpl Sec) const = 0;
virtual bool sectionContainsSymbol(DataRefImpl Sec,
DataRefImpl Symb) const = 0;
virtual relocation_iterator section_rel_begin(DataRefImpl Sec) const = 0;
virtual relocation_iterator section_rel_end(DataRefImpl Sec) const = 0;
virtual section_iterator getRelocatedSection(DataRefImpl Sec) const;
Expand Down Expand Up @@ -400,11 +398,6 @@ inline bool SectionRef::isVirtual() const {
return OwningObject->isSectionVirtual(SectionPimpl);
}

inline bool SectionRef::containsSymbol(SymbolRef S) const {
return OwningObject->sectionContainsSymbol(SectionPimpl,
S.getRawDataRefImpl());
}

inline relocation_iterator SectionRef::relocation_begin() const {
return OwningObject->section_rel_begin(SectionPimpl);
}
Expand Down
8 changes: 0 additions & 8 deletions lib/Object/COFFObjectFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,14 +322,6 @@ bool COFFObjectFile::isSectionVirtual(DataRefImpl Ref) const {
return Sec->PointerToRawData == 0;
}

bool COFFObjectFile::sectionContainsSymbol(DataRefImpl SecRef,
DataRefImpl SymbRef) const {
const coff_section *Sec = toSec(SecRef);
COFFSymbolRef Symb = getCOFFSymbol(SymbRef);
int32_t SecNumber = (Sec - SectionTable) + 1;
return SecNumber == Symb.getSectionNumber();
}

static uint32_t getNumberOfRelocations(const coff_section *Sec,
MemoryBufferRef M, const uint8_t *base) {
// The field for the number of relocations in COFF section table is only
Expand Down
15 changes: 0 additions & 15 deletions lib/Object/MachOObjectFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -567,21 +567,6 @@ bool MachOObjectFile::isSectionVirtual(DataRefImpl Sec) const {
return false;
}

bool MachOObjectFile::sectionContainsSymbol(DataRefImpl Sec,
DataRefImpl Symb) const {
SymbolRef::Type ST = getSymbolType(Symb);
if (ST == SymbolRef::ST_Unknown)
return false;

uint64_t SectBegin = getSectionAddress(Sec);
uint64_t SectEnd = getSectionSize(Sec);
SectEnd += SectBegin;

uint64_t SymAddr;
getSymbolAddress(Symb, SymAddr);
return (SymAddr >= SectBegin) && (SymAddr < SectEnd);
}

relocation_iterator MachOObjectFile::section_rel_begin(DataRefImpl Sec) const {
DataRefImpl Ret;
Ret.d.a = Sec.d.a;
Expand Down
7 changes: 7 additions & 0 deletions lib/Object/ObjectFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ void ObjectFile::anchor() { }
ObjectFile::ObjectFile(unsigned int Type, MemoryBufferRef Source)
: SymbolicFile(Type, Source) {}

bool SectionRef::containsSymbol(SymbolRef S) const {
section_iterator SymSec = getObject()->section_end();
if (S.getSection(SymSec))
return false;
return *this == *SymSec;
}

std::error_code ObjectFile::printSymbolName(raw_ostream &OS,
DataRefImpl Symb) const {
StringRef Name;
Expand Down

0 comments on commit d231306

Please sign in to comment.