autoconf-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: PATCH: fix cross-compilation detection on Blue Gene/L


From: Eric Blake
Subject: Re: PATCH: fix cross-compilation detection on Blue Gene/L
Date: Thu, 11 Jun 2009 07:14:13 -0600
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.21) Gecko/20090302 Thunderbird/2.0.0.21 Mnenhy/0.7.6.666

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to Steven G. Johnson on 6/8/2009 7:42 PM:
> As I discussed recently on the autoconf mailing list, the cross-compiler
> detection on the IBM Blue Gene (when you pass --host but not --build)
> gives a false negative, because no-op executables still run on the build
> machine.
> 
> The attached patch fixes the false negative, by creating a file in the
> test program that is run.  This should be safe because our other
> autoconf tests (e.g. AC_COMPUTE_INT) already assume that files can be
> created (via fopen/fclose) when not cross-compiling, so it's checking
> for a feature we rely on anyway.
> 
> The patch is against git head, and 'make check' passes for me.  My
> copyright assignment for autoconf is already on file with the FSF for
> many years now.

Thanks.  However, next time it would be nicer to use 'git format-patch
- --stdout' or some similar command so that the patch also includes the
commit message and author timestamp by default.  Also, one of the lines
added trailing whitespace, and the formatting was not always consistent.
More importantly, you forgot ObjC; so I refactored the patch a bit before
applying.  In the process, I noticed that Fortran could be simplified, as
well as a documentation hole for m4_copy that was essential to pull off
the Fortran simplification.  Here's the series I pushed:

- --
Don't work too hard, make some time for fun as well!

Eric Blake             address@hidden
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkoxAyUACgkQ84KuGfSFAYACzQCgzNLXqUhnUTXdZDGH3itKOqYh
8jgAoNdA3lmTbzPzjQoY7g45zmEKx9Ym
=KSWG
-----END PGP SIGNATURE-----
>From 685b65a74f45fab915d3b0138ea429e21ee6f25b Mon Sep 17 00:00:00 2001
From: Eric Blake <address@hidden>
Date: Thu, 11 Jun 2009 06:43:39 -0600
Subject: [PATCH 1/3] Clarify m4_copy semantics.

* doc/autoconf.texi (Redefined M4 Macros) <m4_copy>: Update
documentation.
* tests/m4sugar.at (m4@&address@hidden): Enhance test.

Signed-off-by: Eric Blake <address@hidden>
---
 ChangeLog         |    7 +++++++
 doc/autoconf.texi |    8 +++++---
 tests/m4sugar.at  |   10 ++++++++++
 3 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 01fdd3d..df57b30 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2009-06-11  Eric Blake  <address@hidden>
+
+       Clarify m4_copy semantics.
+       * doc/autoconf.texi (Redefined M4 Macros) <m4_copy>: Update
+       documentation.
+       * tests/m4sugar.at (m4@&address@hidden): Enhance test.
+
 2009-06-06  Eric Blake  <address@hidden>

        Improve documentation on trap pitfalls.
diff --git a/doc/autoconf.texi b/doc/autoconf.texi
index 81bce07..9e3327e 100644
--- a/doc/autoconf.texi
+++ b/doc/autoconf.texi
@@ -10646,10 +10646,12 @@ Redefined M4 Macros
 @msindex{copy}
 @msindex{rename}
 These macros aren't directly builtins, but are closely related to
address@hidden and @code{m4_defn}.  They both ensures that @var{dest}
address@hidden and @code{m4_defn}.  They both ensure that @var{dest}
 is undefined, then proceed to copy the entire pushdef stack of
-definitions of @var{source}.  @code{m4_copy} preserves the source, while
address@hidden undefines the original macro name.
+definitions of @var{source}.  @code{m4_copy} preserves the source
+(including in the special case where @var{source} is undefined), while
address@hidden undefines the original macro name (making it an error
+to rename an undefined @var{source}).

 Note that attempting to invoke a renamed macro might not work, since the
 macro may have a dependence on helper macros accessed via composition of
