[llvm] [PowerPC][AIX] support explicit sections for -ffunction-sections (PR #85351)
Chen Zheng via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 18 23:47:49 PDT 2024
https://github.com/chenzheng1030 updated https://github.com/llvm/llvm-project/pull/85351
>From 29ed2a891548af724fa3a9ffef51a8d9add4fb5b Mon Sep 17 00:00:00 2001
From: Chen Zheng <czhengsz at cn.ibm.com>
Date: Thu, 14 Mar 2024 22:02:03 -0400
Subject: [PATCH 1/2] [PowerPC][AIX] support explicit sections for
-ffunction-sections
---
llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp | 6 +-
.../aix-xcoff-funcsect-explicitsect.ll | 142 ++++++++++++++++++
2 files changed, 145 insertions(+), 3 deletions(-)
create mode 100644 llvm/test/CodeGen/PowerPC/aix-xcoff-funcsect-explicitsect.ll
diff --git a/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp b/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
index 9396ca22dacf86..de4edb0a679704 100644
--- a/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
+++ b/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
@@ -2786,9 +2786,9 @@ void PPCAIXAsmPrinter::emitFunctionDescriptor() {
}
void PPCAIXAsmPrinter::emitFunctionEntryLabel() {
- // It's not necessary to emit the label when we have individual
- // function in its own csect.
- if (!TM.getFunctionSections())
+ // For functions without user defined section, it's not necessary to emit the
+ // label when we have individual function in its own csect.
+ if (!TM.getFunctionSections() || MF->getFunction().hasSection())
PPCAsmPrinter::emitFunctionEntryLabel();
// Emit aliasing label for function entry point label.
diff --git a/llvm/test/CodeGen/PowerPC/aix-xcoff-funcsect-explicitsect.ll b/llvm/test/CodeGen/PowerPC/aix-xcoff-funcsect-explicitsect.ll
new file mode 100644
index 00000000000000..4a5af06ca946d7
--- /dev/null
+++ b/llvm/test/CodeGen/PowerPC/aix-xcoff-funcsect-explicitsect.ll
@@ -0,0 +1,142 @@
+; RUN: llc -verify-machineinstrs -mcpu=pwr4 -mattr=-altivec -mtriple powerpc-ibm-aix-xcoff \
+; RUN: -xcoff-traceback-table=false -filetype=obj -function-sections -o %t.o < %s
+; RUN: llvm-readobj -s %t.o | FileCheck %s
+
+define dso_local signext i32 @foo1() section "sect" {
+entry:
+ ret i32 1
+}
+
+define dso_local signext i32 @foo2() section "sect2" {
+entry:
+ ret i32 2
+}
+
+define dso_local signext i32 @foo3() section "sect2" {
+entry:
+ ret i32 3
+}
+
+define dso_local signext i32 @foo4() {
+entry:
+ ret i32 4
+}
+
+; CHECK: Symbol {{[{][[:space:]] *}}Index: [[#INDX:]]{{[[:space:]] *}}Name: sect
+; CHECK-NEXT: Value (RelocatableAddress): 0x0
+; CHECK-NEXT: Section: .text
+; CHECK-NEXT: Type: 0x0
+; CHECK-NEXT: StorageClass: C_HIDEXT (0x6B)
+; CHECK-NEXT: NumberOfAuxEntries: 1
+; CHECK-NEXT: CSECT Auxiliary Entry {
+; CHECK-NEXT: Index: [[#INDX+1]]
+; CHECK-NEXT: SectionLen: 8
+; CHECK-NEXT: ParameterHashIndex: 0x0
+; CHECK-NEXT: TypeChkSectNum: 0x0
+; CHECK-NEXT: SymbolAlignmentLog2: 5
+; CHECK-NEXT: SymbolType: XTY_SD (0x1)
+; CHECK-NEXT: StorageMappingClass: XMC_PR (0x0)
+; CHECK-NEXT: StabInfoIndex: 0x0
+; CHECK-NEXT: StabSectNum: 0x0
+; CHECK-NEXT: }
+; CHECK-NEXT: }
+; CHECK-NEXT: Symbol {
+; CHECK-NEXT: Index: [[#INDX+2]]
+; CHECK-NEXT: Name: .foo1
+; CHECK-NEXT: Value (RelocatableAddress): 0x0
+; CHECK-NEXT: Section: .text
+; CHECK-NEXT: Type: 0x0
+; CHECK-NEXT: StorageClass: C_EXT (0x2)
+; CHECK-NEXT: NumberOfAuxEntries: 1
+; CHECK-NEXT: CSECT Auxiliary Entry {
+; CHECK-NEXT: Index: [[#INDX+3]]
+; CHECK-NEXT: ContainingCsectSymbolIndex: [[#INDX]]
+; CHECK-NEXT: ParameterHashIndex: 0x0
+; CHECK-NEXT: TypeChkSectNum: 0x0
+; CHECK-NEXT: SymbolAlignmentLog2: 0
+; CHECK-NEXT: SymbolType: XTY_LD (0x2
+; CHECK-NEXT: StorageMappingClass: XMC_PR (0x0)
+; CHECK-NEXT: StabInfoIndex: 0x0
+; CHECK-NEXT: StabSectNum: 0x0
+; CHECK-NEXT: }
+; CHECK-NEXT: }
+; CHECK-NEXT: Symbol {
+; CHECK-NEXT: Index: [[#INDX+4]]
+; CHECK-NEXT: Name: sect2
+; CHECK-NEXT: Value (RelocatableAddress): 0x20
+; CHECK-NEXT: Section: .text
+; CHECK-NEXT: Type: 0x0
+; CHECK-NEXT: StorageClass: C_HIDEXT (0x6B)
+; CHECK-NEXT: NumberOfAuxEntries: 1
+; CHECK-NEXT: CSECT Auxiliary Entry {
+; CHECK-NEXT: Index: [[#INDX+5]]
+; CHECK-NEXT: SectionLen: 24
+; CHECK-NEXT: ParameterHashIndex: 0x0
+; CHECK-NEXT: TypeChkSectNum: 0x0
+; CHECK-NEXT: SymbolAlignmentLog2: 5
+; CHECK-NEXT: SymbolType: XTY_SD (0x1)
+; CHECK-NEXT: StorageMappingClass: XMC_PR (0x0)
+; CHECK-NEXT: StabInfoIndex: 0x0
+; CHECK-NEXT: StabSectNum: 0x0
+; CHECK-NEXT: }
+; CHECK-NEXT: }
+; CHECK-NEXT: Symbol {
+; CHECK-NEXT: Index: [[#INDX+6]]
+; CHECK-NEXT: Name: .foo2
+; CHECK-NEXT: Value (RelocatableAddress): 0x20
+; CHECK-NEXT: Section: .text
+; CHECK-NEXT: Type: 0x0
+; CHECK-NEXT: StorageClass: C_EXT (0x2)
+; CHECK-NEXT: NumberOfAuxEntries: 1
+; CHECK-NEXT: CSECT Auxiliary Entry {
+; CHECK-NEXT: Index: [[#INDX+7]]
+; CHECK-NEXT: ContainingCsectSymbolIndex: [[#INDX+4]]
+; CHECK-NEXT: ParameterHashIndex: 0x0
+; CHECK-NEXT: TypeChkSectNum: 0x0
+; CHECK-NEXT: SymbolAlignmentLog2: 0
+; CHECK-NEXT: SymbolType: XTY_LD (0x2)
+; CHECK-NEXT: StorageMappingClass: XMC_PR (0x0)
+; CHECK-NEXT: StabInfoIndex: 0x0
+; CHECK-NEXT: StabSectNum: 0x0
+; CHECK-NEXT: }
+; CHECK-NEXT: }
+; CHECK-NEXT: Symbol {
+; CHECK-NEXT: Index: [[#INDX+8]]
+; CHECK-NEXT: Name: .foo3
+; CHECK-NEXT: Value (RelocatableAddress): 0x30
+; CHECK-NEXT: Section: .text
+; CHECK-NEXT: Type: 0x0
+; CHECK-NEXT: StorageClass: C_EXT (0x2)
+; CHECK-NEXT: NumberOfAuxEntries: 1
+; CHECK-NEXT: CSECT Auxiliary Entry {
+; CHECK-NEXT: Index: [[#INDX+9]]
+; CHECK-NEXT: ContainingCsectSymbolIndex: [[#INDX+4]]
+; CHECK-NEXT: ParameterHashIndex: 0x0
+; CHECK-NEXT: TypeChkSectNum: 0x0
+; CHECK-NEXT: SymbolAlignmentLog2: 0
+; CHECK-NEXT: SymbolType: XTY_LD (0x2)
+; CHECK-NEXT: StorageMappingClass: XMC_PR (0x0)
+; CHECK-NEXT: StabInfoIndex: 0x0
+; CHECK-NEXT: StabSectNum: 0x0
+; CHECK-NEXT: }
+; CHECK-NEXT: }
+; CHECK-NEXT: Symbol {
+; CHECK-NEXT: Index: [[#INDX+10]]
+; CHECK-NEXT: Name: .foo4
+; CHECK-NEXT: Value (RelocatableAddress): 0x40
+; CHECK-NEXT: Section: .text
+; CHECK-NEXT: Type: 0x0
+; CHECK-NEXT: StorageClass: C_EXT (0x2)
+; CHECK-NEXT: NumberOfAuxEntries: 1
+; CHECK-NEXT: CSECT Auxiliary Entry {
+; CHECK-NEXT: Index: 16
+; CHECK-NEXT: SectionLen: 8
+; CHECK-NEXT: ParameterHashIndex: 0x0
+; CHECK-NEXT: TypeChkSectNum: 0x0
+; CHECK-NEXT: SymbolAlignmentLog2: 5
+; CHECK-NEXT: SymbolType: XTY_SD (0x1)
+; CHECK-NEXT: StorageMappingClass: XMC_PR (0x0)
+; CHECK-NEXT: StabInfoIndex: 0x0
+; CHECK-NEXT: StabSectNum: 0x0
+; CHECK-NEXT: }
+; CHECK-NEXT: }
>From 814586438e1af616d80bebe6060247e2f61c653e Mon Sep 17 00:00:00 2001
From: Chen Zheng <czhengsz at cn.ibm.com>
Date: Tue, 19 Mar 2024 02:47:28 -0400
Subject: [PATCH 2/2] address comments
---
llvm/test/CodeGen/PowerPC/aix-xcoff-funcsect-explicitsect.ll | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/test/CodeGen/PowerPC/aix-xcoff-funcsect-explicitsect.ll b/llvm/test/CodeGen/PowerPC/aix-xcoff-funcsect-explicitsect.ll
index 4a5af06ca946d7..4e94228404d61a 100644
--- a/llvm/test/CodeGen/PowerPC/aix-xcoff-funcsect-explicitsect.ll
+++ b/llvm/test/CodeGen/PowerPC/aix-xcoff-funcsect-explicitsect.ll
@@ -54,7 +54,7 @@ entry:
; CHECK-NEXT: ParameterHashIndex: 0x0
; CHECK-NEXT: TypeChkSectNum: 0x0
; CHECK-NEXT: SymbolAlignmentLog2: 0
-; CHECK-NEXT: SymbolType: XTY_LD (0x2
+; CHECK-NEXT: SymbolType: XTY_LD (0x2)
; CHECK-NEXT: StorageMappingClass: XMC_PR (0x0)
; CHECK-NEXT: StabInfoIndex: 0x0
; CHECK-NEXT: StabSectNum: 0x0
More information about the llvm-commits
mailing list