Return ErrorOr from getSymbolAddress.
authorRafael Espindola <rafael.espindola@gmail.com>
Fri, 3 Jul 2015 18:19:00 +0000 (18:19 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Fri, 3 Jul 2015 18:19:00 +0000 (18:19 +0000)
It can fail trying to get the section on ELF and COFF. This makes sure the
error is handled.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241366 91177308-0d34-0410-b5e6-96231b3b80d8

18 files changed:
include/llvm/Object/COFF.h
include/llvm/Object/ELFObjectFile.h
include/llvm/Object/MachO.h
include/llvm/Object/ObjectFile.h
lib/DebugInfo/DWARF/DWARFContext.cpp
lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
lib/Object/COFFObjectFile.cpp
lib/Object/MachOObjectFile.cpp
lib/Object/Object.cpp
lib/Target/X86/MCTargetDesc/X86ELFRelocationInfo.cpp
tools/llvm-cxxdump/llvm-cxxdump.cpp
tools/llvm-nm/llvm-nm.cpp
tools/llvm-objdump/COFFDump.cpp
tools/llvm-objdump/llvm-objdump.cpp
tools/llvm-readobj/ARMWinEHPrinter.cpp
tools/llvm-readobj/Win64EHDumper.cpp
tools/llvm-rtdyld/llvm-rtdyld.cpp
tools/llvm-symbolizer/LLVMSymbolize.cpp

index fc605826a8b084df3b6cb3e8d686f25b2c56e7ed..89f4d1c1ae4b34e74a3c15f8bec579d35e60f325 100644 (file)
@@ -648,8 +648,7 @@ public:
 protected:
   void moveSymbolNext(DataRefImpl &Symb) const override;
   ErrorOr<StringRef> getSymbolName(DataRefImpl Symb) const override;
 protected:
   void moveSymbolNext(DataRefImpl &Symb) const override;
   ErrorOr<StringRef> getSymbolName(DataRefImpl Symb) const override;
-  std::error_code getSymbolAddress(DataRefImpl Symb,
-                                   uint64_t &Res) const override;
+  ErrorOr<uint64_t> getSymbolAddress(DataRefImpl Symb) const override;
   uint64_t getSymbolValue(DataRefImpl Symb) const override;
   uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override;
   uint32_t getSymbolFlags(DataRefImpl Symb) const override;
   uint64_t getSymbolValue(DataRefImpl Symb) const override;
   uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override;
   uint32_t getSymbolFlags(DataRefImpl Symb) const override;
index 5b9b113a2f0b7048ac06850659c135683f1efbce..05698fc6675555c89b94db200ff74751fee67c53 100644 (file)
@@ -196,8 +196,7 @@ protected:
 
   void moveSymbolNext(DataRefImpl &Symb) const override;
   ErrorOr<StringRef> getSymbolName(DataRefImpl Symb) const override;
 
   void moveSymbolNext(DataRefImpl &Symb) const override;
   ErrorOr<StringRef> getSymbolName(DataRefImpl Symb) const override;
-  std::error_code getSymbolAddress(DataRefImpl Symb,
-                                   uint64_t &Res) const override;
+  ErrorOr<uint64_t> getSymbolAddress(DataRefImpl Symb) const override;
   uint64_t getSymbolValue(DataRefImpl Symb) const override;
   uint32_t getSymbolAlignment(DataRefImpl Symb) const override;
   uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override;
   uint64_t getSymbolValue(DataRefImpl Symb) const override;
   uint32_t getSymbolAlignment(DataRefImpl Symb) const override;
   uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override;
@@ -400,15 +399,15 @@ uint64_t ELFObjectFile<ELFT>::getSymbolValue(DataRefImpl Symb) const {
 }
 
 template <class ELFT>
 }
 
 template <class ELFT>
