Skip to content

Commit 1b7406b

Browse files
Wael Yehiatru
authored andcommitted
[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 9d4e8c0)
1 parent 6ee03f1 commit 1b7406b

File tree

5 files changed

+13
-34
lines changed

5 files changed

+13
-34
lines changed

llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2426,23 +2426,6 @@ MCSection *TargetLoweringObjectFileXCOFF::SelectSectionForGlobal(
24262426
Name, Kind, XCOFF::CsectProperties(SMC, XCOFF::XTY_CM));
24272427
}
24282428

2429-
if (Kind.isMergeableCString()) {
2430-
Align Alignment = GO->getParent()->getDataLayout().getPreferredAlign(
2431-
cast<GlobalVariable>(GO));
2432-
2433-
unsigned EntrySize = getEntrySizeForKind(Kind);
2434-
std::string SizeSpec = ".rodata.str" + utostr(EntrySize) + ".";
2435-
SmallString<128> Name;
2436-
Name = SizeSpec + utostr(Alignment.value());
2437-
2438-
if (TM.getDataSections())
2439-
getNameWithPrefix(Name, GO, TM);
2440-
2441-
return getContext().getXCOFFSection(
2442-
Name, Kind, XCOFF::CsectProperties(XCOFF::XMC_RO, XCOFF::XTY_SD),
2443-
/* MultiSymbolsAllowed*/ !TM.getDataSections());
2444-
}
2445-
24462429
if (Kind.isText()) {
24472430
if (TM.getFunctionSections()) {
24482431
return cast<MCSymbolXCOFF>(getFunctionEntryPointSymbol(GO, TM))

llvm/test/CodeGen/PowerPC/aix-return55.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ entry:
2727
;CHECKOBJ64: 0000000000000000 <.foo>:
2828
;CHECKOBJ-NEXT: 0: 38 60 00 37 li 3, 55
2929
;CHECKOBJ-NEXT: 4: 4e 80 00 20 blr{{[[:space:]] *}}
30-
;CHECKOBJ32-NEXT: 00000008 <.rodata.str1.1>:
31-
;CHECKOBJ64-NEXT: 0000000000000008 <.rodata.str1.1>:
30+
;CHECKOBJ32-NEXT: 00000008 <.rodata>:
31+
;CHECKOBJ64-NEXT: 0000000000000008 <.rodata>:
3232
;CHECKOBJ-NEXT: 8: 68 65 6c 6c xori 5, 3, 27756
3333
;CHECKOBJ-NEXT: c: 6f 77 6f 72 xoris 23, 27, 28530
3434
;CHECKOBJ-NEXT: 10: 0a 00 00 00 tdlti 0, 0{{[[:space:]] *}}

llvm/test/CodeGen/PowerPC/aix-xcoff-data-sections.ll

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,16 @@ entry:
7070
; CHECK-NEXT: .vbyte 4, 35 # 0x23
7171
; CHECK-NEXT: .comm a[RW],4,2
7272
; CHECK-NEXT: .comm f[RW],4,2
73-
; CHECK-NEXT: .csect .rodata.str1.1L...str[RO],2
73+
; CHECK-NEXT: .csect L...str[RO],2
7474
; CHECK-NEXT: .string "abcdefgh"
7575
; CHECK32: .csect p[RW],2
7676
; CHECK32-NEXT: .globl p[RW]
7777
; CHECK32-NEXT: .align 2
78-
; CHECK32-NEXT: .vbyte 4, .rodata.str1.1L...str[RO]
78+
; CHECK32-NEXT: .vbyte 4, L...str[RO]
7979
; CHECK64: .csect p[RW],3
8080
; CHECK64-NEXT: .globl p[RW]
8181
; CHECK64-NEXT: .align 3
82-
; CHECK64-NEXT: .vbyte 8, .rodata.str1.1L...str[RO]
82+
; CHECK64-NEXT: .vbyte 8, L...str[RO]
8383
; CHECK: .toc
8484
; CHECK-NEXT: L..C0:
8585
; CHECK-NEXT: .tc p[TC],p[RW]
@@ -93,7 +93,7 @@ entry:
9393
; CHECKOBJ: 00000038 (idx: 7) const_ivar[RO]:
9494
; CHECKOBJ-NEXT: 38: 00 00 00 23 <unknown>
9595
; CHECKOBJ-EMPTY:
96-
; CHECKOBJ-NEXT: 0000003c (idx: 9) .rodata.str1.1L...str[RO]:
96+
; CHECKOBJ-NEXT: 0000003c (idx: 9) L...str[RO]:
9797
; CHECKOBJ-NEXT: 3c: 61 62 63 64
9898
; CHECKOBJ-NEXT: 40: 65 66 67 68
9999
; CHECKOBJ-NEXT: 44: 00 00 00 00 <unknown>
@@ -156,7 +156,7 @@ entry:
156156
; CHECKSYM: }
157157
; CHECKSYM: }
158158
; CHECKSYM: Symbol {
159-
; CHECKSYM: Name: .rodata.str1.1L...str
159+
; CHECKSYM: Name: L...str
160160
; CHECKSYM: Value (RelocatableAddress): 0x3C
161161
; CHECKSYM: Section: .text
162162
; CHECKSYM: Type: 0x0

llvm/test/CodeGen/PowerPC/aix-xcoff-mergeable-str.ll

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,35 +26,31 @@ entry:
2626
ret i8 %1
2727
}
2828

