From owner-svn-src-stable@freebsd.org Tue Aug 14 14:01:13 2018 Return-Path: Delivered-To: svn-src-stable@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id C65E2107907D; Tue, 14 Aug 2018 14:01:13 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 79EE7704E4; Tue, 14 Aug 2018 14:01:13 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 5C88C1C752; Tue, 14 Aug 2018 14:01:13 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w7EE1DW8004305; Tue, 14 Aug 2018 14:01:13 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w7EE1D1P004300; Tue, 14 Aug 2018 14:01:13 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201808141401.w7EE1D1P004300@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Tue, 14 Aug 2018 14:01:13 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r337753 - stable/11/sys/kern X-SVN-Group: stable-11 X-SVN-Commit-Author: kib X-SVN-Commit-Paths: stable/11/sys/kern X-SVN-Commit-Revision: 337753 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 14 Aug 2018 14:01:14 -0000 Author: kib Date: Tue Aug 14 14:01:12 2018 New Revision: 337753 URL: https://svnweb.freebsd.org/changeset/base/337753 Log: MFC r337430, r337436: Add missed handling of local relocs against ifunc target in the obj modules. Modified: stable/11/sys/kern/link_elf_obj.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/kern/link_elf_obj.c ============================================================================== --- stable/11/sys/kern/link_elf_obj.c Tue Aug 14 13:56:49 2018 (r337752) +++ stable/11/sys/kern/link_elf_obj.c Tue Aug 14 14:01:12 2018 (r337753) @@ -140,7 +140,7 @@ static int link_elf_each_function_name(linker_file_t, static int link_elf_each_function_nameval(linker_file_t, linker_function_nameval_callback_t, void *); -static int link_elf_reloc_local(linker_file_t); +static int link_elf_reloc_local(linker_file_t, bool); static long link_elf_symtab_get(linker_file_t, const Elf_Sym **); static long link_elf_strtab_get(linker_file_t, caddr_t *); @@ -439,10 +439,9 @@ link_elf_link_preload(linker_class_t cls, const char * } /* Local intra-module relocations */ - error = link_elf_reloc_local(lf); + error = link_elf_reloc_local(lf, false); if (error != 0) goto out; - *result = lf; return (0); @@ -477,13 +476,20 @@ link_elf_link_preload_finish(linker_file_t lf) ef = (elf_file_t)lf; error = relocate_file(ef); if (error) - return error; + return (error); /* Notify MD code that a module is being loaded. */ error = elf_cpu_load_file(lf); if (error) return (error); +#if defined(__i386__) || defined(__amd64__) + /* Now ifuncs. */ + error = link_elf_reloc_local(lf, true); + if (error != 0) + return (error); +#endif + /* Invoke .ctors */ link_elf_invoke_ctors(lf->ctors_addr, lf->ctors_size); return (0); @@ -962,7 +968,7 @@ link_elf_load_file(linker_class_t cls, const char *fil } /* Local intra-module relocations */ - error = link_elf_reloc_local(lf); + error = link_elf_reloc_local(lf, false); if (error != 0) goto out; @@ -983,6 +989,13 @@ link_elf_load_file(linker_class_t cls, const char *fil if (error) goto out; +#if defined(__i386__) || defined(__amd64__) + /* Now ifuncs. */ + error = link_elf_reloc_local(lf, true); + if (error != 0) + goto out; +#endif + /* Invoke .ctors */ link_elf_invoke_ctors(lf->ctors_addr, lf->ctors_size); @@ -1366,7 +1379,10 @@ elf_obj_lookup(linker_file_t lf, Elf_Size symidx, int /* Quick answer if there is a definition included. */ if (sym->st_shndx != SHN_UNDEF) { - *res = sym->st_value; + res1 = (Elf_Addr)sym->st_value; + if (ELF_ST_TYPE(sym->st_info) == STT_GNU_IFUNC) + res1 = ((Elf_Addr (*)(void))res1)(); + *res = res1; return (0); } @@ -1462,7 +1478,7 @@ link_elf_fix_link_set(elf_file_t ef) } static int -link_elf_reloc_local(linker_file_t lf) +link_elf_reloc_local(linker_file_t lf, bool ifuncs) { elf_file_t ef = (elf_file_t)lf; const Elf_Rel *rellim; @@ -1497,8 +1513,15 @@ link_elf_reloc_local(linker_file_t lf) /* Only do local relocs */ if (ELF_ST_BIND(sym->st_info) != STB_LOCAL) continue; - elf_reloc_local(lf, base, rel, ELF_RELOC_REL, - elf_obj_lookup); + if ((ELF_ST_TYPE(sym->st_info) == STT_GNU_IFUNC) == + ifuncs) + elf_reloc_local(lf, base, rel, ELF_RELOC_REL, + elf_obj_lookup); +#if defined(__i386__) || defined(__amd64__) + else if (ifuncs) + elf_reloc_ifunc(lf, base, rel, ELF_RELOC_REL, + elf_obj_lookup); +#endif } } @@ -1523,8 +1546,15 @@ link_elf_reloc_local(linker_file_t lf) /* Only do local relocs */ if (ELF_ST_BIND(sym->st_info) != STB_LOCAL) continue; - elf_reloc_local(lf, base, rela, ELF_RELOC_RELA, - elf_obj_lookup); + if ((ELF_ST_TYPE(sym->st_info) == STT_GNU_IFUNC) == + ifuncs) + elf_reloc_local(lf, base, rela, ELF_RELOC_RELA, + elf_obj_lookup); +#if defined(__i386__) || defined(__amd64__) + else if (ifuncs) + elf_reloc_ifunc(lf, base, rela, ELF_RELOC_RELA, + elf_obj_lookup); +#endif } } return (0);