Building a.out executables on FreeBSD 3.x

Building a.out executables on FreeBSD 3.x

Post by Carl Masco » Mon, 15 Nov 1999 04:00:00



Apparently folks are still having trouble with this.
This should help.

        BUILDING AN A.OUT EXECUTABLE FROM HELLO.C ON FREEBSD 3

Tested on FreeBSD 3.3-R

Get the following files from /usr/lib on a FreeBSD 2.2 system and
put them in the working directory:

crt0.o
libgcc.a

% setenv OBJFORMAT aout
% cc -c hello.c
% /usr/libexec/aout/ld -e start -dc -dp -o hello crt0.o hello.o libgcc.a
        -L/usr/lib/compat/aout -lc libgcc.a

NOTE 1: "cc -o" cannot be used because it uses /usr/lib/libgcc.a, which
is elf rather than aout.  Note also that "cc -o" looks for crt0.o
in the current directory.  You can see the link command that "cc -o"
uses by adding the -v option.

NOTE 2: If you use additional cc options you may need other *crt*.o
files.  You may also need libgcc_p.a or libgcc_pic.a.

NOTE 3: If you are doing this a lot, put the link command in a
shell script or something.  Better yet, fix the gcc compiler
driver and submit a PR with the fix.

NOTE 4: I have an empty /usr/lib/aout directory on my system
(after a binary install of 3.3-R).  I suspect that's the
"official" home of the 2.2 *crt*.o and libgcc*.a files.
--
Carl Mascott

uunet!world!cmascott

 
 
 

Building a.out executables on FreeBSD 3.x

Post by Steven G. Kar » Mon, 15 Nov 1999 04:00:00




Quote:

> % setenv OBJFORMAT aout
> % cc -c hello.c
> % /usr/libexec/aout/ld -e start -dc -dp -o hello crt0.o hello.o libgcc.a
>    -L/usr/lib/compat/aout -lc libgcc.a

> NOTE 1: "cc -o" cannot be used because it uses /usr/lib/libgcc.a, which
> is elf rather than aout.  Note also that "cc -o" looks for crt0.o
> in the current directory.  You can see the link command that "cc -o"
> uses by adding the -v option.

Does "cc -nostdlib -o .... -L/usr/lib/aout -lc" work?

I don't have a 3.3 system to try this on, but the -nostdlib should
ignore the standard library directories.

Quote:> NOTE 4: I have an empty /usr/lib/aout directory on my system
> (after a binary install of 3.3-R).  I suspect that's the
> "official" home of the 2.2 *crt*.o and libgcc*.a files.

You probably need to install one or more of the compatibility
parts.  In the FreeBSD-4.0 source tree, these are found in
src/lib/compat.

--
Steve

 
 
 

Building a.out executables on FreeBSD 3.x

Post by Carl Masco » Tue, 16 Nov 1999 04:00:00






>> % setenv OBJFORMAT aout
>> % cc -c hello.c
>> % /usr/libexec/aout/ld -e start -dc -dp -o hello crt0.o hello.o libgcc.a
>>        -L/usr/lib/compat/aout -lc libgcc.a

>> NOTE 1: "cc -o" cannot be used because it uses /usr/lib/libgcc.a, which
>> is elf rather than aout.  Note also that "cc -o" looks for crt0.o
>> in the current directory.  You can see the link command that "cc -o"
>> uses by adding the -v option.

>Does "cc -nostdlib -o .... -L/usr/lib/aout -lc" work?

No.  I tried it.  This tells the compiler to search for libc in a directory
that is empty, as I said in Note 4.

Quote:>> NOTE 4: I have an empty /usr/lib/aout directory on my system
>> (after a binary install of 3.3-R).  I suspect that's the
>> "official" home of the 2.2 *crt*.o and libgcc*.a files.

>You probably need to install one or more of the compatibility
>parts.  In the FreeBSD-4.0 source tree, these are found in
>src/lib/compat.

I should have said that I have the compat22 binary distribution
installed.  This distribution contains the pieces needed to RUN
a.out executables, but not the pieces needed to BUILD them.
This distribution does not install anything in /usr/lib/aout.

