Gentoo Archives: gentoo-embedded

From: Martin Guy <martinwguy@×××××.it>
To: gentoo-embedded@l.g.o
Subject: Re: [gentoo-embedded] gcc question - entry point problem in small, static app
Date: Mon, 30 Mar 2009 10:15:33
Message-Id: 56d259a00903300315y26fd33d7u168fa4baef6129cd@mail.gmail.com
In Reply to: [gentoo-embedded] gcc question - entry point problem in small, static app by Christopher Friedt
1 On 3/30/09, Christopher Friedt <chrisfriedt@×××××.com> wrote:
2 > I'm writing code in C for a very small static binary, and the code
3 > doesn't use any headers or rely on any other libraries.
4
5 > I've noticed that there is a lot of static libc junk built into my binary
6 > build my program with options like -nostdlib -nodefaultlibs
7 > -nostartfiles, I get an error that says
8 >
9 > warning: cannot find entry symbol _start; defaulting to 000000000000008074
10
11 These days it is fairly hard, and system- and architecture-dependent,
12 to get a minimal binary from a C program.
13 For example, with GCC/glibc _start() is in /usr/lib/crt1.o, and that
14 is what sets up the environment variables, fills in argc and argv ,
15 calls main() and arranges to call the stdio function exit() if main()
16 returns.
17
18 It used to be (1985 BSD VAX) that if you only used Unix system calls
19 and included a function exit(n){_exit(n);} that would be enough to
20 prevent stdio from being pulled in, for objects of a few hundred
21 bytes.
22
23 "gcc -v" will tell you what it is raking in by default. You can play
24 with providing _start yourself, omitting /usr/lib/crt*.o and making
25 sure you call _exit() yourself. It's an interesting journey.
26
27 Some other people's trips can be relived by googling "tiny elf binary"
28
29 M

Replies

Subject Author
Re: [gentoo-embedded] gcc question - entry point problem in small, static app Arkadi Shishlov <arkadi.shishlov@×××××.com>