[llvm-branch-commits] [llvm] 1b7406b - [XCOFF] Do not put MergeableCStrings in their own section
Tobias Hieta via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Aug 1 01:27:27 PDT 2023
Author: Wael Yehia
Date: 2023-08-01T10:26:03+02:00
New Revision: 1b7406b272bae79cf7ce8d39ba8fa408c08720fe
URL: https://github.com/llvm/llvm-project/commit/1b7406b272bae79cf7ce8d39ba8fa408c08720fe
DIFF: https://github.com/llvm/llvm-project/commit/1b7406b272bae79cf7ce8d39ba8fa408c08720fe.diff
LOG: [XCOFF] Do not put MergeableCStrings in their own section
The current implementation generates a csect with a
".rodata.str.x.y" prefix for a MergeableCString variable definition.
However, a reference to such variable does not get the prefix in its
name because there's not enough information in the containing IR.
In particular, without seeing the initializer and absent of some other
indicators, we cannot tell that the referenced variable is a null-
terminated string.
When the AIX codegen in llvm was being developed, the prefixing was copied
from ELF without having the linker take advantage of the info.
Currently, the AIX linker does not have the capability to merge
MergeableCString variables. If such feature would ever get implemented,
the contract between the linker and compiler would have to be reconsidered.
Here's the before and after of this change:
```
@a = global i64 320255973571806, align 8
@strA = unnamed_addr constant [7 x i8] c"hello\0A\00", align 1 ;; Mergeable1ByteCString
@strB = unnamed_addr constant [8 x i8] c"Blahah\0A\00", align 1 ;; Mergeable1ByteCString
@strC = unnamed_addr constant [2 x i16] [i16 1, i16 0], align 2 ;; Mergeable2ByteCString
@strD = unnamed_addr constant [2 x i16] [i16 1, i16 1], align 2 ;; !isMergeableCString
@strE = external unnamed_addr constant [2 x i16], align 2
-fdata-sections:
.text extern .rodata.str1.1strA .text extern strA
0 SD RO 0 SD RO
.text extern .rodata.str1.1strB .text extern strB
0 SD RO 0 SD RO
.text extern .rodata.str2.2strC ===> .text extern strC
0 SD RO 0 SD RO
.text extern strD .text extern strD
0 SD RO 0 SD RO
.data extern a .data extern a
0 SD RW 0 SD RW
undef extern strE undef extern strE
0 ER UA 0 ER UA
-fno-data-sections:
.text unamex .rodata.str1.1 .text unamex .rodata
0 SD RO 0 SD RO
.text extern strA .text extern strA
0 LD RO 0 LD RO
.text extern strB .text extern strB
0 LD RO 0 LD RO
.text unamex .rodata.str2.2 ===> .text extern strC
0 SD RO 0 LD RO
.text extern strC .text extern strD
0 LD RO 0 LD RO
.text unamex .rodata .data unamex .data
0 SD RO 0 SD RW
.text extern strD .data extern a
0 LD RO 0 LD RW
.data unamex .data undef extern strE
0 SD RW 0 ER UA
.data extern a
0 LD RW
undef extern strE
0 ER UA
```
Reviewed by: David Tenty, Fangrui Song
Differential Revision: https://reviews.llvm.org/D156202
(cherry picked from commit 9d4e8c09f493280acc7637d904bdc84abc11fdc3)
Added:
Modified:
llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
llvm/test/CodeGen/PowerPC/aix-return55.ll
llvm/test/CodeGen/PowerPC/aix-xcoff-data-sections.ll
llvm/test/CodeGen/PowerPC/aix-xcoff-mergeable-str.ll
llvm/test/tools/llvm-objdump/XCOFF/symbol-table.test
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
index 647f570ab807e1..55fb522554fad2 100644
--- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -2426,23 +2426,6 @@ MCSection *TargetLoweringObjectFileXCOFF::SelectSectionForGlobal(
Name, Kind, XCOFF::CsectProperties(SMC, XCOFF::XTY_CM));
}
- if (Kind.isMergeableCString()) {
- Align Alignment = GO->getParent()->getDataLayout().getPreferredAlign(
- cast<GlobalVariable>(GO));
-
- unsigned EntrySize = getEntrySizeForKind(Kind);
- std::string SizeSpec = ".rodata.str" + utostr(EntrySize) + ".";
- SmallString<128> Name;
- Name = SizeSpec + utostr(Alignment.value());
-
- if (TM.getDataSections())
- getNameWithPrefix(Name, GO, TM);
-
- return getContext().getXCOFFSection(
- Name, Kind, XCOFF::CsectProperties(XCOFF::XMC_RO, XCOFF::XTY_SD),
- /* MultiSymbolsAllowed*/ !TM.getDataSections());
- }
-
if (Kind.isText()) {
if (TM.getFunctionSections()) {
return cast<MCSymbolXCOFF>(getFunctionEntryPointSymbol(GO, TM))
diff --git a/llvm/test/CodeGen/PowerPC/aix-return55.ll b/llvm/test/CodeGen/PowerPC/aix-return55.ll
index 384480375a2bee..c7d481ced140ef 100644
--- a/llvm/test/CodeGen/PowerPC/aix-return55.ll
+++ b/llvm/test/CodeGen/PowerPC/aix-return55.ll
@@ -27,8 +27,8 @@ entry:
;CHECKOBJ64: 0000000000000000 <.foo>:
;CHECKOBJ-NEXT: 0: 38 60 00 37 li 3, 55
;CHECKOBJ-NEXT: 4: 4e 80 00 20 blr{{[[:space:]] *}}
-;CHECKOBJ32-NEXT: 00000008 <.rodata.str1.1>:
-;CHECKOBJ64-NEXT: 0000000000000008 <.rodata.str1.1>:
+;CHECKOBJ32-NEXT: 00000008 <.rodata>:
+;CHECKOBJ64-NEXT: 0000000000000008 <.rodata>:
;CHECKOBJ-NEXT: 8: 68 65 6c 6c xori 5, 3, 27756
;CHECKOBJ-NEXT: c: 6f 77 6f 72 xoris 23, 27, 28530
;CHECKOBJ-NEXT: 10: 0a 00 00 00 tdlti 0, 0{{[[:space:]] *}}
diff --git a/llvm/test/CodeGen/PowerPC/aix-xcoff-data-sections.ll b/llvm/test/CodeGen/PowerPC/aix-xcoff-data-sections.ll
index 37445c7d5240cf..9072e98aecb244 100644
--- a/llvm/test/CodeGen/PowerPC/aix-xcoff-data-sections.ll
+++ b/llvm/test/CodeGen/PowerPC/aix-xcoff-data-sections.ll
@@ -70,16 +70,16 @@ entry:
; CHECK-NEXT: .vbyte 4, 35 # 0x23
; CHECK-NEXT: .comm a[RW],4,2
; CHECK-NEXT: .comm f[RW],4,2
-; CHECK-NEXT: .csect .rodata.str1.1L...str[RO],2
+; CHECK-NEXT: .csect L...str[RO],2
; CHECK-NEXT: .string "abcdefgh"
; CHECK32: .csect p[RW],2
; CHECK32-NEXT: .globl p[RW]
; CHECK32-NEXT: .align 2
-; CHECK32-NEXT: .vbyte 4, .rodata.str1.1L...str[RO]
+; CHECK32-NEXT: .vbyte 4, L...str[RO]
; CHECK64: .csect p[RW],3
; CHECK64-NEXT: .globl p[RW]
; CHECK64-NEXT: .align 3
-; CHECK64-NEXT: .vbyte 8, .rodata.str1.1L...str[RO]
+; CHECK64-NEXT: .vbyte 8, L...str[RO]
; CHECK: .toc
; CHECK-NEXT: L..C0:
; CHECK-NEXT: .tc p[TC],p[RW]
@@ -93,7 +93,7 @@ entry:
; CHECKOBJ: 00000038 (idx: 7) const_ivar[RO]:
; CHECKOBJ-NEXT: 38: 00 00 00 23 <unknown>
; CHECKOBJ-EMPTY:
-; CHECKOBJ-NEXT: 0000003c (idx: 9) .rodata.str1.1L...str[RO]:
+; CHECKOBJ-NEXT: 0000003c (idx: 9) L...str[RO]:
; CHECKOBJ-NEXT: 3c: 61 62 63 64
; CHECKOBJ-NEXT: 40: 65 66 67 68
; CHECKOBJ-NEXT: 44: 00 00 00 00 <unknown>
@@ -156,7 +156,7 @@ entry:
; CHECKSYM: }
; CHECKSYM: }
; CHECKSYM: Symbol {
-; CHECKSYM: Name: .rodata.str1.1L...str
+; CHECKSYM: Name: L...str
; CHECKSYM: Value (RelocatableAddress): 0x3C
; CHECKSYM: Section: .text
; CHECKSYM: Type: 0x0
diff --git a/llvm/test/CodeGen/PowerPC/aix-xcoff-mergeable-str.ll b/llvm/test/CodeGen/PowerPC/aix-xcoff-mergeable-str.ll
index 15402b5a5f18a2..7a5be471e89748 100644
--- a/llvm/test/CodeGen/PowerPC/aix-xcoff-mergeable-str.ll
+++ b/llvm/test/CodeGen/PowerPC/aix-xcoff-mergeable-str.ll
@@ -26,35 +26,31 @@ entry:
ret i8 %1
}
-; CHECK: .csect .rodata.str2.2[RO],2
+; CHECK: .csect .rodata[RO],2
; CHECK-NEXT: .align 1
; CHECK-NEXT: L..magic16:
; CHECK-NEXT: .vbyte 2, 264 # 0x108
; CHECK-NEXT: .vbyte 2, 272 # 0x110
; CHECK-NEXT: .vbyte 2, 213 # 0xd5
; CHECK-NEXT: .vbyte 2, 0 # 0x0
-; CHECK-NEXT: .csect .rodata.str4.4[RO],2
; CHECK-NEXT: .align 2
; CHECK-NEXT: L..magic32:
; CHECK-NEXT: .vbyte 4, 464 # 0x1d0
; CHECK-NEXT: .vbyte 4, 472 # 0x1d8
; CHECK-NEXT: .vbyte 4, 413 # 0x19d
; CHECK-NEXT: .vbyte 4, 0 # 0x0
-; CHECK-NEXT: .csect .rodata.str1.1[RO],2
; CHECK-NEXT: L..strA:
; CHECK-NEXT: .byte 'h,'e,'l,'l,'o,' ,'w,'o,'r,'l,'d,'!,0012,0000
; CHECK-NEXT: L...str:
; CHECK-NEXT: .string "abcdefgh"
-; CHECKOBJ: 00000010 <.rodata.str2.2>:
+; CHECKOBJ: 00000010 <.rodata>:
; CHECKOBJ-NEXT: 10: 01 08 01 10
-; CHECKOBJ-NEXT: 14: 00 d5 00 00 {{.*}}{{[[:space:]] *}}
-; CHECKOBJ-NEXT: 00000018 <.rodata.str4.4>:
+; CHECKOBJ-NEXT: 14: 00 d5 00 00
; CHECKOBJ-NEXT: 18: 00 00 01 d0
; CHECKOBJ-NEXT: 1c: 00 00 01 d8
; CHECKOBJ-NEXT: 20: 00 00 01 9d
-; CHECKOBJ-NEXT: 24: 00 00 00 00 {{.*}}{{[[:space:]] *}}
-; CHECKOBJ-NEXT: 00000028 <.rodata.str1.1>:
+; CHECKOBJ-NEXT: 24: 00 00 00 00
; CHECKOBJ-NEXT: 28: 68 65 6c 6c
; CHECKOBJ-NEXT: 2c: 6f 20 77 6f
; CHECKOBJ-NEXT: 30: 72 6c 64 21
diff --git a/llvm/test/tools/llvm-objdump/XCOFF/symbol-table.test b/llvm/test/tools/llvm-objdump/XCOFF/symbol-table.test
index 815a3a5ccea1d0..f8fc114f05a620 100644
--- a/llvm/test/tools/llvm-objdump/XCOFF/symbol-table.test
+++ b/llvm/test/tools/llvm-objdump/XCOFF/symbol-table.test
@@ -71,7 +71,7 @@ entry:
; SYM-NEXT: 00000000 l .text 00000091
; SYM-NEXT: 00000000 g F .text (csect: ) 00000000 .bar
; SYM-NEXT: 00000050 g F .text (csect: ) 00000000 .foo
-; SYM-NEXT: 00000094 l .text 00000013 .rodata.str1.1L...str
+; SYM-NEXT: 00000094 l .text 00000013 L...str
; SYM-NEXT: 000000a8 g O .data 00000004 con
; SYM-NEXT: 000000ac w O .data 00000004 wi
; SYM-NEXT: 000000b0 g O .data 00000004 i
@@ -93,7 +93,7 @@ entry:
; SYM-DES-NEXT: 00000000 l .text 00000091 (idx: 3) [PR]
; SYM-DES-NEXT: 00000000 g F .text (csect: (idx: 3) [PR]) 00000000 (idx: 5) .bar
; SYM-DES-NEXT: 00000050 g F .text (csect: (idx: 3) [PR]) 00000000 (idx: 7) .foo
-; SYM-DES-NEXT: 00000094 l .text 00000013 (idx: 9) .rodata.str1.1L...str[RO]
+; SYM-DES-NEXT: 00000094 l .text 00000013 (idx: 9) L...str[RO]
; SYM-DES-NEXT: 000000a8 g O .data 00000004 (idx: 11) con[RW]
; SYM-DES-NEXT: 000000ac w O .data 00000004 (idx: 13) wi[RW]
; SYM-DES-NEXT: 000000b0 g O .data 00000004 (idx: 15) i[RW]
More information about the llvm-branch-commits
mailing list