With OBJFORMAT=aout in the environment, here's the
link command that "cc -o hello hello.o" produces:

gcc version 2.7.2.3
 /usr/libexec/aout/ld -e start -dc -dp -o hello crt0.o -L/usr/libdata/gcc
-L/usr/lib/aout hello.o /usr/lib/libgcc.a -lc /usr/lib/libgcc.a
ld: /usr/lib/libgcc.a(): bad magic

Here's what's wrong with this link command:

1. It expects crt0.o to be in the current directory.

2. It tries to link /usr/lib/libgcc.a, which is ELF.

3. It doesn't look for the aout libc where it actually lives:
    /usr/lib/compat/aout.

(Note that the linker does not search for files specified
by filename, only for files specified with -l options.)

As I said, even with the compat22 binary distribution
installed, the a.out *crt*.o and libgcc*.a files don't even
exist on the system.

I hope I have now explained all of this clearly.
The workaround I gave should enable folks to build
a.out's on FBSD 3.x.  If you'll excuse me, I have to
"sign off" from this thread now.

--
Carl Mascott

 
 
 

Building a.out executables on FreeBSD 3.x

Post by Cyrille Lefevr » Thu, 18 Nov 1999 04:00:00



> Apparently folks are still having trouble with this.
> This should help.

>         BUILDING AN A.OUT EXECUTABLE FROM HELLO.C ON FREEBSD 3

> Tested on FreeBSD 3.3-R

> Get the following files from /usr/lib on a FreeBSD 2.2 system and
> put them in the working directory:

> crt0.o
> libgcc.a

> % setenv OBJFORMAT aout
> % cc -c hello.c
> % /usr/libexec/aout/ld -e start -dc -dp -o hello crt0.o hello.o libgcc.a
>         -L/usr/lib/compat/aout -lc libgcc.a

> NOTE 1: "cc -o" cannot be used because it uses /usr/lib/libgcc.a, which
> is elf rather than aout.  Note also that "cc -o" looks for crt0.o
> in the current directory.  You can see the link command that "cc -o"
> uses by adding the -v option.

you are wrong.

Quote:> NOTE 2: If you use additional cc options you may need other *crt*.o
> files.  You may also need libgcc_p.a or libgcc_pic.a.

well.

Quote:> NOTE 3: If you are doing this a lot, put the link command in a
> shell script or something.  Better yet, fix the gcc compiler
> driver and submit a PR with the fix.

see below.

Quote:> NOTE 4: I have an empty /usr/lib/aout directory on my system
> (after a binary install of 3.3-R).  I suspect that's the
> "official" home of the 2.2 *crt*.o and libgcc*.a files.

serious things begins now :)

you are luky, I'm just looking how to make a.out file.
I need it to compile something...

first, you need the startup object files :

cd /usr/src/lib/csu/i386
make clean
OBJFORMAT=aout make
install -c -o root -g wheel -m 444 crt0.o c++rt0.o gcrt0.o scrt0.o sgcrt0.o  /us
r/lib/aout
make clean

also, a libgcc in a.out format :

[ -d /usr/obj ] && mv /usr/obj /usr/obj-
cd /usr/src/gnu/usr.bin/cc/libgcc
make clean
OBJFORMAT=aout make
install -c -o root -g wheel -m 444   libgcc.a /usr/lib/aout
install -c -o root -g wheel -m 444   libgcc_pic.a /usr/lib/aout
make clean
[ -d /usr/obj- ] && mv /usr/obj- /usr/obj

never do a make install, this will override your elf objects and libraries :(

if you really need to modify the "specs" file :

gcc -dumpspecs > /usr/libdata/gcc/specs
gcc -dumpspecs > /usr/libdata/gcc/aout/specs

rm -f /usr/bin/gcc-aout
cat > /usr/bin/gcc-aout << 'EOF'
#!/bin/sh -x

LIBRARY_PATH=/usr/lib/compat/aout
export LIBRARY_PATH

if [ -n "$AOUT_LIBRARY_PATH" ]; then
        LIBRARY_PATH=/usr/lib/compat/aout:${AOUT_LIBRARY_PATH}
fi

case " $*" in *" -v "*)
echo LIBRARY_PATH=$LIBRARY_PATH

