Skip to content

Commit 12eddda

Browse files
PanTao2phoebewang
authored andcommitted
[CodeGen] Fix two dots between text section name and symbol name
There is a trailing dot in text section name if it has prefix, don't add repeated dot when connect text section name and symbol name. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D96327
1 parent c17547d commit 12eddda

File tree

2 files changed

+50
-24
lines changed

2 files changed

+50
-24
lines changed

llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,8 @@ getELFSectionNameForGlobal(const GlobalObject *GO, SectionKind Kind,
626626
Name.push_back('.');
627627
TM.getNameWithPrefix(Name, GO, Mang, /*MayAlwaysUsePrivate*/true);
628628
} else if (HasPrefix)
629+
// For distinguishing between .text.${text-section-prefix}. (with trailing
630+
// dot) and .text.${function-name}
629631
Name.push_back('.');
630632
return Name;
631633
}
@@ -939,7 +941,8 @@ MCSection *TargetLoweringObjectFileELF::getSectionForMachineBasicBlock(
939941
} else {
940942
Name += MBB.getParent()->getSection()->getName();
941943
if (TM.getUniqueBasicBlockSectionNames()) {
942-
Name += ".";
944+
if (!Name.endswith("."))
945+
Name += ".";
943946
Name += MBB.getSymbol()->getName();
944947
} else {
945948
UniqueID = NextUniqueID++;

llvm/test/DebugInfo/X86/basic-block-sections_1.ll

Lines changed: 46 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@
77
; From:
88
; 1 int foo(int a) {
99
; 2 if (a > 20)
10-
; 3 return 2;
10+
; 3 return bar();
1111
; 4 else
12-
; 5 return 0;
12+
; 5 return baz();
1313
; 6 }
1414

15-
; NO-SECTIONS: DW_AT_low_pc [DW_FORM_addr] (0x0000000000000000 ".text")
15+
; NO-SECTIONS: DW_AT_low_pc [DW_FORM_addr] (0x0000000000000000 ".text.hot.")
1616
; NO-SECTIONS: DW_AT_high_pc [DW_FORM_data4] ({{.*}})
1717
; BB-SECTIONS: DW_AT_low_pc [DW_FORM_addr] (0x0000000000000000)
1818
; BB-SECTIONS-NEXT: DW_AT_ranges [DW_FORM_sec_offset]
19-
; BB-SECTIONS-NEXT: [{{.*}}) ".text._Z3fooi._Z3fooi.__part.1"
20-
; BB-SECTIONS-NEXT: [{{.*}}) ".text._Z3fooi._Z3fooi.__part.2"
21-
; BB-SECTIONS-NEXT: [{{.*}}) ".text._Z3fooi._Z3fooi.__part.3"
22-
; BB-SECTIONS-NEXT: [{{.*}}) ".text._Z3fooi"
19+
; BB-SECTIONS-NEXT: [{{.*}}) ".text.hot._Z3fooi._Z3fooi.__part.1"
20+
; BB-SECTIONS-NEXT: [{{.*}}) ".text.hot._Z3fooi._Z3fooi.__part.2"
21+
; BB-SECTIONS-NEXT: [{{.*}}) ".text.hot._Z3fooi._Z3fooi.__part.3"
22+
; BB-SECTIONS-NEXT: [{{.*}}) ".text.hot._Z3fooi"
2323
; BB-SECTIONS-ASM: _Z3fooi:
2424
; BB-SECTIONS-ASM: .Ltmp{{[0-9]+}}:
2525
; BB-SECTIONS-ASM-NEXT: .loc 1 2 9 prologue_end
@@ -50,40 +50,46 @@
5050
; BB-SECTIONS-ASM-NEXT: .quad 0
5151
; BB-SECTIONS-LINE-TABLE: 0x0000000000000000 1 0 1 0 0 is_stmt
5252
; BB-SECTIONS-LINE-TABLE-NEXT: 0x0000000000000004 2 9 1 0 0 is_stmt prologue_end
53-
; BB-SECTIONS-LINE-TABLE-NEXT: 0x0000000000000009 2 7 1 0 0
54-
; BB-SECTIONS-LINE-TABLE-NEXT: 0x000000000000000b 3 5 1 0 0 is_stmt
55-
; BB-SECTIONS-LINE-TABLE-NEXT: 0x0000000000000015 5 5 1 0 0 is_stmt
56-
; BB-SECTIONS-LINE-TABLE-NEXT: 0x000000000000001d 6 1 1 0 0 is_stmt
57-
; BB-SECTIONS-LINE-TABLE-NEXT: 0x0000000000000022 6 1 1 0 0 is_stmt end_sequence
53+
; BB-SECTIONS-LINE-TABLE-NEXT: 0x0000000000000008 2 7 1 0 0
54+
; BB-SECTIONS-LINE-TABLE-NEXT: 0x000000000000000a 0 7 1 0 0
55+
; BB-SECTIONS-LINE-TABLE-NEXT: 0x000000000000000f 3 5 1 0 0 is_stmt
56+
; BB-SECTIONS-LINE-TABLE-NEXT: 0x0000000000000015 0 5 1 0 0
57+
; BB-SECTIONS-LINE-TABLE-NEXT: 0x000000000000001a 5 5 1 0 0 is_stmt
58+
; BB-SECTIONS-LINE-TABLE-NEXT: 0x000000000000001e 6 1 1 0 0 is_stmt
59+
; BB-SECTIONS-LINE-TABLE-NEXT: 0x0000000000000024 6 1 1 0 0 is_stmt end_sequence
5860

5961
; Function Attrs: noinline nounwind optnone uwtable
60-
define dso_local i32 @_Z3fooi(i32 %0) !dbg !7 {
62+
define dso_local i32 @_Z3fooi(i32 %0) !dbg !7 !prof !34 !section_prefix !35 {
6163
%2 = alloca i32, align 4
6264
%3 = alloca i32, align 4
6365
store i32 %0, i32* %3, align 4
6466
call void @llvm.dbg.declare(metadata i32* %3, metadata !11, metadata !DIExpression()), !dbg !12
6567
%4 = load i32, i32* %3, align 4, !dbg !13
6668
%5 = icmp sgt i32 %4, 20, !dbg !15
67-
br i1 %5, label %6, label %7, !dbg !16
69+
br i1 %5, label %6, label %8, !dbg !16, !prof !36
6870

6971
6: ; preds = %1
70-
store i32 2, i32* %2, align 4, !dbg !17
71-
br label %8, !dbg !17
72+
%7 = call i32 @bar()
73+
store i32 %7, i32* %2, align 4, !dbg !17
74+
br label %10, !dbg !17
7275

73-
7: ; preds = %1
74-
store i32 0, i32* %2, align 4, !dbg !18
75-
br label %8, !dbg !18
76+
8: ; preds = %1
77+
%9 = call i32 @baz()
78+
store i32 %9, i32* %2, align 4, !dbg !18
79+
br label %10, !dbg !18
7680

77-
8: ; preds = %7, %6
78-
%9 = load i32, i32* %2, align 4, !dbg !19
79-
ret i32 %9, !dbg !19
81+
10: ; preds = %8, %6
82+
%11 = load i32, i32* %2, align 4, !dbg !19
83+
ret i32 %11, !dbg !19
8084
}
8185

8286
; Function Attrs: nounwind readnone speculatable willreturn
8387
declare void @llvm.dbg.declare(metadata, metadata, metadata)
88+
declare i32 @bar()
89+
declare i32 @baz()
8490

8591
!llvm.dbg.cu = !{!0}
86-
!llvm.module.flags = !{!3, !4}
92+
!llvm.module.flags = !{!3, !4, !20}
8793

8894
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 10.0.0 (git@github.com:google/llvm-propeller.git f9421ebf4b3d8b64678bf6c49d1607fdce3f50c5)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None)
8995
!1 = !DIFile(filename: "debuginfo.cc", directory: "/")
@@ -103,3 +109,20 @@ declare void @llvm.dbg.declare(metadata, metadata, metadata)
103109
!17 = !DILocation(line: 3, column: 5, scope: !14)
104110
!18 = !DILocation(line: 5, column: 5, scope: !14)
105111
!19 = !DILocation(line: 6, column: 1, scope: !7)
112+
!20 = !{i32 1, !"ProfileSummary", !21}
113+
!21 = !{!22, !23, !24, !25, !26, !27, !28, !29}
114+
!22 = !{!"ProfileFormat", !"InstrProf"}
115+
!23 = !{!"TotalCount", i64 10000}
116+
!24 = !{!"MaxCount", i64 10}
117+
!25 = !{!"MaxInternalCount", i64 1}
118+
!26 = !{!"MaxFunctionCount", i64 1000}
119+
!27 = !{!"NumCounts", i64 3}
120+
!28 = !{!"NumFunctions", i64 5}
121+
!29 = !{!"DetailedSummary", !30}
122+
!30 = !{!31, !32, !33}
123+
!31 = !{i32 10000, i64 100, i32 1}
124+
!32 = !{i32 999900, i64 100, i32 1}
125+
!33 = !{i32 999999, i64 1, i32 2}
126+
!34 = !{!"function_entry_count", i64 7000}
127+
!35 = !{!"function_section_prefix", !"hot"}
128+
!36 = !{!"branch_weights", i32 6999, i32 1}

0 commit comments

Comments
 (0)