Browse Source

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

Eric Andersen 23 years ago
parent
commit
5ce9147ea3

+ 6 - 0
libc/sysdeps/linux/arm/crt0.S

@@ -92,3 +92,9 @@ _start:
 	/* Ok, now run uClibc's main() -- shouldn't return */
 	bl	__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
+

+ 8 - 0
libc/sysdeps/linux/h8300/crt0.S

@@ -53,3 +53,11 @@ empty_func:
 	.set atexit,empty_func
 #endif
 
+
+/* 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
+
+

+ 6 - 0
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
+

+ 1 - 0
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);
 }

+ 7 - 0
libc/sysdeps/linux/m68k/crt0.S

@@ -60,3 +60,10 @@ empty_func:
 	.set atexit,empty_func
 #endif
 
+
+/* 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
+

+ 1 - 0
libc/sysdeps/linux/m68k/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);
 }

+ 6 - 0
libc/sysdeps/linux/mips/crt0.S

@@ -34,3 +34,9 @@ __start:
 	jal	__uClibc_main
 	hlt:    b hlt                   /* Crash if somehow it does return.  */
 
+/* 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
+

+ 7 - 1
libc/sysdeps/linux/powerpc/crt0.S

@@ -54,4 +54,10 @@ _start:
 	add	5,5,0
 
 	bl	__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
+

+ 4 - 0
libc/sysdeps/linux/powerpc/crt0.c

@@ -53,6 +53,10 @@ void _start2(void)
 		p=((void *)p)+0x10;
 		argc=*(int *)p;
 	}
+	/* 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 */
+	volatile void (*mainp)(int argc,void *argv,void *envp) = main;
 
 	__uClibc_main(argc,p+1,p+2+argc);
 }

+ 7 - 0
libc/sysdeps/linux/sh/crt0.S

@@ -92,4 +92,11 @@ L_main:
 L_abort:
 	.long	abort
 
+/* 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
+
 	.data
+

+ 5 - 0
libc/sysdeps/linux/sparc/crt0.c

@@ -32,6 +32,11 @@ void _start(unsigned int first_arg)
 	argc = *(stack - 1);
 	argv = (char **) stack;
 	envp = (char **)stack + argc + 1;
+	
+	/* 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 */
+	volatile void (*mainp)(int argc,void *argv,void *envp) = main;
 
 	__uClibc_main(argc, argv, envp);
 }

+ 7 - 0
libc/sysdeps/linux/v850/crt0.S

@@ -50,3 +50,10 @@ C_ENTRY(start):
 
 	// should never get here....
 	jr	C_SYMBOL_NAME(abort)
+
+/* 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
+