-std::error_code ELFObjectFile<ELFT>::getSymbolAddress(DataRefImpl Symb,
-                                                      uint64_t &Result) const {
-  Result = getSymbolValue(Symb);
+ErrorOr<uint64_t>
+ELFObjectFile<ELFT>::getSymbolAddress(DataRefImpl Symb) const {
+  uint64_t Result = getSymbolValue(Symb);
   const Elf_Sym *ESym = getSymbol(Symb);
   switch (ESym->st_shndx) {
   case ELF::SHN_COMMON:
   case ELF::SHN_UNDEF:
   case ELF::SHN_ABS:
   const Elf_Sym *ESym = getSymbol(Symb);
   switch (ESym->st_shndx) {
   case ELF::SHN_COMMON:
   case ELF::SHN_UNDEF:
   case ELF::SHN_ABS:
-    return std::error_code();
+    return Result;
   }
 
   const Elf_Ehdr *Header = EF.getHeader();
   }
 
   const Elf_Ehdr *Header = EF.getHeader();
@@ -422,7 +421,7 @@ std::error_code ELFObjectFile<ELFT>::getSymbolAddress(DataRefImpl Symb,
       Result += Section->sh_addr;
   }
 
       Result += Section->sh_addr;
   }
 
-  return std::error_code();
+  return Result;
 }
 
 template <class ELFT>
 }
 
 template <class ELFT>
index f4edfd057303ee488845012f0ed58885dee0463e..7ec5f0756e998c36ec120880aef87aafde5a765e 100644 (file)
@@ -205,8 +205,7 @@ public:
   std::error_code getIndirectName(DataRefImpl Symb, StringRef &Res) const;
   unsigned getSectionType(SectionRef Sec) const;
 
   std::error_code getIndirectName(DataRefImpl Symb, StringRef &Res) const;
   unsigned getSectionType(SectionRef Sec) const;
 
-  std::error_code getSymbolAddress(DataRefImpl Symb,
-                                   uint64_t &Res) const override;
+  ErrorOr<uint64_t> getSymbolAddress(DataRefImpl Symb) const override;
   uint64_t getSymbolValue(DataRefImpl Symb) const override;
   uint32_t getSymbolAlignment(DataRefImpl Symb) const override;
   uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override;
   uint64_t getSymbolValue(DataRefImpl Symb) const override;
   uint32_t getSymbolAlignment(DataRefImpl Symb) const override;
   uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override;
index 62eab1066be50a9dd745fe49210d138dfa0ea93f..ee67d8571896f87e5051e2741b6dc2365c72ffc0 100644 (file)
@@ -135,7 +135,7 @@ public:
   ErrorOr<StringRef> getName() const;
   /// Returns the symbol virtual address (i.e. address at which it will be
   /// mapped).
   ErrorOr<StringRef> getName() const;
   /// Returns the symbol virtual address (i.e. address at which it will be
   /// mapped).
-  std::error_code getAddress(uint64_t &Result) const;
+  ErrorOr<uint64_t> getAddress() const;
 
   /// Return the value of the symbol depending on the object this can be an
   /// offset or a virtual address.
 
   /// Return the value of the symbol depending on the object this can be an
   /// offset or a virtual address.
@@ -198,8 +198,7 @@ protected:
   virtual ErrorOr<StringRef> getSymbolName(DataRefImpl Symb) const = 0;
   std::error_code printSymbolName(raw_ostream &OS,
                                   DataRefImpl Symb) const override;
   virtual ErrorOr<StringRef> getSymbolName(DataRefImpl Symb) const = 0;
   std::error_code printSymbolName(raw_ostream &OS,
                                   DataRefImpl Symb) const override;
-  virtual std::error_code getSymbolAddress(DataRefImpl Symb,
-                                           uint64_t &Res) const = 0;
+  virtual ErrorOr<uint64_t> getSymbolAddress(DataRefImpl Symb) const = 0;
   virtual uint64_t getSymbolValue(DataRefImpl Symb) const = 0;
   virtual uint32_t getSymbolAlignment(DataRefImpl Symb) const;
   virtual uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const = 0;
   virtual uint64_t getSymbolValue(DataRefImpl Symb) const = 0;
   virtual uint32_t getSymbolAlignment(DataRefImpl Symb) const;
   virtual uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const = 0;
@@ -308,8 +307,8 @@ inline ErrorOr<StringRef> SymbolRef::getName() const {
   return getObject()->getSymbolName(getRawDataRefImpl());
 }
 
   return getObject()->getSymbolName(getRawDataRefImpl());
 }
 
