lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <90fdd255-32f4-4caf-90ff-06456b53dac3@t-8ch.de>
Date:   Sun, 9 Jul 2023 23:00:40 +0200
From:   Thomas Weißschuh <thomas@...ch.de>
To:     Zhangjin Wu <falcon@...ylab.org>
Cc:     w@....eu, arnd@...db.de, linux-kernel@...r.kernel.org,
        linux-kselftest@...r.kernel.org
Subject: Re: [PATCH v2 04/12] tools/nolibc: crt.h: add _start_c

On 2023-07-09 20:49:10+0200, Thomas Weißschuh wrote:
> On 2023-07-08 23:29:58+0800, Zhangjin Wu wrote:

> [..]

> > ---
> >  tools/include/nolibc/crt.h | 44 ++++++++++++++++++++++++++++++++++++++
> >  1 file changed, 44 insertions(+)
> > 
> > diff --git a/tools/include/nolibc/crt.h b/tools/include/nolibc/crt.h
> > index 221b7c5346ca..b269294e9664 100644
> > --- a/tools/include/nolibc/crt.h
> > +++ b/tools/include/nolibc/crt.h
> > @@ -13,4 +13,48 @@

> [..]

> >  const unsigned long *_auxv __attribute__((weak));
> >  
> > +int main(int argc, char *argv[], char **envp);
> 
> This will lead to conflicting declarations if the users use a different
> signature. I'm not (yet?) sure how to work around this.
> 
> Also how is the case handled where main() returns "void"?
> I'm not sure how this is currently handled or if the compiler takes core
> of returning 0 in this case.

I looked into this some more.

The diff below allows it to accept different signatures for main().
(Maybe you can improve the naming)

Implicit return values seem to be handled by the compiler automatically.
In C89 mode we get garbage values, in C2X/C23 we get zero.
As per the respective C specs.


diff --git a/tools/include/nolibc/crt.h b/tools/include/nolibc/crt.h
index b269294e9664..dba40bc9413f 100644
--- a/tools/include/nolibc/crt.h
+++ b/tools/include/nolibc/crt.h
@@ -13,7 +13,6 @@
 char **environ __attribute__((weak));
 const unsigned long *_auxv __attribute__((weak));
 
-int main(int argc, char *argv[], char **envp);
 static void exit(int);
 
 void _start_c(long *sp)
@@ -21,6 +20,7 @@ void _start_c(long *sp)
 	int argc, i;
 	char **argv;
 	char **envp;
+	int _nolibc_main_alias(int, char**, char**) __asm__("main");
 
 	/*
 	 * sp  :  argc          <-- argument count, required by main()
@@ -54,7 +54,7 @@ void _start_c(long *sp)
 	_auxv = (void *)(envp + i + 1);
 
 	/* go to application */
-	exit(main(argc, argv, envp));
+	exit(_nolibc_main_alias(argc, argv, envp));
 }
 
 #endif /* _NOLIBC_CRT_H */

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