From 7358cbc83790857d25492428904c8615efbfbdc7 Mon Sep 17 00:00:00 2001 From: "Michael J. Spencer" Date: Thu, 25 Jun 2015 23:40:41 +0000 Subject: [PATCH] [ELF] Add some accessors for lld. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240730 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Object/ELF.h | 12 ++++++++++++ include/llvm/Object/ELFTypes.h | 3 +++ 2 files changed, 15 insertions(+) diff --git a/include/llvm/Object/ELF.h b/include/llvm/Object/ELF.h index 8b28567f72ce..ae0e7376245e 100644 --- a/include/llvm/Object/ELF.h +++ b/include/llvm/Object/ELF.h @@ -227,6 +227,8 @@ class ELFFile { ArchivePointerTypeTraits > Current; }; + typedef iterator_range Elf_Sym_Range; + private: typedef SmallVector Sections_t; typedef DenseMap IndexMap_t; @@ -340,6 +342,9 @@ class ELFFile { Elf_Sym_Iter begin_symbols() const; Elf_Sym_Iter end_symbols() const; + Elf_Sym_Range symbols() const { + return make_range(begin_symbols(), end_symbols()); + } Elf_Dyn_Iter begin_dynamic_table() const; /// \param NULLEnd use one past the first DT_NULL entry as the end instead of @@ -424,6 +429,7 @@ class ELFFile { const Elf_Sym *getSymbol(uint32_t index) const; ErrorOr getSymbolName(Elf_Sym_Iter Sym) const; + ErrorOr getStaticSymbolName(const Elf_Sym *Symb) const; /// \brief Get the name of \p Symb. /// \param SymTab The symbol table section \p Symb is contained in. @@ -961,6 +967,12 @@ ErrorOr ELFFile::getSymbolName(Elf_Sym_Iter Sym) const { return StringRef(getDynamicString(Sym->st_name)); } +template +ErrorOr +ELFFile::getStaticSymbolName(const Elf_Sym *Symb) const { + return getSymbolName(dot_symtab_sec, Symb); +} + template ErrorOr ELFFile::getSymbolName(const Elf_Shdr *Section, const Elf_Sym *Symb) const { diff --git a/include/llvm/Object/ELFTypes.h b/include/llvm/Object/ELFTypes.h index 70f6d8b930b0..ea54cac36d10 100644 --- a/include/llvm/Object/ELFTypes.h +++ b/include/llvm/Object/ELFTypes.h @@ -197,6 +197,9 @@ struct Elf_Sym_Impl : Elf_Sym_Base { return st_shndx >= ELF::SHN_LORESERVE; } bool isUndefined() const { return st_shndx == ELF::SHN_UNDEF; } + bool isExternal() const { + return getBinding() != ELF::STB_LOCAL; + } }; /// Elf_Versym: This is the structure of entries in the SHT_GNU_versym section