Skip to content

Commit

Permalink
Revert "[llvm-objcopy] Add support for relocations"
Browse files Browse the repository at this point in the history
This reverts r312643 because it's failing on llvm-i686-linux-RA.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@312645 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
petrhosek committed Sep 6, 2017
1 parent 0c3d5af commit 891fa9e
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 236 deletions.
91 changes: 0 additions & 91 deletions test/tools/llvm-objcopy/basic-relocations.test

This file was deleted.

30 changes: 0 additions & 30 deletions test/tools/llvm-objcopy/no-symbol-relocation.test

This file was deleted.

86 changes: 0 additions & 86 deletions tools/llvm-objcopy/Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,39 +154,6 @@ void SymbolTableSectionImpl<ELFT>::writeSection(
}
}

template <class ELFT> void RelocationSection<ELFT>::finalize() {
this->Link = Symbols->Index;
this->Info = SecToApplyRel->Index;
}

template <class ELFT>
void setAddend(Elf_Rel_Impl<ELFT, false> &Rel, uint64_t Addend) {}

template <class ELFT>
void setAddend(Elf_Rel_Impl<ELFT, true> &Rela, uint64_t Addend) {
Rela.r_addend = Addend;
}

template <class ELFT>
template <class T>
void RelocationSection<ELFT>::writeRel(T *Buf) const {
for (const auto &Reloc : Relocations) {
Buf->r_offset = Reloc.Offset;
setAddend(*Buf, Reloc.Addend);
Buf->setSymbolAndType(Reloc.Symbol->Index, Reloc.Type, false);
++Buf;
}
}

template <class ELFT>
void RelocationSection<ELFT>::writeSection(llvm::FileOutputBuffer &Out) const {
uint8_t *Buf = Out.getBufferStart() + Offset;
if (Type == SHT_REL)
writeRel(reinterpret_cast<Elf_Rel *>(Buf));
else
writeRel(reinterpret_cast<Elf_Rela *>(Buf));
}

// Returns true IFF a section is wholly inside the range of a segment
static bool sectionWithinSegment(const SectionBase &Section,
const Segment &Segment) {
Expand Down Expand Up @@ -263,36 +230,12 @@ void Object<ELFT>::initSymbolTable(const llvm::object::ELFFile<ELFT> &ElfFile,
}
}

template <class ELFT>
static void getAddend(uint64_t &ToSet, const Elf_Rel_Impl<ELFT, false> &Rel) {}

template <class ELFT>
static void getAddend(uint64_t &ToSet, const Elf_Rel_Impl<ELFT, true> &Rela) {
ToSet = Rela.r_addend;
}

template <class ELFT, class T>
void initRelocations(RelocationSection<ELFT> *Relocs,
SymbolTableSection *SymbolTable, T RelRange) {
for (const auto &Rel : RelRange) {
Relocation ToAdd;
ToAdd.Offset = Rel.r_offset;
getAddend(ToAdd.Addend, Rel);
ToAdd.Type = Rel.getType(false);
ToAdd.Symbol = SymbolTable->getSymbolByIndex(Rel.getSymbol(false));
Relocs->addRelocation(ToAdd);
}
}

template <class ELFT>
std::unique_ptr<SectionBase>
Object<ELFT>::makeSection(const llvm::object::ELFFile<ELFT> &ElfFile,
const Elf_Shdr &Shdr) {
ArrayRef<uint8_t> Data;
switch (Shdr.sh_type) {
case SHT_REL:
case SHT_RELA:
return llvm::make_unique<RelocationSection<ELFT>>();
case SHT_STRTAB:
return llvm::make_unique<StringTableSection>();
case SHT_SYMTAB: {
Expand Down Expand Up @@ -336,35 +279,6 @@ void Object<ELFT>::readSectionHeaders(const ELFFile<ELFT> &ElfFile) {
// details about symbol tables.
if (SymbolTable)
initSymbolTable(ElfFile, SymbolTable);

// Now that all sections and symbols have been added we can add
// relocations that reference symbols and set the link and info fields for
// relocation sections.
for (auto &Section : Sections) {
if (auto RelSec = dyn_cast<RelocationSection<ELFT>>(Section.get())) {
if (RelSec->Link - 1 >= Sections.size() || RelSec->Link == 0) {
error("Link field value " + Twine(RelSec->Link) + " in section " +
RelSec->Name + " is invalid");
}
if (RelSec->Info - 1 >= Sections.size() || RelSec->Info == 0) {
error("Info field value " + Twine(RelSec->Link) + " in section " +
RelSec->Name + " is invalid");
}
auto SymTab =
dyn_cast<SymbolTableSection>(Sections[RelSec->Link - 1].get());
if (SymTab == nullptr) {
error("Link field of relocation section " + RelSec->Name +
" is not a symbol table");
}
RelSec->setSymTab(SymTab);
RelSec->setSection(Sections[RelSec->Info - 1].get());
auto Shdr = unwrapOrError(ElfFile.sections()).begin() + RelSec->Index;
if (RelSec->Type == SHT_REL)
initRelocations(RelSec, SymTab, unwrapOrError(ElfFile.rels(Shdr)));
else
initRelocations(RelSec, SymTab, unwrapOrError(ElfFile.relas(Shdr)));
}
}
}

template <class ELFT> Object<ELFT>::Object(const ELFObjectFile<ELFT> &Obj) {
Expand Down
29 changes: 0 additions & 29 deletions tools/llvm-objcopy/Object.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,35 +146,6 @@ template <class ELFT> class SymbolTableSectionImpl : public SymbolTableSection {
void writeSection(llvm::FileOutputBuffer &Out) const override;
};

struct Relocation {
const Symbol *Symbol;
uint64_t Offset;
uint64_t Addend;
uint32_t Type;
};

template <class ELFT> class RelocationSection : public SectionBase {
private:
typedef typename ELFT::Rel Elf_Rel;
typedef typename ELFT::Rela Elf_Rela;

std::vector<Relocation> Relocations;
SymbolTableSection *Symbols;
SectionBase *SecToApplyRel;

template <class T> void writeRel(T *Buf) const;

public:
void setSymTab(SymbolTableSection *StrTab) { Symbols = StrTab; }
void setSection(SectionBase *Sec) { SecToApplyRel = Sec; }
void addRelocation(Relocation Rel) { Relocations.push_back(Rel); }
void finalize() override;
void writeSection(llvm::FileOutputBuffer &Out) const override;
static bool classof(const SectionBase *S) {
return S->Type == llvm::ELF::SHT_REL || S->Type == llvm::ELF::SHT_RELA;
}
};

template <class ELFT> class Object {
private:
typedef std::unique_ptr<SectionBase> SecPtr;
Expand Down

0 comments on commit 891fa9e

Please sign in to comment.