-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[lld][Hexagon] Fix R_HEX_B22_PCREL range checks #115925
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
Conversation
@llvm/pr-subscribers-lld-elf @llvm/pr-subscribers-backend-hexagon Author: Alexey Karyakin (quic-akaryaki) ChangesRange checks for R_HEX_B22_PCREL did not account for the fact that offset is measured in instructions, not bytes. Add a test for all range-checked relocations. Full diff: https://github.com/llvm/llvm-project/pull/115925.diff 3 Files Affected:
diff --git a/lld/ELF/Arch/Hexagon.cpp b/lld/ELF/Arch/Hexagon.cpp
index 54821c299bde9e..2cea751dbe402d 100644
--- a/lld/ELF/Arch/Hexagon.cpp
+++ b/lld/ELF/Arch/Hexagon.cpp
@@ -317,7 +317,7 @@ void Hexagon::relocate(uint8_t *loc, const Relocation &rel,
case R_HEX_B22_PCREL:
case R_HEX_GD_PLT_B22_PCREL:
case R_HEX_PLT_B22_PCREL:
- checkInt(loc, val, 22, rel);
+ checkInt(loc, val, 24, rel);
or32le(loc, applyMask(0x1ff3ffe, val >> 2));
break;
case R_HEX_B22_PCREL_X:
diff --git a/lld/test/ELF/hexagon-jump-error.s b/lld/test/ELF/hexagon-jump-error.s
index fec873827e573d..53860b5daf2b16 100644
--- a/lld/test/ELF/hexagon-jump-error.s
+++ b/lld/test/ELF/hexagon-jump-error.s
@@ -25,7 +25,7 @@ if (p0) jump #1f
.section b15, "ax"
1:
-# CHECK: relocation R_HEX_B22_PCREL out of range: 8388612 is not in [-2097152, 2097151]
+# CHECK: relocation R_HEX_B22_PCREL out of range: 8388612 is not in [-8388608, 8388607]
jump #1f
.space (1<<23)
.section b22, "ax"
diff --git a/lld/test/ELF/hexagon-jump.s b/lld/test/ELF/hexagon-jump.s
new file mode 100644
index 00000000000000..9c55958524f52a
--- /dev/null
+++ b/lld/test/ELF/hexagon-jump.s
@@ -0,0 +1,45 @@
+# REQUIRES: hexagon
+# RUN: llvm-mc -filetype=obj -triple=hexagon-unknown-elf %s -o %t.o
+
+## Make sure we got the right relocations.
+# RUN: llvm-readelf -r %t.o | FileCheck %s --check-prefix=REL
+# REL: R_HEX_B9_PCREL 00000000 b9
+# REL: R_HEX_B13_PCREL 00000000 b13
+# REL: R_HEX_B15_PCREL 00000000 b15
+# REL: R_HEX_B22_PCREL 00000000 b22
+
+# RUN: ld.lld %t.o -o %t.out --section-start=.text=0x1000000 \
+# RUN: --section-start=b9=0x1000400 --section-start=b13=0x1004000 \
+# RUN: --section-start=b15=0x1010000 --section-start=b22=0x1800000 \
+# RUN: --threads=1
+# RUN: llvm-objdump -d --no-show-raw-insn %t.out | FileCheck %s
+
+# CHECK-NOT: trampoline
+# CHECK: 01000000 <_start>:
+# CHECK: 1000000: { nop }
+# CHECK: 1000004: { r0 = #0x0 ; jump 0x1000400 }
+# CHECK: 1000008: { if (r0==#0) jump:t 0x1004000 }
+# CHECK: 100000c: { if (p0) jump:nt 0x1010000 }
+# CHECK: 1000010: { jump 0x1800000 }
+
+ .globl _start
+ .type _start, @function
+_start:
+## Make sure the first jump is within range
+nop
+{ r0 = #0; jump #b9 }
+if (r0==#0) jump:t #b13
+if (p0) jump #b15
+jump #b22
+
+.section b9, "ax"
+nop
+
+.section b13, "ax"
+nop
+
+.section b15, "ax"
+nop
+
+.section b22, "ax"
+nop
|
@llvm/pr-subscribers-lld Author: Alexey Karyakin (quic-akaryaki) ChangesRange checks for R_HEX_B22_PCREL did not account for the fact that offset is measured in instructions, not bytes. Add a test for all range-checked relocations. Full diff: https://github.com/llvm/llvm-project/pull/115925.diff 3 Files Affected:
diff --git a/lld/ELF/Arch/Hexagon.cpp b/lld/ELF/Arch/Hexagon.cpp
index 54821c299bde9e..2cea751dbe402d 100644
--- a/lld/ELF/Arch/Hexagon.cpp
+++ b/lld/ELF/Arch/Hexagon.cpp
@@ -317,7 +317,7 @@ void Hexagon::relocate(uint8_t *loc, const Relocation &rel,
case R_HEX_B22_PCREL:
case R_HEX_GD_PLT_B22_PCREL:
case R_HEX_PLT_B22_PCREL:
- checkInt(loc, val, 22, rel);
+ checkInt(loc, val, 24, rel);
or32le(loc, applyMask(0x1ff3ffe, val >> 2));
break;
case R_HEX_B22_PCREL_X:
diff --git a/lld/test/ELF/hexagon-jump-error.s b/lld/test/ELF/hexagon-jump-error.s
index fec873827e573d..53860b5daf2b16 100644
--- a/lld/test/ELF/hexagon-jump-error.s
+++ b/lld/test/ELF/hexagon-jump-error.s
@@ -25,7 +25,7 @@ if (p0) jump #1f
.section b15, "ax"
1:
-# CHECK: relocation R_HEX_B22_PCREL out of range: 8388612 is not in [-2097152, 2097151]
+# CHECK: relocation R_HEX_B22_PCREL out of range: 8388612 is not in [-8388608, 8388607]
jump #1f
.space (1<<23)
.section b22, "ax"
diff --git a/lld/test/ELF/hexagon-jump.s b/lld/test/ELF/hexagon-jump.s
new file mode 100644
index 00000000000000..9c55958524f52a
--- /dev/null
+++ b/lld/test/ELF/hexagon-jump.s
@@ -0,0 +1,45 @@
+# REQUIRES: hexagon
+# RUN: llvm-mc -filetype=obj -triple=hexagon-unknown-elf %s -o %t.o
+
+## Make sure we got the right relocations.
+# RUN: llvm-readelf -r %t.o | FileCheck %s --check-prefix=REL
+# REL: R_HEX_B9_PCREL 00000000 b9
+# REL: R_HEX_B13_PCREL 00000000 b13
+# REL: R_HEX_B15_PCREL 00000000 b15
+# REL: R_HEX_B22_PCREL 00000000 b22
+
+# RUN: ld.lld %t.o -o %t.out --section-start=.text=0x1000000 \
+# RUN: --section-start=b9=0x1000400 --section-start=b13=0x1004000 \
+# RUN: --section-start=b15=0x1010000 --section-start=b22=0x1800000 \
+# RUN: --threads=1
+# RUN: llvm-objdump -d --no-show-raw-insn %t.out | FileCheck %s
+
+# CHECK-NOT: trampoline
+# CHECK: 01000000 <_start>:
+# CHECK: 1000000: { nop }
+# CHECK: 1000004: { r0 = #0x0 ; jump 0x1000400 }
+# CHECK: 1000008: { if (r0==#0) jump:t 0x1004000 }
+# CHECK: 100000c: { if (p0) jump:nt 0x1010000 }
+# CHECK: 1000010: { jump 0x1800000 }
+
+ .globl _start
+ .type _start, @function
+_start:
+## Make sure the first jump is within range
+nop
+{ r0 = #0; jump #b9 }
+if (r0==#0) jump:t #b13
+if (p0) jump #b15
+jump #b22
+
+.section b9, "ax"
+nop
+
+.section b13, "ax"
+nop
+
+.section b15, "ax"
+nop
+
+.section b22, "ax"
+nop
|
ec675c9
to
b8f126e
Compare
Range checks for R_HEX_B22_PCREL did not account for the fact that offset is measured in instructions, not bytes. Add a test for all range-checked relocations.
b8f126e
to
3b2f81c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should not add a new test lld/test/ELF/hexagon-jump.s here. Just reuse the existing positive test than tests B22_PCREL.
What is the drawback of adding a test file for a specific purpose? |
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/30/builds/10578 Here is the relevant piece of the build log for the reference
|
Range checks for R_HEX_B22_PCREL did not account for the fact that offset is measured in instructions, not bytes. Add a test for all range-checked relocations.
Range checks for R_HEX_B22_PCREL did not account for the fact that offset is measured in instructions, not bytes. Add a test for all range-checked relocations.
Range checks for R_HEX_B22_PCREL did not account for the fact that offset is measured in instructions, not bytes.
Add a test for all range-checked relocations.