From nobody Sun Jun 25 18:28:06 2023 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 4QpzxL2pqZz4hNDV; Sun, 25 Jun 2023 18:28:06 +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 4QpzxL2Lmcz3tCt; Sun, 25 Jun 2023 18:28:06 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1687717686; 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=aSyDztsq6w35w9h4DzA/COMFp6HHlPtrGOOhi8a9d4E=; b=DkkxGfhPPi3dS7z+3OfxgV0QI0cUAPQBu7rWScyB6sMW+awMhLImnwtbpF2TY2reMdYL47 HYy/3a8E7glytHkfCKzQ46Uhmm5W8xhmxzJuiAnoTssUvp7U0A76FJVwUqCSJVxL+KLxZ3 WS3Eerse1z32JiOU6hF4SDbTcCW99614glyk9dzm00N/hjYr5a2fXneirjbsyYK6zBRz/0 iEE1gpw+WLP1Tyc89oTQxuWmyaCUyU808gmGoErk5IJeozTxSkHmxGntWKEZPyfZAsohKt R5rIqpHkPpfJnxVXyJoDP5aJ0oxOFgC4KFhY1XPinOOV72zFClHMOZJjHuDk8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1687717686; 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=aSyDztsq6w35w9h4DzA/COMFp6HHlPtrGOOhi8a9d4E=; b=MyQf+C8HbROHkSUsbEoIbc6LweWabs+vGwNh2fL7wWyMrLu6H1OyCNTuHeqgTQu7o50Ykh KrYOuH9+yJ8Vdv/hNZlwzCvnzjzfcTKJtvIy1VkcFwizIB/E+aVTsM774htjO8OAheMq6n +smI4ueVcCd4W4OpowCr9vskykXo68tlwb/rjLRJ5U1NhUw60UGTPqd5PSJwhkW49En35Z eUhlkYsy3NlafbZrFkHHESdqcHfrlkce8QpxWRB1lNYptVQdPJXqlhoC+UZvKRw8DuD1w2 kLi69/5KH0+TNqz4IEKQgAMV1yfCrhxyFcUv3zHvA6ls0I0poCOy1if8fkmKSA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1687717686; a=rsa-sha256; cv=none; b=k3lZIxNk5WpqSHqFlYVA7EQYF8Bj2jPpDxz44bFDYLjGVt5ziFjs2lDRMrkWRio6AEmZes 12Sc2VRDMu7dmBIakEbtomUxp/gINPTBqGv5otf55ihTaQjRg/pLBGvtfyrThEHmQVvRhI GxnqhbTL+nDxRdRfphL0aAIJ8hvhoIDhPvyVZuPiShNSidjGu8QLSSti6Pj3hEJV94Q75n k7qtOdxRbZw+4CJEK1l/PsT2s7O7rSyU5fn+e9RxCMPbPCnzVyIukcq2iEZlpd0oCCjxFa MmKuhMWjLR2FBXELOTWlK5MAc66Pl2MOewBC0AzZDwQS6PzzI7uZA9rSxBSx8g== 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 4QpzxL1JzgzdFV; Sun, 25 Jun 2023 18:28:06 +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 35PIS6HW025030; Sun, 25 Jun 2023 18:28:06 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 35PIS6Nx025029; Sun, 25 Jun 2023 18:28:06 GMT (envelope-from git) Date: Sun, 25 Jun 2023 18:28:06 GMT Message-Id: <202306251828.35PIS6Nx025029@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 42ceab3ea1a9 - main - libc.a: implement _rtld_addr_phdr() 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: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 42ceab3ea1a997db93b65404be0ee4b17b5382d7 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=42ceab3ea1a997db93b65404be0ee4b17b5382d7 commit 42ceab3ea1a997db93b65404be0ee4b17b5382d7 Author: Konstantin Belousov AuthorDate: 2023-06-24 10:59:56 +0000 Commit: Konstantin Belousov CommitDate: 2023-06-25 18:27:25 +0000 libc.a: implement _rtld_addr_phdr() to make __cxa_thread_call_dtors() operational for statically linked binaries. Noted by: andrew Reviewed by: emaste, dim Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D40748 --- lib/libc/gen/dlfcn.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/lib/libc/gen/dlfcn.c b/lib/libc/gen/dlfcn.c index 4478b41cfe98..61984e2fe86c 100644 --- a/lib/libc/gen/dlfcn.c +++ b/lib/libc/gen/dlfcn.c @@ -40,6 +40,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include "namespace.h" #include #include "un-namespace.h" @@ -248,13 +249,48 @@ _rtld_atfork_post(int *locks __unused) { } +#ifndef IN_LIBDL +struct _rtld_addr_phdr_cb_data { + const void *addr; + struct dl_phdr_info *dli; +}; + +static int +_rtld_addr_phdr_cb(struct dl_phdr_info *dli, size_t sz, void *arg) +{ + struct _rtld_addr_phdr_cb_data *rd; + const Elf_Phdr *ph; + unsigned i; + + rd = arg; + for (i = 0; i < dli->dlpi_phnum; i++) { + ph = &dli->dlpi_phdr[i]; + if (ph->p_type == PT_LOAD && + dli->dlpi_addr + ph->p_vaddr <= (uintptr_t)rd->addr && + (uintptr_t)rd->addr < dli->dlpi_addr + ph->p_vaddr + + ph->p_memsz) { + memcpy(rd->dli, dli, sz); + return (1); + } + } + return (0); +} +#endif + #pragma weak _rtld_addr_phdr int _rtld_addr_phdr(const void *addr __unused, struct dl_phdr_info *phdr_info_a __unused) { +#ifndef IN_LIBDL + struct _rtld_addr_phdr_cb_data rd; + rd.addr = addr; + rd.dli = phdr_info_a; + return (dl_iterate_phdr(_rtld_addr_phdr_cb, &rd)); +#else return (0); +#endif } #pragma weak _rtld_get_stack_prot