From 8faafa4fb1452b45f7b5bcf77f4e44a6846f6f70 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Sun, 22 Oct 2017 23:33:49 +0000 Subject: [PATCH] Add R_PPC_ADDR16_HI relocation support 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 | 3 +++ lld/test/ELF/ppc-relocs.s | 24 +++++++++++++++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/lld/ELF/Arch/PPC.cpp b/lld/ELF/Arch/PPC.cpp index cf170fcb8c26..b505788aca95 100644 --- a/lld/ELF/Arch/PPC.cpp +++ b/lld/ELF/Arch/PPC.cpp @@ -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; diff --git a/lld/test/ELF/ppc-relocs.s b/lld/test/ELF/ppc-relocs.s index 78542dd64a4c..1160477df278 100644 --- a/lld/test/ELF/ppc-relocs.s +++ b/lld/test/ELF/ppc-relocs.s @@ -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 -- GitLab