How do you compile a C program in to a valid ELF format(or RAW format) so that it can be executed directly from RAM without any OS? Assume that a bootloader exists which is capable of loading the code to any location in RAM and start execution at that address? To be precise , what should be the compiler(GCC) flags? Is there a need for a map file?
A sample helloworld application would be most welcome :)
Just to elaborate my point,
let the main() method be an empty infinite while loop to ensure that no OS specific or standard library calls are used. The desired o/p is a hang. With the usual GCC options the bootloader would definitely fail to load the executable telling it is invalid ELF format. However by passing -dN option to the linker will make it a valid ELF. More compiler/linker options are required to make it hang and not crash!!  What exactly are those compiler options?
file.c:
int main()
{
    while(1);
}
Compilation
    gcc -c  -nostdinc -fno-builtin  file.c
    ld  -dN -nostdlib file.o  
Bootloader loads a.out to RAM and executes.