-inline std::error_code SymbolRef::getAddress(uint64_t &Result) const {
-  return getObject()->getSymbolAddress(getRawDataRefImpl(), Result);
+inline ErrorOr<uint64_t> SymbolRef::getAddress() const {
+  return getObject()->getSymbolAddress(getRawDataRefImpl());
 }
 
 inline uint64_t SymbolRef::getValue() const {
 }
 
 inline uint64_t SymbolRef::getValue() const {
index c25ddad33b7615346012055bbe8ef8a130043d73..96bcf15e0af070aba416434f83fb92bedd402efd 100644 (file)
@@ -677,7 +677,13 @@ DWARFContextInMemory::DWARFContextInMemory(const object::ObjectFile &Obj,
         // First calculate the address of the symbol or section as it appears
         // in the objct file
         if (Sym != Obj.symbol_end()) {
         // First calculate the address of the symbol or section as it appears
         // in the objct file
         if (Sym != Obj.symbol_end()) {
-          Sym->getAddress(SymAddr);
+          ErrorOr<uint64_t> SymAddrOrErr = Sym->getAddress();
+          if (std::error_code EC = SymAddrOrErr.getError()) {
+            errs() << "error: failed to compute symbol address: "
+                   << EC.message() << '\n';
+            continue;
+          }
+          SymAddr = *SymAddrOrErr;
           // Also remember what section this symbol is in for later
           Sym->getSection(RSec);
         } else if (auto *MObj = dyn_cast<MachOObjectFile>(&Obj)) {
           // Also remember what section this symbol is in for later
           Sym->getSection(RSec);
         } else if (auto *MObj = dyn_cast<MachOObjectFile>(&Obj)) {
index fa501824e04ad3abd41c3d74ff17c052d6137e9c..092c696d53e546738769bb63c7d4afc770120de5 100644 (file)
@@ -114,9 +114,10 @@ void RuntimeDyldImpl::mapSectionAddress(const void *LocalAddress,
 }
 
 static std::error_code getOffset(const SymbolRef &Sym, uint64_t &Result) {
 }
 
 static std::error_code getOffset(const SymbolRef &Sym, uint64_t &Result) {
-  uint64_t Address;
-  if (std::error_code EC = Sym.getAddress(Address))
+  ErrorOr<uint64_t> AddressOrErr = Sym.getAddress();
+  if (std::error_code EC = AddressOrErr.getError())
     return EC;
     return EC;
+  uint64_t Address = *AddressOrErr;
 
   if (Address == UnknownAddress) {
     Result = UnknownAddress;
 
   if (Address == UnknownAddress) {
     Result = UnknownAddress;
index 64bb0d5c636d0163c3b3ed530c92d6d9a2106579..9c9a6df368982fd8dfe128e81fd74e27ceff5988 100644 (file)
@@ -163,21 +163,20 @@ uint64_t COFFObjectFile::getSymbolValue(DataRefImpl Ref) const {
   return Sym.getValue();
 }
 
   return Sym.getValue();
 }
 
-std::error_code COFFObjectFile::getSymbolAddress(DataRefImpl Ref,
-                                                 uint64_t &Result) const {
-  Result = getSymbolValue(Ref);
+ErrorOr<uint64_t> COFFObjectFile::getSymbolAddress(DataRefImpl Ref) const {
+  uint64_t Result = getSymbolValue(Ref);
   COFFSymbolRef Symb = getCOFFSymbol(Ref);
   int32_t SectionNumber = Symb.getSectionNumber();
 
   if (Symb.isAnyUndefined() || Symb.isCommon() ||
       COFF::isReservedSectionNumber(SectionNumber))
   COFFSymbolRef Symb = getCOFFSymbol(Ref);
   int32_t SectionNumber = Symb.getSectionNumber();
 
   if (Symb.isAnyUndefined() || Symb.isCommon() ||
       COFF::isReservedSectionNumber(SectionNumber))
-    return std::error_code();
+    return Result;
 
   const coff_section *Section = nullptr;
   if (std::error_code EC = getSection(SectionNumber, Section))
     return EC;
   Result += Section->VirtualAddress;
 
   const coff_section *Section = nullptr;
   if (std::error_code EC = getSection(SectionNumber, Section))
     return EC;
   Result += Section->VirtualAddress;
-  return std::error_code();
+  return Result;
 }
 
 SymbolRef::Type COFFObjectFile::getSymbolType(DataRefImpl Ref) const {
 }
 
 SymbolRef::Type COFFObjectFile::getSymbolType(DataRefImpl Ref) const {
index 53ea444160d2168833de815dc53c84337ad106b4..96718335967bb70b8dca85fbd2802427de56151c 100644 (file)
@@ -376,10 +376,8 @@ uint64_t MachOObjectFile::getSymbolValue(DataRefImpl Sym) const {
   return NValue;
 }
 
   return NValue;
 }
 
-std::error_code MachOObjectFile::getSymbolAddress(DataRefImpl Sym,
-                                                  uint64_t &Res) const {
-  Res = getSymbolValue(Sym);
-  return std::error_code();
+ErrorOr<uint64_t> MachOObjectFile::getSymbolAddress(DataRefImpl Sym) const {
+  return getSymbolValue(Sym);
 }
 
 uint32_t MachOObjectFile::getSymbolAlignment(DataRefImpl DRI) const {
 }
 
 uint32_t MachOObjectFile::getSymbolAlignment(DataRefImpl DRI) const {
index 945252b2104638d54fd5d5b53c446e032aeb34d5..c7d91bcea3e3ec2976f3d3b9946f50c81d62b234 100644 (file)
@@ -180,10 +180,10 @@ const char *LLVMGetSymbolName(LLVMSymbolIteratorRef SI) {
 }
 
 uint64_t LLVMGetSymbolAddress(LLVMSymbolIteratorRef SI) {
 }
 
 uint64_t LLVMGetSymbolAddress(LLVMSymbolIteratorRef SI) {
-  uint64_t ret;
-  if (std::error_code ec = (*unwrap(SI))->getAddress(ret))
-    report_fatal_error(ec.message());
-  return ret;
+  ErrorOr<uint64_t> Ret = (*unwrap(SI))->getAddress();
+  if (std::error_code EC = Ret.getError())
+    report_fatal_error(EC.message());
+  return *Ret;
 }
 
 uint64_t LLVMGetSymbolSize(LLVMSymbolIteratorRef SI) {
 }
 
 uint64_t LLVMGetSymbolSize(LLVMSymbolIteratorRef SI) {
index 89f3945826314ad524ec7a7c09dfa60c8b597e05..ddb764facdbfaaa99e7b0a2974d32053f2bf9a1d 100644 (file)
@@ -34,14 +34,16 @@ public:
       report_fatal_error(EC.message());
     StringRef SymName = *SymNameOrErr;
 
       report_fatal_error(EC.message());
     StringRef SymName = *SymNameOrErr;
 
-    uint64_t  SymAddr; SymI->getAddress(SymAddr);
+    ErrorOr<uint64_t> SymAddr = SymI->getAddress();
+    if (std::error_code EC = SymAddr.getError())
+      report_fatal_error(EC.message());
     uint64_t SymSize = SymI->getSize();
     int64_t Addend = *ELFRelocationRef(Rel).getAddend();
 
     MCSymbol *Sym = Ctx.getOrCreateSymbol(SymName);
     // FIXME: check that the value is actually the same.
     if (!Sym->isVariable())
     uint64_t SymSize = SymI->getSize();
     int64_t Addend = *ELFRelocationRef(Rel).getAddend();
 
     MCSymbol *Sym = Ctx.getOrCreateSymbol(SymName);
     // FIXME: check that the value is actually the same.
     if (!Sym->isVariable())
-      Sym->setVariableValue(MCConstantExpr::create(SymAddr, Ctx));
+      Sym->setVariableValue(MCConstantExpr::create(*SymAddr, Ctx));
 
     const MCExpr *Expr = nullptr;
     // If hasAddend is true, then we need to add Addend (r_addend) to Expr.
 
     const MCExpr *Expr = nullptr;
     // If hasAddend is true, then we need to add Addend (r_addend) to Expr.
index c627a662a96254475b5a30674bb69a0f9262153f..4e06be9e78b961b96db8deb24873e281fdc4af00 100644 (file)
@@ -207,9 +207,10 @@ static void dumpCXXData(const ObjectFile *Obj) {
     StringRef SecContents;
     if (error(Sec.getContents(SecContents)))
       return;
     StringRef SecContents;
     if (error(Sec.getContents(SecContents)))
       return;
-    uint64_t SymAddress;
-    if (error(Sym.getAddress(SymAddress)))
+    ErrorOr<uint64_t> SymAddressOrErr = Sym.getAddress();
+    if (error(SymAddressOrErr.getError()))
       return;
       return;
+    uint64_t SymAddress = *SymAddressOrErr;
     uint64_t SecAddress = Sec.getAddress();
     uint64_t SecSize = Sec.getSize();
     uint64_t SymOffset = SymAddress - SecAddress;
     uint64_t SecAddress = Sec.getAddress();
     uint64_t SecSize = Sec.getSize();
     uint64_t SymOffset = SymAddress - SecAddress;
index c88f37334564728e4e05718d2000d523b2c34164..cf6746109954de9db4c712851c3161047db5c24e 100644 (file)
@@ -901,8 +901,10 @@ static void dumpSymbolNamesFromObject(SymbolicFile &Obj, bool printName,
         S.Size = ELFSymbolRef(Sym).getSize();
     }
     if (PrintAddress && isa<ObjectFile>(Obj)) {
         S.Size = ELFSymbolRef(Sym).getSize();
     }
     if (PrintAddress && isa<ObjectFile>(Obj)) {
-      if (error(SymbolRef(Sym).getAddress(S.Address)))
+      ErrorOr<uint64_t> AddressOrErr = SymbolRef(Sym).getAddress();
+      if (error(AddressOrErr.getError()))
         break;
         break;
+      S.Address = *AddressOrErr;
     }
     S.TypeChar = getNMTypeChar(Obj, Sym);
     if (error(Sym.printName(OS)))
     }
     S.TypeChar = getNMTypeChar(Obj, Sym);
     if (error(Sym.printName(OS)))
index 58bdddfa9918e80d5a5912a454eae38aec1dbfb6..8b94a50ea28b5a28c74a513d75d8f94640e0e417 100644 (file)
@@ -161,8 +161,10 @@ static std::error_code
 resolveSectionAndAddress(const COFFObjectFile *Obj, const SymbolRef &Sym,
                          const coff_section *&ResolvedSection,
                          uint64_t &ResolvedAddr) {
 resolveSectionAndAddress(const COFFObjectFile *Obj, const SymbolRef &Sym,
                          const coff_section *&ResolvedSection,
                          uint64_t &ResolvedAddr) {
-  if (std::error_code EC = Sym.getAddress(ResolvedAddr))
+  ErrorOr<uint64_t> ResolvedAddrOrErr = Sym.getAddress();
+  if (std::error_code EC = ResolvedAddrOrErr.getError())
     return EC;
     return EC;
+  ResolvedAddr = *ResolvedAddrOrErr;
   section_iterator iter(Obj->section_begin());
   if (std::error_code EC = Sym.getSection(iter))
     return EC;
   section_iterator iter(Obj->section_begin());
   if (std::error_code EC = Sym.getSection(iter))
     return EC;
index 7869818546098d4f783f98fe7f0050e976f11776..39eb45a6d85a5ec156ebf4be64c14a0824d83871 100644 (file)
@@ -455,13 +455,12 @@ static void printRelocationTargetName(const MachOObjectFile *O,
 
     for (const SymbolRef &Symbol : O->symbols()) {
       std::error_code ec;
 
     for (const SymbolRef &Symbol : O->symbols()) {
       std::error_code ec;
-      uint64_t Addr;
-      ErrorOr<StringRef> Name = Symbol.getName();
-
-      if ((ec = Symbol.getAddress(Addr)))
+      ErrorOr<uint64_t> Addr = Symbol.getAddress();
+      if ((ec = Addr.getError()))
         report_fatal_error(ec.message());
         report_fatal_error(ec.message());
-      if (Addr != Val)
+      if (*Addr != Val)
         continue;
         continue;
+      ErrorOr<StringRef> Name = Symbol.getName();
       if (std::error_code EC = Name.getError())
         report_fatal_error(EC.message());
       fmt << *Name;
       if (std::error_code EC = Name.getError())
         report_fatal_error(EC.message());
       fmt << *Name;
@@ -824,9 +823,10 @@ static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
     std::vector<std::pair<uint64_t, StringRef>> Symbols;
     for (const SymbolRef &Symbol : Obj->symbols()) {
       if (Section.containsSymbol(Symbol)) {
     std::vector<std::pair<uint64_t, StringRef>> Symbols;
     for (const SymbolRef &Symbol : Obj->symbols()) {
       if (Section.containsSymbol(Symbol)) {
-        uint64_t Address;
-        if (error(Symbol.getAddress(Address)))
+        ErrorOr<uint64_t> AddressOrErr = Symbol.getAddress();
+        if (error(AddressOrErr.getError()))
           break;
           break;
+        uint64_t Address = *AddressOrErr;
         if (Address == UnknownAddress)
           continue;
         Address -= SectionAddr;
         if (Address == UnknownAddress)
           continue;
         Address -= SectionAddr;
@@ -1113,12 +1113,13 @@ void llvm::PrintSymbolTable(const ObjectFile *o) {
     return;
   }
   for (const SymbolRef &Symbol : o->symbols()) {
     return;
   }
   for (const SymbolRef &Symbol : o->symbols()) {
-    uint64_t Address;
+    ErrorOr<uint64_t> AddressOrError = Symbol.getAddress();
+    if (error(AddressOrError.getError()))
+      continue;
+    uint64_t Address = *AddressOrError;
     SymbolRef::Type Type = Symbol.getType();
     uint32_t Flags = Symbol.getFlags();
     section_iterator Section = o->section_end();
     SymbolRef::Type Type = Symbol.getType();
     uint32_t Flags = Symbol.getFlags();
     section_iterator Section = o->section_end();
-    if (error(Symbol.getAddress(Address)))
-      continue;
     if (error(Symbol.getSection(Section)))
       continue;
     StringRef Name;
     if (error(Symbol.getSection(Section)))
       continue;
     StringRef Name;
index a1ea79f3688ea9acf4e5bf6541ba498f375c2a30..bf5ff8e1d03101e68c708c5c09048b98c0c77165 100644 (file)
@@ -201,10 +201,10 @@ ErrorOr<object::SymbolRef> Decoder::getSymbol(const COFFObjectFile &COFF,
     if (FunctionOnly && Symbol.getType() != SymbolRef::ST_Function)
       continue;
 
     if (FunctionOnly && Symbol.getType() != SymbolRef::ST_Function)
       continue;
 
-    uint64_t Address;
-    if (std::error_code EC = Symbol.getAddress(Address))
+    ErrorOr<uint64_t> Address = Symbol.getAddress();
+    if (std::error_code EC = Address.getError())
       return EC;
       return EC;
-    if (Address == VA)
+    if (*Address == VA)
       return Symbol;
   }
   return readobj_error::unknown_symbol;
       return Symbol;
   }
   return readobj_error::unknown_symbol;
@@ -605,7 +605,10 @@ bool Decoder::dumpUnpackedEntry(const COFFObjectFile &COFF,
     if (std::error_code EC = FunctionNameOrErr.getError())
       report_fatal_error(EC.message());
     FunctionName = *FunctionNameOrErr;
     if (std::error_code EC = FunctionNameOrErr.getError())
       report_fatal_error(EC.message());
     FunctionName = *FunctionNameOrErr;
-    Function->getAddress(FunctionAddress);
+    ErrorOr<uint64_t> FunctionAddressOrErr = Function->getAddress();
+    if (std::error_code EC = FunctionAddressOrErr.getError())
+      report_fatal_error(EC.message());
+    FunctionAddress = *FunctionAddressOrErr;
   } else {
     const pe32_header *PEHeader;
     if (COFF.getPE32Header(PEHeader))
   } else {
     const pe32_header *PEHeader;
     if (COFF.getPE32Header(PEHeader))
@@ -620,8 +623,10 @@ bool Decoder::dumpUnpackedEntry(const COFFObjectFile &COFF,
     if (std::error_code EC = Name.getError())
       report_fatal_error(EC.message());
 
     if (std::error_code EC = Name.getError())
       report_fatal_error(EC.message());
 
-    uint64_t Address;
-    XDataRecord->getAddress(Address);
+    ErrorOr<uint64_t> AddressOrErr = XDataRecord->getAddress();
+    if (std::error_code EC = AddressOrErr.getError())
+      report_fatal_error(EC.message());
+    uint64_t Address = *AddressOrErr;
 
     SW.printString("ExceptionRecord", formatSymbol(*Name, Address));
 
 
     SW.printString("ExceptionRecord", formatSymbol(*Name, Address));
 
@@ -666,7 +671,8 @@ bool Decoder::dumpPackedEntry(const object::COFFObjectFile &COFF,
     if (std::error_code EC = FunctionNameOrErr.getError())
       report_fatal_error(EC.message());
     FunctionName = *FunctionNameOrErr;
     if (std::error_code EC = FunctionNameOrErr.getError())
       report_fatal_error(EC.message());
     FunctionName = *FunctionNameOrErr;
-    Function->getAddress(FunctionAddress);
+    ErrorOr<uint64_t> FunctionAddressOrErr = Function->getAddress();
+    FunctionAddress = *FunctionAddressOrErr;
   } else {
     const pe32_header *PEHeader;
     if (COFF.getPE32Header(PEHeader))
   } else {
     const pe32_header *PEHeader;
     if (COFF.getPE32Header(PEHeader))
index 5a8af4135bd7511c8909863d214cc5e96d9ec911..f57eea20e2d9c6de663cc1e54c4812a1c32f5d79 100644 (file)
@@ -144,8 +144,10 @@ static std::error_code resolveRelocation(const Dumper::Context &Ctx,
           Ctx.ResolveSymbol(Section, Offset, Symbol, Ctx.UserData))
     return EC;
 
           Ctx.ResolveSymbol(Section, Offset, Symbol, Ctx.UserData))
     return EC;
 
-  if (std::error_code EC = Symbol.getAddress(ResolvedAddress))
+  ErrorOr<uint64_t> ResolvedAddressOrErr = Symbol.getAddress();
+  if (std::error_code EC = ResolvedAddressOrErr.getError())
     return EC;
     return EC;
+  ResolvedAddress = *ResolvedAddressOrErr;
 
   section_iterator SI = Ctx.COFF.section_begin();
   if (std::error_code EC = Symbol.getSection(SI))
 
   section_iterator SI = Ctx.COFF.section_begin();
   if (std::error_code EC = Symbol.getSection(SI))
index 98c6f5c4399cdb6ad3192e094e6a3a4888c72277..50eb87ab934a1fdc0e710f53f2857c3e63f59ea0 100644 (file)
@@ -269,9 +269,10 @@ static int printLineInfoForInput(bool LoadObjects, bool UseDebugObj) {
         ErrorOr<StringRef> Name = Sym.getName();
         if (!Name)
           continue;
         ErrorOr<StringRef> Name = Sym.getName();
         if (!Name)
           continue;
-        uint64_t Addr;
-        if (Sym.getAddress(Addr))
+        ErrorOr<uint64_t> AddrOrErr = Sym.getAddress();
+        if (!AddrOrErr)
           continue;
           continue;
+        uint64_t Addr = *AddrOrErr;
 
         uint64_t Size = P.second;
         // If we're not using the debug object, compute the address of the
 
         uint64_t Size = P.second;
         // If we're not using the debug object, compute the address of the
index ec3fe4868db33144c272c1e35e4e5c4903ee2229..76f92f42921fd90b2f2e9139089af4c7f09419c8 100644 (file)
@@ -84,9 +84,11 @@ void ModuleInfo::addSymbol(const SymbolRef &Symbol, uint64_t SymbolSize,
   SymbolRef::Type SymbolType = Symbol.getType();
   if (SymbolType != SymbolRef::ST_Function && SymbolType != SymbolRef::ST_Data)
     return;
   SymbolRef::Type SymbolType = Symbol.getType();
   if (SymbolType != SymbolRef::ST_Function && SymbolType != SymbolRef::ST_Data)
     return;
-  uint64_t SymbolAddress;
-  if (error(Symbol.getAddress(SymbolAddress)) ||
-      SymbolAddress == UnknownAddress)
+  ErrorOr<uint64_t> SymbolAddressOrErr = Symbol.getAddress();
+  if (error(SymbolAddressOrErr.getError()))
+    return;
+  uint64_t SymbolAddress = *SymbolAddressOrErr;
+  if (SymbolAddress == UnknownAddress)
     return;
   if (OpdExtractor) {
     // For big-endian PowerPC64 ELF, symbols in the .opd section refer to
     return;
   if (OpdExtractor) {
     // For big-endian PowerPC64 ELF, symbols in the .opd section refer to