mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: musl@lists.openwall.com
Subject: Re: [PATCH] __libc_start_main: slightly simplify stage2 pointer setup
Date: Mon, 22 Oct 2018 13:45:59 -0400	[thread overview]
Message-ID: <20181022174559.GO5150@brightrain.aerifal.cx> (raw)
In-Reply-To: <20181020212744.2906-1-amonakov@ispras.ru>

On Sun, Oct 21, 2018 at 12:27:44AM +0300, Alexander Monakov wrote:
> Use "+r" in the asm instead of implementing a non-transparent copy by
> applying "0" constraint to the source value. Introduce a typedef for
> the function type to avoid spelling it out twice.
> ---
> 
> I didn't get credited in the asm bugfix, but I still want to leave my mark ;)
> 
> Thanks.
> Alexander
> 
>  src/env/__libc_start_main.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/src/env/__libc_start_main.c b/src/env/__libc_start_main.c
> index b4965d7f..7c95f822 100644
> --- a/src/env/__libc_start_main.c
> +++ b/src/env/__libc_start_main.c
> @@ -66,7 +66,8 @@ static void libc_start_init(void)
>  
>  weak_alias(libc_start_init, __libc_start_init);
>  
> -static int libc_start_main_stage2(int (*)(int,char **,char **), int, char **);
> +typedef int lsm2_fn(int (*)(int,char **,char **), int, char **);
> +static lsm2_fn libc_start_main_stage2;
>  
>  int __libc_start_main(int (*main)(int,char **,char **), int argc, char **argv)
>  {
> @@ -79,8 +80,8 @@ int __libc_start_main(int (*main)(int,char **,char **), int argc, char **argv)
>  
>  	/* Barrier against hoisting application code or anything using ssp
>  	 * or thread pointer prior to its initialization above. */
> -	int (*stage2)(int (*)(int,char **,char **), int, char **);
> -	__asm__ ( "" : "=r"(stage2) : "0"(libc_start_main_stage2) : "memory" );
> +	lsm2_fn *stage2 = libc_start_main_stage2;
> +	__asm__ ( "" : "+r"(stage2) : : "memory" );
>  	return stage2(main, argc, argv);
>  }
>  
> -- 
> 2.11.0

This looks better, especially the aspect of using the typedef'd
function type for DRY (assignment to an explicitly declared function
pointer with the right argument type would also achieve that, but
would involve repetition). If nobody objects I'll apply this very
soon, once I get through with some unrelated queued changes.

Rich


      reply	other threads:[~2018-10-22 17:45 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-20 21:27 Alexander Monakov
2018-10-22 17:45 ` Rich Felker [this message]

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

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

  git send-email \
    --in-reply-to=20181022174559.GO5150@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=musl@lists.openwall.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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

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 NNTP newsgroup(s).