Date: Mon, 23 Sep 2019 14:14:43 +0000 (UTC) From: Mark Johnston <markj@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r352623 - in head/sys: amd64/amd64 kern Message-ID: <201909231414.x8NEEh9e040728@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: markj Date: Mon Sep 23 14:14:43 2019 New Revision: 352623 URL: https://svnweb.freebsd.org/changeset/base/352623 Log: Use elf_relocaddr() when handling R_X86_64_RELATIVE relocations. This is required for DPCPU and VNET data variable definitions to work when KLDs are linked as DSOs. R_X86_64_RELATIVE relocations should not appear in object files, so assert this in elf_relocaddr(). Reviewed by: kib MFC after: 1 month Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D21755 Modified: head/sys/amd64/amd64/elf_machdep.c head/sys/kern/link_elf.c Modified: head/sys/amd64/amd64/elf_machdep.c ============================================================================== --- head/sys/amd64/amd64/elf_machdep.c Mon Sep 23 14:11:59 2019 (r352622) +++ head/sys/amd64/amd64/elf_machdep.c Mon Sep 23 14:14:43 2019 (r352623) @@ -267,7 +267,6 @@ elf_reloc_internal(linker_file_t lf, Elf_Addr relocbas */ printf("kldload: unexpected R_COPY relocation\n"); return (-1); - break; case R_X86_64_GLOB_DAT: /* S */ case R_X86_64_JMP_SLOT: /* XXX need addend + offset */ @@ -279,7 +278,7 @@ elf_reloc_internal(linker_file_t lf, Elf_Addr relocbas break; case R_X86_64_RELATIVE: /* B + A */ - addr = relocbase + addend; + addr = elf_relocaddr(lf, relocbase + addend); val = addr; if (*where != val) *where = val; Modified: head/sys/kern/link_elf.c ============================================================================== --- head/sys/kern/link_elf.c Mon Sep 23 14:11:59 2019 (r352622) +++ head/sys/kern/link_elf.c Mon Sep 23 14:14:43 2019 (r352623) @@ -1162,6 +1162,9 @@ elf_relocaddr(linker_file_t lf, Elf_Addr x) { elf_file_t ef; + KASSERT(lf->ops->cls == (kobj_class_t)&link_elf_class, + ("elf_relocaddr: unexpected linker file %p", lf)); + ef = (elf_file_t)lf; if (x >= ef->pcpu_start && x < ef->pcpu_stop) return ((x - ef->pcpu_start) + ef->pcpu_base);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201909231414.x8NEEh9e040728>