Skip to content

[lld][test][PAC] Do not rely on concrete offsets in LTO tests #143358

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

Merged
merged 5 commits into from
Jun 17, 2025

Conversation

kovdan01
Copy link
Contributor

@kovdan01 kovdan01 commented Jun 9, 2025

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.

@llvmbot
Copy link
Member

llvmbot commented Jun 9, 2025

@llvm/pr-subscribers-lld

@llvm/pr-subscribers-lld-elf

Author: Daniil Kovalev (kovdan01)

Changes

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.


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

1 Files Affected:

  • (modified) lld/test/ELF/lto/aarch64-pac-got-func.ll (+21-21)
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"

When changing codegen (e.g. in llvm#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.
@kovdan01 kovdan01 force-pushed the do-not-rely-on-offsets-in-lto-tests branch from 18e28a0 to 4d322b5 Compare June 9, 2025 09:24
@kovdan01 kovdan01 moved this to In Progress in Pointer Authentication Tasks Jun 9, 2025
@atrosinenko
Copy link
Contributor

@kovdan01 As discussed, I tried specifying large symbol alignments and this seems to look cleaner. I pushed my proposal here, please feel free to revert if not needed.

@kovdan01
Copy link
Contributor Author

kovdan01 commented Jun 9, 2025

@kovdan01 As discussed, I tried specifying large symbol alignments and this seems to look cleaner. I pushed my proposal here, please feel free to revert if not needed.

@atrosinenko Thanks! I don't mind using this approach if noone else has objections

Copy link
Collaborator

@asl asl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a neat trick to me

; 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: 00000000000210b8 0000000100000412 R_AARCH64_AUTH_GLOB_DAT 0000000000000000 func_undef + 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can use

[[#%x, ADDR:]]
{{0*}}[[#ADDR+0x8]]

so that the next time we change addresses, we only need to change one line.

Copy link
Contributor Author

@kovdan01 kovdan01 Jun 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Applied your suggestion in 5dbfbff

@kovdan01 kovdan01 force-pushed the do-not-rely-on-offsets-in-lto-tests branch from 9fe76a8 to 5dbfbff Compare June 17, 2025 08:12
Comment on lines 44 to 48
; 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.
Copy link
Contributor

@atrosinenko atrosinenko Jun 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With your latest commit, this paragraph is probably not relevant anymore as the address of the dynamic section is not hardcoded anymore.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deleted, thanks, see 9d94626

@kovdan01 kovdan01 merged commit 72fb8ae into llvm:main Jun 17, 2025
7 checks passed
@github-project-automation github-project-automation bot moved this from In Progress to Done in Pointer Authentication Tasks Jun 17, 2025
ajaden-codes pushed a commit to Jaddyen/llvm-project that referenced this pull request Jun 17, 2025
…43358)

When changing codegen (e.g. in llvm#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.

---------

Co-authored-by: Anatoly Trosinenko <atrosinenko@accesssoftek.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

5 participants