This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[COMMITTED PATCH] NaCl: Call __nacl_main in preference to main.
- From: Roland McGrath <roland at hack dot frob dot com>
- To: "GNU C. Library" <libc-alpha at sourceware dot org>
- Date: Tue, 25 Aug 2015 13:41:00 -0700 (PDT)
- Subject: [COMMITTED PATCH] NaCl: Call __nacl_main in preference to main.
- Authentication-results: sourceware.org; auth=none
The norm for NaCl C libraries is to call __nacl_main if it's defined,
rather than main. This allows for libraries that wrap an application's
original main function.
I've also cherry-picked this onto the 2.22 branch.
Thanks,
Roland
2015-08-25 Roland McGrath <roland@hack.frob.com>
* sysdeps/nacl/start.c (_start): Call __nacl_main instead of main
if the weak reference is not null.
diff --git a/sysdeps/nacl/start.c b/sysdeps/nacl/start.c
index a4b6dd3..8e8bc1a 100644
--- a/sysdeps/nacl/start.c
+++ b/sysdeps/nacl/start.c
@@ -44,6 +44,10 @@
/* The application defines this, of course. */
extern int main (int argc, char **argv, char **envp);
+/* But maybe it defines this too, in which case it takes precedence. */
+extern int __nacl_main (int argc, char **argv, char **envp)
+ __attribute__ ((weak));
+
/* These are defined in libc. */
extern int __libc_csu_init (int argc, char **argv, char **envp);
extern void __libc_csu_fini (void);
@@ -59,7 +63,7 @@ _start (uint32_t info[])
{
/* The generic code actually assumes that envp follows argv. */
- __libc_start_main (&main,
+ __libc_start_main (&__nacl_main ?: &main,
nacl_startup_argc (info),
nacl_startup_argv (info),
nacl_startup_auxv (info),