From nobody Fri Nov 19 04:36:37 2021 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 C4495188DDB1; Fri, 19 Nov 2021 04:36:37 +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 4HwP513D0Pz3px3; Fri, 19 Nov 2021 04:36:37 +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 4C85121EA6; Fri, 19 Nov 2021 04:36:37 +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 1AJ4ab8Q034210; Fri, 19 Nov 2021 04:36:37 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1AJ4abw8034209; Fri, 19 Nov 2021 04:36:37 GMT (envelope-from git) Date: Fri, 19 Nov 2021 04:36:37 GMT Message-Id: <202111190436.1AJ4abw8034209@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: 8ade0046f60b - stable/13 - rtld: Implement LD_SHOW_AUXV 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/stable/13 X-Git-Reftype: branch X-Git-Commit: 8ade0046f60bfc5491662ae363736638aaaf6640 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=8ade0046f60bfc5491662ae363736638aaaf6640 commit 8ade0046f60bfc5491662ae363736638aaaf6640 Author: Konstantin Belousov AuthorDate: 2021-11-13 01:18:13 +0000 Commit: Konstantin Belousov CommitDate: 2021-11-19 04:25:27 +0000 rtld: Implement LD_SHOW_AUXV (cherry picked from commit 64ba1f4cf3a6847a1dacf4bab0409d94898fa168) --- libexec/rtld-elf/rtld.1 | 7 +++++- libexec/rtld-elf/rtld.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 1 deletion(-) diff --git a/libexec/rtld-elf/rtld.1 b/libexec/rtld-elf/rtld.1 index 187dc105667a..66aa2bdabd17 100644 --- a/libexec/rtld-elf/rtld.1 +++ b/libexec/rtld-elf/rtld.1 @@ -28,7 +28,7 @@ .\" .\" $FreeBSD$ .\" -.Dd August 15, 2021 +.Dd November 13, 2021 .Dt RTLD 1 .Os .Sh NAME @@ -309,6 +309,11 @@ will process the filtee dependencies of the loaded objects immediately, instead of postponing it until required. Normally, the filtees are opened at the time of the first symbol resolution from the filter object. +.It Ev LD_SHOW_AUXV +If set, causes +.Nm +to dump content of the aux vector to standard output, before passing +control to any user code. .El .Sh DIRECT EXECUTION MODE .Nm diff --git a/libexec/rtld-elf/rtld.c b/libexec/rtld-elf/rtld.c index c173c5a6e22e..0475134b0d96 100644 --- a/libexec/rtld-elf/rtld.c +++ b/libexec/rtld-elf/rtld.c @@ -104,6 +104,7 @@ static Obj_Entry *dlopen_object(const char *name, int fd, Obj_Entry *refobj, static Obj_Entry *do_load_object(int, const char *, char *, struct stat *, int); static int do_search_info(const Obj_Entry *obj, int, struct dl_serinfo *); static bool donelist_check(DoneList *, const Obj_Entry *); +static void dump_auxv(Elf_Auxinfo **aux_info); static void errmsg_restore(struct dlerror_save *); static struct dlerror_save *errmsg_save(void); static void *fill_search_info(const char *, size_t, void *); @@ -364,6 +365,7 @@ enum { LD_TRACE_LOADED_OBJECTS_FMT1, LD_TRACE_LOADED_OBJECTS_FMT2, LD_TRACE_LOADED_OBJECTS_ALL, + LD_SHOW_AUXV, }; struct ld_env_var_desc { @@ -396,6 +398,7 @@ static struct ld_env_var_desc ld_env_vars[] = { LD_ENV_DESC(TRACE_LOADED_OBJECTS_FMT1, false), LD_ENV_DESC(TRACE_LOADED_OBJECTS_FMT2, false), LD_ENV_DESC(TRACE_LOADED_OBJECTS_ALL, false), + LD_ENV_DESC(SHOW_AUXV, false), }; static const char * @@ -857,6 +860,9 @@ _rtld(Elf_Addr *sp, func_ptr_type *exit_proc, Obj_Entry **objp) if (rtld_verify_versions(&list_main) == -1 && !ld_tracing) rtld_die(); + if (ld_get_env_var(LD_SHOW_AUXV) != NULL) + dump_auxv(aux_info); + if (ld_tracing) { /* We're done */ trace_loaded_objects(obj_main); exit(0); @@ -6058,6 +6064,67 @@ print_usage(const char *argv0) " Arguments to the executed process\n", argv0); } +#define AUXFMT(at, xfmt) [at] = { .name = #at, .fmt = xfmt } +static const struct auxfmt { + const char *name; + const char *fmt; +} auxfmts[] = { + AUXFMT(AT_NULL, NULL), + AUXFMT(AT_IGNORE, NULL), + AUXFMT(AT_EXECFD, "%d"), + AUXFMT(AT_PHDR, "%p"), + AUXFMT(AT_PHENT, "%u"), + AUXFMT(AT_PHNUM, "%u"), + AUXFMT(AT_PAGESZ, "%u"), + AUXFMT(AT_BASE, "%#lx"), + AUXFMT(AT_FLAGS, "%#lx"), + AUXFMT(AT_ENTRY, "%p"), + AUXFMT(AT_NOTELF, NULL), + AUXFMT(AT_UID, "%d"), + AUXFMT(AT_EUID, "%d"), + AUXFMT(AT_GID, "%d"), + AUXFMT(AT_EGID, "%d"), + AUXFMT(AT_EXECPATH, "%s"), + AUXFMT(AT_CANARY, "%p"), + AUXFMT(AT_CANARYLEN, "%u"), + AUXFMT(AT_OSRELDATE, "%u"), + AUXFMT(AT_NCPUS, "%u"), + AUXFMT(AT_PAGESIZES, "%p"), + AUXFMT(AT_PAGESIZESLEN, "%u"), + AUXFMT(AT_TIMEKEEP, "%p"), + AUXFMT(AT_STACKPROT, "%#x"), + AUXFMT(AT_EHDRFLAGS, "%#lx"), + AUXFMT(AT_HWCAP, "%#lx"), + AUXFMT(AT_HWCAP2, "%#lx"), + AUXFMT(AT_BSDFLAGS, "%#lx"), + AUXFMT(AT_ARGC, "%u"), + AUXFMT(AT_ARGV, "%p"), + AUXFMT(AT_ENVC, "%p"), + AUXFMT(AT_ENVV, "%p"), + AUXFMT(AT_PS_STRINGS, "%p"), + AUXFMT(AT_FXRNG, "%p"), +}; + +static void +dump_auxv(Elf_Auxinfo **aux_info) +{ + Elf_Auxinfo *auxp; + const struct auxfmt *fmt; + int i; + + for (i = 0; i < AT_COUNT; i++) { + auxp = aux_info[i]; + if (auxp == NULL) + continue; + fmt = &auxfmts[i]; + if (fmt->fmt == NULL) + continue; + rtld_fdprintf(STDOUT_FILENO, "%s:\t", fmt->name); + rtld_fdprintfx(STDOUT_FILENO, fmt->fmt, auxp->a_un.a_ptr); + rtld_fdprintf(STDOUT_FILENO, "\n"); + } +} + /* * Overrides for libc_pic-provided functions. */