[PATCH] [Object/ELF] Provide symbol helpers

Rui Ueyama ruiu at google.com
Fri Jun 5 12:48:31 PDT 2015


All these member functions don't seem to actually belong to ELFFile. They
just call member functions of their arguments. Does it make more sense if
we add them to Elf_Sym?

On Thu, Jun 4, 2015 at 5:32 PM, Davide Italiano <dccitaliano at gmail.com>
wrote:

> Hi ruiu, rafael, shankar.easwaran,
>
> These were in lld. They can be reused for other tools, e.g. llvm-readobj.
> If needed, we can introduce another class as COFF does (i.e. COFFSymboRef).
> Note: Hexagon has a different notion of common symbol I'm not entirely
> sure I understand.
> I wasn't able to find documentation either, so any help on this side is
> greatly appreciated.
>
> REPOSITORY
>   rL LLVM
>
> http://reviews.llvm.org/D10264
>
> Files:
>   include/llvm/Object/ELF.h
>
> Index: include/llvm/Object/ELF.h
> ===================================================================
> --- include/llvm/Object/ELF.h
> +++ include/llvm/Object/ELF.h
> @@ -421,6 +421,11 @@
>    uint64_t getSymbolIndex(const Elf_Sym *sym) const;
>    ErrorOr<ArrayRef<uint8_t> > getSectionContents(const Elf_Shdr *Sec)
> const;
>    StringRef getLoadName() const;
> +
> +  bool isUndefinedSymbol(const Elf_Sym *Sym) const;
> +  bool isAbsoluteSymbol(const Elf_Sym *Sym) const;
> +  bool isCommonSymbol(const Elf_Sym *Sym) const;
> +  bool isDefinedSymbol(const Elf_Sym *Sym) const;
>  };
>
>  typedef ELFFile<ELFType<support::little, false>> ELF32LEFile;
> @@ -1010,6 +1015,39 @@
>    return StringRef(getDynamicString(name_offset));
>  }
>
> +template <class ELFT>
> +bool ELFFile<ELFT>::isUndefinedSymbol(const Elf_Sym *Sym) const {
> +  return Sym->st_shndx == llvm::ELF::SHN_UNDEF;
> +}
> +
> +template <class ELFT>
> +bool ELFFile<ELFT>::isAbsoluteSymbol(const Elf_Sym *Sym) const {
> +  return Sym->st_shndx == llvm::ELF::SHN_ABS;
> +}
> +
> +template <class ELFT>
> +bool ELFFile<ELFT>::isCommonSymbol(const Elf_Sym *Sym) const {
> +  return Sym->getType() == llvm::ELF::STT_COMMON ||
> +         Sym->st_shndx == llvm::ELF::SHN_COMMON ||
> +         /* Hexagon-specific */
> +         Sym->st_shndx == llvm::ELF::SHN_HEXAGON_SCOMMON ||
> +         Sym->st_shndx == llvm::ELF::SHN_HEXAGON_SCOMMON_1 ||
> +         Sym->st_shndx == llvm::ELF::SHN_HEXAGON_SCOMMON_2 ||
> +         Sym->st_shndx == llvm::ELF::SHN_HEXAGON_SCOMMON_4 ||
> +         Sym->st_shndx == llvm::ELF::SHN_HEXAGON_SCOMMON_8;
> +}
> +
> +template <class ELFT>
> +bool ELFFile<ELFT>::isDefinedSymbol(const Elf_Sym *Sym) const {
> +  return Sym->getType() == llvm::ELF::STT_NOTYPE ||
> +         Sym->getType() == llvm::ELF::STT_OBJECT ||
> +         Sym->getType() == llvm::ELF::STT_FUNC ||
> +         Sym->getType() == llvm::ELF::STT_GNU_IFUNC ||
> +         Sym->getType() == llvm::ELF::STT_SECTION ||
> +         Sym->getType() == llvm::ELF::STT_FILE ||
> +         Sym->getType() == llvm::ELF::STT_TLS;
> +}
> +
>  /// This function returns the hash value for a symbol in the .dynsym
> section
>  /// Name of the API remains consistent as specified in the libelf
>  /// REF : http://www.sco.com/developers/gabi/latest/ch5.dynamic.html#hash
>
> EMAIL PREFERENCES
>   http://reviews.llvm.org/settings/panel/emailpreferences/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150605/c3a89d9d/attachment.html>


More information about the llvm-commits mailing list