From nobody Thu Dec 02 14:15:52 2021 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id C2B9C18C1824; Thu, 2 Dec 2021 14:15:53 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4J4dKP2dXHz4t7Z; Thu, 2 Dec 2021 14:15:53 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 184281EE85; Thu, 2 Dec 2021 14:15:53 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1B2EFqcs009009; Thu, 2 Dec 2021 14:15:52 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1B2EFqOu009008; Thu, 2 Dec 2021 14:15:52 GMT (envelope-from git) Date: Thu, 2 Dec 2021 14:15:52 GMT Message-Id: <202112021415.1B2EFqOu009008@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: e0d7fe1a03d1 - stable/12 - link_elf_obj: Process global ifunc relocs after other global relocs List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: e0d7fe1a03d17b3f6dc03e1079d103ce5a366feb Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1638454553; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=t95MnmWI2K8NaQzs1qwQsU8AA15aolDeoUyfLHHcdOE=; b=PEKmMjIlSFg6SklvgoHgNL7/h4j7sf89KF8Y5c+pPN4qxZQEUGOJXktUUFPOJ6goTO7+A5 OestcxQJSZncF+8rOCh2q2UPwCDjUgxkfbd+5/hvvxf/d3IUvopEFG2h0p7CQpADQDRjQA K72NxQQHF+JDmNYSGzFe5AH3D1oOUYvvZL6NMrOVVQOQj+0LCR6KeFvtaniUzOncIOjXSh tmc/FAnc4YotXkT202uqxMYGxKWfzro7bVg1Ubs9BH1MczrnrmX2ylsq/e+c/u15sqTHXF 1C9Ubz68W5LQ2L0/JGQNOH3zn3V32jsL27VE06piYYzHrsauqQLxkyHQJeuMMg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1638454553; a=rsa-sha256; cv=none; b=Ujqle8wIjmDdRV/z9W79cx131KohCxHERQpotwdE3Ai16slFC5rZ1nYMTmtoMGGCp1fYuY m4pR8APpA1g+/ZqBGrXgvpMwYg5QDKwJwgr19AGHrH3ppa9DmB85NiQUxfG4FUDGkSYqxl 87Xa0eH7qyKjCTME7dBqgHxm5eaL/p845MsXQbsQj6dX4m74874lwkSghL+Jel6hGw5xXM 2NLxGx1RE3524M/a9hR1Gx4mOWXgyQOyAmvqSk/hNc35vlun7X+zD3dHt0Fvx704v+T857 73CA06f78ASiY68R1/1eHFyvYchthmugKPXYYpHPFTvghXKV3oAZp9ockJEkzg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/12 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=e0d7fe1a03d17b3f6dc03e1079d103ce5a366feb commit e0d7fe1a03d17b3f6dc03e1079d103ce5a366feb Author: Mark Johnston AuthorDate: 2021-11-25 21:52:17 +0000 Commit: Mark Johnston CommitDate: 2021-12-02 14:15:42 +0000 link_elf_obj: Process global ifunc relocs after other global relocs This is needed to ensure that resolvers that reference global symbols return correct results. Reviewed by: kib Sponsored by: The FreeBSD Foundation (cherry picked from commit b11e6fd75b1bb9d337b0edab14d160ff65b11aae) --- sys/kern/link_elf_obj.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/sys/kern/link_elf_obj.c b/sys/kern/link_elf_obj.c index c892c14833d6..5b79b0b4c17c 100644 --- a/sys/kern/link_elf_obj.c +++ b/sys/kern/link_elf_obj.c @@ -1244,7 +1244,7 @@ findbase(elf_file_t ef, int sec) } static int -relocate_file(elf_file_t ef) +relocate_file1(elf_file_t ef, bool ifuncs) { const Elf_Rel *rellim; const Elf_Rel *rel; @@ -1278,6 +1278,9 @@ relocate_file(elf_file_t ef) /* Local relocs are already done */ if (ELF_ST_BIND(sym->st_info) == STB_LOCAL) continue; + if ((ELF_ST_TYPE(sym->st_info) == STT_GNU_IFUNC || + elf_is_ifunc_reloc(rel->r_info)) != ifuncs) + continue; if (elf_reloc(&ef->lf, base, rel, ELF_RELOC_REL, elf_obj_lookup)) { symname = symbol_name(ef, rel->r_info); @@ -1310,6 +1313,9 @@ relocate_file(elf_file_t ef) /* Local relocs are already done */ if (ELF_ST_BIND(sym->st_info) == STB_LOCAL) continue; + if ((ELF_ST_TYPE(sym->st_info) == STT_GNU_IFUNC || + elf_is_ifunc_reloc(rela->r_info)) != ifuncs) + continue; if (elf_reloc(&ef->lf, base, rela, ELF_RELOC_RELA, elf_obj_lookup)) { symname = symbol_name(ef, rela->r_info); @@ -1330,6 +1336,17 @@ relocate_file(elf_file_t ef) return (0); } +static int +relocate_file(elf_file_t ef) +{ + int error; + + error = relocate_file1(ef, false); + if (error == 0) + error = relocate_file1(ef, true); + return (error); +} + static int link_elf_lookup_symbol(linker_file_t lf, const char *name, c_linker_sym_t *sym) {