[PATCH] D15809: [ELF/AARCH64] - Implemented R_AARCH64_CONDBR19 relocation.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 29 07:45:47 PST 2015


grimar created this revision.
grimar added reviewers: ruiu, rafael.
grimar added subscribers: llvm-commits, grimar.
Herald added subscribers: rengolin, aemerson.

R_AARCH64_CONDBR19 is calculated as S+A-P,
Set the immediate field of a conditional branch instruction to bits [20:2] of X; check -2^20 ≤ X< 2^20.

Afaik there is no document for AARCH64 instruction encoding from official for unknown reason, so 
I used gold source code and next link as a reference for implementation: http://kitoslab-eng.blogspot.ru/2012/10/armv8-aarch64-instruction-encoding.html. From which is clear that immediate field of a conditional branch instruction is 5 bits off. That is prooved by output which is is equal to gold/bfd now.

http://reviews.llvm.org/D15809

Files:
  ELF/Target.cpp
  test/ELF/Inputs/aarch64-condb-reloc.s
  test/ELF/aarch64-condb-reloc.s

Index: test/ELF/aarch64-condb-reloc.s
===================================================================
--- test/ELF/aarch64-condb-reloc.s
+++ test/ELF/aarch64-condb-reloc.s
@@ -0,0 +1,32 @@
+# RUN: llvm-mc -filetype=obj -triple=aarch64-unknown-freebsd %p/Inputs/aarch64-condb-reloc.s -o %t1
+# RUN: llvm-mc -filetype=obj -triple=aarch64-unknown-freebsd %s -o %t2
+# RUN: ld.lld %t1 %t2 -o %t
+# RUN: llvm-objdump -d %t | FileCheck %s
+# REQUIRES: aarch64
+
+# 0x11024 - 36 = 0x11000
+# 0x11028 - 24 = 0x11010
+# 0x1102c - 16 = 0x1101c
+# CHECK:      Disassembly of section .text:
+# CHECK-NEXT: _foo:
+# CHECK-NEXT:    11000: {{.*}} nop
+# CHECK-NEXT:    11004: {{.*}} nop
+# CHECK-NEXT:    11008: {{.*}} nop
+# CHECK-NEXT:    1100c: {{.*}} nop
+# CHECK:      _bar:
+# CHECK-NEXT:    11010: {{.*}} nop
+# CHECK-NEXT:    11014: {{.*}} nop
+# CHECK-NEXT:    11018: {{.*}} nop
+# CHECK:      _dah:
+# CHECK-NEXT:    1101c: {{.*}} nop
+# CHECK-NEXT:    11020: {{.*}} nop
+# CHECK:      _start:
+# CHECK-NEXT:    11024: {{.*}} b.eq #-36
+# CHECK-NEXT:    11028: {{.*}} b.eq #-24
+# CHECK-NEXT:    1102c: {{.*}} b.eq #-16
+
+.globl _start
+_start:
+ b.eq _foo
+ b.eq _bar
+ b.eq _dah
Index: test/ELF/Inputs/aarch64-condb-reloc.s
===================================================================
--- test/ELF/Inputs/aarch64-condb-reloc.s
+++ test/ELF/Inputs/aarch64-condb-reloc.s
@@ -0,0 +1,17 @@
+.globl _foo
+_foo:
+ nop
+ nop
+ nop
+ nop
+
+.globl _bar
+_bar:
+ nop
+ nop
+ nop
+
+.globl _dah
+_dah:
+ nop
+ nop
Index: ELF/Target.cpp
===================================================================
--- ELF/Target.cpp
+++ ELF/Target.cpp
@@ -1286,6 +1286,12 @@
     or32le(Loc, (X & 0x0FFFFFFC) >> 2);
     break;
   }
+  case R_AARCH64_CONDBR19: {
+    uint64_t X = SA - P;
+    checkInt<21>(X, Type);
+    or32le(Loc, (X & 0x1FFFFC) << 3);
+    break;
+  }
   case R_AARCH64_LD64_GOT_LO12_NC:
     checkAlignment<8>(SA, Type);
     or32le(Loc, (SA & 0xFF8) << 7);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D15809.43736.patch
Type: text/x-patch
Size: 1969 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151229/6ec58cb1/attachment.bin>


More information about the llvm-commits mailing list