diff --git a/tests/m4sugar.at b/tests/m4sugar.at
index bf56c4d..4bc7bd4 100644
--- a/tests/m4sugar.at
+++ b/tests/m4sugar.at
@@ -136,6 +136,14 @@ AT_CHECK_M4SUGAR([-o-], 1, [], [stderr])
 AT_CHECK([grep good stderr], [1])
 AT_CHECK([grep 'm4@&address@hidden: undefined.*oops' stderr], [0], [ignore])

+# Cannot rename an undefined macro.
+AT_DATA_M4SUGAR([script.4s],
+[[m4_rename([oops], [good])
+]])
+
+AT_CHECK_M4SUGAR([-o-], 1, [], [stderr])
+AT_CHECK([grep 'm4@&address@hidden: undefined.*oops' stderr], [0], [ignore])
+
 # Check that pushdef stacks can be renamed.
 AT_CHECK_M4SUGAR_TEXT([[m4_pushdef([a], [1])dnl
 m4_pushdef([a], [2])dnl
@@ -151,6 +159,8 @@ m4_popdef([b], [c])dnl
 a b c
 m4_popdef([b], [c])dnl
 a b c
+dnl m4_copy is intentionally a no-op on undefined source
+m4_copy([oops], [dummy])m4_ifdef([dummy], [[oops]])dnl
 ]], [[0 b c
 a 0 c
 a 0 0
-- 
1.6.3.rc3.2.g4b51


>From 14c613a6c98e4246e0513fe793d004a27e9349ba Mon Sep 17 00:00:00 2001
From: Eric Blake <address@hidden>
Date: Thu, 11 Jun 2009 06:59:57 -0600
Subject: [PATCH 2/3] Simplify AC_LANG(Fortran).

* lib/autoconf/fortran.m4 (AC_LANG(Fortran)): Borrow from Fortran
77, which requires reordering portions of the file.
(AC_LANG_PROGRAM(Fortran), AC_LANG_CALL(Fortran)): Now defined
automatically.

Signed-off-by: Eric Blake <address@hidden>
---
 ChangeLog               |    6 +++++
 lib/autoconf/fortran.m4 |   48 ++++++++++++++++------------------------------
 2 files changed, 23 insertions(+), 31 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index df57b30..a6974a0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2009-06-11  Eric Blake  <address@hidden>

+       Simplify AC_LANG(Fortran).
+       * lib/autoconf/fortran.m4 (AC_LANG(Fortran)): Borrow from Fortran
+       77, which requires reordering portions of the file.
+       (AC_LANG_PROGRAM(Fortran), AC_LANG_CALL(Fortran)): Now defined
+       automatically.
+
        Clarify m4_copy semantics.
        * doc/autoconf.texi (Redefined M4 Macros) <m4_copy>: Update
        documentation.
diff --git a/lib/autoconf/fortran.m4 b/lib/autoconf/fortran.m4
index dcffe58..f7947aa 100644
--- a/lib/autoconf/fortran.m4
+++ b/lib/autoconf/fortran.m4
@@ -1,6 +1,6 @@
 # This file is part of Autoconf.                       -*- Autoconf -*-
 # Fortran languages support.
-# Copyright (C) 2001, 2003, 2004, 2005, 2006, 2007, 2008
+# Copyright (C) 2001, 2003, 2004, 2005, 2006, 2007, 2008, 2009
 # Free Software Foundation, Inc.
 #
 # This program is free software: you can redistribute it and/or modify
@@ -155,9 +155,9 @@ fi[]dnl



-## ----------------------- ##
-## 1. Language selection.  ##
-## ----------------------- ##
+## ------------------------ ##
+## 1a. Language selection.  ##
+## ------------------------ ##


 # AC_LANG(Fortran 77)
@@ -170,16 +170,6 @@ ac_compiler_gnu=$ac_cv_f77_compiler_gnu
 ])


-# AC_LANG(Fortran)
-# ----------------
-AC_LANG_DEFINE([Fortran], [fc], [FC], [],
-[ac_ext=${ac_fc_srcext-f}
-ac_compile='$FC -c $FCFLAGS $ac_fcflags_srcext conftest.$ac_ext 
>&AS_MESSAGE_LOG_FD'
-ac_link='$FC -o conftest$ac_exeext $FCFLAGS $LDFLAGS $ac_fcflags_srcext 
conftest.$ac_ext $LIBS >&AS_MESSAGE_LOG_FD'
-ac_compiler_gnu=$ac_cv_fc_compiler_gnu
-])
-
-
 # AC_LANG_FORTRAN77
 # -----------------
 AU_DEFUN([AC_LANG_FORTRAN77], [AC_LANG(Fortran 77)])
@@ -220,17 +210,6 @@ $2
       end])


