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 > 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> ELF32LEFile; @@ -1010,6 +1015,39 @@ return StringRef(getDynamicString(name_offset)); } +template +bool ELFFile::isUndefinedSymbol(const Elf_Sym *Sym) const { + return Sym->st_shndx == llvm::ELF::SHN_UNDEF; +} + +template +bool ELFFile::isAbsoluteSymbol(const Elf_Sym *Sym) const { + return Sym->st_shndx == llvm::ELF::SHN_ABS; +} + +template +bool ELFFile::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 +bool ELFFile::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