[comp.os.minix] compiling MINIX programs with MSDOS compilers, especially Aztec

rmtodd@uokmax.UUCP (Richard Michael Todd) (06/05/87)

Has anyone else been compiling programs for MINIX using an MSDOS compiler
and dos2out?  I have and the technique works well, although there are a
few things you should watch out for.  Most of these apply to the Aztec
compiler , but some may also apply to other compilers as well.
    1.  Check and make sure that the information that dos2out extracts from
the header and uses to compute the text, data, and bss sizes actually give
the results they should.  Aztec's linker apparently doesn't put the stuff in
the .EXE header that dos2out expects.  I've managed to fix dos2out so that,
for Aztec-created files, it can determine the text size.  The data size it
determines is rounded up to the next higher paragraph and the bss size it
computes is a few bytes high, too.  This causes no problems as long as you
include a "junk" 16-byte array at the beginning of the bss segment, so C
never tries to use a variable that it thinks is in bss (and it doesn't
initialize) and MINIX thinks is in data (and it doesn't initialize).
    2.  For reasons known only to Aztec, the linker *insists* on sticking a
zero word at the beginning of the data segment, causing your variables to
start from address 2.  This badly confuses build, which expects fs's magic
number to be there.  The fix isn't too difficult -- slight changes to build.c
and head.asm.
    3. When constructing your MINIX library under MSDOS, you probably should
NOT use the setjmp.asm routine supplied on the disks, but instead use the
setjmp and longjmp routines from your compiler's library.  Why? MINIX cc
never uses register variables, so it won't save and restore the registers
your compiler uses for register variables, whereas the version supplied with
your compiler will.  Of course, you should also substitute your compiler's
version of setjmp.h for the minix one, since the sizes of the jmp_buf will
differ.
    4.  The book explains that it is important to make sure that the library
is constructed in the proper order, to make sure that routines appear before
routines they call in the library.  (Alas, as a couple of postings mentioned
in this newsgroup, ast made a couple of mistakes in the order of libc.a on
the MINIX disks.)  Aztec C has a utility that will look at a group of
compiled object modules and automatically determine a correct ordering for
the library.  For those who don't have such a utility, here's the listing
of the modules in my library, in order:
setjmp.o abort.o abs.o access.o atol.o brk2.o chdir.o chmod.o chown.o
chroot.o cleanup.o crypt.o ctype.o dup.o dup2.o exec.o exit.o fgets.o fork.o 
fprintf.o fputs.o fread.o freopen.o fclose.o fopen.o creat.o fseek.o fflush.o
ftell.o fwrite.o getegid.o getenv.o geteuid.o getgid.o getgrent.o getpass.o
getpwent.o atoi.o close.o gets.o getuid.o getutil.o ioctl.o isatty.o fstat.o
itoa.o kill.o link.o lseek.o mknod.o mktemp.o getpid.o mount.o open.o perror.o
pipe.o printk.o prints.o rand.o regexp.o index.o regsub.o rindex.o scanf.o
printdat.o getc.o read.o setbuf.o malloc.o bcopy.o brk.o brksize.o setgid.o
setuid.o sleep.o alarm.o pause.o signal.o catchsig.o sprintf.o doprintf.o
putc.o stat.o stb.o stderr.o stime.o strcat.o strcmp.o strcpy.o strlen.o
strncat.o strncmp.o strncpy.o sync.o syslib.o time.o times.o umask.o umount.o
ungetc.o unlink.o utime.o wait.o write.o call.o message.o sendrec.o
cswt.o cswit.o lsubs.o
The last three modules are the three needed from the Aztec library to do
compilations (containing switch code and long math routines).

  If any Aztec C users out there want copies of the changes I needed
to make to dos2out.c, etc., e-mail to me.  If there is sufficient interest,
I may post them, otherwise I'll e-mail individual copies.
___________________________________________________________________________
Richard Todd
USSnail:820 Annie Court,Norman OK 73069
UUCP: {allegra!cbosgd|ihnp4}!okstate!uokmax!rmtodd