diff --git a/llvm/lib/Object/XCOFFObjectFile.cpp b/llvm/lib/Object/XCOFFObjectFile.cpp --- a/llvm/lib/Object/XCOFFObjectFile.cpp +++ b/llvm/lib/Object/XCOFFObjectFile.cpp @@ -191,9 +191,8 @@ } Expected 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 @@ Expected> XCOFFObjectFile::getSectionContents(DataRefImpl Sec) const { - llvm_unreachable("Not yet implemented!"); + if (isSectionVirtual(Sec)) + return ArrayRef(); + + 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(); + + return makeArrayRef(ContentStart,SectionSize); } uint64_t XCOFFObjectFile::getSectionAlignment(DataRefImpl Sec) const { @@ -296,9 +307,8 @@ } 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 @@ } 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 --- /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 +CHECK-NEXT: 10: 00 00 20 40 +CHECK-NEXT: 14: 00 00 00 01 +CHECK-NEXT: 18: 00 00 00 0c +CHECK-NEXT: 1c: 00 04 66 75 +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 +CHECK: 00000084 a: +CHECK-NEXT: 84: 00 00 00 a4 +CHECK: 00000088 b: +CHECK-NEXT: 88: 00 00 00 a0 +CHECK: 0000008c c: +CHECK-NEXT: 8c: 00 00 00 08 +CHECK: 00000090 d: +CHECK-NEXT: 90: 00 00 00 00 +CHECK: 00000094 func: +CHECK-NEXT: 94: 00 00 00 00 +CHECK-NEXT: 98: 00 00 00 80 +CHECK-NEXT: 9c: 00 00 00 00 +CHECK: 000000a0 b: +CHECK-NEXT: a0: 00 00 30 39 +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 +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 --- /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: +# CHECK-NEXT: Contents of section .tdata: +# CHECK-NEXT: 0000 400921f9 f01b866e @.!....n +# CHECK-NEXT: Contents of section .tbss: +# CHECK-NEXT: + +# 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; +# }