29-
; CHECK: .csect .rodata.str2.2[RO],2
29+
; CHECK: .csect .rodata[RO],2
3030
; CHECK-NEXT: .align 1
3131
; CHECK-NEXT: L..magic16:
3232
; CHECK-NEXT: .vbyte 2, 264 # 0x108
3333
; CHECK-NEXT: .vbyte 2, 272 # 0x110
3434
; CHECK-NEXT: .vbyte 2, 213 # 0xd5
3535
; CHECK-NEXT: .vbyte 2, 0 # 0x0
36-
; CHECK-NEXT: .csect .rodata.str4.4[RO],2
3736
; CHECK-NEXT: .align 2
3837
; CHECK-NEXT: L..magic32:
3938
; CHECK-NEXT: .vbyte 4, 464 # 0x1d0
4039
; CHECK-NEXT: .vbyte 4, 472 # 0x1d8
4140
; CHECK-NEXT: .vbyte 4, 413 # 0x19d
4241
; CHECK-NEXT: .vbyte 4, 0 # 0x0
43-
; CHECK-NEXT: .csect .rodata.str1.1[RO],2
4442
; CHECK-NEXT: L..strA:
4543
; CHECK-NEXT: .byte 'h,'e,'l,'l,'o,' ,'w,'o,'r,'l,'d,'!,0012,0000
4644
; CHECK-NEXT: L...str:
4745
; CHECK-NEXT: .string "abcdefgh"
4846

49-
; CHECKOBJ: 00000010 <.rodata.str2.2>:
47+
; CHECKOBJ: 00000010 <.rodata>:
5048
; CHECKOBJ-NEXT: 10: 01 08 01 10
51-
; CHECKOBJ-NEXT: 14: 00 d5 00 00 {{.*}}{{[[:space:]] *}}
52-
; CHECKOBJ-NEXT: 00000018 <.rodata.str4.4>:
49+
; CHECKOBJ-NEXT: 14: 00 d5 00 00
5350
; CHECKOBJ-NEXT: 18: 00 00 01 d0
5451
; CHECKOBJ-NEXT: 1c: 00 00 01 d8
5552
; CHECKOBJ-NEXT: 20: 00 00 01 9d
56-
; CHECKOBJ-NEXT: 24: 00 00 00 00 {{.*}}{{[[:space:]] *}}
57-
; CHECKOBJ-NEXT: 00000028 <.rodata.str1.1>:
53+
; CHECKOBJ-NEXT: 24: 00 00 00 00
5854
; CHECKOBJ-NEXT: 28: 68 65 6c 6c
5955
; CHECKOBJ-NEXT: 2c: 6f 20 77 6f
6056
; CHECKOBJ-NEXT: 30: 72 6c 64 21

llvm/test/tools/llvm-objdump/XCOFF/symbol-table.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ entry:
7171
; SYM-NEXT: 00000000 l .text 00000091
7272
; SYM-NEXT: 00000000 g F .text (csect: ) 00000000 .bar
7373
; SYM-NEXT: 00000050 g F .text (csect: ) 00000000 .foo
74-
; SYM-NEXT: 00000094 l .text 00000013 .rodata.str1.1L...str
74+
; SYM-NEXT: 00000094 l .text 00000013 L...str
7575
; SYM-NEXT: 000000a8 g O .data 00000004 con
7676
; SYM-NEXT: 000000ac w O .data 00000004 wi
7777
; SYM-NEXT: 000000b0 g O .data 00000004 i
@@ -93,7 +93,7 @@ entry:
9393
; SYM-DES-NEXT: 00000000 l .text 00000091 (idx: 3) [PR]
9494
; SYM-DES-NEXT: 00000000 g F .text (csect: (idx: 3) [PR]) 00000000 (idx: 5) .bar
9595
; SYM-DES-NEXT: 00000050 g F .text (csect: (idx: 3) [PR]) 00000000 (idx: 7) .foo
96-
; SYM-DES-NEXT: 00000094 l .text 00000013 (idx: 9) .rodata.str1.1L...str[RO]
96+
; SYM-DES-NEXT: 00000094 l .text 00000013 (idx: 9) L...str[RO]
9797
; SYM-DES-NEXT: 000000a8 g O .data 00000004 (idx: 11) con[RW]
9898
; SYM-DES-NEXT: 000000ac w O .data 00000004 (idx: 13) wi[RW]
9999
; SYM-DES-NEXT: 000000b0 g O .data 00000004 (idx: 15) i[RW]

0 commit comments

Comments
 (0)