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
@@ -118,8 +118,8 @@ static std::error_code getOffset(const SymbolRef &Sym, uint64_t &Result) {
if (std::error_code EC = Sym.getAddress(Address))
return EC;
if (Address == UnknownAddressOrSize) {
Result = UnknownAddressOrSize;
if (Address == UnknownAddress) {
Result = UnknownAddress;
return std::error_code();
}
@@ -129,7 +129,7 @@ static std::error_code getOffset(const SymbolRef &Sym, uint64_t &Result) {
return EC;
if (SecI == Obj->section_end()) {
Result = UnknownAddressOrSize;
Result = UnknownAddress;
return std::error_code();
}
@@ -387,7 +387,7 @@ void RuntimeDyldImpl::computeTotalAllocSize(const ObjectFile &Obj,
uint32_t Flags = I->getFlags();
if (Flags & SymbolRef::SF_Common) {
// Add the common symbols to a list. We'll allocate them all below.
uint64_t Size = I->getSize();
uint64_t Size = I->getCommonSize();
CommonSize += Size;
}
}
@@ -494,7 +494,7 @@ void RuntimeDyldImpl::emitCommonSymbols(const ObjectFile &Obj,
}
uint32_t Align = Sym.getAlignment();
uint64_t Size = Sym.getSize();
uint64_t Size = Sym.getCommonSize();
CommonSize += Align + Size;
SymbolsToAllocate.push_back(Sym);
@@ -517,7 +517,7 @@ void RuntimeDyldImpl::emitCommonSymbols(const ObjectFile &Obj,
for (auto &Sym : SymbolsToAllocate) {
uint32_t Align = Sym.getAlignment();
StringRef Name;
uint64_t Size = Sym.getSize();
uint64_t Size = Sym.getCommonSize();
Check(Sym.getName(Name));
if (Align) {
// This symbol has an alignment requirement.
@@ -64,18 +64,18 @@ RuntimeDyldCOFF::loadObject(const object::ObjectFile &O) {
uint64_t RuntimeDyldCOFF::getSymbolOffset(const SymbolRef &Sym) {
uint64_t Address;
if (Sym.getAddress(Address))
return UnknownAddressOrSize;
return UnknownAddress;
if (Address == UnknownAddressOrSize)
return UnknownAddressOrSize;
if (Address == UnknownAddress)
return UnknownAddress;
const ObjectFile *Obj = Sym.getObject();
section_iterator SecI(Obj->section_end());
if (Sym.getSection(SecI))
return UnknownAddressOrSize;
return UnknownAddress;
if (SecI == Obj->section_end())
return UnknownAddressOrSize;
return UnknownAddress;
uint64_t SectionAddress = SecI->getAddress();
return Address - SectionAddress;