Skip to content

Commit f989643

Browse files
author
diggerlin
committed
[AIX][XCOFF] Fix XCOFFObjectWriter assertion failure with alignment-related gap and improve text section output testing
SUMMARY: 1.if there is a gap between the end virtual address of one section and the beginning virtual address of the next section, the XCOFFObjectWriter.cpp will hit a assert. 2.as discussed in the patch https://reviews.llvm.org/D66969, since implemented the function description. We can output the raw object data for function. we need to create a test for raw text section content and test section header for xcoff object file. Reviewer: daltenty,hubert.reinterpretcast,jasonliu Differential Revision: https://reviews.llvm.org/D71845
1 parent d481e59 commit f989643

File tree

2 files changed

+66
-3
lines changed

2 files changed

+66
-3
lines changed

llvm/lib/MC/XCOFFObjectWriter.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,8 +439,14 @@ void XCOFFObjectWriter::writeSections(const MCAssembler &Asm,
439439
if (Section->Index == Section::UninitializedIndex || Section->IsVirtual)
440440
continue;
441441

442-
assert(CurrentAddressLocation == Section->Address &&
443-
"Sections should be written consecutively.");
442+
// There could be a gap (without corresponding zero padding) between
443+
// sections.
444+
assert(CurrentAddressLocation <= Section->Address &&
445+
"CurrentAddressLocation should be less than or equal to section "
446+
"address.");
447+
448+
CurrentAddressLocation = Section->Address;
449+
444450
for (const auto *Group : Section->Groups) {
445451
for (const auto &Csect : *Group) {
446452
if (uint32_t PaddingSize = Csect.Address - CurrentAddressLocation)

llvm/test/CodeGen/PowerPC/aix-return55.ll

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
1-
; RUN: llc -mcpu=pwr9 -mtriple=powerpc-ibm-aix-xcoff -verify-machineinstrs < %s | FileCheck %s
1+
; RUN: llc -mcpu=pwr4 -mtriple=powerpc-ibm-aix-xcoff -verify-machineinstrs < %s | FileCheck %s
2+
; RUN: llc -mcpu=pwr4 -mtriple=powerpc-ibm-aix-xcoff -verify-machineinstrs -filetype=obj -o %t.o < %s
3+
; RUN: llvm-objdump -D %t.o | FileCheck --check-prefix=CHECKOBJ %s
4+
; RUN: llvm-readobj -sections %t.o | FileCheck --check-prefix=CHECKSECT %s
25

6+
; RUN: not --crash llc -mtriple powerpc64-ibm-aix-xcoff -filetype=obj < %s 2>&1 | \
7+
; RUN: FileCheck --check-prefix=XCOFF64 %s
8+
; XCOFF64: LLVM ERROR: 64-bit XCOFF object files are not supported yet.
9+
10+
@a = global i64 320255973571806, align 8
11+
@d = global double 5.000000e+00, align 8
12+
@strA = private unnamed_addr constant [10 x i8] c"hellowor\0A\00", align 1
313

414
define dso_local signext i32 @foo() {
515
entry:
@@ -9,3 +19,50 @@ entry:
919
; CHECK: blr
1020
}
1121

22+
;CHECKOBJ: 00000000 .text:
23+
;CHECKOBJ-NEXT: 0: 38 60 00 37 li 3, 55
24+
;CHECKOBJ-NEXT: 4: 4e 80 00 20 blr{{[[:space:]] *}}
25+
;CHECKOBJ-NEXT: 00000008 .rodata.str1.1:
26+
;CHECKOBJ-NEXT: 8: 68 65 6c 6c xori 5, 3, 27756
27+
;CHECKOBJ-NEXT: c: 6f 77 6f 72 xoris 23, 27, 28530
28+
;CHECKOBJ-NEXT: 10: 0a 00 00 00 tdlti 0, 0{{[[:space:]] *}}
29+
;CHECKOBJ-NEXT: Disassembly of section .data:{{[[:space:]] *}}
30+
;CHECKOBJ-NEXT: 00000018 a:
31+
;CHECKOBJ-NEXT: 18: 00 01 23 45 <unknown>
32+
;CHECKOBJ-NEXT: 1c: 67 8a bc de oris 10, 28, 48350{{[[:space:]] *}}
33+
;CHECKOBJ-NEXT: 00000020 d:
34+
;CHECKOBJ-NEXT: 20: 40 14 00 00 bdnzf 20, .+0
35+
;CHECKOBJ-NEXT: 24: 00 00 00 00 <unknown>{{[[:space:]] *}}
36+
;CHECKOBJ-NEXT: 00000028 foo:
37+
;CHECKOBJ-NEXT: 28: 00 00 00 00 <unknown>
38+
;CHECKOBJ-NEXT: 2c: 00 00 00 34 <unknown>
39+
;CHECKOBJ-NEXT: 30: 00 00 00 00 <unknown>
40+
41+
;CHECKSECT: Sections [
42+
;CHECKSECT-NEXT: Section {
43+
;CHECKSECT-NEXT: Index: 1
44+
;CHECKSECT-NEXT: Name: .text
45+
;CHECKSECT-NEXT: PhysicalAddress: 0x0
46+
;CHECKSECT-NEXT: VirtualAddress: 0x0
47+
;CHECKSECT-NEXT: Size: 0x14
48+
;CHECKSECT-NEXT: RawDataOffset: 0x64
49+
;CHECKSECT-NEXT: RelocationPointer: 0x0
50+
;CHECKSECT-NEXT: LineNumberPointer: 0x0
51+
;CHECKSECT-NEXT: NumberOfRelocations: 0
52+
;CHECKSECT-NEXT: NumberOfLineNumbers: 0
53+
;CHECKSECT-NEXT: Type: STYP_TEXT (0x20)
54+
;CHECKSECT-NEXT: }
55+
;CHECKSECT-NEXT: Section {
56+
;CHECKSECT-NEXT: Index: 2
57+
;CHECKSECT-NEXT: Name: .data
58+
;CHECKSECT-NEXT: PhysicalAddress: 0x18
59+
;CHECKSECT-NEXT: VirtualAddress: 0x18
60+
;CHECKSECT-NEXT: Size: 0x1C
61+
;CHECKSECT-NEXT: RawDataOffset: 0x78
62+
;CHECKSECT-NEXT: RelocationPointer: 0x94
63+
;CHECKSECT-NEXT: LineNumberPointer: 0x0
64+
;CHECKSECT-NEXT: NumberOfRelocations: 2
65+
;CHECKSECT-NEXT: NumberOfLineNumbers: 0
66+
;CHECKSECT-NEXT: Type: STYP_DATA (0x40)
67+
;CHECKSECT-NEXT: }
68+
;CHECKSECT-NEXT: ]

0 commit comments

Comments
 (0)