summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-objcopy/Object.h
diff options
context:
space:
mode:
authorPetr Hosek <phosek@chromium.org>2017-08-29 02:12:03 +0000
committerPetr Hosek <phosek@chromium.org>2017-08-29 02:12:03 +0000
commit79cee9e784120d42891c5aa8f33ecfcdd2f32dc2 (patch)
treefd7cd35f9485470d5198e3dc66b121bc65d079ce /llvm/tools/llvm-objcopy/Object.h
parentde8ef1393d33e295fa7ba6c6d3d47f7de4497cbb (diff)
downloadbcm5719-llvm-79cee9e784120d42891c5aa8f33ecfcdd2f32dc2.tar.gz
bcm5719-llvm-79cee9e784120d42891c5aa8f33ecfcdd2f32dc2.zip
Reland "[llvm] Add symbol table support to llvm-objcopy"
This change adds support for SHT_SYMTAB sections. Patch by Jake Ehrlich Differential Revision: https://reviews.llvm.org/D34167 llvm-svn: 311974
Diffstat (limited to 'llvm/tools/llvm-objcopy/Object.h')
-rw-r--r--llvm/tools/llvm-objcopy/Object.h36
1 files changed, 36 insertions, 0 deletions
diff --git a/llvm/tools/llvm-objcopy/Object.h b/llvm/tools/llvm-objcopy/Object.h
index 1a3777bbd72..c41bd36490c 100644
--- a/llvm/tools/llvm-objcopy/Object.h
+++ b/llvm/tools/llvm-objcopy/Object.h
@@ -113,6 +113,39 @@ public:
}
};
+struct Symbol {
+ uint8_t Binding;
+ SectionBase *DefinedIn;
+ uint32_t Index;
+ llvm::StringRef Name;
+ uint32_t NameIndex;
+ uint64_t Size;
+ uint8_t Type;
+ uint64_t Value;
+};
+
+class SymbolTableSection : public SectionBase {
+protected:
+ std::vector<std::unique_ptr<Symbol>> Symbols;
+ StringTableSection *SymbolNames;
+
+public:
+ void setStrTab(StringTableSection *StrTab) { SymbolNames = StrTab; }
+ void addSymbol(llvm::StringRef Name, uint8_t Bind, uint8_t Type,
+ SectionBase *DefinedIn, uint64_t Value, uint64_t Sz);
+ void addSymbolNames();
+ const Symbol *getSymbolByIndex(uint32_t Index) const;
+ void finalize() override;
+ static bool classof(const SectionBase *S) {
+ return S->Type == llvm::ELF::SHT_SYMTAB;
+ }
+};
+
+// Only writeSection depends on the ELF type so we implement it in a subclass.
+template <class ELFT> class SymbolTableSectionImpl : public SymbolTableSection {
+ void writeSection(llvm::FileOutputBuffer &Out) const override;
+};
+
template <class ELFT> class Object {
private:
typedef std::unique_ptr<SectionBase> SecPtr;
@@ -122,6 +155,8 @@ private:
typedef typename ELFT::Ehdr Elf_Ehdr;
typedef typename ELFT::Phdr Elf_Phdr;
+ void initSymbolTable(const llvm::object::ELFFile<ELFT> &ElfFile,
+ SymbolTableSection *SymTab);
SecPtr makeSection(const llvm::object::ELFFile<ELFT> &ElfFile,
const Elf_Shdr &Shdr);
void readProgramHeaders(const llvm::object::ELFFile<ELFT> &ElfFile);
@@ -129,6 +164,7 @@ private:
protected:
StringTableSection *SectionNames;
+ SymbolTableSection *SymbolTable;
std::vector<SecPtr> Sections;
std::vector<SegPtr> Segments;
OpenPOWER on IntegriCloud