[llvm] 98f5f02 - [BUG-FIX][XCOFF] fixed a bug of XCOFFObjectFile.cpp when there is padding at the last csect of a sections
via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 10 08:15:19 PST 2019
Author: diggerlin
Date: 2019-12-10T11:14:49-05:00
New Revision: 98f5f022f0cb5ac6605385966ced38e1e2851f6b
URL: https://github.com/llvm/llvm-project/commit/98f5f022f0cb5ac6605385966ced38e1e2851f6b
DIFF: https://github.com/llvm/llvm-project/commit/98f5f022f0cb5ac6605385966ced38e1e2851f6b.diff
LOG: [BUG-FIX][XCOFF] fixed a bug of XCOFFObjectFile.cpp when there is padding at the last csect of a sections
SUMMARY:
Fixed a bug of XCOFFObjectFile.cpp when there is padding at the last csect of a sections.
when there is a tail padding of a section, but the value of CurrentAddressLocation do not be increased by the padding size. it will hit assert assert(CurrentAddressLocation == Section->Address && "We should have no padding between sections.");
Reviewers: daltenty,hubert.reinterpretcast,
Differential Revision: https://reviews.llvm.org/D70859
Added:
Modified:
llvm/lib/MC/XCOFFObjectWriter.cpp
llvm/test/CodeGen/PowerPC/aix-xcoff-mergeable-str.ll
Removed:
################################################################################
diff --git a/llvm/lib/MC/XCOFFObjectWriter.cpp b/llvm/lib/MC/XCOFFObjectWriter.cpp
index 3bbf1a9b755a..c7cba91c8612 100644
--- a/llvm/lib/MC/XCOFFObjectWriter.cpp
+++ b/llvm/lib/MC/XCOFFObjectWriter.cpp
@@ -363,7 +363,7 @@ void XCOFFObjectWriter::writeSections(const MCAssembler &Asm,
continue;
assert(CurrentAddressLocation == Section->Address &&
- "We should have no padding between sections.");
+ "Sections should be written consecutively.");
for (const auto *Group : Section->Groups) {
for (const auto &Csect : *Group) {
if (uint32_t PaddingSize = Csect.Address - CurrentAddressLocation)
@@ -378,8 +378,10 @@ void XCOFFObjectWriter::writeSections(const MCAssembler &Asm,
// the current section minus the the end virtual address of the last csect
// in that section.
if (uint32_t PaddingSize =
- Section->Address + Section->Size - CurrentAddressLocation)
+ Section->Address + Section->Size - CurrentAddressLocation) {
W.OS.write_zeros(PaddingSize);
+ CurrentAddressLocation += PaddingSize;
+ }
}
}
diff --git a/llvm/test/CodeGen/PowerPC/aix-xcoff-mergeable-str.ll b/llvm/test/CodeGen/PowerPC/aix-xcoff-mergeable-str.ll
index 1b12ebb7169c..3df01a08f3d5 100644
--- a/llvm/test/CodeGen/PowerPC/aix-xcoff-mergeable-str.ll
+++ b/llvm/test/CodeGen/PowerPC/aix-xcoff-mergeable-str.ll
@@ -8,7 +8,20 @@
; RUN: llc -verify-machineinstrs -mcpu=pwr7 \
; RUN: -mtriple powerpc64-ibm-aix-xcoff < %s | FileCheck %s
+; RUN: llc -verify-machineinstrs -mcpu=pwr7 -mtriple powerpc-ibm-aix-xcoff -filetype=obj -o %t.o < %s
+; RUN: llvm-objdump -D %t.o | FileCheck --check-prefix=CHECKOBJ %s
+
@strA = private unnamed_addr constant [14 x i8] c"hello world!\0A\00", align 1
+ at .str = private unnamed_addr constant [9 x i8] c"abcdefgh\00", align 1
+ at p = global i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i32 0, i32 0), align 4
+
+; Function Attrs: noinline nounwind optnone
+define i8 @foo() #0 {
+entry:
+ %0 = load i8*, i8** @p, align 4
+ %1 = load i8, i8* %0, align 1
+ ret i8 %1
+}
; CHECK: .csect .rodata.str1.1[RO]
; CHECK-NEXT: .LstrA:
@@ -26,3 +39,24 @@
; CHECK-NEXT: .byte 33
; CHECK-NEXT: .byte 10
; CHECK-NEXT: .byte 0
+; CHECK-NEXT: .L.str:
+; CHECK-NEXT: .byte 97
+; CHECK-NEXT: .byte 98
+; CHECK-NEXT: .byte 99
+; CHECK-NEXT: .byte 100
+; CHECK-NEXT: .byte 101
+; CHECK-NEXT: .byte 102
+; CHECK-NEXT: .byte 103
+; CHECK-NEXT: .byte 104
+; CHECK-NEXT: .byte 0
+
+; CHECKOBJ: 00000010 .rodata.str1.1:
+; CHECKOBJ-NEXT: 10: 68 65 6c 6c xori 5, 3, 27756
+; CHECKOBJ-NEXT: 14: 6f 20 77 6f xoris 0, 25, 30575
+; CHECKOBJ-NEXT: 18: 72 6c 64 21 andi. 12, 19, 25633
+; CHECKOBJ-NEXT: 1c: 0a 00 61 62 tdlti 0, 24930{{[[:space:]] *}}
+; CHECKOBJ-NEXT: 0000001e .L.str:
+; CHECKOBJ-NEXT: 1e: 61 62 63 64 ori 2, 11, 25444
+; CHECKOBJ-NEXT: 22: 65 66 67 68 oris 6, 11, 26472
+; CHECKOBJ-NEXT: 26: 00 <unknown>
+; CHECKOBJ-NEXT: 27: 00 <unknown>
More information about the llvm-commits
mailing list