Add R_PPC_ADDR16_HI relocation support
authorRui Ueyama <ruiu@google.com>
Sun, 22 Oct 2017 23:33:49 +0000 (23:33 +0000)
committerRui Ueyama <ruiu@google.com>
Sun, 22 Oct 2017 23:33:49 +0000 (23:33 +0000)
The support of R_PPC_ADDR16_HI improves ld compatibility and makes
things on par with RuntimeDyldELF that already implements this
relocation.

Patch by vit9696.

llvm-svn: 316306

lld/ELF/Arch/PPC.cpp
lld/test/ELF/ppc-relocs.s

index cf170fc..b505788 100644 (file)
@@ -44,6 +44,9 @@ void PPC::relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const {
   case R_PPC_ADDR16_HA:
     write16be(Loc, (Val + 0x8000) >> 16);
     break;
+  case R_PPC_ADDR16_HI:
+    write16be(Loc, Val >> 16);
+    break;
   case R_PPC_ADDR16_LO:
     write16be(Loc, Val);
     break;
index 78542dd..1160477 100644 (file)
@@ -17,6 +17,20 @@ msg:
 # CHECK: msg:
 # CHECK:    11004:       66 6f 6f 00     oris 15, 19, 28416
 
+.section .R_PPC_ADDR16_HI,"ax",@progbits
+.globl _starti
+_starti:
+  lis 4,msgi@h
+msgi:
+  .string "foo"
+  leni = . - msgi
+
+# CHECK: Disassembly of section .R_PPC_ADDR16_HI:
+# CHECK: _starti:
+# CHECK:    11008:       3c 80 00 01     lis 4, 1
+# CHECK: msgi:
+# CHECK:    1100c:       66 6f 6f 00     oris 15, 19, 28416
+
 .section .R_PPC_ADDR16_LO,"ax",@progbits
   addi 4, 4, msg@l
 mystr:
@@ -25,9 +39,9 @@ mystr:
 
 # CHECK: Disassembly of section .R_PPC_ADDR16_LO:
 # CHECK: .R_PPC_ADDR16_LO:
-# CHECK:    11008:       38 84 10 04     addi 4, 4, 4100
+# CHECK:    11010:       38 84 10 04     addi 4, 4, 4100
 # CHECK: mystr:
-# CHECK:    1100c:       62 6c 61 68     ori 12, 19, 24936
+# CHECK:    11014:       62 6c 61 68     ori 12, 19, 24936
 
 .align  2
 .section .R_PPC_REL24,"ax",@progbits
@@ -39,7 +53,7 @@ mystr:
 
 # CHECK: Disassembly of section .R_PPC_REL24:
 # CHECK: .FR_PPC_REL24:
-# CHECK:    11014:       48 00 00 04     b .+4
+# CHECK:    1101c:       48 00 00 04     b .+4
 
 .section .R_PPC_REL32,"ax",@progbits
 .globl .FR_PPC_REL32
@@ -50,7 +64,7 @@ mystr:
 
 # CHECK: Disassembly of section .R_PPC_REL32:
 # CHECK: .FR_PPC_REL32:
-# CHECK:    11018:       00 00 00 04
+# CHECK:    11020:       00 00 00 04
 
 .section .R_PPC_ADDR32,"ax",@progbits
 .globl .FR_PPC_ADDR32
@@ -61,4 +75,4 @@ mystr:
 
 # CHECK: Disassembly of section .R_PPC_ADDR32:
 # CHECK: .FR_PPC_ADDR32:
-# CHECK:    1101c:       00 01 10 20
+# CHECK:    11024:       00 01 10 28