[llvm] 68494ae - [XRay] xray_fn_idx: fix alignment directive
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 8 21:52:58 PDT 2025
Author: Fangrui Song
Date: 2025-07-08T21:52:53-07:00
New Revision: 68494ae072676726722d87af6d9fd9e7c8b808bb
URL: https://github.com/llvm/llvm-project/commit/68494ae072676726722d87af6d9fd9e7c8b808bb
DIFF: https://github.com/llvm/llvm-project/commit/68494ae072676726722d87af6d9fd9e7c8b808bb.diff
LOG: [XRay] xray_fn_idx: fix alignment directive
Use `emitValueToAlignment` as the section does not contain code.
`emitCodeAlignment` would lead to ALIGN relocations on RISC-V and
LoongArch with linker relaxation.
In addition, change the alignment to wordsize, sufficient for the
runtime requirement (`XRayFunctionSledIndex`).
Related to #147322
Added:
Modified:
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
llvm/test/CodeGen/PowerPC/xray-attribute-instrumentation.ll
llvm/test/CodeGen/SystemZ/xray.ll
llvm/test/CodeGen/X86/xray-attribute-instrumentation.ll
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 07d9380a02c43..0364fcfbcfc75 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -4628,12 +4628,10 @@ void AsmPrinter::emitXRayTable() {
// We then emit a single entry in the index per function. We use the symbols
// that bound the instrumentation map as the range for a specific function.
- // Each entry here will be 2 * word size aligned, as we're writing down two
- // pointers. This should work for both 32-bit and 64-bit platforms.
+ // Each entry contains 2 words and needs to be word-aligned.
if (FnSledIndex) {
OutStreamer->switchSection(FnSledIndex);
- OutStreamer->emitCodeAlignment(Align(2 * WordSizeBytes),
- &getSubtargetInfo());
+ OutStreamer->emitValueToAlignment(Align(WordSizeBytes));
// For Mach-O, use an "l" symbol as the atom of this subsection. The label
//
diff erence uses a SUBTRACTOR external relocation which references the
// symbol.
diff --git a/llvm/test/CodeGen/PowerPC/xray-attribute-instrumentation.ll b/llvm/test/CodeGen/PowerPC/xray-attribute-instrumentation.ll
index c3a5c01aaabeb..97b653a4bf9c1 100644
--- a/llvm/test/CodeGen/PowerPC/xray-attribute-instrumentation.ll
+++ b/llvm/test/CodeGen/PowerPC/xray-attribute-instrumentation.ll
@@ -41,7 +41,7 @@ define i32 @foo() nounwind noinline uwtable "function-instrument"="xray-always"
; CHECK-NEXT: .space 13
; CHECK-NEXT: .Lxray_sleds_end0:
; CHECK-LABEL: xray_fn_idx,"ao", at progbits,foo{{$}}
-; CHECK: .p2align 4
+; CHECK: .p2align 3, 0x0
; CHECK-NEXT: [[IDX:.Lxray_fn_idx[0-9]+]]:
; CHECK-NEXT: .quad .Lxray_sleds_start0-[[IDX]]
; CHECK-NEXT: .quad 2
diff --git a/llvm/test/CodeGen/SystemZ/xray.ll b/llvm/test/CodeGen/SystemZ/xray.ll
index ac4c7b8493ba6..3e1290960eedd 100644
--- a/llvm/test/CodeGen/SystemZ/xray.ll
+++ b/llvm/test/CodeGen/SystemZ/xray.ll
@@ -38,7 +38,7 @@ define signext i32 @foo() "function-instrument"="xray-always" {
; CHECK: .space 13
; CHECK: .Lxray_sleds_end0:
; CHECK: .section xray_fn_idx,"ao", at progbits,foo
-; CHECK: .p2align 4
+; CHECK: .p2align 3, 0
; CHECK: .Lxray_fn_idx0:
; CHECK: .quad .Lxray_sleds_start0-.Lxray_fn_idx0
; CHECK: .quad 2
diff --git a/llvm/test/CodeGen/X86/xray-attribute-instrumentation.ll b/llvm/test/CodeGen/X86/xray-attribute-instrumentation.ll
index fc1f3352ce818..8b4809855f92a 100644
--- a/llvm/test/CodeGen/X86/xray-attribute-instrumentation.ll
+++ b/llvm/test/CodeGen/X86/xray-attribute-instrumentation.ll
@@ -20,7 +20,8 @@ define i32 @foo() nounwind noinline uwtable "function-instrument"="xray-always"
; CHECK-LINUX: .quad .Lxray_sled_1
; CHECK-LINUX-LABEL: .Lxray_sleds_end0:
; CHECK-LINUX-LABEL: .section xray_fn_idx,"ao", at progbits,foo{{$}}
-; CHECK-LINUX: [[IDX:\.Lxray_fn_idx[0-9]+]]:
+; CHECK-LINUX-NEXT: .p2align 3, 0x0
+; CHECK-LINUX-NEXT: [[IDX:\.Lxray_fn_idx[0-9]+]]:
; CHECK-LINUX-NEXT: .quad .Lxray_sleds_start0-[[IDX]]
; CHECK-LINUX-NEXT: .quad 2
More information about the llvm-commits
mailing list