[llvm] 8f8a9f3 - implement printing out raw section data of xcoff objectfile for llvm-objdump

via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 18 12:25:24 PST 2019


Author: diggerlin
Date: 2019-11-18T15:24:55-05:00
New Revision: 8f8a9f3437d4517f674395da30edb59d5514f7bc

URL: https://github.com/llvm/llvm-project/commit/8f8a9f3437d4517f674395da30edb59d5514f7bc
DIFF: https://github.com/llvm/llvm-project/commit/8f8a9f3437d4517f674395da30edb59d5514f7bc.diff

LOG: implement printing out raw section data of xcoff objectfile for llvm-objdump

SUMMARY:
implement printing out raw section data of xcoff objectfile for llvm-objdump
and option -D --disassemble-all option for llvm-objdump

Reviewers: Sean Fertile
Subscribers: rupprecht, seiyai,hiraditya

Differential Revision: https://reviews.llvm.org/D70255

Added: 
    llvm/test/tools/llvm-objdump/xcoff-disassemble-all.test
    llvm/test/tools/llvm-objdump/xcoff-raw-section-data.test

Modified: 
    llvm/lib/Object/XCOFFObjectFile.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Object/XCOFFObjectFile.cpp b/llvm/lib/Object/XCOFFObjectFile.cpp
