diff options
author | David Meyer <pdox@google.com> | 2012-02-28 23:47:53 +0000 |
---|---|---|
committer | David Meyer <pdox@google.com> | 2012-02-28 23:47:53 +0000 |
commit | c46255a32ec92c427e621b6d7eabd887962ce4a4 (patch) | |
tree | 63caf01b15b0c1be7b8ee6f9d93dc14ea41f7371 /include/llvm | |
parent | 9993a3aebb27c5cac55429a23af2d2a0f129cb95 (diff) | |
download | llvm-c46255a32ec92c427e621b6d7eabd887962ce4a4.tar.gz llvm-c46255a32ec92c427e621b6d7eabd887962ce4a4.tar.bz2 llvm-c46255a32ec92c427e621b6d7eabd887962ce4a4.tar.xz |
In the ObjectFile interface, replace isInternal(), isAbsolute(), isGlobal(), and isWeak(), with a bitset of flags.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@151670 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm')
-rw-r--r-- | include/llvm/Object/COFF.h | 5 | ||||
-rw-r--r-- | include/llvm/Object/ELF.h | 53 | ||||
-rw-r--r-- | include/llvm/Object/MachO.h | 5 | ||||
-rw-r--r-- | include/llvm/Object/ObjectFile.h | 46 |
4 files changed, 32 insertions, 77 deletions
diff --git a/include/llvm/Object/COFF.h b/include/llvm/Object/COFF.h index 7140340690..732141219e 100644 --- a/include/llvm/Object/COFF.h +++ b/include/llvm/Object/COFF.h @@ -109,11 +109,8 @@ protected: virtual error_code getSymbolAddress(DataRefImpl Symb, uint64_t &Res) const; virtual error_code getSymbolSize(DataRefImpl Symb, uint64_t &Res) const; virtual error_code getSymbolNMTypeChar(DataRefImpl Symb, char &Res) const; - virtual error_code isSymbolInternal(DataRefImpl Symb, bool &Res) const; - virtual error_code isSymbolGlobal(DataRefImpl Symb, bool &Res) const; - virtual error_code isSymbolWeak(DataRefImpl Symb, bool &Res) const; + virtual error_code getSymbolFlags(DataRefImpl Symb, uint32_t &Res) const; virtual error_code getSymbolType(DataRefImpl Symb, SymbolRef::Type &Res) const; - virtual error_code isSymbolAbsolute(DataRefImpl Symb, bool &Res) const; virtual error_code getSymbolSection(DataRefImpl Symb, section_iterator &Res) const; diff --git a/include/llvm/Object/ELF.h b/include/llvm/Object/ELF.h index 2fd10ef671..e6442f14be 100644 --- a/include/llvm/Object/ELF.h +++ b/include/llvm/Object/ELF.h @@ -336,11 +336,8 @@ protected: virtual error_code getSymbolAddress(DataRefImpl Symb, uint64_t &Res) const; virtual error_code getSymbolSize(DataRefImpl Symb, uint64_t &Res) const; virtual error_code getSymbolNMTypeChar(DataRefImpl Symb, char &Res) const; - virtual error_code isSymbolInternal(DataRefImpl Symb, bool &Res) const; - virtual error_code isSymbolGlobal(DataRefImpl Symb, bool &Res) const; - virtual error_code isSymbolWeak(DataRefImpl Symb, bool &Res) const; + virtual error_code getSymbolFlags(DataRefImpl Symb, uint32_t &Res) const; virtual error_code getSymbolType(DataRefImpl Symb, SymbolRef::Type &Res) const; - virtual error_code isSymbolAbsolute(DataRefImpl Symb, bool &Res) const; virtual error_code getSymbolSection(DataRefImpl Symb, section_iterator &Res) const; @@ -655,32 +652,26 @@ error_code ELFObjectFile<target_endianness, is64Bits> template<support::endianness target_endianness, bool is64Bits> error_code ELFObjectFile<target_endianness, is64Bits> - ::isSymbolGlobal(DataRefImpl Symb, - bool &Result) const { + ::getSymbolFlags(DataRefImpl Symb, + uint32_t &Result) const { validateSymbol(Symb); const Elf_Sym *symb = getSymbol(Symb); - Result = symb->getBinding() == ELF::STB_GLOBAL; - return object_error::success; -} + Result = SymbolRef::SF_None; -template<support::endianness target_endianness, bool is64Bits> -error_code ELFObjectFile<target_endianness, is64Bits> - ::isSymbolWeak(DataRefImpl Symb, - bool &Result) const { - validateSymbol(Symb); - const Elf_Sym *symb = getSymbol(Symb); + if (symb->getBinding() != ELF::STB_LOCAL) + Result |= SymbolRef::SF_Global; - Result = symb->getBinding() == ELF::STB_WEAK; - return object_error::success; -} + if (symb->getBinding() == ELF::STB_WEAK) + Result |= SymbolRef::SF_Weak; + + if (symb->st_shndx == ELF::SHN_ABS) + Result |= SymbolRef::SF_Absolute; + + if (symb->getType() == ELF::STT_FILE || + symb->getType() == ELF::STT_SECTION) + Result |= SymbolRef::SF_FormatSpecific; -template<support::endianness target_endianness, bool is64Bits> -error_code ELFObjectFile<target_endianness, is64Bits> - ::isSymbolAbsolute(DataRefImpl Symb, bool &Res) const { - validateSymbol(Symb); - const Elf_Sym *symb = getSymbol(Symb); - Res = symb->st_shndx == ELF::SHN_ABS; return object_error::success; } @@ -703,20 +694,6 @@ error_code ELFObjectFile<target_endianness, is64Bits> template<support::endianness target_endianness, bool is64Bits> error_code ELFObjectFile<target_endianness, is64Bits> - ::isSymbolInternal(DataRefImpl Symb, - bool &Result) const { - validateSymbol(Symb); - const Elf_Sym *symb = getSymbol(Symb); - - if ( symb->getType() == ELF::STT_FILE - || symb->getType() == ELF::STT_SECTION) - Result = true; - Result = false; - return object_error::success; -} - -template<support::endianness target_endianness, bool is64Bits> -error_code ELFObjectFile<target_endianness, is64Bits> ::getSectionNext(DataRefImpl Sec, SectionRef &Result) const { const uint8_t *sec = reinterpret_cast<const uint8_t *>(Sec.p); sec += Header->e_shentsize; diff --git a/include/llvm/Object/MachO.h b/include/llvm/Object/MachO.h index b6e583f6f3..3edbe08f63 100644 --- a/include/llvm/Object/MachO.h +++ b/include/llvm/Object/MachO.h @@ -55,11 +55,8 @@ protected: virtual error_code getSymbolAddress(DataRefImpl Symb, uint64_t &Res) const; virtual error_code getSymbolSize(DataRefImpl Symb, uint64_t &Res) const; virtual error_code getSymbolNMTypeChar(DataRefImpl Symb, char &Res) const; - virtual error_code isSymbolInternal(DataRefImpl Symb, bool &Res) const; - virtual error_code isSymbolGlobal(DataRefImpl Symb, bool &Res) const; - virtual error_code isSymbolWeak(DataRefImpl Symb, bool &Res) const; + virtual error_code getSymbolFlags(DataRefImpl Symb, uint32_t &Res) const; virtual error_code getSymbolType(DataRefImpl Symb, SymbolRef::Type &Res) const; - virtual error_code isSymbolAbsolute(DataRefImpl Symb, bool &Res) const; virtual error_code getSymbolSection(DataRefImpl Symb, section_iterator &Res) const; diff --git a/include/llvm/Object/ObjectFile.h b/include/llvm/Object/ObjectFile.h index 4aa05e234f..284577c945 100644 --- a/include/llvm/Object/ObjectFile.h +++ b/include/llvm/Object/ObjectFile.h @@ -188,6 +188,15 @@ public: ST_Other }; + enum Flags { + SF_None = 0, + SF_Global = 1 << 0, // Global symbol + SF_Weak = 1 << 1, // Weak symbol + SF_Absolute = 1 << 2, // Absolute symbol + SF_FormatSpecific = 1 << 3 // Specific to the object file format + // (e.g. section symbols) + }; + SymbolRef(DataRefImpl SymbolP, const ObjectFile *Owner); bool operator==(const SymbolRef &Other) const; @@ -205,19 +214,8 @@ public: /// nm for this symbol. error_code getNMTypeChar(char &Result) const; - /// Returns true for symbols that are internal to the object file format such - /// as section symbols. - error_code isInternal(bool &Result) const; - - /// Returns true for symbols that can be used in another objects, - /// such as library functions - error_code isGlobal(bool &Result) const; - - /// Returns true for weak symbols. - error_code isWeak(bool &Result) const; - - /// @brief Return true for absolute symbols. - error_code isAbsolute(bool &Result) const; + /// Get symbol flags (bitwise OR of SymbolRef::Flags) + error_code getFlags(uint32_t &Result) const; /// @brief Get section this symbol is defined in reference to. Result is /// end_sections() if it is undefined or is an absolute symbol. @@ -261,10 +259,8 @@ protected: virtual error_code getSymbolType(DataRefImpl Symb, SymbolRef::Type &Res) const = 0; virtual error_code getSymbolNMTypeChar(DataRefImpl Symb, char &Res) const = 0; - virtual error_code isSymbolInternal(DataRefImpl Symb, bool &Res) const = 0; - virtual error_code isSymbolGlobal(DataRefImpl Symb, bool &Res) const = 0; - virtual error_code isSymbolWeak(DataRefImpl Symb, bool &Res) const = 0; - virtual error_code isSymbolAbsolute(DataRefImpl Symb, bool &Res) const = 0; + virtual error_code getSymbolFlags(DataRefImpl Symb, + uint32_t &Res) const = 0; virtual error_code getSymbolSection(DataRefImpl Symb, section_iterator &Res) const = 0; @@ -382,20 +378,8 @@ inline error_code SymbolRef::getNMTypeChar(char &Result) const { return OwningObject->getSymbolNMTypeChar(SymbolPimpl, Result); } -inline error_code SymbolRef::isInternal(bool &Result) const { - return OwningObject->isSymbolInternal(SymbolPimpl, Result); -} - -inline error_code SymbolRef::isGlobal(bool &Result) const { - return OwningObject->isSymbolGlobal(SymbolPimpl, Result); -} - -inline error_code SymbolRef::isWeak(bool &Result) const { - return OwningObject->isSymbolWeak(SymbolPimpl, Result); -} - -inline error_code SymbolRef::isAbsolute(bool &Result) const { - return OwningObject->isSymbolAbsolute(SymbolPimpl, Result); +inline error_code SymbolRef::getFlags(uint32_t &Result) const { + return OwningObject->getSymbolFlags(SymbolPimpl, Result); } inline error_code SymbolRef::getSection(section_iterator &Result) const { |