-
Notifications
You must be signed in to change notification settings - Fork 13.2k
[AsmPrinter] Link .section_sizes to the correct section #135583
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[AsmPrinter] Link .section_sizes to the correct section #135583
Conversation
@llvm/pr-subscribers-backend-aarch64 @llvm/pr-subscribers-backend-systemz Author: Sergei Barannikov (s-barannikov) ChangesAsmPrinter may switch the current section when e.g., emitting a jump table for a switch. Full diff: https://github.com/llvm/llvm-project/pull/135583.diff 2 Files Affected:
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",@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" }
|
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".
3ceba61
to
2c2c473
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! AArch64 also places jump tables in .rodata . You could add a stack-size-section test for it as well :)
It's so hard to write a test with jump tables for AArch64. Everything I try is optimized out. I even tried 16 prime numbers for the switch cases and the switch is still optimized out 😖 |
Found an option that helped. |
f5b3a1d
to
b612daf
Compare
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/18/builds/14474 Here is the relevant piece of the build log for the reference
|
* origin/main: (199 commits) [NFC][AsmPrinter] Refactor AsmPrinter and AArch64AsmPrinter to prepare for jump table partitions on aarch64 (llvm#125993) [HEXAGON] Fix corner cases for hwloops pass (llvm#135439) [flang] Handle volatility in lowering and codegen (llvm#135311) [MLIR][Shape] Support >2 args in `shape.broadcast` folder (llvm#126808) [DirectX] Use scalar arguments for @llvm.dx.dot intrinsics (llvm#134570) Remove the redundant check for "WeakPtr" in isSmartPtrClass to fix the issue 135612. (llvm#135629) [BOLT] Support relative vtable (llvm#135449) [flang] Fix linking to libMLIR (llvm#135483) [AsmPrinter] Link .section_sizes to the correct section (llvm#135583) [ctxprof] Handle instrumenting functions with `musttail` calls (llvm#135121) [SystemZ] Consider VST/VL as SimpleBDXStore/Load (llvm#135623) [libc++][CI] Pin the XCode version. (llvm#135412) [lldb-dap] Fix win32 build. (llvm#135638) [Interp] Mark inline-virtual.cpp as unsupported with ASan (llvm#135402) [libc++] Removes the _LIBCPP_VERBOSE_ABORT_NOT_NOEXCEPT macro. (llvm#135494) [CVP] Add tests for ucmp/scmp with switch (NFC) [mlir][tosa] Align AbsOp example variable names (llvm#135268) [mlir][tosa] Align AddOp examples to spec (llvm#135266) [mlir][tosa] Align RFFT2d and FFT2d operator examples (llvm#135261) [flang][OpenMP][HLFIR] Support vector subscripted array sections for DEPEND (llvm#133892) ...
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, readelf emits a warning "relocation symbol is not in the expected section".