-O4 limitations in llvm/llvm-gcc-4.2 2.5?

What exactly are the current limitations for using -O4 to create shared
libraries with llvm/llvm-gcc-4.2 2.5? I tried a build of xplor-nih at -O4
with llvm-gcc, llvm-g++ and llvm-gfortran. The build fails to link shared
libraries with errors such as...

Building xplor-nih for platform: Darwin_9_x86

[ -d /Users/howarth/xplor-nih-2.21/bin.Darwin_9_x86/ ] || mkdir /Users/howarth/xplor-nih-2.21/bin.Darwin_9_x86/
touch /Users/howarth/xplor-nih-2.21/bin.Darwin_9_x86/
for lib in libfft pppack specfun lapack blas; do \
   (cd $lib; make XPLORNIH_ROOT=/Users/howarth/xplor-nih-2.21 \
                               ARCH=Darwin_9_x86 lib);\
  done
[ -d bin.Darwin_9_x86 ] || mkdir bin.Darwin_9_x86
cd bin.Darwin_9_x86; make -f /Users/howarth/xplor-nih-2.21/fortlib/libfft/Makefile \
    ARCH=Darwin_9_x86 SRCDIR=/Users/howarth/xplor-nih-2.21/fortlib/libfft/ ARCHDEP=TRUE lib
llvm-gfortran -c -O4 -fPIC -ffast-math -msse4 -ffixed-line-length-120 -fno-second-underscore -DZOMPLEX /Users/howarth/xplor-nih-2.21/fortlib/libfft/dsint.f
llvm-gfortran -c -O4 -fPIC -ffast-math -msse4 -ffixed-line-length-120 -fno-second-underscore -DZOMPLEX /Users/howarth/xplor-nih-2.21/fortlib/libfft/dsinti.f
llvm-gfortran -c -O4 -fPIC -ffast-math -msse4 -ffixed-line-length-120 -fno-second-underscore -DZOMPLEX /Users/howarth/xplor-nih-2.21/fortlib/libfft/dcfftf.f
llvm-gfortran -c -O4 -fPIC -ffast-math -msse4 -ffixed-line-length-120 -fno-second-underscore -DZOMPLEX /Users/howarth/xplor-nih-2.21/fortlib/libfft/dcfftb.f
/Users/howarth/xplor-nih-2.21/fortlib/libfft/dcfftb.f:16.16:

      nf = ifac(2)
               1
