summaryrefslogtreecommitdiff
path: root/libc/sysdeps/linux/i386
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2002-04-14 03:32:14 +0000
committerEric Andersen <andersen@codepoet.org>2002-04-14 03:32:14 +0000
commit5ce9147ea3796f0dca7f8fffce8b4c398eb08915 (patch)
tree2be24c643076c82822ab78c0bd07ab74a48ec9f0 /libc/sysdeps/linux/i386
parented44f35a1aa84c6e42dac46aab75e9f8fcc6d7b7 (diff)
Manuel and I were looking into a problem with applications failing to link
(undefined reference to `main') when the .o file containing main was contained in an static library(a '.a' ar archive). It turns out that due to its single pass nature, GNU ld was failing to pull it into the build. This sticks a dummy reference to main() into crt0.o, so that when an application is linked with the main() function in a static library, we can be sure that main() actually gets linked in. -Erik
Diffstat (limited to 'libc/sysdeps/linux/i386')
-rw-r--r--libc/sysdeps/linux/i386/crt0.S6
-rw-r--r--libc/sysdeps/linux/i386/crt0.c1
2 files changed, 7 insertions, 0 deletions
diff --git a/libc/sysdeps/linux/i386/crt0.S b/libc/sysdeps/linux/i386/crt0.S
index 9e2c101e5..05d2704ba 100644
--- a/libc/sysdeps/linux/i386/crt0.S
+++ b/libc/sysdeps/linux/i386/crt0.S
@@ -77,3 +77,9 @@ _start:
/* Ok, now run uClibc's main() -- shouldn't return */
call __uClibc_main
+/* Stick in a dummy reference to main(), so that if an application
+ * is linking when the main() function is in a static library (.a)
+ * we can be sure that main() actually gets linked in */
+L_dummy_main_reference:
+ .long main
+
diff --git a/libc/sysdeps/linux/i386/crt0.c b/libc/sysdeps/linux/i386/crt0.c
index 6e39caa7c..8e55e5895 100644
--- a/libc/sysdeps/linux/i386/crt0.c
+++ b/libc/sysdeps/linux/i386/crt0.c
@@ -32,6 +32,7 @@ void _start(unsigned int first_arg)
argc = *(stack - 1);
argv = (char **) stack;
envp = (char **)stack + argc + 1;
+ volatile void (*mainp)(int argc,void *argv,void *envp) = main;
__uClibc_main(argc, argv, envp);
}