This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
[PATCH] arm/linux-crt0.c: New file
- From: "Shaun Jackman" <sjackman at gmail dot com>
- To: newlib at sources dot redhat dot com
- Date: Thu, 29 Jun 2006 11:54:03 -0600
- Subject: [PATCH] arm/linux-crt0.c: New file
- Reply-to: "Shaun Jackman" <sjackman at gmail dot com>
This patch replaces the arm/linux-crt0 assembler source file with a C
source file. Some inline assembler is used to switch to Thumb mode.
The purpose of this patch is to allow the compiler to generate the
correct relocation for environ when compiling PIC code. As a bonus,
the C source file is also shorter and easier to read. Alright to
commit?
Cheers,
Shaun
2006-06-29 Shaun Jackman <sjackman@gmail.com>
* arm/linux-crt0.S: Remove file.
* arm/linux-crt0.c: New file. Supports PIC code.
--- /dev/null 2006-06-25 13:04:47.285393520 -0600
+++ arm/linux-crt0.c 2006-06-29 11:43:50.000000000 -0600
@@ -0,0 +1,39 @@
+/** Linux startup code for the ARM processor.
+ * Written by Shaun Jackman <sjackman@gmail.com>.
+ * Copyright 2006 Pathway Connectivity
+ *
+ * Permission to use, copy, modify, and distribute this software
+ * is freely granted, provided that this notice is preserved.
+ */
+
+#include <stdlib.h>
+#include <unistd.h>
+
+static int _main(int argc, char *argv[]) __attribute__((noreturn));
+
+#if __thumb__
+asm("\n"
+ ".code 32\n"
+ ".global _start\n"
+ ".type _start, %function\n"
+ "_start:\n"
+ "\tadr r0, _start_thumb+1\n"
+ "\tbx r0\n"
+ ".size _start, .-_start\n");
+
+__attribute__((naked, used))
+static void _start_thumb(void)
+#else
+__attribute__((naked))
+void _start(void)
+#endif
+{
+ register int *sp asm("sp");
+ _main(*sp, (char **)(sp + 1));
+}
+
+static int _main(int argc, char *argv[])
+{
+ environ = argv + argc + 1;
+ exit(main(argc, argv, environ));
+}