From nobody Thu Nov 25 21:53:45 2021 X-Original-To: dev-commits-src-main@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 124E318A24AA; Thu, 25 Nov 2021 21:53:46 +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 4J0Wpx5KT7z4nZh; Thu, 25 Nov 2021 21:53:45 +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 9055624A78; Thu, 25 Nov 2021 21:53:45 +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 1APLrjUY082515; Thu, 25 Nov 2021 21:53:45 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1APLrjYg082514; Thu, 25 Nov 2021 21:53:45 GMT (envelope-from git) Date: Thu, 25 Nov 2021 21:53:45 GMT Message-Id: <202111252153.1APLrjYg082514@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: b11e6fd75b1b - main - link_elf_obj: Process global ifunc relocs after other global relocs List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: b11e6fd75b1bb9d337b0edab14d160ff65b11aae Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1637877225; 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=0YerwoiloFDxbiZUW4ufVSjEFatrw7eitlGGcWfy29s=; b=W0JhvzhN+rhT/XmK2W5lE6mbHi+xgxV4fZlJXpfNsW+kPw9OMNMsFXN62dp/vP7rB05BaA rt7SHiyZfP8nfZ7gPyqqjc+TythDVceNQ7ryyrk+WBzTW+e0BeO+txbv3ONVlm32JBwGRS m9APLTeMA9pYoU18HHI++dQMI0s6K9ETRRcB6+Rt+xrQxt4UwDj0yoT09v0rG8B5Xm4ALB Rh3H+RchFgJ+pAIeAtSlaoUlcyMUQmB3kc33EuVYm1ZOPClPdjAJl8YE0gSp9ppfkvcIX7 qpKhTeVrk8D8SlRortXAeqOWjY3FPSGkna0jNrbAe++IQYwplt6yVDU1vBwa1Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1637877225; a=rsa-sha256; cv=none; b=Us4FbrHqLDae48RHSty62ydpOGfOLypoEEpmBa7myDg9sF3RgWlL0o/AztOiiZAnIzQbHt yw8xoLtPibRYzOor1Rpz6T8mnw8BZ/yU4qmTwBWPNrScJJbxL/5aKzahpoFNG/LVR6WbA9 CkxrLLwHeDCY/YdJgMhcYR7tukoemRNFci6gWrLfYZZdgRT4l9UslmGGHbWgoVXtaqF3B4 gkqdR2535WtzrcqrLyJrlvAJl3Mr3l4YeJB2iJq8/RYmd55a5jwpYlmTamKTWdO9xfSNCf pkrgIZVMPpiIcNdSEtYkFmwSNlbDw8CnTXDq86f5Rtvo2DmzPCOnoxDmn1OLJQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=b11e6fd75b1bb9d337b0edab14d160ff65b11aae commit b11e6fd75b1bb9d337b0edab14d160ff65b11aae Author: Mark Johnston AuthorDate: 2021-11-25 21:52:17 +0000 Commit: Mark Johnston CommitDate: 2021-11-25 21:53:27 +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 MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D33120 --- 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) {