Generating a.out file format with GCC

18,292

Solution 1

To generate the a.out format with gcc, your linker needs to be told to do so. You can do it by passing it flags from gcc thanks to the -Wl flag.

Here is what you would do for the a.out format:

gcc -Wl,--oformat=a.out-i386-linux file.c -o file.out

You can also display all formats supported by typing:

objdump -i

Solution 2

According to the post Re: How can I control the gcc's output format?, you need to build gcc for a different target (i386-aout).

It sounds plausible as a.out has been deprecated for years (10+).

Share:
18,292
Nulik
Author by

Nulik

A C developer, obsessed with performance. Contact for development on blockchain platforms: [email protected]

Updated on July 01, 2022

Comments

  • Nulik
    Nulik almost 2 years

    How do I generate the a.out file format with GCC on x86 architectures?

    With NASM I can do this easily with the -f flag, for example:

    nasm -f aout start.asm
    objdump -a start.o
    
    start.o:     file format a.out-i386-linux
    start.o
    

    On Linux, compiling .c files produces an ELF object file. How can I produce a.out files with GCC?

  • Nulik
    Nulik over 12 years
    I am developing an operating system and I need kernel and applications to be packed together in one image file so it is loaded quickly with one read and one write (the whole image) , a.out looks to be the ideal format for this, being simple and supported by a lot of bootloaders.
  • Nulik
    Nulik over 12 years
    the problem is, I have many object files (.o) which are in elf format, so when I link them with OUTPUT_FORMAT(a.out-i386-linux) parameter in the linker script i get this error: "can not represent section `.comment' in a.out object file format". This is why I need the "gcc -c file.c" being compiled from the beginning into a.out format, and not ELF.
  • Nulik
    Nulik over 12 years
    I found the solution to the above, with -fno-ident option .comment section wasn't generated, i booted my a.out kernel fine with grub. thanks
  • Quentin Casasnovas
    Quentin Casasnovas over 12 years
    Sorry I missed your first comment, and glad that you found the fix yourself :)