unofficial mirror of libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Adhemerval Zanella via Libc-alpha <libc-alpha@sourceware.org>
To: libc-alpha@sourceware.org, vmihalko@redhat.com
Subject: Re: [PATCH v3] ld.so: add an --argv0 option
Date: Tue, 1 Sep 2020 12:09:44 -0300	[thread overview]
Message-ID: <a6437fb4-4e66-b13a-7367-aaa6c191f39d@linaro.org> (raw)
In-Reply-To: <20200831132208.1174687-1-vmihalko@redhat.com>



On 31/08/2020 10:22, vincent via Libc-alpha wrote:
> From: Vincent Mihalkovic <vmihalko@redhat.com>
> 
> I hope everything is fine now, thanks for the feedback and help with
> the patch. I was writing the test case against this documentation:
> https://sourceware.org/glibc/wiki/Testing/Testsuite and could't find
> any documentation for libsupport, that's why I didn't use it.

On the 'Writing a test case' bullet it has a minimal example where it does
use libsupport and it also points the documentation at support/README-testing.c.
Maybe we can outline it is what we refer as libsupport on patch review.

LGTM with the elf/argv0test.c indentation fixed.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>

> 
> ---
>  elf/Makefile          | 13 +++++++++++--
>  elf/argv0test.c       | 32 ++++++++++++++++++++++++++++++++
>  elf/rtld.c            | 17 ++++++++++++++++-
>  elf/tst-rtld-argv0.sh | 37 +++++++++++++++++++++++++++++++++++++
>  4 files changed, 96 insertions(+), 3 deletions(-)
>  create mode 100644 elf/argv0test.c
>  create mode 100755 elf/tst-rtld-argv0.sh
> 
> diff --git a/elf/Makefile b/elf/Makefile
> index 0b787218..f38904d8 100644
> --- a/elf/Makefile
> +++ b/elf/Makefile
> @@ -210,7 +210,8 @@ tests += restest1 preloadtest loadfail multiload origtest resolvfail \
>  	 tst-filterobj tst-filterobj-dlopen tst-auxobj tst-auxobj-dlopen \
>  	 tst-audit14 tst-audit15 tst-audit16 \
>  	 tst-single_threaded tst-single_threaded-pthread \
> -	 tst-tls-ie tst-tls-ie-dlmopen
> +	 tst-tls-ie tst-tls-ie-dlmopen \
> +	 argv0test
>  #	 reldep9
>  tests-internal += loadtest unload unload2 circleload1 \
>  	 neededtest neededtest2 neededtest3 neededtest4 \

Ok.

> @@ -414,7 +415,7 @@ endif
>  ifeq (yes,$(build-shared))
>  ifeq ($(run-built-tests),yes)
>  tests-special += $(objpfx)tst-pathopt.out $(objpfx)tst-rtld-load-self.out \
> -		 $(objpfx)tst-rtld-preload.out
> +		 $(objpfx)tst-rtld-preload.out $(objpfx)argv0test.out
>  endif
>  tests-special += $(objpfx)check-textrel.out $(objpfx)check-execstack.out \
>  		 $(objpfx)check-wx-segment.out \

Ok.

> @@ -1796,3 +1797,11 @@ $(objpfx)tst-tls-ie-dlmopen.out: \
>    $(objpfx)tst-tls-ie-mod6.so
>  
>  $(objpfx)tst-tls-surplus: $(libdl)
> +
> +ARGV0 = test-argv0
> +$(objpfx)argv0test.out: tst-rtld-argv0.sh $(objpfx)ld.so \
> +			$(objpfx)argv0test
> +	$(SHELL) $< $(objpfx)ld.so $(objpfx)argv0test \
> +            '$(test-wrapper-env)' '$(run_program_env)' \
> +            '$(rpath-link)' '$(ARGV0)' > $@; \
> +    $(evaluate-test)

Ok.

> diff --git a/elf/argv0test.c b/elf/argv0test.c
> new file mode 100644
> index 00000000..6c6c7e9a
> --- /dev/null
> +++ b/elf/argv0test.c
> @@ -0,0 +1,32 @@
> +/* Test for --argv0 option ld.so.
> +
> +   Copyright (C) 2020 Free Software Foundation, Inc.
> +   This file is part of the GNU C Library.
> +
> +   The GNU C Library is free software; you can redistribute it and/or
> +   modify it under the terms of the GNU Lesser General Public
> +   License as published by the Free Software Foundation; either
> +   version 2.1 of the License, or (at your option) any later version.
> +
> +   The GNU C Library is distributed in the hope that it will be useful,
> +   but WITHOUT ANY WARRANTY; without even the implied warranty of
> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> +   Lesser General Public License for more details.
> +
> +   You should have received a copy of the GNU Lesser General Public
> +   License along with the GNU C Library; if not, see
> +   <https://www.gnu.org/licenses/>.  */
> +
> +#include <string.h>
> +#include <support/check.h>
> +
> +static int
> +do_test (int argc, char **argv)
> +{
> +    TEST_COMPARE_BLOB (argv[0], strlen (argv[0]),
> +                       "test-argv0", strlen ("test-argv0"));
> +return 0;
> +}
> +
> +#define TEST_FUNCTION_ARGV do_test
> +#include <support/test-driver.c>

