On Mon, 30 Mar 2009 11:15:30 +0100 Martin Guy <[email protected]> wrote:
> On 3/30/09, Christopher Friedt <[email protected]> wrote:
> > I'm writing code in C for a very small static binary, and the code
> > doesn't use any headers or rely on any other libraries.
>
> > I've noticed that there is a lot of static libc junk built into my
> > binary build my program with options like -nostdlib -nodefaultlibs
> > -nostartfiles, I get an error that says
> >
> > warning: cannot find entry symbol _start; defaulting to
> > 000000000000008074
>
> These days it is fairly hard, and system- and architecture-dependent,
> to get a minimal binary from a C program.
I don't know if arm is different, but I used the following on i386 to get flat
binary that does not require any runtime support:
1. provide void _start(void) instead of main()
2. use LD and OBJCOPY directly:
IMAGE = image
IMAGE_OFFSET = 0x20000
CC = gcc
LD = ld
OBJCOPY = objcopy
CFLAGS = -march=i486 -O2 -fomit-frame-pointer -pipe -Wall
LDFLAGS = -m elf_i386 -Ttext $(IMAGE_OFFSET) -T
OBJCOPYFLAGS = -O binary
LIBS = ./../libucos.a /usr/lib/libc.a
INCL = -I./../
OBJS = main.o
all: $(IMAGE)
$(IMAGE): $(OBJS) $(LIBS) ./../_startup.o
$(LD) $(LDFLAGS) $(LIBS) $(OBJS) -o $(IMAGE).linked
$(OBJCOPY) $(OBJCOPYFLAGS) $(IMAGE).linked $(IMAGE)
@chmod -x image
@rm -f $(IMAGE).linked
3. ucos-ldscript linker script is stock ldscript modified to
SEARCH_DIR(/home/arkadi/work/ucos-gcc);
STARTUP(_startup.o) # my _start() is in _startup.c
comment out all ALIGN()
use different offset (that depends on loader and memory layout)
SECTIONS
{
/* Read-only sections, merged into text segment: */
/*. = 0x08048000 + SIZEOF_HEADERS;*/
. = 0x00020000 + SIZEOF_HEADERS;
Time has passed since than, so things may changed.