[PATCH] D116181: [XCOFF][AIX] Support toc-data attribute for read-only globals

Yousuf via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 22 11:35:20 PST 2021


yoalione created this revision.
yoalione added reviewers: sfertile, bmahjour.
Herald added subscribers: hiraditya, nemanjai.
yoalione requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

The patch handles the addition of constant global variables to the table of contents.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D116181

Files:
  llvm/lib/MC/MCSectionXCOFF.cpp
  llvm/test/CodeGen/PowerPC/toc-data-const.ll


Index: llvm/test/CodeGen/PowerPC/toc-data-const.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/PowerPC/toc-data-const.ll
@@ -0,0 +1,26 @@
+; RUN: llc -mtriple powerpc-ibm-aix-xcoff < %s | FileCheck %s --check-prefix CHECK
+; RUN: llc -mtriple powerpc64-ibm-aix-xcoff < %s | FileCheck %s --check-prefix CHECK
+
+ at i1 = external constant i32 #0
+ at i2 = constant i32* @i1 #0
+
+define i32 @read() {
+  %1  = load i32, i32* @i1, align 4
+  ret i32 %1
+}
+
+define i32** @retptr() {
+  ret i32** @i2
+}
+
+; CHECK:       .read:
+; CHECK:        la 3, i1[TD](2)
+
+; CHECK:       .retptr:
+; CHECK:        la 3, i2[TD](2)
+
+; CHECK-DAG:   .toc
+; CHECK:         .extern i1[TD]
+; CHECK:         .csect i2[TD]
+
+attributes #0 = { "toc-data" }
Index: llvm/lib/MC/MCSectionXCOFF.cpp
===================================================================
--- llvm/lib/MC/MCSectionXCOFF.cpp
+++ llvm/lib/MC/MCSectionXCOFF.cpp
@@ -34,7 +34,8 @@
   }
 
   if (getKind().isReadOnly()) {
-    if (getMappingClass() != XCOFF::XMC_RO)
+    if (getMappingClass() != XCOFF::XMC_RO &&
+        getMappingClass() != XCOFF::XMC_TD)
       report_fatal_error("Unhandled storage-mapping class for .rodata csect.");
     printCsectDirective(OS);
     return;
@@ -70,7 +71,8 @@
   }
 
   if (isCsect() && getMappingClass() == XCOFF::XMC_TD) {
-    assert((getKind().isBSSExtern() || getKind().isBSSLocal()) &&
+    assert((getKind().isBSSExtern() || getKind().isBSSLocal() ||
+            getKind().isReadOnlyWithRel()) &&
            "Unexepected section kind for toc-data");
     printCsectDirective(OS);
     return;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D116181.395907.patch
Type: text/x-patch
Size: 1651 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211222/49935a6d/attachment.bin>


More information about the llvm-commits mailing list