Warning: Array reference at (1) is out of bounds
llvm-gfortran -c -O4 -fPIC -ffast-math -msse4 -ffixed-line-length-120 -fno-second-underscore -DZOMPLEX /Users/howarth/xplor-nih-2.21/fortlib/libfft/dcffti.f
llvm-gfortran -c -O4 -fPIC -ffast-math -msse4 -ffixed-line-length-120 -fno-second-underscore -DZOMPLEX /Users/howarth/xplor-nih-2.21/fortlib/libfft/drffti.f
llvm-gfortran -c -O4 -fPIC -ffast-math -msse4 -ffixed-line-length-120 -fno-second-underscore -DZOMPLEX /Users/howarth/xplor-nih-2.21/fortlib/libfft/drfftf.f
llvm-gfortran -c -O4 -fPIC -ffast-math -msse4 -ffixed-line-length-120 -fno-second-underscore -DZOMPLEX /Users/howarth/xplor-nih-2.21/fortlib/libfft/drfftb.f
llvm-gfortran -c -O4 -fPIC -ffast-math -msse4 -ffixed-line-length-120 -fno-second-underscore -DZOMPLEX /Users/howarth/xplor-nih-2.21/fortlib/libfft/c_ffti.F -o zffti.o
llvm-gfortran -c -O4 -fPIC -ffast-math -msse4 -ffixed-line-length-120 -fno-second-underscore -DZOMPLEX /Users/howarth/xplor-nih-2.21/fortlib/libfft/c_fftf.F -o zfftf.o
llvm-gfortran -c -O4 -fPIC -ffast-math -msse4 -ffixed-line-length-120 -fno-second-underscore -DZOMPLEX /Users/howarth/xplor-nih-2.21/fortlib/libfft/c_fftb.F -o zfftb.o
llvm-gcc-4 -c /Users/howarth/xplor-nih-2.21/fortlib/libfft/ctrans.c -O4 -fPIC -ffast-math -msse4 -DX_MMAP_FLAGS=0 -DFORTRAN_INIT -fno-common -DDARWIN -D_REENTRANT -DNDEBUG -I/Users/howarth/xplor-nih-2.21/fortlib/libfft/ -I/Users/howarth/xplor-nih-2.21/arch/Darwin_9_x86/include -DZOMPLEX -I/usr/include/sys
llvm-gcc-4 -c -O4 -fPIC -ffast-math -msse4 -DX_MMAP_FLAGS=0 -DFORTRAN_INIT -fno-common -DDARWIN -D_REENTRANT -DNDEBUG -I/Users/howarth/xplor-nih-2.21/fortlib/libfft/ -I/Users/howarth/xplor-nih-2.21/arch/Darwin_9_x86/include -DZOMPLEX -I/usr/include/sys /Users/howarth/xplor-nih-2.21/fortlib/libfft/c_fft1d.c -o zfft1d.o
llvm-gcc-4 -c -O4 -fPIC -ffast-math -msse4 -DX_MMAP_FLAGS=0 -DFORTRAN_INIT -fno-common -DDARWIN -D_REENTRANT -DNDEBUG -I/Users/howarth/xplor-nih-2.21/fortlib/libfft/ -I/Users/howarth/xplor-nih-2.21/arch/Darwin_9_x86/include -DZOMPLEX -I/usr/include/sys /Users/howarth/xplor-nih-2.21/fortlib/libfft/c_fft2d.c -o zfft2d.o
llvm-gcc-4 -c -O4 -fPIC -ffast-math -msse4 -DX_MMAP_FLAGS=0 -DFORTRAN_INIT -fno-common -DDARWIN -D_REENTRANT -DNDEBUG -I/Users/howarth/xplor-nih-2.21/fortlib/libfft/ -I/Users/howarth/xplor-nih-2.21/arch/Darwin_9_x86/include -DZOMPLEX -I/usr/include/sys /Users/howarth/xplor-nih-2.21/fortlib/libfft/c_fft3d.c -o zfft3d.o
llvm-gfortran -c -O4 -fPIC -ffast-math -msse4 -ffixed-line-length-120 -fno-second-underscore -DZOMPLEX /Users/howarth/xplor-nih-2.21/fortlib/libfft/ftrans.F
llvm-gfortran -c -O4 -fPIC -ffast-math -msse4 -ffixed-line-length-120 -fno-second-underscore -DZOMPLEX /Users/howarth/xplor-nih-2.21/fortlib/libfft/c_mp_fft.F -o zmp_fft.o
llvm-gfortran -c -O4 -fPIC -ffast-math -msse4 -ffixed-line-length-120 -fno-second-underscore -DZOMPLEX /Users/howarth/xplor-nih-2.21/fortlib/libfft/c_scal_fft.F -o zscal_fft.o
llvm-gfortran -c -O4 -fPIC -ffast-math -msse4 -ffixed-line-length-120 -fno-second-underscore -DZOMPLEX /Users/howarth/xplor-nih-2.21/fortlib/libfft/c_prod_fft.F -o zprod_fft.o
llvm-gcc-4 -c /Users/howarth/xplor-nih-2.21/fortlib/libfft/fft_ftn.c -O4 -fPIC -ffast-math -msse4 -DX_MMAP_FLAGS=0 -DFORTRAN_INIT -fno-common -DDARWIN -D_REENTRANT -DNDEBUG -I/Users/howarth/xplor-nih-2.21/fortlib/libfft/ -I/Users/howarth/xplor-nih-2.21/arch/Darwin_9_x86/include -DZOMPLEX -I/usr/include/sys
llvm-gcc-4 -O4 -dynamiclib -o libfft.dylib dsint.o dsinti.o dcfftf.o dcfftb.o dcffti.o drffti.o drfftf.o drfftb.o zffti.o zfftf.o zfftb.o ctrans.o zfft1d.o zfft2d.o zfft3d.o ftrans.o zmp_fft.o zscal_fft.o zprod_fft.o fft_ftn.o -flat_namespace -undefined suppress -single_module -lcrypto -v -noall_load
Using built-in specs.
Target: i686-apple-darwin9
Configured with: ../llvm-gcc4.2-2.5.source/configure --prefix=/sw --prefix=/sw/lib/llvm-gcc-4.2 --mandir=/sw/share/man --infodir=/sw/share/info --with-gmp=/sw --with-libiconv-prefix=/usr --with-system-zlib --with-as=/Developer/usr/bin/as --with-ld=/Developer/usr/bin/ld --with-nm=/Developer/usr/bin/nm --build=i686-apple-darwin9 --target=i686-apple-darwin9 --host=i686-apple-darwin9 --with-arch=nocona --with-tune=generic --with-gxx-include-dir=/usr/include/c++/4.0.0 --enable-llvm=/sw/src/fink.build/llvm-gcc42-2.5-1/llvm-2.5/../llvm_objdir --enable-languages=c,c++,fortran
Thread model: posix
gcc version 4.2.1 (Based on Apple Inc. build 5636) (LLVM build)
/sw/lib/llvm-gcc-4.2/libexec/gcc/i686-apple-darwin9/4.2.1/collect2 -dynamic -dylib -arch i386 -flat_namespace -macosx_version_min 10.5.6 -single_module -undefined suppress -weak_reference_mismatches non-weak -undefined suppress -o libfft.dylib -ldylib1.10.5.o -L/usr/lib/i686-apple-darwin9/4.2.1 -L/sw/lib/llvm-gcc-4.2/lib/gcc/i686-apple-darwin9/4.2.1 -L/usr/lib/gcc/i686-apple-darwin9/4.2.1 -L/sw/lib/llvm-gcc-4.2/lib/gcc/i686-apple-darwin9/4.2.1/../../.. dsint.o dsinti.o dcfftf.o dcfftb.o dcffti.o drffti.o drfftf.o drfftb.o zffti.o zfftf.o zfftb.o ctrans.o zfft1d.o zfft2d.o zfft3d.o ftrans.o zmp_fft.o zscal_fft.o zprod_fft.o fft_ftn.o -lcrypto -lgcc_s.10.5 -lgcc -lSystem
ld: in dsint.o, could not parse object file dsint.o: Unknown instruction
collect2: ld returned 1 exit status
make[3]: *** [libfft.dylib] Error 1
make[2]: *** [lib] Error 2

Is there a wiki on the state of the LTO support somewhere?
                Jack

Hi Jack,

If you have Xcode 3.1.1+, the linker in /Developer/usr/bin will at /Developer/usr/lib/libLTO.dylib if you try to build LLVM files. I'd suggest replacing /Developer/usr/lib/libLTO.dylib with libLTO from LLVM 2.5 and then things should work. It may also work to drop in LLVM 2.5's liblto into /usr/lib and then use /usr/bin/ld, but I've never tested that.

-Chris