From owner-svn-src-all@freebsd.org Sun Jun 7 00:41:44 2020 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id ABF4C3426FF; Sun, 7 Jun 2020 00:41:44 +0000 (UTC) (envelope-from kib@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 "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 49fcyc3vS8z4JCb; Sun, 7 Jun 2020 00:41:44 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 80CD0AB6C; Sun, 7 Jun 2020 00:41:44 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 0570fiB0020048; Sun, 7 Jun 2020 00:41:44 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 0570fi7L020046; Sun, 7 Jun 2020 00:41:44 GMT (envelope-from kib@FreeBSD.org) Message-Id: <202006070041.0570fi7L020046@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Sun, 7 Jun 2020 00:41:44 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r361881 - stable/12/libexec/rtld-elf X-SVN-Group: stable-12 X-SVN-Commit-Author: kib X-SVN-Commit-Paths: stable/12/libexec/rtld-elf X-SVN-Commit-Revision: 361881 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 07 Jun 2020 00:41:44 -0000 Author: kib Date: Sun Jun 7 00:41:43 2020 New Revision: 361881 URL: https://svnweb.freebsd.org/changeset/base/361881 Log: MFC r361672, r361675, r361676, r361680: rtld direct exec: add -b and -v options. Modified: stable/12/libexec/rtld-elf/rtld.1 stable/12/libexec/rtld-elf/rtld.c Directory Properties: stable/12/ (props changed) Modified: stable/12/libexec/rtld-elf/rtld.1 ============================================================================== --- stable/12/libexec/rtld-elf/rtld.1 Sun Jun 7 00:07:21 2020 (r361880) +++ stable/12/libexec/rtld-elf/rtld.1 Sun Jun 7 00:41:43 2020 (r361881) @@ -28,7 +28,7 @@ .\" .\" $FreeBSD$ .\" -.Dd May 20, 2017 +.Dd June 1, 2020 .Dt RTLD 1 .Os .Sh NAME @@ -302,6 +302,7 @@ Execution options may be specified. The syntax of the direct invocation is .Bd -ragged -offset indent .Pa /libexec/ld-elf.so.1 +.Op Fl b Ar exe .Op Fl f Ar fd .Op Fl p .Op Fl - @@ -311,6 +312,17 @@ The syntax of the direct invocation is .Pp The options are: .Bl -tag -width indent +.It Fl b Ar exe +Use the executable +.Fa exe +instead of +.Fa image_path +for activation. +If this option is specified, +.Ar image_path +is only used to provide the +.Va argv[0] +value to the program. .It Fl f Ar fd File descriptor .Ar fd @@ -333,6 +345,8 @@ character, uses the search path provided by the environment variable .Dv PATH to find the binary to execute. +.It Fl v +Display information about this run-time linker binary, then exit. .It Fl - Ends the .Nm Modified: stable/12/libexec/rtld-elf/rtld.c ============================================================================== --- stable/12/libexec/rtld-elf/rtld.c Sun Jun 7 00:07:21 2020 (r361880) +++ stable/12/libexec/rtld-elf/rtld.c Sun Jun 7 00:41:43 2020 (r361881) @@ -136,7 +136,8 @@ static void objlist_put_after(Objlist *, Obj_Entry *, static void objlist_remove(Objlist *, Obj_Entry *); static int open_binary_fd(const char *argv0, bool search_in_path, const char **binpath_res); -static int parse_args(char* argv[], int argc, bool *use_pathp, int *fdp); +static int parse_args(char* argv[], int argc, bool *use_pathp, int *fdp, + const char **argv0); static int parse_integer(const char *); static void *path_enumerate(const char *, path_enum_proc, const char *, void *); static void print_usage(const char *argv0); @@ -439,8 +440,7 @@ _rtld(Elf_Addr *sp, func_ptr_type *exit_proc, Obj_Entr } dbg("opening main program in direct exec mode"); if (argc >= 2) { - rtld_argc = parse_args(argv, argc, &search_in_path, &fd); - argv0 = argv[rtld_argc]; + rtld_argc = parse_args(argv, argc, &search_in_path, &fd, &argv0); explicit_fd = (fd != -1); binpath = NULL; if (!explicit_fd) @@ -5563,15 +5563,20 @@ open_binary_fd(const char *argv0, bool search_in_path, * Parse a set of command-line arguments. */ static int -parse_args(char* argv[], int argc, bool *use_pathp, int *fdp) +parse_args(char* argv[], int argc, bool *use_pathp, int *fdp, + const char **argv0) { const char *arg; - int fd, i, j, arglen; + char machine[64]; + size_t sz; + int arglen, fd, i, j, mib[2]; char opt; + bool seen_b, seen_f; dbg("Parsing command-line arguments"); *use_pathp = false; *fdp = -1; + seen_b = seen_f = false; for (i = 1; i < argc; i++ ) { arg = argv[i]; @@ -5598,7 +5603,21 @@ parse_args(char* argv[], int argc, bool *use_pathp, in if (opt == 'h') { print_usage(argv[0]); _exit(0); + } else if (opt == 'b') { + if (seen_f) { + _rtld_error("Both -b and -f specified"); + rtld_die(); + } + i++; + *argv0 = argv[i]; + seen_b = true; + break; } else if (opt == 'f') { + if (seen_b) { + _rtld_error("Both -b and -f specified"); + rtld_die(); + } + /* * -f XX can be used to specify a * descriptor for the binary named at @@ -5622,9 +5641,28 @@ parse_args(char* argv[], int argc, bool *use_pathp, in rtld_die(); } *fdp = fd; + seen_f = true; break; } else if (opt == 'p') { *use_pathp = true; + } else if (opt == 'v') { + machine[0] = '\0'; + mib[0] = CTL_HW; + mib[1] = HW_MACHINE; + sz = sizeof(machine); + sysctl(mib, nitems(mib), machine, &sz, NULL, 0); + rtld_printf( + "FreeBSD ld-elf.so.1 %s\n" + "FreeBSD_version %d\n" + "Default lib path %s\n" + "Env prefix %s\n" + "Hint file %s\n" + "libmap file %s\n", + machine, + __FreeBSD_version, ld_standard_library_path, + ld_env_prefix, ld_elf_hints_default, + ld_path_libmap_conf); + _exit(0); } else { _rtld_error("Invalid argument: '%s'", arg); print_usage(argv[0]); @@ -5633,6 +5671,8 @@ parse_args(char* argv[], int argc, bool *use_pathp, in } } + if (!seen_b) + *argv0 = argv[i]; return (i); } @@ -5667,15 +5707,18 @@ static void print_usage(const char *argv0) { - rtld_printf("Usage: %s [-h] [-f ] [--] []\n" - "\n" - "Options:\n" - " -h Display this help message\n" - " -p Search in PATH for named binary\n" - " -f Execute instead of searching for \n" - " -- End of RTLD options\n" - " Name of process to execute\n" - " Arguments to the executed process\n", argv0); + rtld_printf( + "Usage: %s [-h] [-b ] [-f ] [-p] [--] []\n" + "\n" + "Options:\n" + " -h Display this help message\n" + " -b Execute instead of , arg0 is \n" + " -f Execute instead of searching for \n" + " -p Search in PATH for named binary\n" + " -v Display identification information\n" + " -- End of RTLD options\n" + " Name of process to execute\n" + " Arguments to the executed process\n", argv0); } /*