From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/13371 Path: news.gmane.org!.POSTED!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: [PATCH] __libc_start_main: slightly simplify stage2 pointer setup Date: Mon, 22 Oct 2018 13:45:59 -0400 Message-ID: <20181022174559.GO5150@brightrain.aerifal.cx> References: <20181020212744.2906-1-amonakov@ispras.ru> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: blaine.gmane.org 1540230249 23597 195.159.176.226 (22 Oct 2018 17:44:09 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 22 Oct 2018 17:44:09 +0000 (UTC) User-Agent: Mutt/1.5.21 (2010-09-15) To: musl@lists.openwall.com Original-X-From: musl-return-13387-gllmg-musl=m.gmane.org@lists.openwall.com Mon Oct 22 19:44:05 2018 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1gEeFI-00063J-R8 for gllmg-musl@m.gmane.org; Mon, 22 Oct 2018 19:44:04 +0200 Original-Received: (qmail 11733 invoked by uid 550); 22 Oct 2018 17:46:13 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 11715 invoked from network); 22 Oct 2018 17:46:12 -0000 Content-Disposition: inline In-Reply-To: <20181020212744.2906-1-amonakov@ispras.ru> Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:13371 Archived-At: 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