[llvm] [Test][JitLink] Correctly generate the R_X86_64_PC8 relocation. (PR #109283)

Xing Guo via llvm-commits llvm-commits at lists.llvm.org
Sat Sep 21 22:27:38 PDT 2024


https://github.com/higuoxing updated https://github.com/llvm/llvm-project/pull/109283

>From 953dbfafcaa65747f2cf095840d2a8ebff4453e6 Mon Sep 17 00:00:00 2001
From: Xing Guo <higuoxing at gmail.com>
Date: Sun, 22 Sep 2024 13:24:50 +0800
Subject: [PATCH] [JITLink] Correctly generate the R_X86_64_PC8 relocation.

Previously, ELF_R_X86_64_PC8.s doesn't produce the R_X86_64_PC8
relocation. This patch helps fix it by emitting a byte `main - .` to the
.rodata section.

Before:

```
llvm-mc -triple=x86_64-unknown-linux -position-independent -filetype=obj -o - ELF_R_X86_64_PC8.s | llvm-readobj -r -

File: <stdin>
Format: elf64-x86-64
Arch: x86_64
AddressSize: 64bit
LoadName: <Not found>
Relocations [
]
```

After:

```
llvm-mc -triple=x86_64-unknown-linux -position-independent -filetype=obj -o - ELF_R_X86_64_PC8.s | llvm-readobj -r -

File: <stdin>
Format: elf64-x86-64
Arch: x86_64
AddressSize: 64bit
LoadName: <Not found>
Relocations [
  Section (4) .rela.rodata {
    0x0 R_X86_64_PC8 main 0x0
  }
]
```
---
 .../test/ExecutionEngine/JITLink/x86-64/ELF_R_X86_64_PC8.s | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/llvm/test/ExecutionEngine/JITLink/x86-64/ELF_R_X86_64_PC8.s b/llvm/test/ExecutionEngine/JITLink/x86-64/ELF_R_X86_64_PC8.s
index cac6dd9c612b6f..46b851a836abb8 100644
--- a/llvm/test/ExecutionEngine/JITLink/x86-64/ELF_R_X86_64_PC8.s
+++ b/llvm/test/ExecutionEngine/JITLink/x86-64/ELF_R_X86_64_PC8.s
@@ -12,8 +12,5 @@ main:
 	retq
 	.size	main, .-main
 
-	.type	P, at object
-	.globl	P
-P:
-	.byte main-. # Generate R_X86_64_PC8 relocation.
-  .size P, .-P
+	.rodata
+	.byte	main-. # Generate R_X86_64_PC8 relocation.



More information about the llvm-commits mailing list