diff --git a/llvm/lib/MC/XCOFFObjectWriter.cpp b/llvm/lib/MC/XCOFFObjectWriter.cpp --- a/llvm/lib/MC/XCOFFObjectWriter.cpp +++ b/llvm/lib/MC/XCOFFObjectWriter.cpp @@ -350,19 +350,19 @@ void XCOFFObjectWriter::writeSections(const MCAssembler &Asm, const MCAsmLayout &Layout) { - uint32_t CurrentAddressLocation = 0; + uint32_t CurrentAddressLocation; for (const auto *Section : Sections) { // Nothing to write for this Section. if (Section->Index == Section::UninitializedIndex || Section->IsVirtual) continue; - assert(CurrentAddressLocation == Section->Address && - "We should have no padding between sections."); + CurrentAddressLocation = Section->Address; for (const auto *Group : Section->Groups) { for (const auto &Csect : *Group) { if (uint32_t PaddingSize = Csect.Address - CurrentAddressLocation) W.OS.write_zeros(PaddingSize); - Asm.writeSectionData(W.OS, Csect.MCCsect, Layout); + if (Csect.Size) + Asm.writeSectionData(W.OS, Csect.MCCsect, Layout); CurrentAddressLocation = Csect.Address + Csect.Size; } } @@ -410,7 +410,7 @@ W.write(0); W.write(Strings.getOffset(SymbolName)); } else { - char Name[XCOFF::NameSize]; + char Name[XCOFF::NameSize+1]; std::strncpy(Name, SymbolName.data(), XCOFF::NameSize); ArrayRef NameRef(Name, XCOFF::NameSize); W.write(NameRef); diff --git a/llvm/test/CodeGen/PowerPC/aix-xcoff-mergeablestring.ll b/llvm/test/CodeGen/PowerPC/aix-xcoff-mergeablestring.ll new file mode 100644 --- /dev/null +++ b/llvm/test/CodeGen/PowerPC/aix-xcoff-mergeablestring.ll @@ -0,0 +1,27 @@ +; RUN: llc -verify-machineinstrs -mcpu=pwr9 -mtriple powerpc-ibm-aix-xcoff -filetype=obj -o %t.o < %s +; RUN: llvm-objdump -D %t.o | FileCheck --check-prefix=CHECK %s + +@.str = private unnamed_addr constant [9 x i8] c"abcdefgh\00", align 1 +@p = global i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i32 0, i32 0), align 4 +@.str.1 = private unnamed_addr constant [12 x i8] c"01234566789\00", align 1 +@q = global i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, 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: 00000010 .rodata.str1.1: +; CHECK-NEXT: 10: 61 62 63 64 ori 2, 11, 25444 +; CHECK-NEXT: 14: 65 66 67 68 oris 6, 11, 26472 +; CHECK-NEXT: 18: 00 30 31 32 {{[[:space:]] *}} +; CHECK-NEXT: 00000019 .L.str.1: +; CHECK-NEXT: 19: 30 31 32 33 addic 1, 17, 12851 +; CHECK-NEXT: 1d: 34 35 36 36 addic. 1, 21, 13878 +; CHECK-NEXT: 21: 37 38 39 00 addic. 25, 24, 14592 +; CHECK-NEXT: 25: 00 +; CHECK-NEXT: 26: 00 +; CHECK-NEXT: 27: 00