Indentation seems off, use double space and align the 'return'.

> diff --git a/elf/rtld.c b/elf/rtld.c
> index 5b882163..e66e033c 100644
> --- a/elf/rtld.c
> +++ b/elf/rtld.c
> @@ -1202,6 +1202,8 @@ dl_main (const ElfW(Phdr) *phdr,
>  	 installing it.  */
>        rtld_is_main = true;
>  
> +      char *argv0 = NULL;
> +
>        /* Note the place where the dynamic linker actually came from.  */
>        GL(dl_rtld_map).l_name = rtld_progname;
>  
> @@ -1259,6 +1261,14 @@ dl_main (const ElfW(Phdr) *phdr,
>  	else if (! strcmp (_dl_argv[1], "--preload") && _dl_argc > 2)
>  	  {
>  	    preloadarg = _dl_argv[2];
> +	    _dl_skip_args += 2;
> +	    _dl_argc -= 2;
> +	    _dl_argv += 2;
> +	  }
> +	else if (! strcmp (_dl_argv[1], "--argv0") && _dl_argc > 2)
> +	  {
> +	    argv0 = _dl_argv[2];
> +
>  	    _dl_skip_args += 2;
>  	    _dl_argc -= 2;
>  	    _dl_argv += 2;

Ok.

> @@ -1292,7 +1302,8 @@ of this helper program; chances are you did not intend to run this program.\n\
>    --inhibit-rpath LIST  ignore RUNPATH and RPATH information in object names\n\
>  			in LIST\n\
>    --audit LIST          use objects named in LIST as auditors\n\
> -  --preload LIST        preload objects named in LIST\n");
> +  --preload LIST        preload objects named in LIST\n\
> +  --argv0 STRING        set argv[0] to STRING before running\n");
>  
>        ++_dl_skip_args;
>        --_dl_argc;
> @@ -1384,6 +1395,10 @@ of this helper program; chances are you did not intend to run this program.\n\
>  	    break;
>  	  }
>  #endif
> +
> +      /* Set the argv[0] string now that we've processed the executable.  */
> +      if (argv0 != NULL)
> +		_dl_argv[0] = argv0;
>      }
>    else
>      {

Ok.

> diff --git a/elf/tst-rtld-argv0.sh b/elf/tst-rtld-argv0.sh
> new file mode 100755
> index 00000000..14d97fb3
> --- /dev/null
> +++ b/elf/tst-rtld-argv0.sh
> @@ -0,0 +1,37 @@
> +#!/bin/sh
> +# Test for --argv0 option ld.so.
> +# Copyright (C) 2020 Free Software Foundation, Inc.
> +# This file is part of the GNU C Library.
> +#
> +# The GNU C Library is free software; you can redistribute it and/or
> +# modify it under the terms of the GNU Lesser General Public
> +# License as published by the Free Software Foundation; either
> +# version 2.1 of the License, or (at your option) any later version.
> +#
> +# The GNU C Library is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> +# Lesser General Public License for more details.
> +#
> +# You should have received a copy of the GNU Lesser General Public
> +# License along with the GNU C Library; if not, see
> +# <https://www.gnu.org/licenses/>.
> +
> +set -e
> +
> +rtld=$1
> +test_program=$2
> +test_wrapper_env=$3
> +run_program_env=$4
> +library_path=$5
> +argv0=$6
> +
> +echo "# [${test_wrapper_env}] [${run_program_env}] [$rtld] [--library-path]" \
> +     "[$library_path] [--argv0] [$argv0] [$test_program]"
> +${test_wrapper_env} \
> +${run_program_env} \
> +$rtld --library-path "$library_path" \
> +  --argv0 "$argv0" $test_program 2>&1 && rc=0 || rc=$?
> +echo "# exit status $rc"
> +
> +exit $rc
> 

Ok.

  reply	other threads:[~2020-09-01 15:09 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-12 11:06 [PATCH] ld.so: add an --argv0 option Vincent Mihalkovic via Libc-alpha
2020-08-25 15:10 ` Adhemerval Zanella via Libc-alpha
2020-08-26 11:53   ` [PATCH v2] " vmihalko--- via Libc-alpha
2020-08-26 13:55     ` Adhemerval Zanella via Libc-alpha
2020-08-31 13:22       ` [PATCH v3] " vincent via Libc-alpha
2020-09-01 15:09         ` Adhemerval Zanella via Libc-alpha [this message]
2020-09-14 14:17           ` [PATCH v4] " vincent via Libc-alpha
2020-09-14 15:03             ` Andreas Schwab
2020-09-14 21:32               ` [PATCH v5] " vincent via Libc-alpha
2020-09-23  6:06                 ` vincent via Libc-alpha
2020-09-24  9:53                   ` Florian Weimer via Libc-alpha
2020-09-24 12:43                     ` [PATCH v6] " vincent via Libc-alpha
2020-09-29  8:21                     ` vincent via Libc-alpha
2020-09-29 10:37                       ` Florian Weimer via Libc-alpha

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/libc/involved.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a6437fb4-4e66-b13a-7367-aaa6c191f39d@linaro.org \
    --to=libc-alpha@sourceware.org \
    --cc=adhemerval.zanella@linaro.org \
    --cc=vmihalko@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).