Skip to content

Commit 277bcf7

Browse files
[ELF][AsmPrinter] Emit trailing dot for constant pool section when it has a hotness prefix (#150859)
Currently, `TargetLoweringObjectFileELF::getSectionForConstant` produce `.<section>.hot` or `.<section>.unlikely` for a constant with non-empty section prefix. This PR changes the implementation add trailing dot when section prefix is not empty, to disambiguate `.hot` as a hotness prefix from `.hot` as a (pure C) variable name. Relevant discussions are in #148985 (comment) and #148985 (comment) and
1 parent 10f9f57 commit 277bcf7

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,27 +1060,27 @@ MCSection *TargetLoweringObjectFileELF::getSectionForConstant(
10601060

10611061
auto &Context = getContext();
10621062
if (Kind.isMergeableConst4() && MergeableConst4Section)
1063-
return Context.getELFSection(".rodata.cst4." + SectionSuffix,
1063+
return Context.getELFSection(".rodata.cst4." + SectionSuffix + ".",
10641064
ELF::SHT_PROGBITS,
10651065
ELF::SHF_ALLOC | ELF::SHF_MERGE, 4);
10661066
if (Kind.isMergeableConst8() && MergeableConst8Section)
1067-
return Context.getELFSection(".rodata.cst8." + SectionSuffix,
1067+
return Context.getELFSection(".rodata.cst8." + SectionSuffix + ".",
10681068
ELF::SHT_PROGBITS,
10691069
ELF::SHF_ALLOC | ELF::SHF_MERGE, 8);
10701070
if (Kind.isMergeableConst16() && MergeableConst16Section)
1071-
return Context.getELFSection(".rodata.cst16." + SectionSuffix,
1071+
return Context.getELFSection(".rodata.cst16." + SectionSuffix + ".",
10721072
ELF::SHT_PROGBITS,
10731073
ELF::SHF_ALLOC | ELF::SHF_MERGE, 16);
10741074
if (Kind.isMergeableConst32() && MergeableConst32Section)
1075-
return Context.getELFSection(".rodata.cst32." + SectionSuffix,
1075+
return Context.getELFSection(".rodata.cst32." + SectionSuffix + ".",
10761076
ELF::SHT_PROGBITS,
10771077
ELF::SHF_ALLOC | ELF::SHF_MERGE, 32);
10781078
if (Kind.isReadOnly())
1079-
return Context.getELFSection(".rodata." + SectionSuffix, ELF::SHT_PROGBITS,
1080-
ELF::SHF_ALLOC);
1079+
return Context.getELFSection(".rodata." + SectionSuffix + ".",
1080+
ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
10811081

10821082
assert(Kind.isReadOnlyWithRel() && "Unknown section kind");
1083-
return Context.getELFSection(".data.rel.ro." + SectionSuffix,
1083+
return Context.getELFSection(".data.rel.ro." + SectionSuffix + ".",
10841084
ELF::SHT_PROGBITS,
10851085
ELF::SHF_ALLOC | ELF::SHF_WRITE);
10861086
}

llvm/test/CodeGen/AArch64/constant-pool-partition.ll

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
; function, constant pools for this constant should not have `.unlikely` suffix.
2020

2121
;; Constant pools for function @cold_func.
22-
; CHECK: .section .rodata.cst8.hot,"aM",@progbits,8
22+
; CHECK: .section .rodata.cst8.hot.,"aM",@progbits,8
2323
; CHECK-NEXT: .p2align
2424
; CHECK-NEXT: .LCPI0_0:
2525
; CHECK-NEXT: .xword 0x3fe5c28f5c28f5c3 // double 0.68000000000000005
26-
; CHECK-NEXT: .section .rodata.cst8.unlikely,"aM",@progbits,8
26+
; CHECK-NEXT: .section .rodata.cst8.unlikely.,"aM",@progbits,8
2727
; CHECK-NEXT: .p2align
2828
; CHECK-NEXT: .LCPI0_1:
2929
; CHECK-NEXT: .xword 0x3fe5eb851eb851ec // double 0.68500000000000005
@@ -58,7 +58,7 @@
5858
; CHECK-NEXT: .word 3 // 0x3
5959
; CHECK-NEXT: .word 5 // 0x5
6060
; CHECK-NEXT: .word 7 // 0x7
61-
; CHECK-NEXT: .section .rodata.cst16.hot,"aM",@progbits,16
61+
; CHECK-NEXT: .section .rodata.cst16.hot.,"aM",@progbits,16
6262
; CHECK-NEXT: .p2align
6363
; CHECK-NEXT: .LCPI1_2:
6464
; CHECK-NEXT: .word 442 // 0x1ba
@@ -67,11 +67,11 @@
6767
; CHECK-NEXT: .word 0 // 0x0
6868

6969
;; Constant pools for function @hot_func
70-
; CHECK: .section .rodata.cst8.hot,"aM",@progbits,8
70+
; CHECK: .section .rodata.cst8.hot.,"aM",@progbits,8
7171
; CHECK-NEXT: .p2align
7272
; CHECK-NEXT: .LCPI2_0:
7373
; CHECK-NEXT: .xword 0x3fe5c28f5c28f5c3 // double 0.68000000000000005
74-
; CHECK-NEXT: .section .rodata.cst16.hot,"aM",@progbits,16
74+
; CHECK-NEXT: .section .rodata.cst16.hot.,"aM",@progbits,16
7575
; CHECK-NEXT: .p2align
7676
; CHECK-NEXT: .LCPI2_1:
7777
; CHECK-NEXT: .word 0 // 0x0

llvm/test/CodeGen/X86/constant-pool-partition.ll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ target triple = "x86_64-grtev4-linux-gnu"
2424
; RUN: %s -o - 2>&1 | FileCheck %s --dump-input=always
2525

2626
;; For function @cold_func
27-
; CHECK: .section .rodata.cst8.hot,"aM",@progbits,8
27+
; CHECK: .section .rodata.cst8.hot.,"aM",@progbits,8
2828
; CHECK-NEXT: .p2align
2929
; CHECK-NEXT: .LCPI0_0:
3030
; CHECK-NEXT: .quad 0x3fe5c28f5c28f5c3 # double 0.68000000000000005
31-
; CHECK-NEXT: .section .rodata.cst8.unlikely,"aM",@progbits,8
31+
; CHECK-NEXT: .section .rodata.cst8.unlikely.,"aM",@progbits,8
3232
; CHECK-NEXT: .p2align
3333
; CHECK-NEXT: .LCPI0_1:
3434
; CHECK-NEXT: .quad 0x3eb0000000000000 # double 9.5367431640625E-7
@@ -50,11 +50,11 @@ target triple = "x86_64-grtev4-linux-gnu"
5050
; CHECK-NEXT: .long 0x3e000000 # float 0.125
5151

5252
;; For function @hot_func
53-
; CHECK: .section .rodata.cst8.hot,"aM",@progbits,8
53+
; CHECK: .section .rodata.cst8.hot.,"aM",@progbits,8
5454
; CHECK-NEXT: .p2align
5555
; CHECK-NEXT: .LCPI3_0:
5656
; CHECK-NEXT: .quad 0x3fe5c28f5c28f5c3 # double 0.68000000000000005
57-
; CHECK-NEXT: .section .rodata.cst16.hot,"aM",@progbits,16
57+
; CHECK-NEXT: .section .rodata.cst16.hot.,"aM",@progbits,16
5858
; CHECK-NEXT: .p2align
5959
; CHECK-NEXT: .LCPI3_1:
6060
; CHECK-NEXT: .long 2147483648 # 0x80000000

0 commit comments

Comments
 (0)