Simplify interface of function that doesn't fail.
authorRafael Espindola <rafael.espindola@gmail.com>
Sun, 31 May 2015 23:52:50 +0000 (23:52 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Sun, 31 May 2015 23:52:50 +0000 (23:52 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@238700 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Object/ELFObjectFile.h
include/llvm/Object/MachO.h
include/llvm/Object/ObjectFile.h
lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
lib/Object/MachOObjectFile.cpp
lib/Object/ObjectFile.cpp
tools/llvm-objdump/llvm-objdump.cpp

index 9bd4c3241118d6d03ea39d0db83cbb3d41732cfe..f5911c69e1e0159da623470b5900baabd1d53f31 100644 (file)
@@ -79,8 +79,7 @@ protected:
                                 StringRef &Res) const override;
   std::error_code getSymbolAddress(DataRefImpl Symb,
                                    uint64_t &Res) const override;
-  std::error_code getSymbolAlignment(DataRefImpl Symb,
-                                     uint32_t &Res) const override;
+  uint32_t getSymbolAlignment(DataRefImpl Symb) const override;
   std::error_code getSymbolSize(DataRefImpl Symb, uint64_t &Res) const override;
   uint32_t getSymbolFlags(DataRefImpl Symb) const override;
   std::error_code getSymbolOther(DataRefImpl Symb, uint8_t &Res) const override;
@@ -326,14 +325,11 @@ std::error_code ELFObjectFile<ELFT>::getSymbolAddress(DataRefImpl Symb,
 }
 
 template <class ELFT>
-std::error_code ELFObjectFile<ELFT>::getSymbolAlignment(DataRefImpl Symb,
-                                                        uint32_t &Res) const {
+uint32_t ELFObjectFile<ELFT>::getSymbolAlignment(DataRefImpl Symb) const {
   Elf_Sym_Iter Sym = toELFSymIter(Symb);
   if (Sym->st_shndx == ELF::SHN_COMMON)
-    Res = Sym->st_value;
-  else
-    Res = 0;
-  return object_error::success;
+    return Sym->st_value;
+  return 0;
 }
 
 template <class ELFT>
index 0fe327d6adcad2f6cc52131cc3013ff2acbd353a..f3251273a16a5455a595ac53311d7ff0fab08d01 100644 (file)
@@ -204,8 +204,7 @@ public:
 
   std::error_code getSymbolAddress(DataRefImpl Symb,
                                    uint64_t &Res) const override;
-  std::error_code getSymbolAlignment(DataRefImpl Symb,
-                                     uint32_t &Res) const override;
+  uint32_t getSymbolAlignment(DataRefImpl Symb) const override;
   std::error_code getSymbolSize(DataRefImpl Symb, uint64_t &Res) const override;
   std::error_code getSymbolType(DataRefImpl Symb,
                                 SymbolRef::Type &Res) const override;
index 14cd082870b025fccbb9f75fa95cdc911d144205..fc1b11d25e8ceb179b86b913fd51e333989f1ede 100644 (file)
@@ -146,7 +146,7 @@ public:
   /// mapped).
   std::error_code getAddress(uint64_t &Result) const;
   /// @brief Get the alignment of this symbol as the actual value (not log 2).
-  std::error_code getAlignment(uint32_t &Result) const;
+  uint32_t getAlignment() const;
   std::error_code getSize(uint64_t &Result) const;
   std::error_code getType(SymbolRef::Type &Result) const;
   std::error_code getOther(uint8_t &Result) const;
@@ -206,8 +206,7 @@ protected:
                                   DataRefImpl Symb) const override;
   virtual std::error_code getSymbolAddress(DataRefImpl Symb,
                                            uint64_t &Res) const = 0;
-  virtual std::error_code getSymbolAlignment(DataRefImpl Symb,
-                                             uint32_t &Res) const;
+  virtual uint32_t getSymbolAlignment(DataRefImpl Symb) const;
   virtual std::error_code getSymbolSize(DataRefImpl Symb,
                                         uint64_t &Res) const = 0;
   virtual std::error_code getSymbolType(DataRefImpl Symb,
@@ -334,8 +333,8 @@ inline std::error_code SymbolRef::getAddress(uint64_t &Result) const {
   return getObject()->getSymbolAddress(getRawDataRefImpl(), Result);
 }
 
-inline std::error_code SymbolRef::getAlignment(uint32_t &Result) const {
-  return getObject()->getSymbolAlignment(getRawDataRefImpl(), Result);
+inline uint32_t SymbolRef::getAlignment() const {
+  return getObject()->getSymbolAlignment(getRawDataRefImpl());
 }
 
 inline std::error_code SymbolRef::getSize(uint64_t &Result) const {
index 89535095dae67702a956d434f83ca28acd31bd89..ad6c6ae3ad4db65fbcb5656e97d1ec6bbfb2086f 100644 (file)
@@ -494,9 +494,8 @@ void RuntimeDyldImpl::emitCommonSymbols(const ObjectFile &Obj,
       continue;
     }
 
-    uint32_t Align = 0;
+    uint32_t Align = Sym.getAlignment();
     uint64_t Size = 0;
-    Check(Sym.getAlignment(Align));
     Check(Sym.getSize(Size));
 
     CommonSize += Align + Size;
@@ -518,10 +517,9 @@ void RuntimeDyldImpl::emitCommonSymbols(const ObjectFile &Obj,
 
   // Assign the address of each symbol
   for (auto &Sym : SymbolsToAllocate) {
-    uint32_t Align;
+    uint32_t Align = Sym.getAlignment();
     uint64_t Size;
     StringRef Name;
-    Check(Sym.getAlignment(Align));
     Check(Sym.getSize(Size));
     Check(Sym.getName(Name));
     if (Align) {
index 439dceb323b7cce204e830a22626e00982675b11..cae5b799ac114f9a9a0c31c00cc13c5660f7e24e 100644 (file)
@@ -401,16 +401,13 @@ std::error_code MachOObjectFile::getSymbolAddress(DataRefImpl Symb,
   return object_error::success;
 }
 
-std::error_code MachOObjectFile::getSymbolAlignment(DataRefImpl DRI,
-                                                    uint32_t &Result) const {
+uint32_t MachOObjectFile::getSymbolAlignment(DataRefImpl DRI) const {
   uint32_t flags = getSymbolFlags(DRI);
   if (flags & SymbolRef::SF_Common) {
     MachO::nlist_base Entry = getSymbolTableEntryBase(this, DRI);
-    Result = 1 << MachO::GET_COMM_ALIGN(Entry.n_desc);
-  } else {
-    Result = 0;
+    return 1 << MachO::GET_COMM_ALIGN(Entry.n_desc);
   }
-  return object_error::success;
+  return 0;
 }
 
 std::error_code MachOObjectFile::getSymbolSize(DataRefImpl DRI,
index 01b76543fa2eb97db234aa84d4caec7663897052..0950c7daafdeb20cd224aa4313d4c8a2ae913534 100644 (file)
@@ -37,11 +37,7 @@ std::error_code ObjectFile::printSymbolName(raw_ostream &OS,
   return object_error::success;
 }
 
-std::error_code ObjectFile::getSymbolAlignment(DataRefImpl DRI,
-                                               uint32_t &Result) const {
-  Result = 0;
-  return object_error::success;
-}
+uint32_t ObjectFile::getSymbolAlignment(DataRefImpl DRI) const { return 0; }
 
 section_iterator ObjectFile::getRelocatedSection(DataRefImpl Sec) const {
   return section_iterator(SectionRef(Sec, this));
index 5a8b56e5aa27871d2506bce904b458ef741373dc..b460758399c6426f70ce6f6a43d7da766c4e40e9 100644 (file)
@@ -697,9 +697,7 @@ void llvm::PrintSymbolTable(const ObjectFile *o) {
     bool Hidden = Flags & SymbolRef::SF_Hidden;
 
     if (Common) {
-      uint32_t Alignment;
-      if (error(Symbol.getAlignment(Alignment)))
-        Alignment = 0;
+      uint32_t Alignment = Symbol.getAlignment();
       Address = Size;
       Size = Alignment;
     }