Change how symbol sizes are handled in lib/Object.

COFF and MachO only define symbol sizes for common symbols. Reflect that
in the class hierarchy by having a method for common symbols only in the base
and a general one in ELF.

This avoids the need of using a magic value for the size, which had a few
problems
* Most callers didn't check for it.
* The ones that did could not tell the magic value from a file actually having
  that value.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240529 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola
2015-06-24 10:20:30 +00:00
parent 9ece8eb945
commit 821b06f3a8
19 changed files with 89 additions and 79 deletions

View File

@ -375,14 +375,14 @@ std::error_code MachOObjectFile::getSymbolAddress(DataRefImpl Symb,
MachO::nlist_64 Entry = getSymbol64TableEntry(Symb);
if ((Entry.n_type & MachO::N_TYPE) == MachO::N_UNDF &&
Entry.n_value == 0)
Res = UnknownAddressOrSize;
Res = UnknownAddress;
else
Res = Entry.n_value;
} else {
MachO::nlist Entry = getSymbolTableEntry(Symb);
if ((Entry.n_type & MachO::N_TYPE) == MachO::N_UNDF &&
Entry.n_value == 0)
Res = UnknownAddressOrSize;
Res = UnknownAddress;
else
Res = Entry.n_value;
}
@ -398,13 +398,10 @@ uint32_t MachOObjectFile::getSymbolAlignment(DataRefImpl DRI) const {
return 0;
}
uint64_t MachOObjectFile::getSymbolSize(DataRefImpl DRI) const {
uint64_t MachOObjectFile::getCommonSymbolSizeImpl(DataRefImpl DRI) const {
uint64_t Value;
getSymbolAddress(DRI, Value);
uint32_t flags = getSymbolFlags(DRI);
if (flags & SymbolRef::SF_Common)
return Value;
return UnknownAddressOrSize;
return Value;
}
std::error_code MachOObjectFile::getSymbolType(DataRefImpl Symb,
@ -453,7 +450,7 @@ uint32_t MachOObjectFile::getSymbolFlags(DataRefImpl DRI) const {
if ((MachOType & MachO::N_TYPE) == MachO::N_UNDF) {
uint64_t Value;
getSymbolAddress(DRI, Value);
if (Value && Value != UnknownAddressOrSize)
if (Value && Value != UnknownAddress)
Result |= SymbolRef::SF_Common;
}