HOWTO USE BOUNDS-CHECKING WITH AIX-3.2.5

Simple programs may be checked by typing:

        gcc -g -fbounds-checking myfile.c -o myprog -lm

Anyhow, there a problems with some libraries like e.g. libX11.a
By default libX11.a is a shared library, and due to the special
behaviour of AIX it always uses the unchecked "malloc"-routines
from libc.a instead of those from ...../libcheck.a
(this leads to a funny mixture of checked and unchecked mallocs...)

Solution

        gcc -g -c -fbounds-checking myfirst.c
        gcc -g -c -fbounds-checking mysecond.c

Normally you would type now: (which doesn't work with AIX)
        gcc -fbounds-checking myfirst.o mysecond.o -o myprog -lX11 -lm

Better link statically:
        cc myfirst.o mysecond.o -o mystaticprog \
         -L/usr/local/lib/gcc-lib/rs6000-ibm-aix3.2.5/2.7.0 -lcheck -lgcc \
         -lIM -liconv -lX11 -lm \
         -bnso -bloadmap:/tmp/loadmap \
         -bI:/lib/syscalls.exp -bI:/usr/lpp/X11/bin/smt.exp

  Because linking with 'cc' we have to explicitly say where
  -lcheck and -lgcc are.
  "-bnso -bI:/lib/syscalls.exp -bI:/usr/lpp/X11/bin/smt.exp" tell cc to
  link statically and "-lIM -liconv" is needed by "-lX11" if linked statically.


If you have a more recent AIX-3.2.5++ there might be a error message
about an unresolved symbol 'pthread_yield'. In this case you have to
add an additional -bI:./foo.imp to the last line
         -bI:/lib/syscalls.exp -bI:/usr/lpp/X11/bin/smt.exp -bI:./foo.imp

And create the file ./foo.imp containing two lines:
#!
pthread_yield

This tells cc to resolve this symbol at runtime, not while statically
linking. (Thanks to Mr. David L. Crow for this solution)

Due to my lack of understanding AIX corrections, hints and explanations
are always welcome...

Joerg

P.S.: A last AIX-tip: If you don't have gdb (GNU-debugger) and want
	to use the dbx, you should say 'gcc -gxcoff3' insead 'gcc -g'

