mirror of
				https://github.com/c64scene-ar/llvm-6502.git
				synced 2025-11-04 05:17:07 +00:00 
			
		
		
		
	Fixed ObjectFile functions:
- getSymbolOffset() renamed as getSymbolFileOffset() - getSymbolFileOffset(), getSymbolAddress(), getRelocationAddress() returns same result for ELFObjectFile, MachOObjectFile and COFFObjectFile. - added getRelocationOffset() - fixed MachOObjectFile::getSymbolSize() - fixed MachOObjectFile::getSymbolSection() - fixed MachOObjectFile::getSymbolOffset() for symbols without section data. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@145408 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
		@@ -73,11 +73,12 @@ void LLVMMoveToNextRelocation(LLVMRelocationIteratorRef RI);
 | 
				
			|||||||
// SymbolRef accessors
 | 
					// SymbolRef accessors
 | 
				
			||||||
const char *LLVMGetSymbolName(LLVMSymbolIteratorRef SI);
 | 
					const char *LLVMGetSymbolName(LLVMSymbolIteratorRef SI);
 | 
				
			||||||
uint64_t LLVMGetSymbolAddress(LLVMSymbolIteratorRef SI);
 | 
					uint64_t LLVMGetSymbolAddress(LLVMSymbolIteratorRef SI);
 | 
				
			||||||
uint64_t LLVMGetSymbolOffset(LLVMSymbolIteratorRef SI);
 | 
					uint64_t LLVMGetSymbolFileOffset(LLVMSymbolIteratorRef SI);
 | 
				
			||||||
uint64_t LLVMGetSymbolSize(LLVMSymbolIteratorRef SI);
 | 
					uint64_t LLVMGetSymbolSize(LLVMSymbolIteratorRef SI);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// RelocationRef accessors
 | 
					// RelocationRef accessors
 | 
				
			||||||
uint64_t LLVMGetRelocationAddress(LLVMRelocationIteratorRef RI);
 | 
					uint64_t LLVMGetRelocationAddress(LLVMRelocationIteratorRef RI);
 | 
				
			||||||
 | 
					uint64_t LLVMGetRelocationOffset(LLVMRelocationIteratorRef RI);
 | 
				
			||||||
LLVMSymbolIteratorRef LLVMGetRelocationSymbol(LLVMRelocationIteratorRef RI);
 | 
					LLVMSymbolIteratorRef LLVMGetRelocationSymbol(LLVMRelocationIteratorRef RI);
 | 
				
			||||||
uint64_t LLVMGetRelocationType(LLVMRelocationIteratorRef RI);
 | 
					uint64_t LLVMGetRelocationType(LLVMRelocationIteratorRef RI);
 | 
				
			||||||
// NOTE: Caller takes ownership of returned string of the two
 | 
					// NOTE: Caller takes ownership of returned string of the two
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -105,7 +105,7 @@ private:
 | 
				
			|||||||
protected:
 | 
					protected:
 | 
				
			||||||
  virtual error_code getSymbolNext(DataRefImpl Symb, SymbolRef &Res) const;
 | 
					  virtual error_code getSymbolNext(DataRefImpl Symb, SymbolRef &Res) const;
 | 
				
			||||||
  virtual error_code getSymbolName(DataRefImpl Symb, StringRef &Res) const;
 | 
					  virtual error_code getSymbolName(DataRefImpl Symb, StringRef &Res) const;
 | 
				
			||||||
  virtual error_code getSymbolOffset(DataRefImpl Symb, uint64_t &Res) const;
 | 
					  virtual error_code getSymbolFileOffset(DataRefImpl Symb, uint64_t &Res) const;
 | 
				
			||||||
  virtual error_code getSymbolAddress(DataRefImpl Symb, uint64_t &Res) const;
 | 
					  virtual error_code getSymbolAddress(DataRefImpl Symb, uint64_t &Res) const;
 | 
				
			||||||
  virtual error_code getSymbolSize(DataRefImpl Symb, uint64_t &Res) const;
 | 
					  virtual error_code getSymbolSize(DataRefImpl Symb, uint64_t &Res) const;
 | 
				
			||||||
  virtual error_code getSymbolNMTypeChar(DataRefImpl Symb, char &Res) const;
 | 
					  virtual error_code getSymbolNMTypeChar(DataRefImpl Symb, char &Res) const;
 | 
				
			||||||
