1 |
I'm sure many of you have run into this problem at some point, so here goes: |
2 |
|
3 |
I'm writing code in C for a very small static binary, and the code |
4 |
doesn't use any headers or rely on any other libraries. It's quite |
5 |
tiny and only does a very specific job - it initializes a uart and |
6 |
repeatedly prints a message out in an infinite loop. It's intended to |
7 |
be run by the bootloader instead of a kernel to test out the uart |
8 |
hardware. |
9 |
|
10 |
When I'm compiling the code, I'm using |
11 |
|
12 |
arm-softfloat-linux-gnueabi-gcc -Wall -fomit-frame-pointer -pipe -Os |
13 |
-march=armv5te -static -o hello_uart hello_uart.c |
14 |
|
15 |
That compiles fine, but I've noticed that there is a lot of static |
16 |
libc junk built into my binary, several hundred kilobytes worth of |
17 |
junk, and I know for a fact that I don't need it. However, when I |
18 |
build my program with options like -nostdlib -nodefaultlibs |
19 |
-nostartfiles, I get an error that says |
20 |
|
21 |
warning: cannot find entry symbol _start; defaulting to 000000000000008074 |
22 |
|
23 |
How is a program like the one below supposed to be compiled in order |
24 |
to get a static, executable chunk of arm machine code? |
25 |
|
26 |
I guess main() shouldn't even be there. Do I need to write everything |
27 |
in assembler, and just link some sort of entry in a .S file, and then |
28 |
link main.o with func.o ? I was sort of hoping that it would "just |
29 |
work" in C without having to resort to anything slightly more tedious. |
30 |
|
31 |
Any thoughts would be appreciated |
32 |
|
33 |
C |
34 |
|
35 |
================== |
36 |
|
37 |
// some defines used in the setup and puts functions |
38 |
#define X 1 |
39 |
#define Y 2 |
40 |
|
41 |
static void uart_puts( char * s ) { |
42 |
// puts code |
43 |
} |
44 |
|
45 |
static void uart_setup() { |
46 |
// setup uart |
47 |
} |
48 |
|
49 |
int main() { |
50 |
uart_setup(); |
51 |
while(1) |
52 |
puts( "Hello, UART World!\n\r" ); |
53 |
// never really returns |
54 |
return 0; |
55 |
} |