[lld] [lld][test][PAC] Do not rely on concrete offsets in LTO tests (PR #143358)
Daniil Kovalev via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 17 07:50:14 PDT 2025
https://github.com/kovdan01 updated https://github.com/llvm/llvm-project/pull/143358
>From 4d322b50608e8be098b25030302d8d545c06fac9 Mon Sep 17 00:00:00 2001
From: Daniil Kovalev <dkovalev at accesssoftek.com>
Date: Mon, 9 Jun 2025 12:24:08 +0300
Subject: [PATCH 1/4] [lld][test][PAC] Do not rely on concrete offsets in LTO
tests
When changing codegen (e.g. in #130809), offsets in binaries produced by
LTO tests might change. We do not need to match concrete offset values, it's
enough to ensure that hex values in particular places are identical.
---
lld/test/ELF/lto/aarch64-pac-got-func.ll | 42 ++++++++++++------------
1 file changed, 21 insertions(+), 21 deletions(-)
diff --git a/lld/test/ELF/lto/aarch64-pac-got-func.ll b/lld/test/ELF/lto/aarch64-pac-got-func.ll
index a37c67a2f3ba8..aa84952e7aad8 100644
--- a/lld/test/ELF/lto/aarch64-pac-got-func.ll
+++ b/lld/test/ELF/lto/aarch64-pac-got-func.ll
@@ -5,29 +5,29 @@
; RUN: llvm-readelf -r -x.got %t | FileCheck %s
; CHECK: Relocation section '.rela.dyn' at offset 0x3d0 contains 8 entries:
-; CHECK-NEXT: Offset Info Type Symbol's Value Symbol's Name + Addend
-; CHECK-NEXT: 00000000000206a0 0000000100000412 R_AARCH64_AUTH_GLOB_DAT 0000000000000000 func_undef + 0
-; CHECK-NEXT: 00000000000206a8 0000000200000412 R_AARCH64_AUTH_GLOB_DAT 0000000000000000 g1 + 0
-; CHECK-NEXT: 00000000000206b0 0000000300000412 R_AARCH64_AUTH_GLOB_DAT 0000000000000000 g2 + 0
-; CHECK-NEXT: 00000000000206b8 0000000400000412 R_AARCH64_AUTH_GLOB_DAT 0000000000000000 g3 + 0
-; CHECK-NEXT: 00000000000206c0 0000000500000412 R_AARCH64_AUTH_GLOB_DAT 0000000000000000 g4 + 0
-; CHECK-NEXT: 00000000000206c8 0000000600000412 R_AARCH64_AUTH_GLOB_DAT 0000000000000000 var_undef + 0
-; CHECK-NEXT: 0000000000020690 0000000700000412 R_AARCH64_AUTH_GLOB_DAT 0000000000010490 func + 0
-; CHECK-NEXT: 0000000000020698 0000000a00000412 R_AARCH64_AUTH_GLOB_DAT 00000000000306d0 var + 0
+; CHECK-NEXT: Offset Info Type Symbol's Value Symbol's Name + Addend
+; CHECK-NEXT: {{(0{8})}}[[OFFSET1:([[:xdigit:]]{8})]] 0000000100000412 R_AARCH64_AUTH_GLOB_DAT 0000000000000000 func_undef + 0
+; CHECK-NEXT: {{([[:xdigit:]]{16})}} 0000000200000412 R_AARCH64_AUTH_GLOB_DAT 0000000000000000 g1 + 0
+; CHECK-NEXT: {{(0{8})}}[[OFFSET2:([[:xdigit:]]{8})]] 0000000300000412 R_AARCH64_AUTH_GLOB_DAT 0000000000000000 g2 + 0
+; CHECK-NEXT: {{([[:xdigit:]]{16})}} 0000000400000412 R_AARCH64_AUTH_GLOB_DAT 0000000000000000 g3 + 0
+; CHECK-NEXT: {{(0{8})}}[[OFFSET3:([[:xdigit:]]{8})]] 0000000500000412 R_AARCH64_AUTH_GLOB_DAT 0000000000000000 g4 + 0
+; CHECK-NEXT: {{([[:xdigit:]]{16})}} 0000000600000412 R_AARCH64_AUTH_GLOB_DAT 0000000000000000 var_undef + 0
+; CHECK-NEXT: {{(0{8})}}[[OFFSET4:([[:xdigit:]]{8})]] 0000000700000412 R_AARCH64_AUTH_GLOB_DAT {{([[:xdigit:]]{16})}} func + 0
+; CHECK-NEXT: {{([[:xdigit:]]{16})}} 0000000a00000412 R_AARCH64_AUTH_GLOB_DAT {{([[:xdigit:]]{16})}} var + 0
; CHECK: Hex dump of section '.got':
-; CHECK-NEXT: 0x00020690 00000000 00000080 00000000 000000a0
-;; ^^ func: 0b10000000 bit 63 address diversity = true, bits 61..60 key = IA
-;; ^^ var: 0b10100000 bit 63 address diversity = true, bits 61..60 key = DA
-; CHECK-NEXT: 0x000206a0 00000000 00000080 00000000 000000a0
-;; ^^ func_undef: 0b10000000 bit 63 address diversity = true, bits 61..60 key = IA
-;; ^^ g1: 0b10100000 bit 63 address diversity = true, bits 61..60 key = DA
-; CHECK-NEXT: 0x000206b0 00000000 000000a0 00000000 000000a0
-;; ^^ g2: 0b10100000 bit 63 address diversity = true, bits 61..60 key = DA
-;; ^^ g3: 0b10100000 bit 63 address diversity = true, bits 61..60 key = DA
-; CHECK-NEXT: 0x000206c0 00000000 000000a0 00000000 000000a0
-;; ^^ g4: 0b10100000 bit 63 address diversity = true, bits 61..60 key = DA
-;; ^^ var_undef: 0b10100000 bit 63 address diversity = true, bits 61..60 key = DA
+; CHECK-NEXT: 0x[[OFFSET4]] 00000000 00000080 00000000 000000a0
+;; ^^ func: 0b10000000 bit 63 address diversity = true, bits 61..60 key = IA
+;; ^^ var: 0b10100000 bit 63 address diversity = true, bits 61..60 key = DA
+; CHECK-NEXT: 0x[[OFFSET1]] 00000000 00000080 00000000 000000a0
+;; ^^ func_undef: 0b10000000 bit 63 address diversity = true, bits 61..60 key = IA
+;; ^^ g1: 0b10100000 bit 63 address diversity = true, bits 61..60 key = DA
+; CHECK-NEXT: 0x[[OFFSET2]] 00000000 000000a0 00000000 000000a0
+;; ^^ g2: 0b10100000 bit 63 address diversity = true, bits 61..60 key = DA
+;; ^^ g3: 0b10100000 bit 63 address diversity = true, bits 61..60 key = DA
+; CHECK-NEXT: 0x[[OFFSET3]] 00000000 000000a0 00000000 000000a0
+;; ^^ g4: 0b10100000 bit 63 address diversity = true, bits 61..60 key = DA
+;; ^^ var_undef: 0b10100000 bit 63 address diversity = true, bits 61..60 key = DA
target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
target triple = "aarch64-unknown-linux-gnu"
>From e2063ced54a2586c67c0f9b0f0711519801efd96 Mon Sep 17 00:00:00 2001
From: Anatoly Trosinenko <atrosinenko at accesssoftek.com>
Date: Mon, 9 Jun 2025 15:28:25 +0300
Subject: [PATCH 2/4] Another approach: use large enough alignment
---
lld/test/ELF/lto/aarch64-pac-got-func.ll | 60 ++++++++++++++----------
1 file changed, 35 insertions(+), 25 deletions(-)
diff --git a/lld/test/ELF/lto/aarch64-pac-got-func.ll b/lld/test/ELF/lto/aarch64-pac-got-func.ll
index aa84952e7aad8..4abc9b0471632 100644
--- a/lld/test/ELF/lto/aarch64-pac-got-func.ll
+++ b/lld/test/ELF/lto/aarch64-pac-got-func.ll
@@ -5,29 +5,29 @@
; RUN: llvm-readelf -r -x.got %t | FileCheck %s
; CHECK: Relocation section '.rela.dyn' at offset 0x3d0 contains 8 entries:
-; CHECK-NEXT: Offset Info Type Symbol's Value Symbol's Name + Addend
-; CHECK-NEXT: {{(0{8})}}[[OFFSET1:([[:xdigit:]]{8})]] 0000000100000412 R_AARCH64_AUTH_GLOB_DAT 0000000000000000 func_undef + 0
-; CHECK-NEXT: {{([[:xdigit:]]{16})}} 0000000200000412 R_AARCH64_AUTH_GLOB_DAT 0000000000000000 g1 + 0
-; CHECK-NEXT: {{(0{8})}}[[OFFSET2:([[:xdigit:]]{8})]] 0000000300000412 R_AARCH64_AUTH_GLOB_DAT 0000000000000000 g2 + 0
-; CHECK-NEXT: {{([[:xdigit:]]{16})}} 0000000400000412 R_AARCH64_AUTH_GLOB_DAT 0000000000000000 g3 + 0
-; CHECK-NEXT: {{(0{8})}}[[OFFSET3:([[:xdigit:]]{8})]] 0000000500000412 R_AARCH64_AUTH_GLOB_DAT 0000000000000000 g4 + 0
-; CHECK-NEXT: {{([[:xdigit:]]{16})}} 0000000600000412 R_AARCH64_AUTH_GLOB_DAT 0000000000000000 var_undef + 0
-; CHECK-NEXT: {{(0{8})}}[[OFFSET4:([[:xdigit:]]{8})]] 0000000700000412 R_AARCH64_AUTH_GLOB_DAT {{([[:xdigit:]]{16})}} func + 0
-; CHECK-NEXT: {{([[:xdigit:]]{16})}} 0000000a00000412 R_AARCH64_AUTH_GLOB_DAT {{([[:xdigit:]]{16})}} var + 0
+; CHECK-NEXT: Offset Info Type Symbol's Value Symbol's Name + Addend
+; CHECK-NEXT: 00000000000210b8 0000000100000412 R_AARCH64_AUTH_GLOB_DAT 0000000000000000 func_undef + 0
+; CHECK-NEXT: 00000000000210c0 0000000200000412 R_AARCH64_AUTH_GLOB_DAT 0000000000000000 g1 + 0
+; CHECK-NEXT: 00000000000210c8 0000000300000412 R_AARCH64_AUTH_GLOB_DAT 0000000000000000 g2 + 0
+; CHECK-NEXT: 00000000000210d0 0000000400000412 R_AARCH64_AUTH_GLOB_DAT 0000000000000000 g3 + 0
+; CHECK-NEXT: 00000000000210d8 0000000500000412 R_AARCH64_AUTH_GLOB_DAT 0000000000000000 g4 + 0
+; CHECK-NEXT: 00000000000210e0 0000000600000412 R_AARCH64_AUTH_GLOB_DAT 0000000000000000 var_undef + 0
+; CHECK-NEXT: 00000000000210a8 0000000700000412 R_AARCH64_AUTH_GLOB_DAT 0000000000010800 func + 0
+; CHECK-NEXT: 00000000000210b0 0000000a00000412 R_AARCH64_AUTH_GLOB_DAT 0000000000031400 var + 0
; CHECK: Hex dump of section '.got':
-; CHECK-NEXT: 0x[[OFFSET4]] 00000000 00000080 00000000 000000a0
-;; ^^ func: 0b10000000 bit 63 address diversity = true, bits 61..60 key = IA
-;; ^^ var: 0b10100000 bit 63 address diversity = true, bits 61..60 key = DA
-; CHECK-NEXT: 0x[[OFFSET1]] 00000000 00000080 00000000 000000a0
-;; ^^ func_undef: 0b10000000 bit 63 address diversity = true, bits 61..60 key = IA
-;; ^^ g1: 0b10100000 bit 63 address diversity = true, bits 61..60 key = DA
-; CHECK-NEXT: 0x[[OFFSET2]] 00000000 000000a0 00000000 000000a0
-;; ^^ g2: 0b10100000 bit 63 address diversity = true, bits 61..60 key = DA
-;; ^^ g3: 0b10100000 bit 63 address diversity = true, bits 61..60 key = DA
-; CHECK-NEXT: 0x[[OFFSET3]] 00000000 000000a0 00000000 000000a0
-;; ^^ g4: 0b10100000 bit 63 address diversity = true, bits 61..60 key = DA
-;; ^^ var_undef: 0b10100000 bit 63 address diversity = true, bits 61..60 key = DA
+; CHECK-NEXT: 0x000210a8 00000000 00000080 00000000 000000a0
+;; ^^ func: 0b10000000 bit 63 address diversity = true, bits 61..60 key = IA
+;; ^^ var: 0b10100000 bit 63 address diversity = true, bits 61..60 key = DA
+; CHECK-NEXT: 0x000210b8 00000000 00000080 00000000 000000a0
+;; ^^ func_undef: 0b10000000 bit 63 address diversity = true, bits 61..60 key = IA
+;; ^^ g1: 0b10100000 bit 63 address diversity = true, bits 61..60 key = DA
+; CHECK-NEXT: 0x000210c8 00000000 000000a0 00000000 000000a0
+;; ^^ g2: 0b10100000 bit 63 address diversity = true, bits 61..60 key = DA
+;; ^^ g3: 0b10100000 bit 63 address diversity = true, bits 61..60 key = DA
+; CHECK-NEXT: 0x000210d8 00000000 000000a0 00000000 000000a0
+;; ^^ g4: 0b10100000 bit 63 address diversity = true, bits 61..60 key = DA
+;; ^^ var_undef: 0b10100000 bit 63 address diversity = true, bits 61..60 key = DA
target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
target triple = "aarch64-unknown-linux-gnu"
@@ -37,16 +37,26 @@ target triple = "aarch64-unknown-linux-gnu"
@g3 = external global ptr
@g4 = external global ptr
-define void @func() {
+; Minor codegen changes may influence function sizes and thus move subsequent
+; symbols. To prevent accidental changes to symbol addresses, request an
+; alignment that is larger than any expected function's size.
+;
+; Note that it is handy to have a trivial function like _start at the end of
+; the .text section, as most offsets of interest point to the dynamic section,
+; and one cannot easily control its alignment. On the other hand, the _start
+; function almost certainly contains a single ret instruction and is itself
+; aligned, making offsets of the subsequent sections predictable.
+
+define void @func() align 1024 {
entry:
ret void
}
declare void @func_undef()
- at var = global i32 42
+ at var = global i32 42, align 1024
@var_undef = external global i32
-define void @bar() #0 {
+define void @bar() #0 align 1024 {
entry:
store ptr ptrauth (ptr @func, i32 0), ptr @g1
store ptr ptrauth (ptr @func_undef, i32 0), ptr @g2
@@ -55,7 +65,7 @@ entry:
ret void
}
-define void @_start() {
+define void @_start() align 1024 {
entry:
ret void
}
>From 5dbfbffc1c77ce045f1f41baa1f3fba800712d4a Mon Sep 17 00:00:00 2001
From: Daniil Kovalev <dkovalev at accesssoftek.com>
Date: Tue, 17 Jun 2025 11:05:55 +0300
Subject: [PATCH 3/4] Address review comments
---
lld/test/ELF/lto/aarch64-pac-got-func.ll | 42 ++++++++++++------------
1 file changed, 21 insertions(+), 21 deletions(-)
diff --git a/lld/test/ELF/lto/aarch64-pac-got-func.ll b/lld/test/ELF/lto/aarch64-pac-got-func.ll
index 4abc9b0471632..efa7c66ae5f2a 100644
--- a/lld/test/ELF/lto/aarch64-pac-got-func.ll
+++ b/lld/test/ELF/lto/aarch64-pac-got-func.ll
@@ -5,29 +5,29 @@
; RUN: llvm-readelf -r -x.got %t | FileCheck %s
; CHECK: Relocation section '.rela.dyn' at offset 0x3d0 contains 8 entries:
-; CHECK-NEXT: Offset Info Type Symbol's Value Symbol's Name + Addend
-; CHECK-NEXT: 00000000000210b8 0000000100000412 R_AARCH64_AUTH_GLOB_DAT 0000000000000000 func_undef + 0
-; CHECK-NEXT: 00000000000210c0 0000000200000412 R_AARCH64_AUTH_GLOB_DAT 0000000000000000 g1 + 0
-; CHECK-NEXT: 00000000000210c8 0000000300000412 R_AARCH64_AUTH_GLOB_DAT 0000000000000000 g2 + 0
-; CHECK-NEXT: 00000000000210d0 0000000400000412 R_AARCH64_AUTH_GLOB_DAT 0000000000000000 g3 + 0
-; CHECK-NEXT: 00000000000210d8 0000000500000412 R_AARCH64_AUTH_GLOB_DAT 0000000000000000 g4 + 0
-; CHECK-NEXT: 00000000000210e0 0000000600000412 R_AARCH64_AUTH_GLOB_DAT 0000000000000000 var_undef + 0
-; CHECK-NEXT: 00000000000210a8 0000000700000412 R_AARCH64_AUTH_GLOB_DAT 0000000000010800 func + 0
-; CHECK-NEXT: 00000000000210b0 0000000a00000412 R_AARCH64_AUTH_GLOB_DAT 0000000000031400 var + 0
+; CHECK-NEXT: Offset Info Type Symbol's Value Symbol's Name + Addend
+; CHECK-NEXT: [[#%x,ADDR:]] 0000000100000412 R_AARCH64_AUTH_GLOB_DAT 0000000000000000 func_undef + 0
+; CHECK-NEXT: {{0*}}[[#ADDR+0x8]] 0000000200000412 R_AARCH64_AUTH_GLOB_DAT 0000000000000000 g1 + 0
+; CHECK-NEXT: {{0*}}[[#ADDR+0x10]] 0000000300000412 R_AARCH64_AUTH_GLOB_DAT 0000000000000000 g2 + 0
+; CHECK-NEXT: {{0*}}[[#ADDR+0x18]] 0000000400000412 R_AARCH64_AUTH_GLOB_DAT 0000000000000000 g3 + 0
+; CHECK-NEXT: {{0*}}[[#ADDR+0x20]] 0000000500000412 R_AARCH64_AUTH_GLOB_DAT 0000000000000000 g4 + 0
+; CHECK-NEXT: {{0*}}[[#ADDR+0x28]] 0000000600000412 R_AARCH64_AUTH_GLOB_DAT 0000000000000000 var_undef + 0
+; CHECK-NEXT: {{0*}}[[#ADDR-0x10]] 0000000700000412 R_AARCH64_AUTH_GLOB_DAT 0000000000010800 func + 0
+; CHECK-NEXT: {{0*}}[[#ADDR-0x8]] 0000000a00000412 R_AARCH64_AUTH_GLOB_DAT 0000000000031400 var + 0
; CHECK: Hex dump of section '.got':
-; CHECK-NEXT: 0x000210a8 00000000 00000080 00000000 000000a0
-;; ^^ func: 0b10000000 bit 63 address diversity = true, bits 61..60 key = IA
-;; ^^ var: 0b10100000 bit 63 address diversity = true, bits 61..60 key = DA
-; CHECK-NEXT: 0x000210b8 00000000 00000080 00000000 000000a0
-;; ^^ func_undef: 0b10000000 bit 63 address diversity = true, bits 61..60 key = IA
-;; ^^ g1: 0b10100000 bit 63 address diversity = true, bits 61..60 key = DA
-; CHECK-NEXT: 0x000210c8 00000000 000000a0 00000000 000000a0
-;; ^^ g2: 0b10100000 bit 63 address diversity = true, bits 61..60 key = DA
-;; ^^ g3: 0b10100000 bit 63 address diversity = true, bits 61..60 key = DA
-; CHECK-NEXT: 0x000210d8 00000000 000000a0 00000000 000000a0
-;; ^^ g4: 0b10100000 bit 63 address diversity = true, bits 61..60 key = DA
-;; ^^ var_undef: 0b10100000 bit 63 address diversity = true, bits 61..60 key = DA
+; CHECK-NEXT: 0x{{0*}}[[#ADDR-0x10]] 00000000 00000080 00000000 000000a0
+;; ^^ func: 0b10000000 bit 63 address diversity = true, bits 61..60 key = IA
+;; ^^ var: 0b10100000 bit 63 address diversity = true, bits 61..60 key = DA
+; CHECK-NEXT: 0x{{0*}}[[#ADDR]] 00000000 00000080 00000000 000000a0
+;; ^^ func_undef: 0b10000000 bit 63 address diversity = true, bits 61..60 key = IA
+;; ^^ g1: 0b10100000 bit 63 address diversity = true, bits 61..60 key = DA
+; CHECK-NEXT: 0x{{0*}}[[#ADDR+0x10]] 00000000 000000a0 00000000 000000a0
+;; ^^ g2: 0b10100000 bit 63 address diversity = true, bits 61..60 key = DA
+;; ^^ g3: 0b10100000 bit 63 address diversity = true, bits 61..60 key = DA
+; CHECK-NEXT: 0x{{0*}}[[#ADDR+0x20]] 00000000 000000a0 00000000 000000a0
+;; ^^ g4: 0b10100000 bit 63 address diversity = true, bits 61..60 key = DA
+;; ^^ var_undef: 0b10100000 bit 63 address diversity = true, bits 61..60 key = DA
target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
target triple = "aarch64-unknown-linux-gnu"
>From 9d9462608fda2bf21a56524a7951a4b06711b737 Mon Sep 17 00:00:00 2001
From: Daniil Kovalev <dkovalev at accesssoftek.com>
Date: Tue, 17 Jun 2025 17:49:41 +0300
Subject: [PATCH 4/4] Delete unneeded comment
---
lld/test/ELF/lto/aarch64-pac-got-func.ll | 10 ----------
1 file changed, 10 deletions(-)
diff --git a/lld/test/ELF/lto/aarch64-pac-got-func.ll b/lld/test/ELF/lto/aarch64-pac-got-func.ll
index efa7c66ae5f2a..0baa3559a6f90 100644
--- a/lld/test/ELF/lto/aarch64-pac-got-func.ll
+++ b/lld/test/ELF/lto/aarch64-pac-got-func.ll
@@ -37,16 +37,6 @@ target triple = "aarch64-unknown-linux-gnu"
@g3 = external global ptr
@g4 = external global ptr
-; Minor codegen changes may influence function sizes and thus move subsequent
-; symbols. To prevent accidental changes to symbol addresses, request an
-; alignment that is larger than any expected function's size.
-;
-; Note that it is handy to have a trivial function like _start at the end of
-; the .text section, as most offsets of interest point to the dynamic section,
-; and one cannot easily control its alignment. On the other hand, the _start
-; function almost certainly contains a single ret instruction and is itself
-; aligned, making offsets of the subsequent sections predictable.
-
define void @func() align 1024 {
entry:
ret void
More information about the llvm-commits
mailing list