From nobody Fri Apr 01 00:51:32 2022 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 2FED11A53105; Fri, 1 Apr 2022 00:51:33 +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 4KV1nw48c4z3ngD; Fri, 1 Apr 2022 00:51:32 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1648774292; 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=QKWNMyl9jg4XhRHPcLgIGwVgQ/StfceG07ceUYdMMlc=; b=tTj9IkywBj7F9LcFQMpCMyuKUheiWmnMf/2r4+KkSA22aqfoWLQV+7MJdAk1HTkangXv2i xqCrqUqp3LH+OpgaTOJ3/9wCNfVNTb3S1BOylW0EbFymQlN3cBsaKF0BVcnQEv0dXn69xn TrnmgY8Of4DJoxz4PQ7lFh/ROnYJJ0OvWnDlRLcQN9zeN94D0bGjetU4WrO1h7ZArhcH0r FwLTYJRYryOOKBtlIqcuQxYmSdbez2Vzj+T/1CvSzsD8sFwhePA0YBYIiAi0EjkxnBbZQ3 yh/v5tqsD6DWUe1//wTc1lb8G6dzjpWmut67yW83YEzzzNIWxipT2ekGcVwS4w== 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 4DB191E7A; Fri, 1 Apr 2022 00:51:32 +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 2310pW48012667; Fri, 1 Apr 2022 00:51:32 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2310pWiu012666; Fri, 1 Apr 2022 00:51:32 GMT (envelope-from git) Date: Fri, 1 Apr 2022 00:51:32 GMT Message-Id: <202204010051.2310pWiu012666@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: 0913953c9ed0 - main - rtld: trace preloaded objects 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: 0913953c9ed0f6ac3dd57aa06e1d7c8a1a6c5530 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1648774292; 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=QKWNMyl9jg4XhRHPcLgIGwVgQ/StfceG07ceUYdMMlc=; b=hzd3wjSMUldvsmXQhRqhvxkeva37lHX2fGBcq6kNbB4XexzckNLxrnHL6TSbUB6CHSgfdM QE5Q+CmaEhN0cNGhCaCXjbLVyPcFuasY9ZDWf5xcGaRyhI2IprP4fUugK//k6ra8vXT5u9 i8uNXwU35ij49pgIfwGaaZiGUdrSxBZe91xdwavgRyJagN5NHf6USsFCvE82P+NstTiDXP CURRQ1pYxGNTMuqrKMFn6Oib4Mi5PEnci6UEP702nb5pZqul93saZwrgIVb6HTQn9TtEdG CUFTJoQBzK3Yz3wECf2euhPxsbxFLTa0kbx1hP9yUUjDOaRKQa+LozMkVw3UuQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1648774292; a=rsa-sha256; cv=none; b=F9Tmxs7yrexFM0cyYFFC6TY1CuMI+kyEAXmqaIGKNe0ockLqSA7ipKU/4eXKAoqGI4GE5B VH3tdgvwxJHrpOv4kPQNtUW1z9WPhEwXIqTJkQjz9FptG5vCLnxj3Hj2dLOMdZaSzrmNg+ wSM0xIMCYX7/WmA+y6WhgWUXO5jUNlC17M5Hc4S/iYJ7Nd1D6lX/nkN2oKw0zZagUPRPU6 OdMH8Hs82ZaHnloqWNaqT+je6Sgc2DLes6PfudKTSlDKW7QkUteIi07Gyntfykjdng1BoJ 8pdu25aEEw5s87go+5pApRI8R48w6Op6m7eC6xbfggjd8Q66JECTajiHbFDe6Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=0913953c9ed0f6ac3dd57aa06e1d7c8a1a6c5530 commit 0913953c9ed0f6ac3dd57aa06e1d7c8a1a6c5530 Author: Konstantin Belousov AuthorDate: 2022-03-30 21:01:54 +0000 Commit: Konstantin Belousov CommitDate: 2022-04-01 00:51:22 +0000 rtld: trace preloaded objects Before, preloaded objects, if not listed as needed for any normally linked objects, were silently ignored. Preloaded objects are printed with the `[preloaded]` herald. The list includes the objects not listed explicitly as recursive dependencies of the main object, effectively dsos loaded by LD_PRELOAD mechanism. vdso is listed as well, since it is not needed by anything. Since there is no DT_NEEDED entry for LD_PRELOADed objects, they are usually printed using LD_TRACE_LOADED_OBJECTS_FTM2 format due to the failure of the heuristic based on the presence of the 'lib' prefix. Reviewed by: markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D34716 --- libexec/rtld-elf/rtld.c | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/libexec/rtld-elf/rtld.c b/libexec/rtld-elf/rtld.c index 3860e1dba3eb..6e499ebc5208 100644 --- a/libexec/rtld-elf/rtld.c +++ b/libexec/rtld-elf/rtld.c @@ -172,7 +172,7 @@ static int symlook_needed(SymLook *, const Needed_Entry *, DoneList *); static int symlook_obj1_sysv(SymLook *, const Obj_Entry *); static int symlook_obj1_gnu(SymLook *, const Obj_Entry *); static void *tls_get_addr_slow(Elf_Addr **, int, size_t, bool) __noinline; -static void trace_loaded_objects(Obj_Entry *); +static void trace_loaded_objects(Obj_Entry *, bool); static void unlink_object(Obj_Entry *); static void unload_object(Obj_Entry *, RtldLockState *lockstate); static void unref_dag(Obj_Entry *); @@ -872,7 +872,7 @@ _rtld(Elf_Addr *sp, func_ptr_type *exit_proc, Obj_Entry **objp) dump_auxv(aux_info); if (ld_tracing) { /* We're done */ - trace_loaded_objects(obj_main); + trace_loaded_objects(obj_main, true); exit(0); } @@ -3834,7 +3834,7 @@ dlopen_object(const char *name, int fd, Obj_Entry *refobj, int lo_flags, lock_release(rtld_bind_lock, lockstate); return (obj); trace: - trace_loaded_objects(obj); + trace_loaded_objects(obj, false); if (lockstate == &mlockstate) lock_release(rtld_bind_lock, lockstate); exit(0); @@ -4992,17 +4992,17 @@ trace_print_obj(Obj_Entry *obj, const char *name, const char *path, } static void -trace_loaded_objects(Obj_Entry *obj) +trace_loaded_objects(Obj_Entry *obj, bool show_preload) { const char *fmt1, *fmt2, *main_local; - bool list_containers; + const char *name, *path; + bool first_spurious, list_containers; trace_calc_fmts(&main_local, &fmt1, &fmt2); list_containers = ld_get_env_var(LD_TRACE_LOADED_OBJECTS_ALL) != NULL; for (; obj != NULL; obj = TAILQ_NEXT(obj, next)) { Needed_Entry *needed; - const char *name, *path; if (obj->marker) continue; @@ -5022,6 +5022,23 @@ trace_loaded_objects(Obj_Entry *obj) fmt1, fmt2); } } + + if (show_preload) { + first_spurious = true; + TAILQ_FOREACH(obj, &obj_list, next) { + if (obj->marker || obj == obj_main || obj->traced) + continue; + + if (first_spurious) { + rtld_printf("[preloaded]\n"); + first_spurious = false; + } + Name_Entry *fname = STAILQ_FIRST(&obj->names); + name = fname == NULL ? "" : fname->name; + trace_print_obj(obj, name, obj->path, main_local, + fmt1, fmt2); + } + } } /*