From nobody Fri Apr 01 00:51:28 2022 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 3D9681A52DD3; Fri, 1 Apr 2022 00:51:29 +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 4KV1ns0T3rz3nM6; Fri, 1 Apr 2022 00:51:29 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1648774289; 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=U34dkt8/EC+bYKfZ1R5dC/bH/d6EZ6nj+9W1d5aAy5I=; b=NEBmYgXY+ERehwY8LaKCYgYVRAysVgyST2Z6Uz8raJFOpbC9Y+0spSECdPGj0i1IH4yMyv rsifL4pxfz0esCUdh26Xdc1zNonFh0gOYRUQh3lEJFsIPPcQxFuBS4Kbf0xhUylKnzQzZt Ku11xDV4Hy7cQoMOV38GVGPjhiTJjaDljMFy8RoAhDdVyB+CHI3dJ2LXKXqhhe9ZcPDm1w 8GtdGRqNcqRnPLneD929IP7L29lmjE+CSs+nox4N7/ucSTe6ASAW8UVbfK4YyE/+OBGyxm jUjcPPLM5RVTHgbfyQEw+LTOhD9MqnxTIQ62Cqlz+9J/eETN6ijkzsFjyDU6Tw== 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 D8FF72262; Fri, 1 Apr 2022 00:51:28 +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 2310pSec012588; Fri, 1 Apr 2022 00:51:28 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2310pSVs012587; Fri, 1 Apr 2022 00:51:28 GMT (envelope-from git) Date: Fri, 1 Apr 2022 00:51:28 GMT Message-Id: <202204010051.2310pSVs012587@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: 24d0c9c1f565 - main - rtld: extract printer for a single traced object into a helper 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: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 24d0c9c1f565bab6e97ec629f223e85b18bc700a Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1648774289; 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=U34dkt8/EC+bYKfZ1R5dC/bH/d6EZ6nj+9W1d5aAy5I=; b=UYkK05SEVqTKANK8/3nK8JN5cdY1QoQHIDnXJQ8ZKVAzFboBBaYAYWZTCUA23koSnhW6J/ oYu32jCFceChJKT2HcIYxpdUeBD3+ic2ZPKtr9Goahz4c0so7RHaxg2BqLcWIY2WwbReaX gSxcssEu+bkyXOmliAHh6g+Od+a1mOHHB+aNHu0/Xy6jja6HKx+qgLOQQlBNF0MK9r8b70 c3Ll/Z8dxDYlsxHsOBB7Nfn96LCJdurngdKxDhm3f2eCpMeqxMOMaSlwlAH30oB7klaFYZ yFGbtaV97Fn4WNUoFRX6ngj6zv8uuRJ8wPznA9eF9ZSVJcs/vd3UOuse475MRg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1648774289; a=rsa-sha256; cv=none; b=ys21f536UK/pJ0ywlhFmdf23rogL+KLpCDK4pB8NrAH0vQFbvnWqMQhh6KGPsxaIMzxlb+ +tpR0RgSZMaJn6F/wqePImh7zhI/whiAih2GPZvvPed7GUduaVmgBJ1cRv2E8FlChAUUlA c9D5aNZK7cxSgVcgyIpWN2t+Pb3XhgO6nx0Y6X2nEkMswql9BBvG8dSx7rbnU2NQ7Mg+HV xgSBkMQV/iNpK29ixnIXDe6YzfVZgb75TKC1jxpxpvbcyJqKxCUg/bgonzHhU3ju7BO5I2 BMpshCHBfyD3AdikJIMbOVd1h4sQp1zcCFEuvDjt52h4+G+Fd1o+H6Avcoemjw== 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=24d0c9c1f565bab6e97ec629f223e85b18bc700a commit 24d0c9c1f565bab6e97ec629f223e85b18bc700a Author: Konstantin Belousov AuthorDate: 2022-03-30 20:46:21 +0000 Commit: Konstantin Belousov CommitDate: 2022-04-01 00:51:21 +0000 rtld: extract printer for a single traced object into a helper Reviewed by: markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D34716 --- libexec/rtld-elf/rtld.c | 118 ++++++++++++++++++++++++------------------------ 1 file changed, 58 insertions(+), 60 deletions(-) diff --git a/libexec/rtld-elf/rtld.c b/libexec/rtld-elf/rtld.c index a5c2755a0cb2..8260897eb3b3 100644 --- a/libexec/rtld-elf/rtld.c +++ b/libexec/rtld-elf/rtld.c @@ -4935,11 +4935,66 @@ trace_calc_fmts(const char **main_local, const char **fmt1, const char **fmt2) *fmt2 = "\t%o (%x)\n"; } +static void +trace_print_obj(Obj_Entry *obj, const char *name, const char *path, + const char *main_local, const char *fmt1, const char *fmt2) +{ + const char *fmt; + int c; + + fmt = strncmp(name, "lib", 3) == 0 ? fmt1 : fmt2; /* XXX bogus */ + while ((c = *fmt++) != '\0') { + switch (c) { + default: + rtld_putchar(c); + continue; + case '\\': + switch (c = *fmt) { + case '\0': + continue; + case 'n': + rtld_putchar('\n'); + break; + case 't': + rtld_putchar('\t'); + break; + } + break; + case '%': + switch (c = *fmt) { + case '\0': + continue; + case '%': + default: + rtld_putchar(c); + break; + case 'A': + rtld_putstr(main_local); + break; + case 'a': + rtld_putstr(obj_main->path); + break; + case 'o': + rtld_putstr(name); + break; + case 'p': + rtld_putstr(path); + break; + case 'x': + rtld_printf("%p", obj != NULL ? + obj->mapbase : NULL); + break; + } + break; + } + ++fmt; + } +} + static void trace_loaded_objects(Obj_Entry *obj) { - const char *fmt1, *fmt2, *fmt, *main_local, *list_containers; - int c; + const char *fmt1, *fmt2, *main_local, *list_containers; trace_calc_fmts(&main_local, &fmt1, &fmt2); list_containers = ld_get_env_var(LD_TRACE_LOADED_OBJECTS_ALL); @@ -4947,7 +5002,6 @@ trace_loaded_objects(Obj_Entry *obj) for (; obj != NULL; obj = TAILQ_NEXT(obj, next)) { Needed_Entry *needed; const char *name, *path; - bool is_lib; if (obj->marker) continue; @@ -4963,63 +5017,7 @@ trace_loaded_objects(Obj_Entry *obj) path = "not found"; name = obj->strtab + needed->name; - is_lib = strncmp(name, "lib", 3) == 0; /* XXX - bogus */ - - fmt = is_lib ? fmt1 : fmt2; - while ((c = *fmt++) != '\0') { - switch (c) { - default: - rtld_putchar(c); - continue; - case '\\': - switch (c = *fmt) { - case '\0': - continue; - case 'n': - rtld_putchar('\n'); - break; - case 't': - rtld_putchar('\t'); - break; - } - break; - case '%': - switch (c = *fmt) { - case '\0': - continue; - case '%': - default: - rtld_putchar(c); - break; - case 'A': - rtld_putstr(main_local); - break; - case 'a': - rtld_putstr(obj_main->path); - break; - case 'o': - rtld_putstr(name); - break; -#if 0 - case 'm': - rtld_printf("%d", sodp->sod_major); - break; - case 'n': - rtld_printf("%d", sodp->sod_minor); - break; -#endif - case 'p': - rtld_putstr(path); - break; - case 'x': - rtld_printf("%p", needed->obj ? needed->obj->mapbase : - 0); - break; - } - break; - } - ++fmt; - } + trace_print_obj(obj, name, path, main_local, fmt1, fmt2); } } }