[lld] r344747 - [PPC64] Fix offset checks on rel24 call relocations.

Sean Fertile via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 18 08:43:41 PDT 2018


Author: sfertile
Date: Thu Oct 18 08:43:41 2018
New Revision: 344747

URL: http://llvm.org/viewvc/llvm-project?rev=344747&view=rev
Log:
[PPC64] Fix offset checks on rel24 call relocations.

Adjusted the range check on a call instruction from 24 bits signed to
26 bits signed. While the instruction only encodes 24 bits, the target is
assumed to be 4 byte aligned, and the value that is encoded in the instruction
gets shifted left by 2 to form the offset. Also added a check that the offset is
indeed at least 4 byte aligned.

Differential Revision: https://reviews.llvm.org/D53401

Added:
    lld/trunk/test/ELF/ppc64-call-reach.s
Modified:
    lld/trunk/ELF/Arch/PPC64.cpp

Modified: lld/trunk/ELF/Arch/PPC64.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Arch/PPC64.cpp?rev=344747&r1=344746&r2=344747&view=diff
==============================================================================
--- lld/trunk/ELF/Arch/PPC64.cpp (original)
+++ lld/trunk/ELF/Arch/PPC64.cpp Thu Oct 18 08:43:41 2018
@@ -697,7 +697,8 @@ void PPC64::relocateOne(uint8_t *Loc, Re
     break;
   case R_PPC64_REL24: {
     uint32_t Mask = 0x03FFFFFC;
-    checkInt(Loc, Val, 24, Type);
+    checkInt(Loc, Val, 26, Type);
+    checkAlignment(Loc, Val, 4, Type);
     write32(Loc, (read32(Loc) & ~Mask) | (Val & Mask));
     break;
   }

Added: lld/trunk/test/ELF/ppc64-call-reach.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/ppc64-call-reach.s?rev=344747&view=auto
==============================================================================
--- lld/trunk/test/ELF/ppc64-call-reach.s (added)
+++ lld/trunk/test/ELF/ppc64-call-reach.s Thu Oct 18 08:43:41 2018
@@ -0,0 +1,66 @@
+# REQUIRES: ppc
+
+# RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %s -o %t.o
+# RUN: ld.lld --defsym callee=0x12010010 --defsym tail_callee=0x12010020 \
+# RUN: %t.o -o %t
+# RUN: llvm-objdump -d %t | FileCheck %s
+# RUN: ld.lld --defsym callee=0x12010010 --defsym tail_callee=0x12010020 \
+# RUN: %t.o -o %t
+# RUN: llvm-objdump -d %t | FileCheck %s
+# RUN: ld.lld --defsym callee=0xE010014 --defsym tail_callee=0xE010024 \
+# RUN: %t.o -o %t
+# RUN: llvm-objdump -d %t | FileCheck --check-prefix=NEGOFFSET  %s
+# RUN: not ld.lld --defsym callee=0x12010018 --defsym tail_callee=0x12010028 \
+# RUN: %t.o -o %t 2>&1 | FileCheck --check-prefix=OVERFLOW %s
+# RUN: not ld.lld --defsym callee=0x1001002D --defsym tail_callee=0x1001002F \
+# RUN: %t.o -o %t 2>&1 | FileCheck --check-prefix=MISSALIGNED %s
+
+# RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %s -o %t.o
+# RUN: ld.lld --defsym callee=0x12010010 --defsym tail_callee=0x12010020 \
+# RUN: %t.o -o %t
+# RUN: llvm-objdump -d %t | FileCheck %s
+# RUN: ld.lld --defsym callee=0x12010010 --defsym tail_callee=0x12010020 \
+# RUN: %t.o -o %t
+# RUN: llvm-objdump -d %t | FileCheck %s
+# RUN: ld.lld --defsym callee=0xE010014 --defsym tail_callee=0xE010024 \
+# RUN: %t.o -o %t
+# RUN: llvm-objdump -d %t | FileCheck --check-prefix=NEGOFFSET  %s
+# RUN: not ld.lld --defsym callee=0x12010018 --defsym tail_callee=0x12010028 \
+# RUN: %t.o -o %t 2>&1 | FileCheck --check-prefix=OVERFLOW %s
+# RUN: not ld.lld --defsym callee=0x1001002D --defsym tail_callee=0x1001002F \
+# RUN: %t.o -o %t 2>&1 | FileCheck --check-prefix=MISSALIGNED %s
+
+# OVERFLOW: ld.lld: error: {{.*}}.o:(.text+0x14): relocation R_PPC64_REL24 out of range: 33554436 is not in [-33554432, 33554431]
+# OVERFLOW: ld.lld: error: {{.*}}.o:(.text+0x24): relocation R_PPC64_REL24 out of range: 33554436 is not in [-33554432, 33554431]
+
+# MISSALIGNED: ld.lld: error: {{.*}}.o:(.text+0x14): improper alignment for relocation R_PPC64_REL24: 0x19 is not aligned to 4 bytes
+# MISSALIGNED: ld.lld: error: {{.*}}.o:(.text+0x24): improper alignment for relocation R_PPC64_REL24: 0xB is not aligned to 4 bytes
+
+        .global test
+        .p2align        4
+        .type   test, at function
+test:
+.Lgep:
+        addis 2, 12, .TOC.-.Lgep at ha
+        addi  2, 2,  .TOC.-.Lgep at l
+.Llep:
+        .localentry test, .Llep-.Lgep
+        mflr 0
+        std 0, 16(1)
+        stdu 1, 32(1)
+        bl callee
+        addi 1, 1, 32
+        ld 0, 16(1)
+        mtlr 0
+        b tail_callee
+
+# Check that we are branching to the definitions, and not range-extending
+# thunks.
+# CHECK-LABEL: test
+# CHECK:  10010014: {{.*}}  bl .+33554428
+# CHECK:  10010024: {{.*}}  b  .+33554428
+
+# NEGOFFSET-LABEL: test
+# NEGOFFSET:  10010014: {{.*}}  bl .+33554432
+# NEGOFFSET:  10010024: {{.*}}  b  .+33554432
+




More information about the llvm-commits mailing list