From nobody Thu Dec 2 14:15:27 2021 X-Original-To: dev-commits-src-branches@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 B9EE418C148D; Thu, 2 Dec 2021 14:15:27 +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 4J4dJv2d3lz4sqX; Thu, 2 Dec 2021 14:15:27 +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 39E481ECA8; Thu, 2 Dec 2021 14:15:27 +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 1B2EFRKF008865; Thu, 2 Dec 2021 14:15:27 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1B2EFRn7008864; Thu, 2 Dec 2021 14:15:27 GMT (envelope-from git) Date: Thu, 2 Dec 2021 14:15:27 GMT Message-Id: <202112021415.1B2EFRn7008864@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: 2e837779a7ef - stable/13 - link_elf_obj: Process global ifunc relocs after other global relocs List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@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/13 X-Git-Reftype: branch X-Git-Commit: 2e837779a7efe3cd315988de931257d980cc789c Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1638454527; 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=rpECGlxPM0KimYPu5cJSYP+30tJabtIt1y1Et5EOtWI=; b=cuWBXroBLYbIw8UHxfLWaKZaqV75v1xDjLTlnosYX44xGFg1SlzqGx5GIU5XSab73kLDYM ATBl2U06L67zOoswN3dG/269u214hROPjyClK8kCN5NIvcFa43tuw+twavkVgJ56YNFesI 3ecysFTxvYIE5kRHWegxl1om6M8d6n8fB0g4FjjfK6bZGVBfLJI9yWnAd/K2VQlSxTJzNX nmDkDXgCFJiBr661RloeT4+xjnbhTaDA4cL4J5su3eKQPkvoDZ4WvdX1wlHTxLGhoIWr0h NDJpH1X5j1I4omDKp75QoPgBDVeh9PWDuRMuF5/lA1/AcAJi0PJAnU7TMqkIPA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1638454527; a=rsa-sha256; cv=none; b=TNt7k+TfnqkPWVb7gwPTFxz/5Qcah6iPWXSMuGaFAQWZLeb4kCgCoOoxU5UaUIFMOSx6GI Vsed2PfWZe2jwYziv6e8GJZReSB+tWZ/b+/yyQDEdJ3N81NM3ZRr8RzODH0g/FmuZpZP4E fj+vhXGiTMZT3Fe2Z7MXrzG31X6/EEPBi+Fqs/RZqwP4s10KnFNfjtr6m16nxqeVSYMAR7 oLCZZPHegAz+dn1hBlSxzZMIQ7Qpt4YP9Cic/XNTKZS2uN/AE+B86iYlbngfHUavxdmiOO uAH5FWJ35YKQogf4HTdTiEijCnsMkaWmm0uLjqzgEnt6DzX8dITu6yqHOOiDJg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=2e837779a7efe3cd315988de931257d980cc789c commit 2e837779a7efe3cd315988de931257d980cc789c Author: Mark Johnston AuthorDate: 2021-11-25 21:52:17 +0000 Commit: Mark Johnston CommitDate: 2021-12-02 14:15:15 +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 5c6db11e1937..bafbd9f4c616 100644 --- a/sys/kern/link_elf_obj.c +++ b/sys/kern/link_elf_obj.c @@ -1321,7 +1321,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; @@ -1354,6 +1354,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); @@ -1386,6 +1389,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); @@ -1406,6 +1412,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) {