@@ -135,6 +135,8 @@ protected:
 | 
				
			|||||||
                                       RelocationRef &Res) const;
 | 
					                                       RelocationRef &Res) const;
 | 
				
			||||||
  virtual error_code getRelocationAddress(DataRefImpl Rel,
 | 
					  virtual error_code getRelocationAddress(DataRefImpl Rel,
 | 
				
			||||||
                                          uint64_t &Res) const;
 | 
					                                          uint64_t &Res) const;
 | 
				
			||||||
 | 
					  virtual error_code getRelocationOffset(DataRefImpl Rel,
 | 
				
			||||||
 | 
					                                         uint64_t &Res) const;
 | 
				
			||||||
  virtual error_code getRelocationSymbol(DataRefImpl Rel,
 | 
					  virtual error_code getRelocationSymbol(DataRefImpl Rel,
 | 
				
			||||||
                                         SymbolRef &Res) const;
 | 
					                                         SymbolRef &Res) const;
 | 
				
			||||||
  virtual error_code getRelocationType(DataRefImpl Rel,
 | 
					  virtual error_code getRelocationType(DataRefImpl Rel,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -49,7 +49,7 @@ public:
 | 
				
			|||||||
protected:
 | 
					protected:
 | 
				
			||||||
  virtual error_code getSymbolNext(DataRefImpl Symb, SymbolRef &Res) const;
 | 
					  virtual error_code getSymbolNext(DataRefImpl Symb, SymbolRef &Res) const;
 | 
				
			||||||
  virtual error_code getSymbolName(DataRefImpl Symb, StringRef &Res) const;
 | 
					  virtual error_code getSymbolName(DataRefImpl Symb, StringRef &Res) const;
 | 
				
			||||||
  virtual error_code getSymbolOffset(DataRefImpl Symb, uint64_t &Res) const;
 | 
					  virtual error_code getSymbolFileOffset(DataRefImpl Symb, uint64_t &Res) const;
 | 
				
			||||||
  virtual error_code getSymbolAddress(DataRefImpl Symb, uint64_t &Res) const;
 | 
					  virtual error_code getSymbolAddress(DataRefImpl Symb, uint64_t &Res) const;
 | 
				
			||||||
  virtual error_code getSymbolSize(DataRefImpl Symb, uint64_t &Res) const;
 | 
					  virtual error_code getSymbolSize(DataRefImpl Symb, uint64_t &Res) const;
 | 
				
			||||||
  virtual error_code getSymbolNMTypeChar(DataRefImpl Symb, char &Res) const;
 | 
					  virtual error_code getSymbolNMTypeChar(DataRefImpl Symb, char &Res) const;
 | 
				
			||||||
@@ -79,6 +79,8 @@ protected:
 | 
				
			|||||||
                                       RelocationRef &Res) const;
 | 
					                                       RelocationRef &Res) const;
 | 
				
			||||||
  virtual error_code getRelocationAddress(DataRefImpl Rel,
 | 
					  virtual error_code getRelocationAddress(DataRefImpl Rel,
 | 
				
			||||||
                                          uint64_t &Res) const;
 | 
					                                          uint64_t &Res) const;
 | 
				
			||||||
 | 
					  virtual error_code getRelocationOffset(DataRefImpl Rel,
 | 
				
			||||||
 | 
					                                         uint64_t &Res) const;
 | 
				
			||||||
  virtual error_code getRelocationSymbol(DataRefImpl Rel,
 | 
					  virtual error_code getRelocationSymbol(DataRefImpl Rel,
 | 
				
			||||||
                                         SymbolRef &Res) const;
 | 
					                                         SymbolRef &Res) const;
 | 
				
			||||||
  virtual error_code getRelocationType(DataRefImpl Rel,
 | 
					  virtual error_code getRelocationType(DataRefImpl Rel,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -104,6 +104,7 @@ public:
 | 
				
			|||||||
  error_code getNext(RelocationRef &Result) const;
 | 
					  error_code getNext(RelocationRef &Result) const;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  error_code getAddress(uint64_t &Result) const;
 | 
					  error_code getAddress(uint64_t &Result) const;
 | 
				
			||||||
 | 
					  error_code getOffset(uint64_t &Result) const;
 | 
				
			||||||
  error_code getSymbol(SymbolRef &Result) const;
 | 
					  error_code getSymbol(SymbolRef &Result) const;
 | 
				
			||||||
  error_code getType(uint64_t &Result) const;
 | 
					  error_code getType(uint64_t &Result) const;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -195,7 +196,7 @@ public:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  error_code getName(StringRef &Result) const;
 | 
					  error_code getName(StringRef &Result) const;
 | 
				
			||||||
  error_code getAddress(uint64_t &Result) const;
 | 
					  error_code getAddress(uint64_t &Result) const;
 | 
				
			||||||
  error_code getOffset(uint64_t &Result) const;
 | 
					  error_code getFileOffset(uint64_t &Result) const;
 | 
				
			||||||
  error_code getSize(uint64_t &Result) const;
 | 
					  error_code getSize(uint64_t &Result) const;
 | 
				
			||||||
  error_code getType(SymbolRef::Type &Result) const;
 | 
					  error_code getType(SymbolRef::Type &Result) const;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -254,7 +255,7 @@ protected:
 | 
				
			|||||||
  virtual error_code getSymbolNext(DataRefImpl Symb, SymbolRef &Res) const = 0;
 | 
					  virtual error_code getSymbolNext(DataRefImpl Symb, SymbolRef &Res) const = 0;
 | 
				
			||||||
  virtual error_code getSymbolName(DataRefImpl Symb, StringRef &Res) const = 0;
 | 
					  virtual error_code getSymbolName(DataRefImpl Symb, StringRef &Res) const = 0;
 | 
				
			||||||
  virtual error_code getSymbolAddress(DataRefImpl Symb, uint64_t &Res) const =0;
 | 
					  virtual error_code getSymbolAddress(DataRefImpl Symb, uint64_t &Res) const =0;
 | 
				
			||||||
  virtual error_code getSymbolOffset(DataRefImpl Symb, uint64_t &Res) const =0;
 | 
					  virtual error_code getSymbolFileOffset(DataRefImpl Symb, uint64_t &Res) const =0;
 | 
				
			||||||
  virtual error_code getSymbolSize(DataRefImpl Symb, uint64_t &Res) const = 0;
 | 
					  virtual error_code getSymbolSize(DataRefImpl Symb, uint64_t &Res) const = 0;
 | 
				
			||||||
  virtual error_code getSymbolType(DataRefImpl Symb,
 | 
					  virtual error_code getSymbolType(DataRefImpl Symb,
 | 
				
			||||||
                                   SymbolRef::Type &Res) const = 0;
 | 
					                                   SymbolRef::Type &Res) const = 0;
 | 
				
			||||||
@@ -289,6 +290,8 @@ protected:
 | 
				
			|||||||
                                       RelocationRef &Res) const = 0;
 | 
					                                       RelocationRef &Res) const = 0;
 | 
				
			||||||
  virtual error_code getRelocationAddress(DataRefImpl Rel,
 | 
					  virtual error_code getRelocationAddress(DataRefImpl Rel,
 | 
				
			||||||
                                          uint64_t &Res) const =0;
 | 
					                                          uint64_t &Res) const =0;
 | 
				
			||||||
 | 
					  virtual error_code getRelocationOffset(DataRefImpl Rel,
 | 
				
			||||||
 | 
					                                         uint64_t &Res) const =0;
 | 
				
			||||||
  virtual error_code getRelocationSymbol(DataRefImpl Rel,
 | 
					  virtual error_code getRelocationSymbol(DataRefImpl Rel,
 | 
				
			||||||
                                         SymbolRef &Res) const = 0;
 | 
					                                         SymbolRef &Res) const = 0;
 | 
				
			||||||
  virtual error_code getRelocationType(DataRefImpl Rel,
 | 
					  virtual error_code getRelocationType(DataRefImpl Rel,
 | 
				
			||||||
@@ -363,8 +366,8 @@ inline error_code SymbolRef::getAddress(uint64_t &Result) const {
 | 
				
			|||||||
  return OwningObject->getSymbolAddress(SymbolPimpl, Result);
 | 
					  return OwningObject->getSymbolAddress(SymbolPimpl, Result);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
inline error_code SymbolRef::getOffset(uint64_t &Result) const {
 | 
					inline error_code SymbolRef::getFileOffset(uint64_t &Result) const {
 | 
				
			||||||
  return OwningObject->getSymbolOffset(SymbolPimpl, Result);
 | 
					  return OwningObject->getSymbolFileOffset(SymbolPimpl, Result);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
inline error_code SymbolRef::getSize(uint64_t &Result) const {
 | 
					inline error_code SymbolRef::getSize(uint64_t &Result) const {
 | 
				
			||||||
@@ -486,6 +489,10 @@ inline error_code RelocationRef::getAddress(uint64_t &Result) const {
 | 
				
			|||||||
  return OwningObject->getRelocationAddress(RelocationPimpl, Result);
 | 
					  return OwningObject->getRelocationAddress(RelocationPimpl, Result);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					inline error_code RelocationRef::getOffset(uint64_t &Result) const {
 | 
				
			||||||
 | 
					  return OwningObject->getRelocationOffset(RelocationPimpl, Result);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
inline error_code RelocationRef::getSymbol(SymbolRef &Result) const {
 | 
					inline error_code RelocationRef::getSymbol(SymbolRef &Result) const {
 | 
				
			||||||
  return OwningObject->getRelocationSymbol(RelocationPimpl, Result);
 | 
					  return OwningObject->getRelocationSymbol(RelocationPimpl, Result);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -101,7 +101,7 @@ error_code COFFObjectFile::getSymbolNext(DataRefImpl Symb,
 | 
				
			|||||||
  return getSymbolName(symb, Result);
 | 
					  return getSymbolName(symb, Result);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
error_code COFFObjectFile::getSymbolOffset(DataRefImpl Symb,
 | 
					error_code COFFObjectFile::getSymbolFileOffset(DataRefImpl Symb,
 | 
				
			||||||
                                            uint64_t &Result) const {
 | 
					                                            uint64_t &Result) const {
 | 
				
			||||||
  const coff_symbol *symb = toSymb(Symb);
 | 
					  const coff_symbol *symb = toSymb(Symb);
 | 
				
			||||||
  const coff_section *Section = NULL;
 | 
					  const coff_section *Section = NULL;
 | 
				
			||||||
@@ -113,7 +113,7 @@ error_code COFFObjectFile::getSymbolOffset(DataRefImpl Symb,
 | 
				
			|||||||
  if (Type == 'U' || Type == 'w')
 | 
					  if (Type == 'U' || Type == 'w')
 | 
				
			||||||
    Result = UnknownAddressOrSize;
 | 
					    Result = UnknownAddressOrSize;
 | 
				
			||||||
  else if (Section)
 | 
					  else if (Section)
 | 
				
			||||||
    Result = Section->VirtualAddress + symb->Value;
 | 
					    Result = Section->PointerToRawData + symb->Value;
 | 
				
			||||||
  else
 | 
					  else
 | 
				
			||||||
    Result = symb->Value;
 | 
					    Result = symb->Value;
 | 
				
			||||||
  return object_error::success;
 | 
					  return object_error::success;
 | 
				
			||||||
@@ -131,11 +131,9 @@ error_code COFFObjectFile::getSymbolAddress(DataRefImpl Symb,
 | 
				
			|||||||
  if (Type == 'U' || Type == 'w')
 | 
					  if (Type == 'U' || Type == 'w')
 | 
				
			||||||
    Result = UnknownAddressOrSize;
 | 
					    Result = UnknownAddressOrSize;
 | 
				
			||||||
  else if (Section)
 | 
					  else if (Section)
 | 
				
			||||||
    Result = reinterpret_cast<uintptr_t>(base() +
 | 
					    Result = Section->VirtualAddress + symb->Value;
 | 
				
			||||||
                                         Section->PointerToRawData +
 | 
					 | 
				
			||||||
                                         symb->Value);
 | 
					 | 
				
			||||||
  else
 | 
					  else
 | 
				
			||||||
    Result = reinterpret_cast<uintptr_t>(base() + symb->Value);
 | 
					    Result = symb->Value;
 | 
				
			||||||
  return object_error::success;
 | 
					  return object_error::success;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -624,6 +622,11 @@ error_code COFFObjectFile::getRelocationAddress(DataRefImpl Rel,
 | 
				
			|||||||
  Res = toRel(Rel)->VirtualAddress;
 | 
					  Res = toRel(Rel)->VirtualAddress;
 | 
				
			||||||
  return object_error::success;
 | 
					  return object_error::success;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					error_code COFFObjectFile::getRelocationOffset(DataRefImpl Rel,
 | 
				
			||||||
 | 
					                                               uint64_t &Res) const {
 | 
				
			||||||
 | 
					  Res = toRel(Rel)->VirtualAddress;
 | 
				
			||||||
 | 
					  return object_error::success;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
error_code COFFObjectFile::getRelocationSymbol(DataRefImpl Rel,
 | 
					error_code COFFObjectFile::getRelocationSymbol(DataRefImpl Rel,
 | 
				
			||||||
                                               SymbolRef &Res) const {
 | 
					                                               SymbolRef &Res) const {
 | 
				
			||||||
  const coff_relocation* R = toRel(Rel);
 | 
					  const coff_relocation* R = toRel(Rel);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -325,7 +325,7 @@ class ELFObjectFile : public ObjectFile {
 | 
				
			|||||||
protected:
 | 
					protected:
 | 
				
			||||||
  virtual error_code getSymbolNext(DataRefImpl Symb, SymbolRef &Res) const;
 | 
					  virtual error_code getSymbolNext(DataRefImpl Symb, SymbolRef &Res) const;
 | 
				
			||||||
  virtual error_code getSymbolName(DataRefImpl Symb, StringRef &Res) const;
 | 
					  virtual error_code getSymbolName(DataRefImpl Symb, StringRef &Res) const;
 | 
				
			||||||
  virtual error_code getSymbolOffset(DataRefImpl Symb, uint64_t &Res) const;
 | 
					  virtual error_code getSymbolFileOffset(DataRefImpl Symb, uint64_t &Res) const;
 | 
				
			||||||
  virtual error_code getSymbolAddress(DataRefImpl Symb, uint64_t &Res) const;
 | 
					  virtual error_code getSymbolAddress(DataRefImpl Symb, uint64_t &Res) const;
 | 
				
			||||||
  virtual error_code getSymbolSize(DataRefImpl Symb, uint64_t &Res) const;
 | 
					  virtual error_code getSymbolSize(DataRefImpl Symb, uint64_t &Res) const;
 | 
				
			||||||
  virtual error_code getSymbolNMTypeChar(DataRefImpl Symb, char &Res) const;
 | 
					  virtual error_code getSymbolNMTypeChar(DataRefImpl Symb, char &Res) const;
 | 
				
			||||||
@@ -355,6 +355,8 @@ protected:
 | 
				
			|||||||
                                       RelocationRef &Res) const;
 | 
					                                       RelocationRef &Res) const;
 | 
				
			||||||
  virtual error_code getRelocationAddress(DataRefImpl Rel,
 | 
					  virtual error_code getRelocationAddress(DataRefImpl Rel,
 | 
				
			||||||
                                          uint64_t &Res) const;
 | 
					                                          uint64_t &Res) const;
 | 
				
			||||||
 | 
					  virtual error_code getRelocationOffset(DataRefImpl Rel,
 | 
				
			||||||
 | 
					                                         uint64_t &Res) const;
 | 
				
			||||||
  virtual error_code getRelocationSymbol(DataRefImpl Rel,
 | 
					  virtual error_code getRelocationSymbol(DataRefImpl Rel,
 | 
				
			||||||
                                         SymbolRef &Res) const;
 | 
					                                         SymbolRef &Res) const;
 | 
				
			||||||
  virtual error_code getRelocationType(DataRefImpl Rel,
 | 
					  virtual error_code getRelocationType(DataRefImpl Rel,
 | 
				
			||||||
@@ -462,7 +464,42 @@ ELFObjectFile<target_endianness, is64Bits>
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
template<support::endianness target_endianness, bool is64Bits>
 | 
					template<support::endianness target_endianness, bool is64Bits>
 | 
				
			||||||
error_code ELFObjectFile<target_endianness, is64Bits>
 | 
					error_code ELFObjectFile<target_endianness, is64Bits>
 | 
				
			||||||
                        ::getSymbolOffset(DataRefImpl Symb,
 | 
					                        ::getSymbolFileOffset(DataRefImpl Symb,
 | 
				
			||||||
 | 
					                                          uint64_t &Result) const {
 | 
				
			||||||
 | 
					  validateSymbol(Symb);
 | 
				
			||||||
 | 
					  const Elf_Sym  *symb = getSymbol(Symb);
 | 
				
			||||||
 | 
					  const Elf_Shdr *Section;
 | 
				
			||||||
 | 
					  switch (getSymbolTableIndex(symb)) {
 | 
				
			||||||
 | 
					  case ELF::SHN_COMMON:
 | 
				
			||||||
 | 
					   // Undefined symbols have no address yet.
 | 
				
			||||||
 | 
					  case ELF::SHN_UNDEF:
 | 
				
			||||||
 | 
					    Result = UnknownAddressOrSize;
 | 
				
			||||||
 | 
					    return object_error::success;
 | 
				
			||||||
 | 
					  case ELF::SHN_ABS:
 | 
				
			||||||
 | 
					    Result = symb->st_value;
 | 
				
			||||||
 | 
					    return object_error::success;
 | 
				
			||||||
 | 
					  default: Section = getSection(symb);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  switch (symb->getType()) {
 | 
				
			||||||
 | 
					  case ELF::STT_SECTION:
 | 
				
			||||||
 | 
					    Result = Section ? Section->sh_addr : UnknownAddressOrSize;
 | 
				
			||||||
 | 
					    return object_error::success;
 | 
				
			||||||
 | 
					  case ELF::STT_FUNC:
 | 
				
			||||||
 | 
					  case ELF::STT_OBJECT:
 | 
				
			||||||
 | 
					  case ELF::STT_NOTYPE:
 | 
				
			||||||
 | 
					    Result = symb->st_value +
 | 
				
			||||||
 | 
					             (Section ? Section->sh_offset - Section->sh_addr : 0);
 | 
				
			||||||
 | 
					    return object_error::success;
 | 
				
			||||||
 | 
					  default:
 | 
				
			||||||
 | 
					    Result = UnknownAddressOrSize;
 | 
				
			||||||
 | 
					    return object_error::success;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					template<support::endianness target_endianness, bool is64Bits>
 | 
				
			||||||
 | 
					error_code ELFObjectFile<target_endianness, is64Bits>
 | 
				
			||||||
 | 
					                        ::getSymbolAddress(DataRefImpl Symb,
 | 
				
			||||||
                                           uint64_t &Result) const {
 | 
					                                           uint64_t &Result) const {
 | 
				
			||||||
  validateSymbol(Symb);
 | 
					  validateSymbol(Symb);
 | 
				
			||||||
  const Elf_Sym  *symb = getSymbol(Symb);
 | 
					  const Elf_Sym  *symb = getSymbol(Symb);
 | 
				
			||||||
@@ -494,43 +531,6 @@ error_code ELFObjectFile<target_endianness, is64Bits>
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
template<support::endianness target_endianness, bool is64Bits>
 | 
					 | 
				
			||||||
error_code ELFObjectFile<target_endianness, is64Bits>
 | 
					 | 
				
			||||||
                        ::getSymbolAddress(DataRefImpl Symb,
 | 
					 | 
				
			||||||
                                           uint64_t &Result) const {
 | 
					 | 
				
			||||||
  validateSymbol(Symb);
 | 
					 | 
				
			||||||
  const Elf_Sym  *symb = getSymbol(Symb);
 | 
					 | 
				
			||||||
  const Elf_Shdr *Section;
 | 
					 | 
				
			||||||
  switch (getSymbolTableIndex(symb)) {
 | 
					 | 
				
			||||||
  case ELF::SHN_COMMON: // Fall through.
 | 
					 | 
				
			||||||
   // Undefined symbols have no address yet.
 | 
					 | 
				
			||||||
  case ELF::SHN_UNDEF:
 | 
					 | 
				
			||||||
    Result = UnknownAddressOrSize;
 | 
					 | 
				
			||||||
    return object_error::success;
 | 
					 | 
				
			||||||
  case ELF::SHN_ABS:
 | 
					 | 
				
			||||||
    Result = reinterpret_cast<uintptr_t>(base()+symb->st_value);
 | 
					 | 
				
			||||||
    return object_error::success;
 | 
					 | 
				
			||||||
  default: Section = getSection(symb);
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  const uint8_t* addr = base();
 | 
					 | 
				
			||||||
  if (Section)
 | 
					 | 
				
			||||||
    addr += Section->sh_offset;
 | 
					 | 
				
			||||||
  switch (symb->getType()) {
 | 
					 | 
				
			||||||
  case ELF::STT_SECTION:
 | 
					 | 
				
			||||||
    Result = reinterpret_cast<uintptr_t>(addr);
 | 
					 | 
				
			||||||
    return object_error::success;
 | 
					 | 
				
			||||||
  case ELF::STT_FUNC: // Fall through.
 | 
					 | 
				
			||||||
  case ELF::STT_OBJECT: // Fall through.
 | 
					 | 
				
			||||||
  case ELF::STT_NOTYPE:
 | 
					 | 
				
			||||||
    addr += symb->st_value;
 | 
					 | 
				
			||||||
    Result = reinterpret_cast<uintptr_t>(addr);
 | 
					 | 
				
			||||||
    return object_error::success;
 | 
					 | 
				
			||||||
  default:
 | 
					 | 
				
			||||||
    Result = UnknownAddressOrSize;
 | 
					 | 
				
			||||||
    return object_error::success;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
template<support::endianness target_endianness, bool is64Bits>
 | 
					template<support::endianness target_endianness, bool is64Bits>
 | 
				
			||||||
error_code ELFObjectFile<target_endianness, is64Bits>
 | 
					error_code ELFObjectFile<target_endianness, is64Bits>
 | 
				
			||||||
                        ::getSymbolSize(DataRefImpl Symb,
 | 
					                        ::getSymbolSize(DataRefImpl Symb,
 | 
				
			||||||
@@ -920,6 +920,29 @@ error_code ELFObjectFile<target_endianness, is64Bits>
 | 
				
			|||||||
  return object_error::success;
 | 
					  return object_error::success;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					template<support::endianness target_endianness, bool is64Bits>
 | 
				
			||||||
 | 
					error_code ELFObjectFile<target_endianness, is64Bits>
 | 
				
			||||||
 | 
					                        ::getRelocationOffset(DataRefImpl Rel,
 | 
				
			||||||
 | 
					                                              uint64_t &Result) const {
 | 
				
			||||||
 | 
					  uint64_t offset;
 | 
				
			||||||
 | 
					  const Elf_Shdr *sec = getSection(Rel.w.b);
 | 
				
			||||||
 | 
					  switch (sec->sh_type) {
 | 
				
			||||||
 | 
					    default :
 | 
				
			||||||
 | 
					      report_fatal_error("Invalid section type in Rel!");
 | 
				
			||||||
 | 
					    case ELF::SHT_REL : {
 | 
				
			||||||
 | 
					      offset = getRel(Rel)->r_offset;
 | 
				
			||||||
 | 
					      break;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    case ELF::SHT_RELA : {
 | 
				
			||||||
 | 
					      offset = getRela(Rel)->r_offset;
 | 
				
			||||||
 | 
					      break;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Result = offset - sec->sh_addr;
 | 
				
			||||||
 | 
					  return object_error::success;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
template<support::endianness target_endianness, bool is64Bits>
 | 
					template<support::endianness target_endianness, bool is64Bits>
 | 
				
			||||||
error_code ELFObjectFile<target_endianness, is64Bits>
 | 
					error_code ELFObjectFile<target_endianness, is64Bits>
 | 
				
			||||||
                        ::getRelocationType(DataRefImpl Rel,
 | 
					                        ::getRelocationType(DataRefImpl Rel,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -125,23 +125,27 @@ error_code MachOObjectFile::getSymbolName(DataRefImpl DRI,
 | 
				
			|||||||
  return object_error::success;
 | 
					  return object_error::success;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
error_code MachOObjectFile::getSymbolOffset(DataRefImpl DRI,
 | 
					error_code MachOObjectFile::getSymbolFileOffset(DataRefImpl DRI,
 | 
				
			||||||
                                                uint64_t &Result) const {
 | 
					                                                uint64_t &Result) const {
 | 
				
			||||||
  uint64_t SectionOffset;
 | 
					 | 
				
			||||||
  uint8_t SectionIndex;
 | 
					 | 
				
			||||||
  if (MachOObj->is64Bit()) {
 | 
					  if (MachOObj->is64Bit()) {
 | 
				
			||||||
    InMemoryStruct<macho::Symbol64TableEntry> Entry;
 | 
					    InMemoryStruct<macho::Symbol64TableEntry> Entry;
 | 
				
			||||||
    getSymbol64TableEntry(DRI, Entry);
 | 
					    getSymbol64TableEntry(DRI, Entry);
 | 
				
			||||||
    Result = Entry->Value;
 | 
					    Result = Entry->Value;
 | 
				
			||||||
    SectionIndex = Entry->SectionIndex;
 | 
					    if (Entry->SectionIndex) {
 | 
				
			||||||
 | 
					      InMemoryStruct<macho::Section64> Section;
 | 
				
			||||||
 | 
					      getSection64(Sections[Entry->SectionIndex-1], Section);
 | 
				
			||||||
 | 
					      Result += Section->Offset - Section->Address;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
  } else {
 | 
					  } else {
 | 
				
			||||||
    InMemoryStruct<macho::SymbolTableEntry> Entry;
 | 
					    InMemoryStruct<macho::SymbolTableEntry> Entry;
 | 
				
			||||||
    getSymbolTableEntry(DRI, Entry);
 | 
					    getSymbolTableEntry(DRI, Entry);
 | 
				
			||||||
    Result = Entry->Value;
 | 
					    Result = Entry->Value;
 | 
				
			||||||
    SectionIndex = Entry->SectionIndex;
 | 
					    if (Entry->SectionIndex) {
 | 
				
			||||||
 | 
					      InMemoryStruct<macho::Section> Section;
 | 
				
			||||||
 | 
					      getSection(Sections[Entry->SectionIndex-1], Section);
 | 
				
			||||||
 | 
					      Result += Section->Offset - Section->Address;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  getSectionAddress(Sections[SectionIndex-1], SectionOffset);
 | 
					 | 
				
			||||||
  Result -= SectionOffset;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return object_error::success;
 | 
					  return object_error::success;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -162,9 +166,66 @@ error_code MachOObjectFile::getSymbolAddress(DataRefImpl DRI,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
error_code MachOObjectFile::getSymbolSize(DataRefImpl DRI,
 | 
					error_code MachOObjectFile::getSymbolSize(DataRefImpl DRI,
 | 
				
			||||||
                                          uint64_t &Result) const {
 | 
					                                          uint64_t &Result) const {
 | 
				
			||||||
 | 
					  uint32_t LoadCommandCount = MachOObj->getHeader().NumLoadCommands;
 | 
				
			||||||
 | 
					  uint64_t BeginOffset;
 | 
				
			||||||
 | 
					  uint64_t EndOffset = 0;
 | 
				
			||||||
 | 
					  uint8_t SectionIndex;
 | 
				
			||||||
 | 
					  if (MachOObj->is64Bit()) {
 | 
				
			||||||
 | 
					    InMemoryStruct<macho::Symbol64TableEntry> Entry;
 | 
				
			||||||
 | 
					    getSymbol64TableEntry(DRI, Entry);
 | 
				
			||||||
 | 
					    BeginOffset = Entry->Value;
 | 
				
			||||||
 | 
					    SectionIndex = Entry->SectionIndex;
 | 
				
			||||||
 | 
					    if (!SectionIndex) {
 | 
				
			||||||
      Result = UnknownAddressOrSize;
 | 
					      Result = UnknownAddressOrSize;
 | 
				
			||||||
      return object_error::success;
 | 
					      return object_error::success;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    // Unfortunately symbols are unsorted so we need to touch all
 | 
				
			||||||
 | 
					    // symbols from load command
 | 
				
			||||||
 | 
					    DRI.d.b = 0;
 | 
				
			||||||
 | 
					    uint32_t Command = DRI.d.a;
 | 
				
			||||||
 | 
					    while (Command == DRI.d.a) {
 | 
				
			||||||
 | 
					      moveToNextSymbol(DRI);
 | 
				
			||||||
 | 
					      if (DRI.d.a < LoadCommandCount) {
 | 
				
			||||||
 | 
					        getSymbol64TableEntry(DRI, Entry);
 | 
				
			||||||
 | 
					        if (Entry->SectionIndex == SectionIndex && Entry->Value > BeginOffset)
 | 
				
			||||||
 | 
					          if (!EndOffset || Entry->Value < EndOffset)
 | 
				
			||||||
 | 
					            EndOffset = Entry->Value;
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      DRI.d.b++;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  } else {
 | 
				
			||||||
 | 
					    InMemoryStruct<macho::SymbolTableEntry> Entry;
 | 
				
			||||||
 | 
					    getSymbolTableEntry(DRI, Entry);
 | 
				
			||||||
 | 
					    BeginOffset = Entry->Value;
 | 
				
			||||||
 | 
					    SectionIndex = Entry->SectionIndex;
 | 
				
			||||||
 | 
					    if (!SectionIndex) {
 | 
				
			||||||
 | 
					      Result = UnknownAddressOrSize;
 | 
				
			||||||
 | 
					      return object_error::success;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    // Unfortunately symbols are unsorted so we need to touch all
 | 
				
			||||||
 | 
					    // symbols from load command
 | 
				
			||||||
 | 
					    DRI.d.b = 0;
 | 
				
			||||||
 | 
					    uint32_t Command = DRI.d.a;
 | 
				
			||||||
 | 
					    while (Command == DRI.d.a) {
 | 
				
			||||||
 | 
					      moveToNextSymbol(DRI);
 | 
				
			||||||
 | 
					      if (DRI.d.a < LoadCommandCount) {
 | 
				
			||||||
 | 
					        getSymbolTableEntry(DRI, Entry);
 | 
				
			||||||
 | 
					        if (Entry->SectionIndex == SectionIndex && Entry->Value > BeginOffset)
 | 
				
			||||||
 | 
					          if (!EndOffset || Entry->Value < EndOffset)
 | 
				
			||||||
 | 
					            EndOffset = Entry->Value;
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      DRI.d.b++;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  if (!EndOffset) {
 | 
				
			||||||
 | 
					    uint64_t Size;
 | 
				
			||||||
 | 
					    getSectionSize(Sections[SectionIndex-1], Size);
 | 
				
			||||||
 | 
					    getSectionAddress(Sections[SectionIndex-1], EndOffset);
 | 
				
			||||||
 | 
					    EndOffset += Size;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  Result = EndOffset - BeginOffset;
 | 
				
			||||||
 | 
					  return object_error::success;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
error_code MachOObjectFile::getSymbolNMTypeChar(DataRefImpl DRI,
 | 
					error_code MachOObjectFile::getSymbolNMTypeChar(DataRefImpl DRI,
 | 
				
			||||||
                                                char &Result) const {
 | 
					                                                char &Result) const {
 | 
				
			||||||
@@ -275,7 +336,7 @@ error_code MachOObjectFile::getSymbolSection(DataRefImpl Symb,
 | 
				
			|||||||
  if (index == 0)
 | 
					  if (index == 0)
 | 
				
			||||||
    Res = end_sections();
 | 
					    Res = end_sections();
 | 
				
			||||||
  else
 | 
					  else
 | 
				
			||||||
    Res = section_iterator(SectionRef(Sections[index], this));
 | 
					    Res = section_iterator(SectionRef(Sections[index-1], this));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return object_error::success;
 | 
					  return object_error::success;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -622,6 +683,20 @@ error_code MachOObjectFile::getRelocationAddress(DataRefImpl Rel,
 | 
				
			|||||||
  Res = reinterpret_cast<uintptr_t>(sectAddress + RelAddr);
 | 
					  Res = reinterpret_cast<uintptr_t>(sectAddress + RelAddr);
 | 
				
			||||||
  return object_error::success;
 | 
					  return object_error::success;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					error_code MachOObjectFile::getRelocationOffset(DataRefImpl Rel,
 | 
				
			||||||
 | 
					                                                uint64_t &Res) const {
 | 
				
			||||||
 | 
					  InMemoryStruct<macho::RelocationEntry> RE;
 | 
				
			||||||
 | 
					  getRelocation(Rel, RE);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  unsigned Arch = getArch();
 | 
				
			||||||
 | 
					  bool isScattered = (Arch != Triple::x86_64) &&
 | 
				
			||||||
 | 
					                     (RE->Word0 & macho::RF_Scattered);
 | 
				
			||||||
 | 
					  if (isScattered)
 | 
				
			||||||
 | 
					    Res = RE->Word0 & 0xFFFFFF;
 | 
				
			||||||
 | 
					  else
 | 
				
			||||||
 | 
					    Res = RE->Word0;
 | 
				
			||||||
 | 
					  return object_error::success;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
error_code MachOObjectFile::getRelocationSymbol(DataRefImpl Rel,
 | 
					error_code MachOObjectFile::getRelocationSymbol(DataRefImpl Rel,
 | 
				
			||||||
                                                SymbolRef &Res) const {
 | 
					                                                SymbolRef &Res) const {
 | 
				
			||||||
  InMemoryStruct<macho::RelocationEntry> RE;
 | 
					  InMemoryStruct<macho::RelocationEntry> RE;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -150,9 +150,9 @@ uint64_t LLVMGetSymbolAddress(LLVMSymbolIteratorRef SI) {
 | 
				
			|||||||
  return ret;
 | 
					  return ret;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
uint64_t LLVMGetSymbolOffset(LLVMSymbolIteratorRef SI) {
 | 
					uint64_t LLVMGetSymbolFileOffset(LLVMSymbolIteratorRef SI) {
 | 
				
			||||||
  uint64_t ret;
 | 
					  uint64_t ret;
 | 
				
			||||||
  if (error_code ec = (*unwrap(SI))->getOffset(ret))
 | 
					  if (error_code ec = (*unwrap(SI))->getFileOffset(ret))
 | 
				
			||||||
    report_fatal_error(ec.message());
 | 
					    report_fatal_error(ec.message());
 | 
				
			||||||
  return ret;
 | 
					  return ret;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -172,6 +172,13 @@ uint64_t LLVMGetRelocationAddress(LLVMRelocationIteratorRef RI) {
 | 
				
			|||||||
  return ret;
 | 
					  return ret;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					uint64_t LLVMGetRelocationOffset(LLVMRelocationIteratorRef RI) {
 | 
				
			||||||
 | 
					  uint64_t ret;
 | 
				
			||||||
 | 
					  if (error_code ec = (*unwrap(RI))->getOffset(ret))
 | 
				
			||||||
 | 
					    report_fatal_error(ec.message());
 | 
				
			||||||
 | 
					  return ret;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
LLVMSymbolIteratorRef LLVMGetRelocationSymbol(LLVMRelocationIteratorRef RI) {
 | 
					LLVMSymbolIteratorRef LLVMGetRelocationSymbol(LLVMRelocationIteratorRef RI) {
 | 
				
			||||||
  SymbolRef ret;
 | 
					  SymbolRef ret;
 | 
				
			||||||
  if (error_code ec = (*unwrap(RI))->getSymbol(ret))
 | 
					  if (error_code ec = (*unwrap(RI))->getSymbol(ret))
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6,6 +6,10 @@ RUN: llvm-nm %p/Inputs/trivial-object-test.elf-i386 \
 | 
				
			|||||||
RUN:         | FileCheck %s -check-prefix ELF
 | 
					RUN:         | FileCheck %s -check-prefix ELF
 | 
				
			||||||
RUN: llvm-nm %p/Inputs/trivial-object-test.elf-x86-64 \
 | 
					RUN: llvm-nm %p/Inputs/trivial-object-test.elf-x86-64 \
 | 
				
			||||||
RUN:         | FileCheck %s -check-prefix ELF
 | 
					RUN:         | FileCheck %s -check-prefix ELF
 | 
				
			||||||
 | 
					RUN: llvm-nm %p/Inputs/trivial-object-test.macho-i386 \
 | 
				
			||||||
 | 
					RUN:         | FileCheck %s -check-prefix macho
 | 
				
			||||||
 | 
					RUN: llvm-nm %p/Inputs/trivial-object-test.macho-x86-64 \
 | 
				
			||||||
 | 
					RUN:         | FileCheck %s -check-prefix macho64
 | 
				
			||||||
 | 
					
 | 
				
			||||||
COFF: 00000000 d .data
 | 
					COFF: 00000000 d .data
 | 
				
			||||||
COFF: 00000000 t .text
 | 
					COFF: 00000000 t .text
 | 
				
			||||||
@@ -17,3 +21,13 @@ COFF:          U {{_?}}puts
 | 
				
			|||||||
ELF:          U SomeOtherFunction
 | 
					ELF:          U SomeOtherFunction
 | 
				
			||||||
ELF: 00000000 T main
 | 
					ELF: 00000000 T main
 | 
				
			||||||
ELF:          U puts
 | 
					ELF:          U puts
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					macho: 00000000 U _SomeOtherFunction
 | 
				
			||||||
 | 
					macho: 00000000 s _main
 | 
				
			||||||
 | 
					macho: 00000000 U _puts
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					macho64: 00000028 s L_.str
 | 
				
			||||||
 | 
					macho64: 00000000 u _SomeOtherFunction
 | 
				
			||||||
 | 
					macho64: 00000000 s _main
 | 
				
			||||||
 | 
					macho64: 00000000 u _puts
 | 
				
			||||||
@@ -2,6 +2,8 @@ RUN: llvm-objdump -t %p/Inputs/trivial-object-test.coff-i386 \
 | 
				
			|||||||
RUN:              | FileCheck %s -check-prefix COFF-i386
 | 
					RUN:              | FileCheck %s -check-prefix COFF-i386
 | 
				
			||||||
RUN: llvm-objdump -t %p/Inputs/trivial-object-test.elf-i386 \
 | 
					RUN: llvm-objdump -t %p/Inputs/trivial-object-test.elf-i386 \
 | 
				
			||||||
RUN:              | FileCheck %s -check-prefix ELF-i386
 | 
					RUN:              | FileCheck %s -check-prefix ELF-i386
 | 
				
			||||||
 | 
					RUN: llvm-objdump -t %p/Inputs/trivial-object-test.macho-i386 \
 | 
				
			||||||
 | 
					RUN:              | FileCheck %s -check-prefix macho-i386
 | 
				
			||||||
 | 
					
 | 
				
			||||||
COFF-i386: trivial-object-test.coff-i386:     file format
 | 
					COFF-i386: trivial-object-test.coff-i386:     file format
 | 
				
			||||||
COFF-i386: SYMBOL TABLE:
 | 
					COFF-i386: SYMBOL TABLE:
 | 
				
			||||||
@@ -23,3 +25,9 @@ ELF-i386: 00000031 l    d  .note.GNU-stack        00000000 .note.GNU-stack
 | 
				
			|||||||
ELF-i386: 00000000 g     F .text  00000024 main
 | 
					ELF-i386: 00000000 g     F .text  00000024 main
 | 
				
			||||||
ELF-i386: 00000000         *UND*  00000000 SomeOtherFunction
 | 
					ELF-i386: 00000000         *UND*  00000000 SomeOtherFunction
 | 
				
			||||||
ELF-i386: 00000000         *UND*  00000000 puts
 | 
					ELF-i386: 00000000         *UND*  00000000 puts
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					macho-i386: trivial-object-test.macho-i386:        file format Mach-O 32-bit i386
 | 
				
			||||||
 | 
					macho-i386: SYMBOL TABLE:
 | 
				
			||||||
 | 
					macho-i386: 00000000 g     F __TEXT,__text  00000024 _main
 | 
				
			||||||
 | 
					macho-i386: 00000000         *UND*  00000000 _SomeOtherFunction
 | 
				
			||||||
 | 
					macho-i386: 00000000         *UND*  00000000 _puts
 | 
				
			||||||
@@ -286,7 +286,7 @@ static void DumpSymbolNamesFromObject(ObjectFile *obj) {
 | 
				
			|||||||
      if (error(i->getSize(s.Size))) break;
 | 
					      if (error(i->getSize(s.Size))) break;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if (PrintAddress)
 | 
					    if (PrintAddress)
 | 
				
			||||||
      if (error(i->getOffset(s.Address))) break;
 | 
					      if (error(i->getAddress(s.Address))) break;
 | 
				
			||||||
    if (error(i->getNMTypeChar(s.TypeChar))) break;
 | 
					    if (error(i->getNMTypeChar(s.TypeChar))) break;
 | 
				
			||||||
    if (error(i->getName(s.Name))) break;
 | 
					    if (error(i->getName(s.Name))) break;
 | 
				
			||||||
    SymbolList.push_back(s);
 | 
					    SymbolList.push_back(s);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -419,7 +419,7 @@ void llvm::DisassembleInputMachO(StringRef Filename) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
      // Start at the address of the symbol relative to the section's address.
 | 
					      // Start at the address of the symbol relative to the section's address.
 | 
				
			||||||
      uint64_t Start = 0;
 | 
					      uint64_t Start = 0;
 | 
				
			||||||
      Symbols[SymIdx].getOffset(Start);
 | 
					      Symbols[SymIdx].getAddress(Start);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      // Stop disassembling either at the beginning of the next symbol or at
 | 
					      // Stop disassembling either at the beginning of the next symbol or at
 | 
				
			||||||
      // the end of the section.
 | 
					      // the end of the section.
 | 
				
			||||||
@@ -432,7 +432,7 @@ void llvm::DisassembleInputMachO(StringRef Filename) {
 | 
				
			|||||||
        if (NextSymType == SymbolRef::ST_Function) {
 | 
					        if (NextSymType == SymbolRef::ST_Function) {
 | 
				
			||||||
          Sections[SectIdx].containsSymbol(Symbols[NextSymIdx],
 | 
					          Sections[SectIdx].containsSymbol(Symbols[NextSymIdx],
 | 
				
			||||||
                                           containsNextSym);
 | 
					                                           containsNextSym);
 | 
				
			||||||
          Symbols[NextSymIdx].getOffset(NextSym);
 | 
					          Symbols[NextSymIdx].getAddress(NextSym);
 | 
				
			||||||
          break;
 | 
					          break;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        ++NextSymIdx;
 | 
					        ++NextSymIdx;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -186,7 +186,7 @@ static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
 | 
				
			|||||||
      bool contains;
 | 
					      bool contains;
 | 
				
			||||||
      if (!error(i->containsSymbol(*si, contains)) && contains) {
 | 
					      if (!error(i->containsSymbol(*si, contains)) && contains) {
 | 
				
			||||||
        uint64_t Address;
 | 
					        uint64_t Address;
 | 
				
			||||||
        if (error(si->getOffset(Address))) break;
 | 
					        if (error(si->getAddress(Address))) break;
 | 
				
			||||||
        StringRef Name;
 | 
					        StringRef Name;
 | 
				
			||||||
        if (error(si->getName(Name))) break;
 | 
					        if (error(si->getName(Name))) break;
 | 
				
			||||||
        Symbols.push_back(std::make_pair(Address, Name));
 | 
					        Symbols.push_back(std::make_pair(Address, Name));
 | 
				
			||||||
@@ -477,7 +477,7 @@ static void PrintSymbolTable(const ObjectFile *o) {
 | 
				
			|||||||
                         se = o->end_symbols(); si != se; si.increment(ec)) {
 | 
					                         se = o->end_symbols(); si != se; si.increment(ec)) {
 | 
				
			||||||
      if (error(ec)) return;
 | 
					      if (error(ec)) return;
 | 
				
			||||||
      StringRef Name;
 | 
					      StringRef Name;
 | 
				
			||||||
      uint64_t Offset;
 | 
					      uint64_t Address;
 | 
				
			||||||
      bool Global;
 | 
					      bool Global;
 | 
				
			||||||
      SymbolRef::Type Type;
 | 
					      SymbolRef::Type Type;
 | 
				
			||||||
      bool Weak;
 | 
					      bool Weak;
 | 
				
			||||||
@@ -485,7 +485,7 @@ static void PrintSymbolTable(const ObjectFile *o) {
 | 
				
			|||||||
      uint64_t Size;
 | 
					      uint64_t Size;
 | 
				
			||||||
      section_iterator Section = o->end_sections();
 | 
					      section_iterator Section = o->end_sections();
 | 
				
			||||||
      if (error(si->getName(Name))) continue;
 | 
					      if (error(si->getName(Name))) continue;
 | 
				
			||||||
      if (error(si->getOffset(Offset))) continue;
 | 
					      if (error(si->getAddress(Address))) continue;
 | 
				
			||||||
      if (error(si->isGlobal(Global))) continue;
 | 
					      if (error(si->isGlobal(Global))) continue;
 | 
				
			||||||
      if (error(si->getType(Type))) continue;
 | 
					      if (error(si->getType(Type))) continue;
 | 
				
			||||||
      if (error(si->isWeak(Weak))) continue;
 | 
					      if (error(si->isWeak(Weak))) continue;
 | 
				
			||||||
@@ -493,8 +493,10 @@ static void PrintSymbolTable(const ObjectFile *o) {
 | 
				
			|||||||
      if (error(si->getSize(Size))) continue;
 | 
					      if (error(si->getSize(Size))) continue;
 | 
				
			||||||
      if (error(si->getSection(Section))) continue;
 | 
					      if (error(si->getSection(Section))) continue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      if (Offset == UnknownAddressOrSize)
 | 
					      if (Address == UnknownAddressOrSize)
 | 
				
			||||||
        Offset = 0;
 | 
					        Address = 0;
 | 
				
			||||||
 | 
					      if (Size == UnknownAddressOrSize)
 | 
				
			||||||
 | 
					        Size = 0;
 | 
				
			||||||
      char GlobLoc = ' ';
 | 
					      char GlobLoc = ' ';
 | 
				
			||||||
      if (Type != SymbolRef::ST_External)
 | 
					      if (Type != SymbolRef::ST_External)
 | 
				
			||||||
        GlobLoc = Global ? 'g' : 'l';
 | 
					        GlobLoc = Global ? 'g' : 'l';
 | 
				
			||||||
@@ -506,7 +508,7 @@ static void PrintSymbolTable(const ObjectFile *o) {
 | 
				
			|||||||
      else if (Type == SymbolRef::ST_Function)
 | 
					      else if (Type == SymbolRef::ST_Function)
 | 
				
			||||||
        FileFunc = 'F';
 | 
					        FileFunc = 'F';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      outs() << format("%08"PRIx64, Offset) << " "
 | 
					      outs() << format("%08"PRIx64, Address) << " "
 | 
				
			||||||
             << GlobLoc // Local -> 'l', Global -> 'g', Neither -> ' '
 | 
					             << GlobLoc // Local -> 'l', Global -> 'g', Neither -> ' '
 | 
				
			||||||
             << (Weak ? 'w' : ' ') // Weak?
 | 
					             << (Weak ? 'w' : ' ') // Weak?
 | 
				
			||||||
             << ' ' // Constructor. Not supported yet.
 | 
					             << ' ' // Constructor. Not supported yet.
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user