From 8b4f33c5f6df623fcd09edc6aaa64510ba6f7c53 Mon Sep 17 00:00:00 2001 From: Marcel Moolenaar Date: Sat, 26 Jul 2014 17:07:32 +0000 Subject: [PATCH] Fix relocations related to dpcpu and vnet sets. The address is rebased to point to the allocated memory, but for architectures that have non-zero relocation addends, the address comparison happens on the "unfinalized" address. After the addend is taken into account, call elf_relocaddr() to make sure we rebase properly. --- sys/powerpc/powerpc/elf32_machdep.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/sys/powerpc/powerpc/elf32_machdep.c b/sys/powerpc/powerpc/elf32_machdep.c index dbe58df1573..2c62df2b5da 100644 --- a/sys/powerpc/powerpc/elf32_machdep.c +++ b/sys/powerpc/powerpc/elf32_machdep.c @@ -190,8 +190,7 @@ elf_reloc_internal(linker_file_t lf, Elf_Addr relocbase, const void *data, addr = lookup(lf, symidx, 1); if (addr == 0) return -1; - addr += addend; - *where = addr; + *where = elf_relocaddr(lf, addr + addend); break; case R_PPC_ADDR16_LO: /* #lo(S) */ @@ -204,9 +203,8 @@ elf_reloc_internal(linker_file_t lf, Elf_Addr relocbase, const void *data, * are relative to relocbase. Detect this condition. */ if (addr > relocbase && addr <= (relocbase + addend)) - addr = relocbase + addend; - else - addr += addend; + addr = relocbase; + addr = elf_relocaddr(lf, addr + addend); *hwhere = addr & 0xffff; break; @@ -220,9 +218,8 @@ elf_reloc_internal(linker_file_t lf, Elf_Addr relocbase, const void *data, * are relative to relocbase. Detect this condition. */ if (addr > relocbase && addr <= (relocbase + addend)) - addr = relocbase + addend; - else - addr += addend; + addr = relocbase; + addr = elf_relocaddr(lf, addr + addend); *hwhere = ((addr >> 16) + ((addr & 0x8000) ? 1 : 0)) & 0xffff; break;