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.
llvm-svn: 240529
diff --git a/llvm/tools/llvm-symbolizer/LLVMSymbolize.cpp b/llvm/tools/llvm-symbolizer/LLVMSymbolize.cpp
index 448cfe9..b6af342 100644
--- a/llvm/tools/llvm-symbolizer/LLVMSymbolize.cpp
+++ b/llvm/tools/llvm-symbolizer/LLVMSymbolize.cpp
@@ -94,7 +94,7 @@
return;
uint64_t SymbolAddress;
if (error(Symbol.getAddress(SymbolAddress)) ||
- SymbolAddress == UnknownAddressOrSize)
+ SymbolAddress == UnknownAddress)
return;
if (OpdExtractor) {
// For big-endian PowerPC64 ELF, symbols in the .opd section refer to
@@ -109,15 +109,12 @@
SymbolAddress = OpdExtractor->getAddress(&OpdOffset32);
}
uint64_t SymbolSize;
- // Getting symbol size is linear for Mach-O files, so assume that symbol
- // occupies the memory range up to the following symbol.
- if (isa<MachOObjectFile>(Module))
+ // Onyl ELF has a size for every symbol so assume that symbol occupies the
+ // memory range up to the following symbol.
+ if (auto *E = dyn_cast<ELFObjectFileBase>(Module))
+ SymbolSize = E->getSymbolSize(Symbol);
+ else
SymbolSize = 0;
- else {
- SymbolSize = Symbol.getSize();
- if (SymbolSize == UnknownAddressOrSize)
- return;
- }
StringRef SymbolName;
if (error(Symbol.getName(SymbolName)))
return;