-# AC_LANG_PROGRAM(Fortran)([PROLOGUE], [BODY])
-# -----------------------------------------------
-# FIXME: can the PROLOGUE be used?
-m4_define([AC_LANG_PROGRAM(Fortran)],
-[m4_ifval([$1],
-       [m4_warn([syntax], [$0: ignoring PROLOGUE: $1])])dnl
-      program main
-$2
-      end])
-
-
 # AC_LANG_CALL(Fortran 77)(PROLOGUE, FUNCTION)
 # --------------------------------------------
 # FIXME: This is a guess, help!
@@ -239,13 +218,20 @@ m4_define([AC_LANG_CALL(Fortran 77)],
 [      call $2])])


-# AC_LANG_CALL(Fortran)(PROLOGUE, FUNCTION)
-# --------------------------------------------
-# FIXME: This is a guess, help!
-m4_define([AC_LANG_CALL(Fortran)],
-[AC_LANG_PROGRAM([$1],
-[      call $2])])

+## ------------------------ ##
+## 1b. Language selection.  ##
+## ------------------------ ##
+
+
+# AC_LANG(Fortran)
+# ----------------
+AC_LANG_DEFINE([Fortran], [fc], [FC], [Fortran 77],
+[ac_ext=${ac_fc_srcext-f}
+ac_compile='$FC -c $FCFLAGS $ac_fcflags_srcext conftest.$ac_ext 
>&AS_MESSAGE_LOG_FD'
+ac_link='$FC -o conftest$ac_exeext $FCFLAGS $LDFLAGS $ac_fcflags_srcext 
conftest.$ac_ext $LIBS >&AS_MESSAGE_LOG_FD'
+ac_compiler_gnu=$ac_cv_fc_compiler_gnu
+])


 ## -------------------------------------------- ##
-- 
1.6.3.rc3.2.g4b51


>From ca473068618a0b879a4ffe20910a9f827d223c6d Mon Sep 17 00:00:00 2001
From: Steven G. Johnson <address@hidden>
Date: Thu, 11 Jun 2009 07:07:32 -0600
Subject: [PATCH 3/3] Create a file in test program when detecting 
cross-compilation.

* lib/autoconf/lang.m4 (_AC_LANG_IO_PROGRAM): New macro, returns
program that creates a file.
(_AC_COMPILER_EXEEXT,_AC_COMPILER_EXEEXT_WORKS): Call new macro
and document why it's needed to robustly detect cross-compiling.
(AC_LANG_DEFINE): Copy implementation across similar languages.
* lib/autoconf/c.m4 (_AC_LANG_IO_PROGRAM(C)): Implement new macro.
* lib/autoconf/fortran.m4 (_AC_LANG_IO_PROGRAM(Fortran 77)):
Likewise.
* lib/autoconf/erlang.m4 (_AC_LANG_IO_PROGRAM(Erlang)): Likewise.

Signed-off-by: Eric Blake <address@hidden>
---
 ChangeLog               |   14 ++++++++++++++
 lib/autoconf/c.m4       |   11 +++++++++++
 lib/autoconf/erlang.m4  |   11 +++++++++++
 lib/autoconf/fortran.m4 |   11 +++++++++++
 lib/autoconf/lang.m4    |   32 ++++++++++++++++++++++++++------
 5 files changed, 73 insertions(+), 6 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index a6974a0..f474f70 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2009-06-11  Steven G. Johnson  <address@hidden>
