]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - opencl/llvm.git/commitdiff
llvm-objdump: don't print relocations in non-relocatable files.
authorRafael Espindola <rafael.espindola@gmail.com>
Sun, 17 Aug 2014 19:09:37 +0000 (19:09 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Sun, 17 Aug 2014 19:09:37 +0000 (19:09 +0000)
This matches the behavior of GNU objdump.

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

include/llvm/Object/COFF.h
include/llvm/Object/ELFObjectFile.h
include/llvm/Object/MachO.h
include/llvm/Object/ObjectFile.h
lib/Object/COFFObjectFile.cpp
lib/Object/MachOObjectFile.cpp
test/Object/objdump-reloc-shared.test [new file with mode: 0644]
tools/llvm-objdump/llvm-objdump.cpp

index 1e8d2c18f3ac3cf605b281e87e9b20349b48a29b..fdeab2c92f34615141e6ca1ff42d4cabf2f467aa 100644 (file)
@@ -462,6 +462,8 @@ public:
   std::error_code getHintName(uint32_t Rva, uint16_t &Hint,
                               StringRef &Name) const;
 
+  bool isRelocatableObject() const override;
+
   static inline bool classof(const Binary *v) { return v->isCOFF(); }
 };
 
index 0ca4c7cb1733ac9979dd94c1d748b57a412cfa62..8a9e12576558005f3393526c15005ac8e4d9b2d7 100644 (file)
@@ -224,6 +224,8 @@ public:
 
   std::pair<symbol_iterator, symbol_iterator>
   getELFDynamicSymbolIterators() const override;
+
+  bool isRelocatableObject() const override;
 };
 
 // Use an alignment of 2 for the typedefs since that is the worst case for
@@ -945,6 +947,10 @@ ELFObjectFile<ELFT>::getELFDynamicSymbolIterators() const {
   return std::make_pair(dynamic_symbol_begin(), dynamic_symbol_end());
 }
 
+template <class ELFT> bool ELFObjectFile<ELFT>::isRelocatableObject() const {
+  return EF.getHeader()->e_type == ELF::ET_REL;
+}
+
 inline std::error_code getELFRelocationAddend(const RelocationRef R,
                                               int64_t &Addend) {
   const ObjectFile *Obj = R.getObjectFile();
index 808ab11b7657ed1db4791645301ea22e00e0b63d..539f1569a05676dfbc37ef15b9b7242a88dcaf66 100644 (file)
@@ -219,6 +219,8 @@ public:
   static bool isValidArch(StringRef ArchFlag);
   static Triple getHostArch();
 
+  bool isRelocatableObject() const override;
+
   static bool classof(const Binary *v) {
     return v->isMachO();
   }
index af890f5c398e44da201c01b5b235d2e6bd890bbe..100f65b47a09bb7bb67a9d421e6220f0b9a49ceb 100644 (file)
@@ -302,6 +302,9 @@ public:
     return object_error::invalid_file_type;
   }
 
+  /// True if this is a relocatable object (.o/.obj).
+  virtual bool isRelocatableObject() const = 0;
+
   /// @returns Pointer to ObjectFile subclass to handle this type of object.
   /// @param ObjectPath The path to the object file. ObjectPath.isObject must
   ///        return true.
index 29ea0a1a79c33315c636c3e124ae2c40f6b10f2d..717f019509bd7d8f2f515669f46837135b24df3a 100644 (file)
@@ -979,6 +979,10 @@ COFFObjectFile::getRelocationValueString(DataRefImpl Rel,
   return object_error::success;
 }
 
+bool COFFObjectFile::isRelocatableObject() const {
+  return !DataDirectory;
+}
+
 bool ImportDirectoryEntryRef::
 operator==(const ImportDirectoryEntryRef &Other) const {
   return ImportTable == Other.ImportTable && Index == Other.Index;
index 8e19eb5631d8ac4845ead2c7d923e759e24ffc6a..afc729f9f8212d6a2ba1e99af1ba02d0f289516d 100644 (file)
@@ -1688,6 +1688,10 @@ void MachOObjectFile::ReadULEB128s(uint64_t Index,
   }
 }
 
+bool MachOObjectFile::isRelocatableObject() const {
+  return getHeader().filetype == MachO::MH_OBJECT;
+}
+
 ErrorOr<std::unique_ptr<MachOObjectFile>>
 ObjectFile::createMachOObjectFile(std::unique_ptr<MemoryBuffer> &Buffer) {
   StringRef Magic = Buffer->getBuffer().slice(0, 4);
diff --git a/test/Object/objdump-reloc-shared.test b/test/Object/objdump-reloc-shared.test
new file mode 100644 (file)
index 0000000..d899ffb
--- /dev/null
@@ -0,0 +1,5 @@
+RUN: llvm-objdump -r %p/Inputs/elf-reloc-no-sym.x86_64 \
+RUN:              | FileCheck %s
+
+; CHECK: elf-reloc-no-sym.x86_64:       file format ELF64-x86-64
+; CHECK-NOT: {{.}}
index d7c9df1d6e7173a55057291d7e708de28e1ea752..791011ddefaee10dcf88221d05eff2d3c9cce58e 100644 (file)
@@ -562,6 +562,11 @@ static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
 static void PrintRelocations(const ObjectFile *Obj) {
   StringRef Fmt = Obj->getBytesInAddress() > 4 ? "%016" PRIx64 :
                                                  "%08" PRIx64;
+  // Regular objdump doesn't print relocations in non-relocatable object
+  // files.
+  if (!Obj->isRelocatableObject())
+    return;
+
   for (const SectionRef &Section : Obj->sections()) {
     if (Section.relocation_begin() == Section.relocation_end())
       continue;