[PATCH] D70859: [XCOFF] fixed a bug of XCOFFObjectFile.cpp and adding new test case to verify one mergeable string for xcoffobjectfile

Digger via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 29 07:48:38 PST 2019


DiggerLin created this revision.
DiggerLin added reviewers: jasonliu, daltenty, sfertile, hubert.reinterpretcast.
Herald added subscribers: llvm-commits, jsji, hiraditya, nemanjai.
Herald added a reviewer: jdoerfert.
Herald added a project: LLVM.
DiggerLin edited reviewers, added: xingxue; removed: jdoerfert.
Herald added a reviewer: jdoerfert.
Herald added a subscriber: wuzish.
DiggerLin removed a reviewer: jdoerfert.
Herald added a reviewer: jdoerfert.
DiggerLin removed a reviewer: jdoerfert.
Herald added a reviewer: jdoerfert.
DiggerLin removed a reviewer: jdoerfert.
Herald added a reviewer: jdoerfert.

1. Fixed a bug. when there is padding between two sections, 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.");
2. Fixed warning.

/srv/llvm-buildbot-srcatch/llvm-build-dir/openmp-gcc-x86_64-linux-debian/llvm.src/llvm/lib/MC/XCOFFObjectWriter.cpp:414:17: warning: 'char* strncpy(char*, const char*, size_t)' specified bound 8 equals destination size [-Wstringop-truncation]

3. When the Csect size is zero(for examle TOC csect, the size is zero ) , it do not need to invoke Asm.writeSectionData(W.OS, Csect.MCCsect, Layout);

4  Add a test case to verify output one byte mergeablestring for xcoffobjectfile.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D70859

Files:
  llvm/lib/MC/XCOFFObjectWriter.cpp
  llvm/test/CodeGen/PowerPC/aix-xcoff-mergeablestring.ll


Index: llvm/test/CodeGen/PowerPC/aix-xcoff-mergeablestring.ll
===================================================================
--- /dev/null
+++ 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
+
+ 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
+ at .str.1 = private unnamed_addr constant [12 x i8] c"01234566789\00", align 1
+ at 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                   <unknown>{{[[: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                            <unknown>
+; CHECK-NEXT:       26: 00                            <unknown>
+; CHECK-NEXT:       27: 00                            <unknown>
Index: llvm/lib/MC/XCOFFObjectWriter.cpp
===================================================================
--- llvm/lib/MC/XCOFFObjectWriter.cpp
+++ 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<int32_t>(0);
     W.write<uint32_t>(Strings.getOffset(SymbolName));
   } else {
-    char Name[XCOFF::NameSize];
+    char Name[XCOFF::NameSize+1];
     std::strncpy(Name, SymbolName.data(), XCOFF::NameSize);
     ArrayRef<char> NameRef(Name, XCOFF::NameSize);
     W.write(NameRef);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D70859.231543.patch
Type: text/x-patch
Size: 3128 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191129/7ab03530/attachment.bin>


More information about the llvm-commits mailing list