+       and Eric Blake  <address@hidden>
+
+       Create a file in test program when detecting cross-compilation.
+       * lib/autoconf/lang.m4 (_AC_LANG_IO_PROGRAM): New macro, returns
+       program that creates a file.
+       (_AC_COMPILER_EXEEXT,_AC_COMPILER_EXEEXT_WORKS): Call new macro
+       and document why it's needed to robustly detect cross-compiling.
+       (AC_LANG_DEFINE): Copy implementation across similar languages.
+       * lib/autoconf/c.m4 (_AC_LANG_IO_PROGRAM(C)): Implement new macro.
+       * lib/autoconf/fortran.m4 (_AC_LANG_IO_PROGRAM(Fortran 77)):
+       Likewise.
+       * lib/autoconf/erlang.m4 (_AC_LANG_IO_PROGRAM(Erlang)): Likewise.
+
 2009-06-11  Eric Blake  <address@hidden>

        Simplify AC_LANG(Fortran).
diff --git a/lib/autoconf/c.m4 b/lib/autoconf/c.m4
index ffdbd45..33d1895 100644
--- a/lib/autoconf/c.m4
+++ b/lib/autoconf/c.m4
@@ -129,6 +129,17 @@ $2
 }])


+# _AC_LANG_IO_PROGRAM(C)
+# ----------------------
+# Produce source that performs I/O, necessary for proper
+# cross-compiler detection.
+m4_define([_AC_LANG_IO_PROGRAM(C)],
+[AC_LANG_PROGRAM(address@hidden:@include <stdio.h>],
+[FILE *f = fopen ("conftest.out", "w");
+ return ferror (f) || fclose (f) != 0;
+])])
+
+
 # AC_LANG_CALL(C)(PROLOGUE, FUNCTION)
 # -----------------------------------
 # Avoid conflicting decl of main.
diff --git a/lib/autoconf/erlang.m4 b/lib/autoconf/erlang.m4
index 1e4418b..72268be 100644
--- a/lib/autoconf/erlang.m4
+++ b/lib/autoconf/erlang.m4
@@ -152,6 +152,17 @@ $2
 ])


+# _AC_LANG_IO_PROGRAM(Erlang)
+# ---------------------------
+# Produce source that performs I/O.
+m4_define([_AC_LANG_IO_PROGRAM(Erlang)],
+[AC_LANG_PROGRAM([], [dnl
+   ReturnValue = case file:write_file("conftest.out", "") of
+       {error, _} -> 1;
+       ok -> 0
+   end,
+   halt(ReturnValue)])])
+

 ## -------------------------------------------- ##
 ## 3. Looking for Compilers and Preprocessors.  ##
diff --git a/lib/autoconf/fortran.m4 b/lib/autoconf/fortran.m4
index f7947aa..5a399e4 100644
--- a/lib/autoconf/fortran.m4
+++ b/lib/autoconf/fortran.m4
@@ -210,6 +210,17 @@ $2
       end])


+# _AC_LANG_IO_PROGRAM(Fortran 77)
+# -------------------------------
+# Produce source that performs I/O.
+m4_define([_AC_LANG_IO_PROGRAM(Fortran 77)],
+[AC_LANG_PROGRAM([],
+[dnl
+      open(unit=9,file='conftest.out')
+      close(unit=9)
+])])
+
+
 # AC_LANG_CALL(Fortran 77)(PROLOGUE, FUNCTION)
 # --------------------------------------------
 # FIXME: This is a guess, help!
diff --git a/lib/autoconf/lang.m4 b/lib/autoconf/lang.m4
index bcd037b..efdcdd0 100644
--- a/lib/autoconf/lang.m4
+++ b/lib/autoconf/lang.m4
@@ -1,6 +1,6 @@
 # This file is part of Autoconf.                       -*- Autoconf -*-
 # Programming languages support.
-# Copyright (C) 2000, 2001, 2002, 2004, 2005, 2006, 2007, 2008 Free
+# Copyright (C) 2000, 2001, 2002, 2004, 2005, 2006, 2007, 2008, 2009 Free
 # Software Foundation, Inc.
 #
 # This program is free software: you can redistribute it and/or modify
