public inbox for gentoo-embedded@lists.gentoo.org
 help / color / mirror / Atom feed
From: Christopher Friedt <chrisfriedt@gmail.com>
To: gentoo-embedded@lists.gentoo.org
Subject: [gentoo-embedded] gcc question - entry point problem in small, static app
Date: Mon, 30 Mar 2009 10:44:43 +0200	[thread overview]
Message-ID: <3ea34a000903300144l443a39fqfa5a2252db9b9e89@mail.gmail.com> (raw)

I'm sure many of you have run into this problem at some point, so here goes:

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. It's quite
tiny and only does a very specific job - it initializes a uart and
repeatedly prints a message out in an infinite loop. It's intended to
be run by the bootloader instead of a kernel to test out the uart
hardware.

When I'm compiling the code, I'm using

arm-softfloat-linux-gnueabi-gcc -Wall -fomit-frame-pointer -pipe -Os
-march=armv5te -static -o hello_uart hello_uart.c

That compiles fine, but I've noticed that there is a lot of static
libc junk built into my binary, several hundred kilobytes worth of
junk, and I know for a fact that I don't need it. However, when I
build my program with options like -nostdlib -nodefaultlibs
-nostartfiles, I get an error that says

warning: cannot find entry symbol _start; defaulting to 000000000000008074

How is a program like the one below supposed to be compiled in order
to get a static, executable chunk of arm machine code?

I guess main() shouldn't even be there. Do I need to write everything
in assembler, and just link some sort of entry in a .S file, and then
link main.o with func.o ? I was sort of hoping that it would "just
work" in C without having to resort to anything slightly more tedious.

Any thoughts would be appreciated

C

==================

// some defines used in the setup and puts functions
#define X 1
#define Y 2

static void uart_puts( char * s ) {
    // puts code
}

static void uart_setup() {
    // setup uart
}

int main() {
    uart_setup();
    while(1)
        puts( "Hello, UART World!\n\r" );
     // never really returns
     return 0;
}



             reply	other threads:[~2009-03-30  8:44 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-30  8:44 Christopher Friedt [this message]
2009-03-30 10:08 ` [gentoo-embedded] gcc question - entry point problem in small, static app Ahmed Ammar
2009-03-30 12:03   ` Christopher Friedt
2009-03-31  8:07     ` Mike Frysinger
2009-03-31 11:25       ` Christopher Friedt
2009-03-30 10:15 ` Martin Guy
2009-03-30 10:52   ` Arkadi Shishlov
2009-03-30 11:37     ` Peter Stuge

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3ea34a000903300144l443a39fqfa5a2252db9b9e89@mail.gmail.com \
    --to=chrisfriedt@gmail.com \
    --cc=gentoo-embedded@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox