From: Rui Ueyama Date: Tue, 1 Nov 2016 18:30:26 +0000 (+0000) Subject: Implement R_PPC_REL24 and R_PPC_REL32 relocations. X-Git-Tag: llvmorg-4.0.0-rc1~5726 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7fd5c84f46985583ecdfd0a11de712b97ce242d7;p=platform%2Fupstream%2Fllvm.git Implement R_PPC_REL24 and R_PPC_REL32 relocations. This enables LLD to relocate PC-relative R_PPC_REL32 and R_PPC_REL24 types (as used in bl instructions). Patch from Jack Andersen! llvm-svn: 285719 --- diff --git a/lld/ELF/Target.cpp b/lld/ELF/Target.cpp index c3a3c29..e4de88f 100644 --- a/lld/ELF/Target.cpp +++ b/lld/ELF/Target.cpp @@ -47,6 +47,7 @@ namespace elf { TargetInfo *Target; static void or32le(uint8_t *P, int32_t V) { write32le(P, read32le(P) | V); } +static void or32be(uint8_t *P, int32_t V) { write32be(P, read32be(P) | V); } StringRef getRelName(uint32_t Type) { return getELFRelocationTypeName(Config->EMachine, Type); @@ -965,13 +966,25 @@ void PPCTargetInfo::relocateOne(uint8_t *Loc, uint32_t Type, case R_PPC_ADDR16_LO: write16be(Loc, applyPPCLo(Val)); break; + case R_PPC_REL24: + or32be(Loc, Val & 0x3FFFFFC); + break; + case R_PPC_REL32: + write32be(Loc, Val); + break; default: fatal("unrecognized reloc " + Twine(Type)); } } RelExpr PPCTargetInfo::getRelExpr(uint32_t Type, const SymbolBody &S) const { - return R_ABS; + switch (Type) { + case R_PPC_REL24: + case R_PPC_REL32: + return R_PC; + default: + return R_ABS; + } } PPC64TargetInfo::PPC64TargetInfo() { diff --git a/lld/test/ELF/ppc-relocs.s b/lld/test/ELF/ppc-relocs.s index a70cac1..95c5043 100644 --- a/lld/test/ELF/ppc-relocs.s +++ b/lld/test/ELF/ppc-relocs.s @@ -28,3 +28,26 @@ mystr: # CHECK: 11008: 38 84 10 04 addi 4, 4, 4100 # CHECK: mystr: # CHECK: 1100c: 62 6c 61 68 ori 12, 19, 24936 + +.align 2 +.section .R_PPC_REL24,"ax",@progbits +.globl .FR_PPC_REL24 +.FR_PPC_REL24: + b .Lfoox +.section .R_PPC_REL24_2,"ax",@progbits +.Lfoox: + +# CHECK: Disassembly of section .R_PPC_REL24: +# CHECK: .FR_PPC_REL24: +# CHECK: 11014: 48 00 00 04 b .+4 + +.section .R_PPC_REL32,"ax",@progbits +.globl .FR_PPC_REL32 +.FR_PPC_REL32: + .long .Lfoox3 - . +.section .R_PPC_REL32_2,"ax",@progbits +.Lfoox3: + +# CHECK: Disassembly of section .R_PPC_REL32: +# CHECK: .FR_PPC_REL32: +# CHECK: 11018: 00 00 00 04