@@ -200,7 +200,8 @@ m4_define([AC_LANG_DEFINE],
 [m4_copy([AC_LANG_CALL($4)], [AC_LANG_CALL($1)])]
 [m4_copy([AC_LANG_FUNC_LINK_TRY($4)], [AC_LANG_FUNC_LINK_TRY($1)])]
 [m4_copy([AC_LANG_BOOL_COMPILE_TRY($4)], [AC_LANG_BOOL_COMPILE_TRY($1)])]
-[m4_copy([AC_LANG_INT_SAVE($4)], [AC_LANG_INT_SAVE($1)])])])
+[m4_copy([AC_LANG_INT_SAVE($4)], [AC_LANG_INT_SAVE($1)])]
+[m4_copy([_AC_LANG_IO_PROGRAM($4)], [_AC_LANG_IO_PROGRAM($1)])])])

 ## ----------------------- ##
 ## 2. Producing programs.  ##
@@ -248,6 +249,15 @@ AC_DEFUN([AC_LANG_PROGRAM],
 [AC_LANG_SOURCE([_AC_LANG_DISPATCH([$0], _AC_LANG, $@)])])


+# _AC_LANG_IO_PROGRAM
+# -----------------------------------
+# Produce valid source for the current language that creates
+# a file.  (This is used when detecting whether executables
+# work, e.g. to detect cross-compiling.)
+AC_DEFUN([_AC_LANG_IO_PROGRAM],
+[AC_LANG_SOURCE([_AC_LANG_DISPATCH([$0], _AC_LANG, $@)])])
+
+
 # AC_LANG_CALL(PROLOGUE, FUNCTION)
 # --------------------------------
 # Call the FUNCTION.
@@ -556,11 +566,19 @@ ac_exeext=$ac_cv_exeext

 # _AC_COMPILER_EXEEXT_WORKS
 # -------------------------
+# FIXME: These cross compiler hacks should be removed for Autoconf 3.0
+#
+# It is not sufficient to run a no-op program -- this succeeds and gives
+# a false negative when cross-compiling for the compute nodes on the
+# IBM Blue Gene/L.  Instead, _AC_COMPILER_EXEEXT calls _AC_LANG_IO_PROGRAM
+# to create a program that writes to a file, which is sufficient to
+# detect cross-compiling on Blue Gene.  Note also that AC_COMPUTE_INT
+# requires programs that create files when not cross-compiling, so it
+# is safe and not a bad idea to check for this capability in general.
 m4_define([_AC_COMPILER_EXEEXT_WORKS],
 [# Check that the compiler produces executables we can run.  If not, either
 # the compiler is broken, or we cross compile.
 AC_MSG_CHECKING([whether the _AC_LANG compiler works])
-# FIXME: These cross compiler hacks should be removed for Autoconf 3.0
 # If not cross compiling, check that we can run a simple program.
 if test "$cross_compiling" != yes; then
   if _AC_DO_TOKENS([./$ac_file]); then
@@ -629,13 +647,15 @@ AC_MSG_RESULT([$ac_cv_exeext])
 #
 # Do not rename this macro; Automake decides whether EXEEXT is used
 # by checking whether `_AC_COMPILER_EXEEXT' has been expanded.
+#
+# See _AC_COMPILER_EXEEXT_WORKS for why we call _AC_LANG_IO_PROGRAM.
 m4_define([_AC_COMPILER_EXEEXT],
-[AC_LANG_CONFTEST([AC_LANG_PROGRAM()])
+[AC_LANG_CONFTEST([_AC_LANG_IO_PROGRAM])
 ac_clean_files_save=$ac_clean_files
-ac_clean_files="$ac_clean_files a.out a.out.dSYM a.exe b.out"
+ac_clean_files="$ac_clean_files a.out a.out.dSYM a.exe b.out conftest.out"
 _AC_COMPILER_EXEEXT_DEFAULT
 _AC_COMPILER_EXEEXT_WORKS
-rm -f -r a.out a.out.dSYM a.exe conftest$ac_cv_exeext b.out
+rm -f -r a.out a.out.dSYM a.exe conftest$ac_cv_exeext b.out conftest.out
 ac_clean_files=$ac_clean_files_save
 _AC_COMPILER_EXEEXT_CROSS
 _AC_COMPILER_EXEEXT_O
-- 
1.6.3.rc3.2.g4b51


reply via email to

[Prev in Thread] Current Thread [Next in Thread]