Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to generate an 'a.out' format executable file with gcc/binutils?

895 views
Skip to first unread message

Alan Camus

unread,
Apr 19, 2006, 7:01:47 AM4/19/06
to
Hi, everyone,

I'm running Fedora Core 4 Linux, bintuils 2.16, and gcc-4.0. Can I
generate an a.out executable file under this circumstances ? Thanks.

Alan Camus <albc...@gmail.com>

John Reiser

unread,
Apr 19, 2006, 10:29:54 AM4/19/06
to
> I'm running Fedora Core 4 Linux, bintuils 2.16, and gcc-4.0. Can I
> generate an a.out executable file under this circumstances ? Thanks.

Run "info ld" and search for the "--oformat <format>" optional argument to ld.
This may be specified by an invocation such as "gcc -Wl,--oformat,<format>".
Run "objdump -i" and notice 'a.out-i386-linux' as one of the formats
that is supported by libbfd.

--

Alan Camus

unread,
Apr 20, 2006, 5:43:56 AM4/20/06
to
John Reiser 写道:

Thank you. I've try this method before the post, but got results as this:


[root@localhost test]# cat hello.c
#include <stdlib.h>
#include <stdio.h>

int main()
{
printf("hello from %s\n", __FILE__);
return 0;
}

[root@localhost test]# gcc -Wl,--oformat,a.out-i386-linux hello.c
/usr/lib/gcc/i386-redhat-linux/4.0.2/libgcc_s.so: could not read
symbols: File in wrong format
collect2: ld returned 1 exit status


Then I tried to compile and link statically, but failed one more:

[root@localhost test]# gcc -Wl,--oformat,a.out-i386-linux hello.c -static
/usr/bin/ld: a.out: can not represent section `.note.ABI-tag' in a.out
object file format
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: ld returned 1 exit status
[root@localhost test]#

Need I re-compile the GNU binutils (and gcc ? ) to enable `a.out'
generating ? or anything else could I do ?

Thanks again :-)
Alan Camus

Tauno Voipio

unread,
Apr 20, 2006, 3:25:10 AM4/20/06
to


If you're targeting a program executable in your Linux, you
may be out of luck here.

The shared libraries called by your program (libc, libgcc) expect
an ELF format executable. The a.out format cannot carry enough
information to link properly with them.

What are you attempting to achieve with a.out?

--

Tauno Voipio
tauno voipio (at) iki fi

Alan Camus

unread,
Apr 20, 2006, 11:39:49 AM4/20/06
to
Tauno Voipio 写道:

Thanks :-) I do not want anything special with `a.out', all the
motivation with this is that somebody has asked me, and I cannot provide
a solution :-)

Alan Camus <albc...@gmail.com>

Alan Camus

unread,
Apr 20, 2006, 11:41:56 AM4/20/06
to
Tauno Voipio 写道:

Yet another question, could I link my program and the essential
libraries (libc.a, libgcc.a) STATICALLY ?

Tauno Voipio

unread,
Apr 20, 2006, 12:39:14 PM4/20/06
to

Maybe. You need *all* the referenced libraries in static form.
And - there is no simple way to convert a shared library into a
static library.

You need a kernel able to load and execute the a.out binaries,
though. Static linking is very uneconomical from memory usage
standpoint, so there are good grounds to leave it for special
cases only.

Pete Zaitcev

unread,
Apr 21, 2006, 8:27:27 PM4/21/06
to
On Thu, 20 Apr 2006 15:39:49 +0000, Alan Camus wrote:

>> What are you attempting to achieve with a.out?
>
> Thanks :-) I do not want anything special with `a.out', all the
> motivation with this is that somebody has asked me, and I cannot provide
> a solution :-)

Ask them what the real application is. Don't be so gullible as
to throw a question on us and expect a solution. It won't happen
until we know what is actually required. For example, Sun bootstraps
in a.out format are generated with elftoaout(1).

And please trim your quotations.

-- Pete

Alan Camus

unread,
Apr 24, 2006, 6:26:03 AM4/24/06
to
Pete Zaitcev wrote:
>
> Ask them what the real application is. Don't be so gullible as
> to throw a question on us and expect a solution. It won't happen
> until we know what is actually required. For example, Sun bootstraps
> in a.out format are generated with elftoaout(1).
>
> And please trim your quotations.
>
> -- Pete
>
I'm sorry that I have made some tries( gcc with -Wl, objcopy,etc) but
have not post them here, and thanks to your advice I read "How To Ask
Questions The Smart Way" once again, I'll never make the same mistake
again. Thank you all.

Alan

0 new messages