From 81444107760bc57c0911efdb87f25f29d5a1d9da Mon Sep 17 00:00:00 2001 From: Zaara Syeda Date: Mon, 13 May 2024 10:57:49 -0400 Subject: [PATCH] [PowerPC] Fix assembler error with toc-data and data-sections We should not emit the label for the toc-data variable when data-sections=false. --- llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp | 6 ++++-- .../PowerPC/toc-data-no-data-sections.ll | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 llvm/test/CodeGen/PowerPC/toc-data-no-data-sections.ll diff --git a/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp b/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp index 51b79dc2b04b4..5f830d97986ca 100644 --- a/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp +++ b/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp @@ -2821,8 +2821,10 @@ void PPCAIXAsmPrinter::emitGlobalVariableHelper(const GlobalVariable *GV) { // When -fdata-sections is enabled, every GlobalVariable will // be put into its own csect; therefore, label is not necessary here. - if (!TM.getDataSections() || GV->hasSection()) - OutStreamer->emitLabel(EmittedInitSym); + if (!TM.getDataSections() || GV->hasSection()) { + if (Csect->getMappingClass() != XCOFF::XMC_TD) + OutStreamer->emitLabel(EmittedInitSym); + } // No alias to emit. if (!GOAliasMap[GV].size()) { diff --git a/llvm/test/CodeGen/PowerPC/toc-data-no-data-sections.ll b/llvm/test/CodeGen/PowerPC/toc-data-no-data-sections.ll new file mode 100644 index 0000000000000..77851fb830253 --- /dev/null +++ b/llvm/test/CodeGen/PowerPC/toc-data-no-data-sections.ll @@ -0,0 +1,18 @@ +; RUN: llc -mtriple powerpc64-ibm-aix-xcoff -data-sections=false -verify-machineinstrs < %s | FileCheck %s + +@a1 = global i32 0, align 4 #0 + +define void @foo() { +entry: + store i32 1, ptr @a1, align 4 + ret void +} + +attributes #0 = { "toc-data" } + +; CHECK: .toc +; CHECK-NEXT: .csect a1[TD],2 +; CHECK-NEXT: .globl a1[TD] +; CHECK-NEXT: .align 2 +; CHECK-NOT: a1[TD]: +; CHECK-NEXT: .vbyte 4, 0