index 5ca2a6a03f04..6cc8deca73b6 100644
--- a/llvm/lib/Object/XCOFFObjectFile.cpp
+++ b/llvm/lib/Object/XCOFFObjectFile.cpp
@@ -191,9 +191,8 @@ Expected<StringRef> XCOFFObjectFile::getSymbolName(DataRefImpl Symb) const {
 }
 
 Expected<uint64_t> XCOFFObjectFile::getSymbolAddress(DataRefImpl Symb) const {
-  uint64_t Result = 0;
-  llvm_unreachable("Not yet implemented!");
-  return Result;
+  assert(!is64Bit() && "Symbol table support not implemented for 64-bit.");
+  return toSymbolEntry(Symb)->Value;
 }
 
 uint64_t XCOFFObjectFile::getSymbolValueImpl(DataRefImpl Symb) const {
@@ -266,7 +265,19 @@ uint64_t XCOFFObjectFile::getSectionSize(DataRefImpl Sec) const {
 
 Expected<ArrayRef<uint8_t>>
 XCOFFObjectFile::getSectionContents(DataRefImpl Sec) const {
-  llvm_unreachable("Not yet implemented!");
+  if (isSectionVirtual(Sec))
+    return ArrayRef<uint8_t>();
+
+  const uint64_t OffsetToRaw = is64Bit()
+                                   ? toSection64(Sec)->FileOffsetToRawData
+                                   : toSection32(Sec)->FileOffsetToRawData;
+
+  const uint8_t * ContentStart = base() + OffsetToRaw;
+  uint64_t SectionSize = getSectionSize(Sec);
+  if (checkOffset(Data, uintptr_t(ContentStart), SectionSize))
+    return make_error<BinaryError>();
+
+  return makeArrayRef(ContentStart,SectionSize);
 }
 
 uint64_t XCOFFObjectFile::getSectionAlignment(DataRefImpl Sec) const {
@@ -296,9 +307,8 @@ bool XCOFFObjectFile::isSectionBSS(DataRefImpl Sec) const {
 }
 
 bool XCOFFObjectFile::isSectionVirtual(DataRefImpl Sec) const {
-  bool Result = false;
-  llvm_unreachable("Not yet implemented!");
-  return Result;
+  return is64Bit() ? toSection64(Sec)->FileOffsetToRawData == 0
+                   : toSection32(Sec)->FileOffsetToRawData == 0;
 }
 
 relocation_iterator XCOFFObjectFile::section_rel_begin(DataRefImpl Sec) const {
@@ -384,7 +394,6 @@ Triple::ArchType XCOFFObjectFile::getArch() const {
 }
 
 SubtargetFeatures XCOFFObjectFile::getFeatures() const {
-  llvm_unreachable("Not yet implemented!");
   return SubtargetFeatures();
 }
 

diff  --git a/llvm/test/tools/llvm-objdump/xcoff-disassemble-all.test b/llvm/test/tools/llvm-objdump/xcoff-disassemble-all.test
new file mode 100644
index 000000000000..84d5811677af
--- /dev/null
+++ b/llvm/test/tools/llvm-objdump/xcoff-disassemble-all.test
@@ -0,0 +1,55 @@
+# RUN: llvm-objdump -D %p/Inputs/xcoff-section-headers.o | \
+# RUN: FileCheck %s
+
+# xcoff-section-headers.o Compiled with IBM XL C/C++ for AIX, V16.1.0
+# compiler command: xlc -qtls -o xcoff-section-headers.o -c test.c
+# test.c:
+# int a;
+# int b = 12345;
+# __thread int c;
+# __thread double d = 3.14159;
+#
+# int func(void)  {
+#   return a;
+# }
+
+CHECK: Inputs/xcoff-section-headers.o:	file format aixcoff-rs6000
+CHECK: Disassembly of section .text:
+CHECK: 00000000 .text:
+CHECK-NEXT:        0: 80 62 00 04                  	lwz 3, 4(2)
+CHECK-NEXT:        4: 80 63 00 00                  	lwz 3, 0(3)
+CHECK-NEXT:        8: 4e 80 00 20                  	blr
+CHECK-NEXT:        c: 00 00 00 00                  	<unknown>
+CHECK-NEXT:       10: 00 00 20 40                  	<unknown>
+CHECK-NEXT:       14: 00 00 00 01                  	<unknown>
+CHECK-NEXT:       18: 00 00 00 0c                  	<unknown>
+CHECK-NEXT:       1c: 00 04 66 75                  	<unknown>
+CHECK-NEXT:       20: 6e 63 00 00                  	xoris 3, 19, 0
+CHECK-NEXT: 		...
+CHECK: Disassembly of section .data:
+CHECK: 00000080 func:
+CHECK-NEXT:       80: 00 00 00 94                  	<unknown>
+CHECK: 00000084 a:
+CHECK-NEXT:       84: 00 00 00 a4                  	<unknown>
+CHECK: 00000088 b:
+CHECK-NEXT:       88: 00 00 00 a0                  	<unknown>
+CHECK: 0000008c c:
+CHECK-NEXT:       8c: 00 00 00 08                  	<unknown>
+CHECK: 00000090 d:
+CHECK-NEXT:       90: 00 00 00 00                  	<unknown>
+CHECK: 00000094 func:
+CHECK-NEXT:       94: 00 00 00 00                  	<unknown>
+CHECK-NEXT:       98: 00 00 00 80                  	<unknown>
+CHECK-NEXT:       9c: 00 00 00 00                  	<unknown>
+CHECK: 000000a0 b:
+CHECK-NEXT:       a0: 00 00 30 39                  	<unknown>
+CHECK: Disassembly of section .bss:
+CHECK: 000000a4 a:
+CHECK-NEXT: ...
+CHECK: Disassembly of section .tdata:
+CHECK: 00000000 d:
+CHECK-NEXT:        0: 40 09 21 f9                  	bdnzfl	9, .+8696
+CHECK-NEXT:        4: f0 1b 86 6e                  	<unknown>
+CHECK: Disassembly of section .tbss:
+CHECK: 00000008 c:
+CHECK-NEXT: ...

diff  --git a/llvm/test/tools/llvm-objdump/xcoff-raw-section-data.test b/llvm/test/tools/llvm-objdump/xcoff-raw-section-data.test
new file mode 100644
index 000000000000..12469446b2d9
--- /dev/null
+++ b/llvm/test/tools/llvm-objdump/xcoff-raw-section-data.test
@@ -0,0 +1,35 @@
+# RUN: llvm-objdump --full-contents %p/Inputs/xcoff-section-headers.o | \
+# RUN: FileCheck %s
+
+# CHECK:      Inputs/xcoff-section-headers.o:   file format aixcoff-rs6000
+# CHECK: Contents of section .text:
+# CHECK-NEXT:  0000 80620004 80630000 4e800020 00000000  .b...c..N.. ....
+# CHECK-NEXT:  0010 00002040 00000001 0000000c 00046675  .. @..........fu
+# CHECK-NEXT:  0020 6e630000 00000000 00000000 00000000  nc..............
+# CHECK-NEXT:  0030 00000000 00000000 00000000 00000000  ................
+# CHECK-NEXT:  0040 00000000 00000000 00000000 00000000  ................
+# CHECK-NEXT:  0050 00000000 00000000 00000000 00000000  ................
+# CHECK-NEXT:  0060 00000000 00000000 00000000 00000000  ................
+# CHECK-NEXT:  0070 00000000 00000000 00000000 00000000  ................
+# CHECK-NEXT: Contents of section .data:
+# CHECK-NEXT:  0080 00000094 000000a4 000000a0 00000008  ................
+# CHECK-NEXT:  0090 00000000 00000000 00000080 00000000  ................
+# CHECK-NEXT:  00a0 00003039                             ..09
+# CHECK-NEXT: Contents of section .bss:
+# CHECK-NEXT: <skipping contents of bss section at [00a4, 00a8)>
+# CHECK-NEXT: Contents of section .tdata:
+# CHECK-NEXT:  0000 400921f9 f01b866e                    @.!....n
+# CHECK-NEXT: Contents of section .tbss:
+# CHECK-NEXT: <skipping contents of bss section at [0008, 000c)>
+
+# xcoff-section-headers.o Compiled with IBM XL C/C++ for AIX, V16.1.0
+# compiler command: xlc -qtls -o xcoff-section-headers.o -c test.c
+# test.c:
+# int a;
+# int b = 12345;
+# __thread int c;
+# __thread double d = 3.14159;
+#
+# int func(void)  {
+#   return a;
+# }


        


More information about the llvm-commits mailing list