;; esac


EOF
chmod +x /usr/bin/gcc-aout

you need the -B option to reach the specs file and the LIBRARY_PATH
to reach the a.out shared libraries. the COMPILER_PATH not seems to be
needed. you can use the AOUT_LIBRARY_PATH to complete the library
search path. so, this will not conflict with the LIBRARY_PATH reserved
for the elf use.

now, do whatever you want in the "specs" file in /usr/libdata/aout/specs

a simple test prog...

root# cd /tmp
root# cat > c.c << EOF
#include <math.h>
main () { printf ("hello world : %f\n", cos(M_PI)); return; }
EOF

in a.out format...

root# gcc-aout -v -o c c.c -lm
LIBRARY_PATH=/usr/lib/compat/aout
gcc -B/usr/libdata/gcc/aout/ -aout -v -o c c.c -lm
Reading specs from /usr/libdata/gcc/aout/specs
gcc version 2.7.2.3
 /usr/libexec/cpp -lang-c -v -isystem /usr/libdata/gcc/aout/include -undef -D__G
NUC__=2 -D__GNUC_MINOR__=7 -Dunix -Di386 -D__FreeBSD__=3 -D__FreeBSD_cc_version=
330001 -D__unix__ -D__i386__ -D__FreeBSD__=3 -D__FreeBSD_cc_version=330001 -D__u
nix -D__i386 -Asystem(unix) -Asystem(FreeBSD) -Acpu(i386) -Amachine(i386) -D__UN
DERSCORES__ c.c /var/tmp/ccc37531.i
GNU CPP version 2.7.2.3 (i386 FreeBSD)
#include "..." search starts here:
#include <...> search starts here:
 /usr/libdata/gcc/aout/include
 /usr/include
End of search list.
 /usr/libexec/cc1 /var/tmp/ccc37531.i -munderscores -quiet -dumpbase c.c -maout
-version -o /var/tmp/ccc37531.s
GNU C version 2.7.2.3 (i386 FreeBSD) compiled by GNU C version 2.7.2.1.
 /usr/libexec/aout/as -v -o /var/tmp/ccc375311.o /var/tmp/ccc37531.s
GNU assembler version 1.92.3, FreeBSD $Revision: 1.6 $
 /usr/libexec/aout/ld -e start -dc -dp -o c /usr/lib/aout/crt0.o -L/usr/libdata/
gcc/aout -L/usr/lib/compat/aout -L/usr/libdata/gcc/aout -L/usr/libdata/gcc -L/us
r/lib/aout /var/tmp/ccc375311.o -lm /usr/lib/aout/libgcc.a -lc /usr/lib/aout/lib
gcc.a

root# ./c
hello world : -1.000000

in elf format...

root# gcc -v -o c c.c -lm
Reading specs from /usr/libdata/gcc/specs
gcc version 2.7.2.3
 /usr/libexec/cpp -lang-c -v -undef -D__GNUC__=2 -D__GNUC_MINOR__=7 -Dunix -Di38
6 -D__FreeBSD__=3 -D__FreeBSD_cc_version=330001 -D__unix__ -D__i386__ -D__FreeBS
D__=3 -D__FreeBSD_cc_version=330001 -D__unix -D__i386 -Asystem(unix) -Asystem(Fr
eeBSD) -Acpu(i386) -Amachine(i386) -D__ELF__ c.c /var/tmp/ccE37537.i
GNU CPP version 2.7.2.3 (i386 FreeBSD)
#include "..." search starts here:
#include <...> search starts here:
 /usr/include
End of search list.
 /usr/libexec/cc1 /var/tmp/ccE37537.i -quiet -dumpbase c.c -version -o /var/tmp/
ccE37537.s
GNU C version 2.7.2.3 (i386 FreeBSD) compiled by GNU C version 2.7.2.1.
 /usr/libexec/elf/as -v -o /var/tmp/ccE375371.o /var/tmp/ccE37537.s
GNU assembler version 2.9.1 (i386-unknown-freebsdelf), using BFD version 2.9.1
 /usr/libexec/elf/ld -m elf_i386 -dynamic-linker /usr/libexec/ld-elf.so.1 -o c /
