Skip to content

Commit

Permalink
This only needs a StringRef. No functionality change.
Browse files Browse the repository at this point in the history
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@212371 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
espindola committed Jul 5, 2014
1 parent 38dbb02 commit db8cb22
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
20 changes: 10 additions & 10 deletions include/llvm/Object/ELF.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ StringRef getELFRelocationTypeName(uint32_t Machine, uint32_t Type);

// Subclasses of ELFFile may need this for template instantiation
inline std::pair<unsigned char, unsigned char>
getElfArchType(MemoryBuffer *Object) {
if (Object->getBufferSize() < ELF::EI_NIDENT)
getElfArchType(StringRef Object) {
if (Object.size() < ELF::EI_NIDENT)
return std::make_pair((uint8_t)ELF::ELFCLASSNONE,(uint8_t)ELF::ELFDATANONE);
return std::make_pair((uint8_t) Object->getBufferStart()[ELF::EI_CLASS],
(uint8_t) Object->getBufferStart()[ELF::EI_DATA]);
return std::make_pair((uint8_t)Object.begin()[ELF::EI_CLASS],
(uint8_t)Object.begin()[ELF::EI_DATA]);
}

template <class ELFT>
Expand Down Expand Up @@ -230,10 +230,10 @@ class ELFFile {
typedef SmallVector<const Elf_Shdr *, 2> Sections_t;
typedef DenseMap<unsigned, unsigned> IndexMap_t;

MemoryBuffer *Buf;
StringRef Buf;

const uint8_t *base() const {
return reinterpret_cast<const uint8_t *>(Buf->getBufferStart());
return reinterpret_cast<const uint8_t *>(Buf.begin());
}

const Elf_Ehdr *Header;
Expand Down Expand Up @@ -317,7 +317,7 @@ class ELFFile {
std::pair<const Elf_Shdr *, const Elf_Sym *>
getRelocationSymbol(const Elf_Shdr *RelSec, const RelT *Rel) const;

ELFFile(MemoryBuffer *Object, std::error_code &ec);
ELFFile(StringRef Object, std::error_code &ec);

bool isMipsELF64() const {
return Header->e_machine == ELF::EM_MIPS &&
Expand Down Expand Up @@ -536,7 +536,7 @@ ELFFile<ELFT>::getSymbol(uint32_t Index) const {
template <class ELFT>
ErrorOr<ArrayRef<uint8_t> >
ELFFile<ELFT>::getSectionContents(const Elf_Shdr *Sec) const {
if (Sec->sh_offset + Sec->sh_size > Buf->getBufferSize())
if (Sec->sh_offset + Sec->sh_size > Buf.size())
return object_error::parse_failed;
const uint8_t *Start = base() + Sec->sh_offset;
return ArrayRef<uint8_t>(Start, Sec->sh_size);
Expand Down Expand Up @@ -621,13 +621,13 @@ typename ELFFile<ELFT>::uintX_t ELFFile<ELFT>::getStringTableIndex() const {
}

template <class ELFT>
ELFFile<ELFT>::ELFFile(MemoryBuffer *Object, std::error_code &ec)
ELFFile<ELFT>::ELFFile(StringRef Object, std::error_code &ec)
: Buf(Object), SectionHeaderTable(nullptr), dot_shstrtab_sec(nullptr),
dot_strtab_sec(nullptr), dot_symtab_sec(nullptr),
SymbolTableSectionHeaderIndex(nullptr), dot_gnu_version_sec(nullptr),
dot_gnu_version_r_sec(nullptr), dot_gnu_version_d_sec(nullptr),
dt_soname(nullptr) {
const uint64_t FileSize = Buf->getBufferSize();
const uint64_t FileSize = Buf.size();

if (sizeof(Elf_Ehdr) > FileSize)
// FIXME: Proper error handling.
Expand Down
2 changes: 1 addition & 1 deletion include/llvm/Object/ELFObjectFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ ELFObjectFile<ELFT>::ELFObjectFile(std::unique_ptr<MemoryBuffer> Object,
support::little,
ELFT::Is64Bits),
std::move(Object)),
EF(Data.get(), EC) {}
EF(Data->getBuffer(), EC) {}

template <class ELFT>
basic_symbol_iterator ELFObjectFile<ELFT>::symbol_begin_impl() const {
Expand Down
3 changes: 2 additions & 1 deletion lib/Object/ELFObjectFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ using namespace object;

ErrorOr<ObjectFile *>
ObjectFile::createELFObjectFile(std::unique_ptr<MemoryBuffer> &Obj) {
std::pair<unsigned char, unsigned char> Ident = getElfArchType(Obj.get());
std::pair<unsigned char, unsigned char> Ident =
getElfArchType(Obj->getBuffer());
std::size_t MaxAlignment =
1ULL << countTrailingZeros(uintptr_t(Obj->getBufferStart()));

Expand Down

0 comments on commit db8cb22

Please sign in to comment.