There is a problem with the way autoconf tries to detect
if a compiler is in fact a cross compiler. Currently,
autoconf will write out the following program:

#ifdef __cplusplus
extern "C" void exit (int);
#endif
int main(){return(0);}

If this program compiles that autoconf sets the
ac_cv_prog_cxx_works var to "yes" and tries
to run it.

  if (./conftest; exit) 2>/dev/null; then
    ac_cv_prog_cxx_cross=no
  else
    ac_cv_prog_cxx_cross=yes
  fi

If the program can not be run, autoconf assumes
that the compiler is a cross compiler. This
approach has a some serious problems. If the
program can be compiled and linked but
it does not run because of some problem
with the runtime linker, then autoconf
will think that the compiler is a cross
compiler.


Here is the output I got when tring to run
this on a Solaris box with g++ and autoconf 2.14.

$ ./configure
checking host system type... sparc-sun-solaris2.7
checking build system type... sparc-sun-solaris2.7
checking for c++... c++
checking whether the C++ compiler (c++   ) works... yes
checking whether the C++ compiler (c++   ) is a cross-compiler... yes
checking whether we are using GNU C++... yes

...

checking whether byte ordering is bigendian... configure: error: cannot run
test program while cross compiling


What is really going wrong here is that the ./conftest
executable can not be run on the system because or a
problem with the LD_LIBRARY_PATH. If you try it from
the command line you get the following. In this case,
the /usr/local/lib dir does not appear on the rld path.

% c++ a.C
% ./a.out
ld.so.1: ./a.out: fatal: libstdc++.so.2.10.0: open failed: No such file or directory
Killed

I guess one could make the argument that the AC_C_BIGENDIAN macro
inside aclang.m4 could be improved to account for the cross compiler
case, but the real problem is the way autoconf tries to detect
the cross compiler case.

To really fix this problem I suggest that we add an extra check
to make sure the host is not the same as the build. This of
course assumes that my earlier patch to actually set host and
build correctly has been applied.

Index: acgeneral.m4
===================================================================
RCS file: /cvs/autoconf/acgeneral.m4,v
retrieving revision 1.437
diff -u -r1.437 acgeneral.m4
--- acgeneral.m4        2000/04/13 08:25:12     1.437
+++ acgeneral.m4        2000/04/24 08:00:25
@@ -2609,7 +2622,7 @@
   # If we can't run a trivial program, we are probably using a cross compiler.
   if (./conftest; exit) 2>/dev/null; then
     [$3]=no
-  else
+  elif test $host != $build; then
     [$3]=yes
   fi],
 [[$2]=no])[]dnl

This test would only be run if running the ./conftest executable failed.
If folks think this is a good idea I can send it to autoconf-patches.

As a more general question, is it really a good idea to redirect
the error output to /dev/null when running a test program like this?
Why not write the output to the log file. That would make it a lot
easier to debug this sort of problem because the rld errors would
show up in the log file.

thanks
Mo DeJong
Red Hat Inc.

Reply via email to