usr/lib/crt1.o /usr/lib/crti.o /usr/lib/crtbegin.o -L/usr/libdata/gcc /var/tmp/c
cE375371.o -lm /usr/lib/libgcc.a -lc /usr/lib/libgcc.a /usr/lib/crtend.o /usr/li
b/crtn.o

root# ./c
hello world : -1.000000

OUAOUHHH!

some usefull gcc options :

root# strings /usr/bin/gcc | grep -- ^-print

root# gcc -print-prog-name=ld
/usr/libexec/elf/ld
root# gcc-aout -print-prog-name=ld
/usr/libexec/aout/ld

root# gcc -print-multi-directory
elf
root# gcc-aout -print-multi-directory
aout

root# gcc -print-multi-lib

elf;
root# gcc-aout -print-multi-lib

elf;

root# gcc -print-libgcc-file-name
/usr/lib/libgcc.a
root# gcc-aout -print-libgcc-file-name
/usr/lib/aout/libgcc.a

root# gcc -print-file-name=specs
/usr/libdata/gcc/specs
root# gcc-aout -print-file-name=specs
/usr/libdata/gcc/aout/specs

root# gcc -print-search-dirs
install: /usr/libexec/(null)
programs: /usr/libexec/elf/:/usr/libexec/:/usr/bin/
libraries: /usr/libdata/gcc/:/usr/lib/

root# gcc-aout -print-search-dirs
install: /usr/libexec/(null)
programs: /usr/libdata/gcc/aout/:/usr/libexec/aout/:/usr/libexec/:/usr/bin/
libraries: /usr/libdata/gcc/aout/:/usr/lib/compat/aout/:/usr/libdata/gcc/:/usr/l
ib/

about the specs file, bcoz I'm using FreeBSD 3.3, I'm not able to
give you a good specs file for a.out building to put in your
/usr/libdata/aout. sorry :)

have fun and good luck!

Cyrille.
--


 
 
 

1. building static executables from dynamic executables on solaris

is it possible? ld gives me errors:

ldd /usr/bin/diff
        libc.so.1 =>     /usr/lib/libc.so.1
        libdl.so.1 =>    /usr/lib/libdl.so.1
        /usr/platform/SUNW,Sun-Fire-280R/lib/libc_psr.so.1

ld: fatal: file /usr/bin/diff: unknown file type
ld: fatal: File processing errors. No output written to diff.a

/usr/bin/diff:  ELF 32-bit MSB executable SPARC Version 1, dynamically linked, stripped


ld: fatal: file /usr/bin/diff: unknown file type
ld: fatal: File processing errors. No output written to diff.a

otherwise, is it possible to emacs the binary file and have it use
/ust/lib/libdl.so.1 /usr/platform/SUNW,Sun-Fire-280R/lib/libc_psr.so.1

instead of

/usr/lib/libdl.so.1 /usr/platform/SUNW,Sun-Fire-280R/lib/libc_psr.so.1

by changing setenv LD_LIBRARY_PATH, I could force it to use
  /ust/lib/libc.so.1  /ust/lib/libdl.so.1
but  could force it to use /usr/platform/SUNW,Sun-Fire-280R/lib/libc_psr.so.1

(/ust is mounted on a read only disk)

Thank you very much.
If you have any questions, please don't hesitate to contact me.
Thanks, Ghaouar Camij Toschian,
(please remove KeinSpam  from the email address )


Group / 386 Cory Hall / 510 643-6138

2. Anyone using mod_SNMP fpr Apache in an Enterprise Environment

3. How to build gcc2.7.1 with ELF & a.out support?

4. Slackware Installation with Fasttrak66

5. Building static executables under Solaris

6. telnet, logon as root

7. Building QT a.out lib on Linux

8. Pull the list from shadow passwd, any idea?

9. Building 3.0 kernel A.OUT??

10. Problem building tcl v7.5a2 as a.out shared lib

11. building ELF executables on NT system

12. Can I build static executables under AIX 3.2 ?

13. Building 64 bit executables in Solaris