Object: make the following changes into SymbolRef

- Add enum SymbolType and function getSymbolType()
- Add function isGlobal() - it's returns true for symbols that can be used in another objects, such as library functions.
- Rename function getAddress() to getOffset() and add new function getAddress(), because currently getAddress() returns section offset of symbol first byte. new getAddress() return symbol address.
- Change usage SymbolRef::getAddress() to getOffset() in tools/llvm-nm and tools/llvm-objdump.

Patch by Danil Malyshev!

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@139683 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Benjamin Kramer
2011-09-14 01:22:52 +00:00
parent 357b571841
commit ac241fe9f0
7 changed files with 225 additions and 5 deletions

View File

@@ -92,10 +92,13 @@ private:
protected:
virtual error_code getSymbolNext(DataRefImpl Symb, SymbolRef &Res) const;
virtual error_code getSymbolName(DataRefImpl Symb, StringRef &Res) const;
virtual error_code getSymbolOffset(DataRefImpl Symb, uint64_t &Res) const;
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 getSymbolType(DataRefImpl Symb, SymbolRef::SymbolType &Res) const;
virtual error_code getSectionNext(DataRefImpl Sec, SectionRef &Res) const;
virtual error_code getSectionName(DataRefImpl Sec, StringRef &Res) const;

View File

@@ -51,6 +51,13 @@ public:
std::memset(&SymbolPimpl, 0, sizeof(SymbolPimpl));
}
enum SymbolType {
ST_Function,
ST_Data,
ST_External, // Defined in another object file
ST_Other
};
SymbolRef(DataRefImpl SymbolP, const ObjectFile *Owner);
bool operator==(const SymbolRef &Other) const;
@@ -59,7 +66,9 @@ public:
error_code getName(StringRef &Result) const;
error_code getAddress(uint64_t &Result) const;
error_code getOffset(uint64_t &Result) const;
error_code getSize(uint64_t &Result) const;
error_code getSymbolType(SymbolRef::SymbolType &Result) const;
/// Returns the ascii char that should be displayed in a symbol table dump via
/// nm for this symbol.
@@ -68,6 +77,10 @@ public:
/// 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;
};
/// RelocationRef - This is a value type class that represents a single
@@ -151,9 +164,12 @@ protected:
virtual error_code getSymbolNext(DataRefImpl Symb, SymbolRef &Res) const = 0;
virtual error_code getSymbolName(DataRefImpl Symb, StringRef &Res) const = 0;
virtual error_code getSymbolAddress(DataRefImpl Symb, uint64_t &Res) const =0;
virtual error_code getSymbolOffset(DataRefImpl Symb, uint64_t &Res) const =0;
virtual error_code getSymbolSize(DataRefImpl Symb, uint64_t &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 getSymbolType(DataRefImpl Symb, SymbolRef::SymbolType &Res) const = 0;
// Same as above for SectionRef.
friend class SectionRef;
@@ -274,6 +290,10 @@ inline error_code SymbolRef::getAddress(uint64_t &Result) const {
return OwningObject->getSymbolAddress(SymbolPimpl, Result);
}
inline error_code SymbolRef::getOffset(uint64_t &Result) const {
return OwningObject->getSymbolOffset(SymbolPimpl, Result);
}
inline error_code SymbolRef::getSize(uint64_t &Result) const {
return OwningObject->getSymbolSize(SymbolPimpl, Result);
}
@@ -286,6 +306,14 @@ 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::getSymbolType(SymbolRef::SymbolType &Result) const {
return OwningObject->getSymbolType(SymbolPimpl, Result);
}
/// SectionRef
inline SectionRef::SectionRef(DataRefImpl SectionP,