[PATCH] D159513: [Bolt] fix a relocation bug for R_AARCH64_CALL26
Sinan Lin via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 14 02:13:11 PDT 2023
sinan created this revision.
sinan added reviewers: Kepontry, rafauler, yota9, Amir.
Herald added subscribers: treapster, ayermolo, kristof.beyls.
Herald added a reviewer: maksfb.
Herald added a project: All.
sinan requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
If the R_AARCH64_CALL26 against a symbol that has a lower address, then `encodeValueAArch64` will return a wrong value.
In the included test case, the expected output of `encodeValueAArch64` is 97ffffff, but it returns `3fffffffffffffff`, and then an invalid instruction is encoded.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D159513
Files:
bolt/lib/Core/Relocation.cpp
bolt/test/AArch64/reloc-call26-overflow.s
Index: bolt/test/AArch64/reloc-call26-overflow.s
===================================================================
--- /dev/null
+++ bolt/test/AArch64/reloc-call26-overflow.s
@@ -0,0 +1,25 @@
+# REQUIRES: system-linux
+
+# RUN: llvm-mc -filetype=obj -triple aarch64-unknown-unknown \
+# RUN: %s -o %t.o
+# RUN: %clang %cflags %t.o -o %t.exe -Wl,-q
+# RUN: llvm-bolt %t.exe -o %t.bolt --funcs=func1 --force-patch
+# RUN: llvm-objdump -d --disassemble-symbols='_start' %t.bolt | \
+# RUN: FileCheck %s
+
+# CHECK: {{.*}} bl {{.*}} <func1>
+
+ .text
+ .align 4
+ .global func1
+ .type func1, %function
+func1:
+ ret
+ .size func1, .-func1
+ .global _start
+ .type _start, %function
+_start:
+ bl func1
+ mov w8, #93
+ svc #0
+ .size _start, .-_start
Index: bolt/lib/Core/Relocation.cpp
===================================================================
--- bolt/lib/Core/Relocation.cpp
+++ bolt/lib/Core/Relocation.cpp
@@ -352,7 +352,7 @@
assert(isInt<28>(Value) && "only PC +/- 128MB is allowed for direct call");
// Immediate goes in bits 25:0 of BL.
// OP 1001_01 goes in bits 31:26 of BL.
- Value = (Value >> 2) | 0x94000000ULL;
+ Value = ((Value >> 2) & 0x3ffffff) | 0x94000000ULL;
break;
}
return Value;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D159513.556751.patch
Type: text/x-patch
Size: 1266 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230914/f8c6a37c/attachment.bin>
More information about the llvm-commits
mailing list