Skip to content

Commit 3ceba61

Browse files
committed
[AsmPrinter] Link .section_sizes to the correct section
AsmPrinter may switch the current section when e.g., emitting a jump table for a switch. `.stack_sizes` should still be linked to the function section. If the section is wrong, objdump emits a warning "relocation symbol is not in the expected section".
1 parent 974bda8 commit 3ceba61

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1586,7 +1586,7 @@ void AsmPrinter::emitStackSizeSection(const MachineFunction &MF) {
15861586
return;
15871587

15881588
MCSection *StackSizeSection =
1589-
getObjFileLowering().getStackSizesSection(*getCurrentSection());
1589+
getObjFileLowering().getStackSizesSection(*MF.getSection());
15901590
if (!StackSizeSection)
15911591
return;
15921592

llvm/test/CodeGen/SystemZ/stack-size-section.ll

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,34 @@ define void @dynalloc(i32 %N) #0 {
3838
ret void
3939
}
4040

41+
; Check that .stack_sizes section is linked to the function's section (.text),
42+
; and not to the section containing the jump table (.rodata).
43+
; CHECK-LABEL: .section .stack_sizes,"o",@progbits,.text{{$}}
44+
; CHECK-LABEL: .quad .Lfunc_begin4
45+
; CHECK-LABEL: .ascii "\260!"
46+
define i32 @jump_table(i32 %x) {
47+
%arr = alloca [1024 x i32]
48+
switch i32 %x, label %sw.epilog [
49+
i32 0, label %sw.bb0
50+
i32 1, label %sw.bb1
51+
i32 2, label %sw.bb2
52+
i32 3, label %sw.bb3
53+
]
54+
55+
sw.bb0:
56+
ret i32 0
57+
58+
sw.bb1:
59+
ret i32 1
60+
61+
sw.bb2:
62+
ret i32 2
63+
64+
sw.bb3:
65+
ret i32 3
66+
67+
sw.epilog:
68+
ret i32 -1
69+
}
70+
4171
attributes #0 = { "frame-pointer"="all" }

0 commit comments

Comments
 (0)