[llvm] [AsmPrinter] Link .section_sizes to the correct section (PR #135583)

via llvm-commits llvm-commits at lists.llvm.org
Sun Apr 13 20:22:35 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-systemz

Author: Sergei Barannikov (s-barannikov)

<details>
<summary>Changes</summary>

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".

---
Full diff: https://github.com/llvm/llvm-project/pull/135583.diff


2 Files Affected:

- (modified) llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (+1-1) 
- (modified) llvm/test/CodeGen/SystemZ/stack-size-section.ll (+30) 


``````````diff
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index cf8f1c878ea5a..821879a1f7c36 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -1586,7 +1586,7 @@ void AsmPrinter::emitStackSizeSection(const MachineFunction &MF) {
     return;
 
   MCSection *StackSizeSection =
-      getObjFileLowering().getStackSizesSection(*getCurrentSection());
+      getObjFileLowering().getStackSizesSection(*MF.getSection());
   if (!StackSizeSection)
     return;
 
diff --git a/llvm/test/CodeGen/SystemZ/stack-size-section.ll b/llvm/test/CodeGen/SystemZ/stack-size-section.ll
index 024f20bfc2dc8..6225ce0ef23a1 100644
--- a/llvm/test/CodeGen/SystemZ/stack-size-section.ll
+++ b/llvm/test/CodeGen/SystemZ/stack-size-section.ll
@@ -38,4 +38,34 @@ define void @dynalloc(i32 %N) #0 {
   ret void
 }
 
+; Check that .stack_sizes section is linked to the function's section (.text),
+; and not to the section containing the jump table (.rodata).
+; CHECK-LABEL: .section .stack_sizes,"o", at progbits,.text{{$}}
+; CHECK-LABEL: .quad .Lfunc_begin4
+; CHECK-LABEL: .ascii "\260!"
+define i32 @jump_table(i32 %x) {
+  %arr = alloca [1024 x i32]
+  switch i32 %x, label %sw.epilog [
+    i32 0, label %sw.bb0
+    i32 1, label %sw.bb1
+    i32 2, label %sw.bb2
+    i32 3, label %sw.bb3
+  ]
+
+sw.bb0:
+  ret i32 0
+
+sw.bb1:
+  ret i32 1
+
+sw.bb2:
+  ret i32 2
+
+sw.bb3:
+  ret i32 3
+
+sw.epilog:
+  ret i32 -1
+}
+
 attributes #0 = { "frame-pointer"="all" }

``````````

</details>


https://github.com/llvm/llvm-project/pull/135583


More information about the llvm-commits mailing list