Simplify another function that doesn't fail.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@238703 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola 2015-06-01 00:27:26 +00:00
parent 75ce6bba4e
commit 481f35f113
14 changed files with 31 additions and 48 deletions

View File

@ -613,7 +613,7 @@ protected:
StringRef &Res) const override; StringRef &Res) const override;
std::error_code getSymbolAddress(DataRefImpl Symb, std::error_code getSymbolAddress(DataRefImpl Symb,
uint64_t &Res) const override; uint64_t &Res) const override;
std::error_code getSymbolSize(DataRefImpl Symb, uint64_t &Res) const override; uint64_t getSymbolSize(DataRefImpl Symb) const override;
uint32_t getSymbolFlags(DataRefImpl Symb) const override; uint32_t getSymbolFlags(DataRefImpl Symb) const override;
std::error_code getSymbolType(DataRefImpl Symb, std::error_code getSymbolType(DataRefImpl Symb,
SymbolRef::Type &Res) const override; SymbolRef::Type &Res) const override;

View File

@ -80,7 +80,7 @@ protected:
std::error_code getSymbolAddress(DataRefImpl Symb, std::error_code getSymbolAddress(DataRefImpl Symb,
uint64_t &Res) const override; uint64_t &Res) const override;
uint32_t getSymbolAlignment(DataRefImpl Symb) const override; uint32_t getSymbolAlignment(DataRefImpl Symb) const override;
std::error_code getSymbolSize(DataRefImpl Symb, uint64_t &Res) const override; uint64_t getSymbolSize(DataRefImpl Symb) const override;
uint32_t getSymbolFlags(DataRefImpl Symb) const override; uint32_t getSymbolFlags(DataRefImpl Symb) const override;
std::error_code getSymbolOther(DataRefImpl Symb, uint8_t &Res) const override; std::error_code getSymbolOther(DataRefImpl Symb, uint8_t &Res) const override;
std::error_code getSymbolType(DataRefImpl Symb, std::error_code getSymbolType(DataRefImpl Symb,
@ -333,10 +333,8 @@ uint32_t ELFObjectFile<ELFT>::getSymbolAlignment(DataRefImpl Symb) const {
} }
template <class ELFT> template <class ELFT>
std::error_code ELFObjectFile<ELFT>::getSymbolSize(DataRefImpl Symb, uint64_t ELFObjectFile<ELFT>::getSymbolSize(DataRefImpl Symb) const {
uint64_t &Result) const { return toELFSymIter(Symb)->st_size;
Result = toELFSymIter(Symb)->st_size;
return object_error::success;
} }
template <class ELFT> template <class ELFT>

View File

@ -205,7 +205,7 @@ public:
std::error_code getSymbolAddress(DataRefImpl Symb, std::error_code getSymbolAddress(DataRefImpl Symb,
uint64_t &Res) const override; uint64_t &Res) const override;
uint32_t getSymbolAlignment(DataRefImpl Symb) const override; uint32_t getSymbolAlignment(DataRefImpl Symb) const override;
std::error_code getSymbolSize(DataRefImpl Symb, uint64_t &Res) const override; uint64_t getSymbolSize(DataRefImpl Symb) const override;
std::error_code getSymbolType(DataRefImpl Symb, std::error_code getSymbolType(DataRefImpl Symb,
SymbolRef::Type &Res) const override; SymbolRef::Type &Res) const override;
uint32_t getSymbolFlags(DataRefImpl Symb) const override; uint32_t getSymbolFlags(DataRefImpl Symb) const override;

View File

@ -147,7 +147,7 @@ public:
std::error_code getAddress(uint64_t &Result) const; std::error_code getAddress(uint64_t &Result) const;
/// @brief Get the alignment of this symbol as the actual value (not log 2). /// @brief Get the alignment of this symbol as the actual value (not log 2).
uint32_t getAlignment() const; uint32_t getAlignment() const;
std::error_code getSize(uint64_t &Result) const; uint64_t getSize() const;
std::error_code getType(SymbolRef::Type &Result) const; std::error_code getType(SymbolRef::Type &Result) const;
std::error_code getOther(uint8_t &Result) const; std::error_code getOther(uint8_t &Result) const;
@ -207,8 +207,7 @@ protected:
virtual std::error_code getSymbolAddress(DataRefImpl Symb, virtual std::error_code getSymbolAddress(DataRefImpl Symb,
uint64_t &Res) const = 0; uint64_t &Res) const = 0;
virtual uint32_t getSymbolAlignment(DataRefImpl Symb) const; virtual uint32_t getSymbolAlignment(DataRefImpl Symb) const;
virtual std::error_code getSymbolSize(DataRefImpl Symb, virtual uint64_t getSymbolSize(DataRefImpl Symb) const = 0;
uint64_t &Res) const = 0;
virtual std::error_code getSymbolType(DataRefImpl Symb, virtual std::error_code getSymbolType(DataRefImpl Symb,
SymbolRef::Type &Res) const = 0; SymbolRef::Type &Res) const = 0;
virtual std::error_code getSymbolSection(DataRefImpl Symb, virtual std::error_code getSymbolSection(DataRefImpl Symb,
@ -337,8 +336,8 @@ inline uint32_t SymbolRef::getAlignment() const {
return getObject()->getSymbolAlignment(getRawDataRefImpl()); return getObject()->getSymbolAlignment(getRawDataRefImpl());
} }
inline std::error_code SymbolRef::getSize(uint64_t &Result) const { inline uint64_t SymbolRef::getSize() const {
return getObject()->getSymbolSize(getRawDataRefImpl(), Result); return getObject()->getSymbolSize(getRawDataRefImpl());
} }
inline std::error_code SymbolRef::getSection(section_iterator &Result) const { inline std::error_code SymbolRef::getSection(section_iterator &Result) const {

View File

@ -387,8 +387,7 @@ void RuntimeDyldImpl::computeTotalAllocSize(const ObjectFile &Obj,
uint32_t Flags = I->getFlags(); uint32_t Flags = I->getFlags();
if (Flags & SymbolRef::SF_Common) { if (Flags & SymbolRef::SF_Common) {
// Add the common symbols to a list. We'll allocate them all below. // Add the common symbols to a list. We'll allocate them all below.
uint64_t Size = 0; uint64_t Size = I->getSize();
Check(I->getSize(Size));
CommonSize += Size; CommonSize += Size;
} }
} }
@ -495,8 +494,7 @@ void RuntimeDyldImpl::emitCommonSymbols(const ObjectFile &Obj,
} }
uint32_t Align = Sym.getAlignment(); uint32_t Align = Sym.getAlignment();
uint64_t Size = 0; uint64_t Size = Sym.getSize();
Check(Sym.getSize(Size));
CommonSize += Align + Size; CommonSize += Align + Size;
SymbolsToAllocate.push_back(Sym); SymbolsToAllocate.push_back(Sym);
@ -518,9 +516,8 @@ void RuntimeDyldImpl::emitCommonSymbols(const ObjectFile &Obj,
// Assign the address of each symbol // Assign the address of each symbol
for (auto &Sym : SymbolsToAllocate) { for (auto &Sym : SymbolsToAllocate) {
uint32_t Align = Sym.getAlignment(); uint32_t Align = Sym.getAlignment();
uint64_t Size;
StringRef Name; StringRef Name;
Check(Sym.getSize(Size)); uint64_t Size = Sym.getSize();
Check(Sym.getName(Name)); Check(Sym.getName(Name));
if (Align) { if (Align) {
// This symbol has an alignment requirement. // This symbol has an alignment requirement.

View File

@ -236,16 +236,12 @@ uint32_t COFFObjectFile::getSymbolFlags(DataRefImpl Ref) const {
return Result; return Result;
} }
std::error_code COFFObjectFile::getSymbolSize(DataRefImpl Ref, uint64_t COFFObjectFile::getSymbolSize(DataRefImpl Ref) const {
uint64_t &Result) const {
COFFSymbolRef Symb = getCOFFSymbol(Ref); COFFSymbolRef Symb = getCOFFSymbol(Ref);
if (Symb.isCommon()) if (Symb.isCommon())
Result = Symb.getValue(); return Symb.getValue();
else return UnknownAddressOrSize;
Result = UnknownAddressOrSize;
return object_error::success;
} }
std::error_code std::error_code

View File

@ -410,16 +410,13 @@ uint32_t MachOObjectFile::getSymbolAlignment(DataRefImpl DRI) const {
return 0; return 0;
} }
std::error_code MachOObjectFile::getSymbolSize(DataRefImpl DRI, uint64_t MachOObjectFile::getSymbolSize(DataRefImpl DRI) const {
uint64_t &Result) const {
uint64_t Value; uint64_t Value;
getSymbolAddress(DRI, Value); getSymbolAddress(DRI, Value);
uint32_t flags = getSymbolFlags(DRI); uint32_t flags = getSymbolFlags(DRI);
if (flags & SymbolRef::SF_Common) if (flags & SymbolRef::SF_Common)
Result = Value; return Value;
else return UnknownAddressOrSize;
Result = UnknownAddressOrSize;
return object_error::success;
} }
std::error_code MachOObjectFile::getSymbolType(DataRefImpl Symb, std::error_code MachOObjectFile::getSymbolType(DataRefImpl Symb,

View File

@ -187,10 +187,7 @@ uint64_t LLVMGetSymbolAddress(LLVMSymbolIteratorRef SI) {
} }
uint64_t LLVMGetSymbolSize(LLVMSymbolIteratorRef SI) { uint64_t LLVMGetSymbolSize(LLVMSymbolIteratorRef SI) {
uint64_t ret; return (*unwrap(SI))->getSize();
if (std::error_code ec = (*unwrap(SI))->getSize(ret))
report_fatal_error(ec.message());
return ret;
} }
// RelocationRef accessors // RelocationRef accessors

View File

@ -31,7 +31,7 @@ public:
StringRef SymName; SymI->getName(SymName); StringRef SymName; SymI->getName(SymName);
uint64_t SymAddr; SymI->getAddress(SymAddr); uint64_t SymAddr; SymI->getAddress(SymAddr);
uint64_t SymSize; SymI->getSize(SymSize); uint64_t SymSize = SymI->getSize();
int64_t Addend; getELFRelocationAddend(Rel, Addend); int64_t Addend; getELFRelocationAddend(Rel, Addend);
MCSymbol *Sym = Ctx.getOrCreateSymbol(SymName); MCSymbol *Sym = Ctx.getOrCreateSymbol(SymName);

View File

@ -204,9 +204,10 @@ static void dumpCXXData(const ObjectFile *Obj) {
StringRef SecContents; StringRef SecContents;
if (error(Sec.getContents(SecContents))) if (error(Sec.getContents(SecContents)))
return; return;
uint64_t SymAddress, SymSize; uint64_t SymAddress;
if (error(Sym.getAddress(SymAddress)) || error(Sym.getSize(SymSize))) if (error(Sym.getAddress(SymAddress)))
return; return;
uint64_t SymSize = Sym.getSize();
uint64_t SecAddress = Sec.getAddress(); uint64_t SecAddress = Sec.getAddress();
uint64_t SecSize = Sec.getSize(); uint64_t SecSize = Sec.getSize();
uint64_t SymOffset = SymAddress - SecAddress; uint64_t SymOffset = SymAddress - SecAddress;

View File

@ -934,8 +934,7 @@ static void dumpSymbolNamesFromObject(SymbolicFile &Obj, bool printName,
S.Address = UnknownAddressOrSize; S.Address = UnknownAddressOrSize;
if (PrintSize && isa<ELFObjectFileBase>(Obj)) { if (PrintSize && isa<ELFObjectFileBase>(Obj)) {
symbol_iterator SymI = I; symbol_iterator SymI = I;
if (error(SymI->getSize(S.Size))) S.Size = SymI->getSize();
break;
} }
if (PrintAddress && isa<ObjectFile>(Obj)) if (PrintAddress && isa<ObjectFile>(Obj))
if (error(symbol_iterator(I)->getAddress(S.Address))) if (error(symbol_iterator(I)->getAddress(S.Address)))

View File

@ -676,7 +676,6 @@ void llvm::PrintSymbolTable(const ObjectFile *o) {
StringRef Name; StringRef Name;
uint64_t Address; uint64_t Address;
SymbolRef::Type Type; SymbolRef::Type Type;
uint64_t Size;
uint32_t Flags = Symbol.getFlags(); uint32_t Flags = Symbol.getFlags();
section_iterator Section = o->section_end(); section_iterator Section = o->section_end();
if (error(Symbol.getName(Name))) if (error(Symbol.getName(Name)))
@ -685,8 +684,7 @@ void llvm::PrintSymbolTable(const ObjectFile *o) {
continue; continue;
if (error(Symbol.getType(Type))) if (error(Symbol.getType(Type)))
continue; continue;
if (error(Symbol.getSize(Size))) uint64_t Size = Symbol.getSize();
continue;
if (error(Symbol.getSection(Section))) if (error(Symbol.getSection(Section)))
continue; continue;

View File

@ -292,8 +292,7 @@ static int printLineInfoForInput(bool LoadObjects, bool UseDebugObj) {
uint64_t Size; uint64_t Size;
if (isa<ELFObjectFileBase>(SymbolObj)) { if (isa<ELFObjectFileBase>(SymbolObj)) {
if (Sym.getSize(Size)) Size = Sym.getSize();
continue;
} else { } else {
object::section_iterator Sec = SymbolObj->section_end(); object::section_iterator Sec = SymbolObj->section_end();
if (Sym.getSection(Sec)) if (Sym.getSection(Sec))

View File

@ -113,9 +113,11 @@ void ModuleInfo::addSymbol(const SymbolRef &Symbol, DataExtractor *OpdExtractor,
// occupies the memory range up to the following symbol. // occupies the memory range up to the following symbol.
if (isa<MachOObjectFile>(Module)) if (isa<MachOObjectFile>(Module))
SymbolSize = 0; SymbolSize = 0;
else if (error(Symbol.getSize(SymbolSize)) || else {
SymbolSize == UnknownAddressOrSize) SymbolSize = Symbol.getSize();
if (SymbolSize == UnknownAddressOrSize)
return; return;
}
StringRef SymbolName; StringRef SymbolName;
if (error(Symbol.getName(SymbolName))) if (error(Symbol.getName(SymbolName)))
return; return;