summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorZack Weinberg <zackw@panix.com>2020-11-02 13:15:00 -0500
committerZack Weinberg <zackw@panix.com>2020-11-02 13:15:00 -0500
commitf1047b2e9656ba1cb3b672df22b2178ad0b38738 (patch)
treeae091d8ded2e8d6e07227fbd8e60bf61970379a6 /tests
parent45f1c8ba95c84a2980aa2ed3d03f1674fcc114fa (diff)
downloadautoconf-f1047b2e9656ba1cb3b672df22b2178ad0b38738.tar.gz
AC_OPENMP: Avoid clobbering ‘mp’ and/or ‘penmp’ (#110353)
Some of the compiler options that AC_OPENMP tests, mean “enable OpenMP” to one compiler, but “write output to a file named ‘mp’ or ‘penmp’” to other compilers. The author of AC_OPENMP believed that this could only happen if compilation was *successful*, but didn’t realize that one of the options means “write *preprocessed* output to a file named ‘penmp’” to SunPRO C, and that this *would* succeed on the test program. (AC_LINK_IFELSE fails anyway, because the compilation didn’t create conftest$exeext.) The option that actually means “enable OpenMP” to SunPRO C is earlier in the list than the option that means “write preprocessed output to a file named ‘penmp’”, so we might never have noticed this, but for a second bug: if you have a bad combination of Solaris operating system patches installed, it’s possible for this compiler to successfully *compile* a program that uses OpenMP, but then fail to *link* it because the OpenMP runtime library is out of sync with the core C library. AC_OPENMP doesn’t distinguish this case from “that option doesn’t mean ‘enable OpenMP’” so it goes on to other entries in the list and hits the “write preprocessed output” one. Implement four layers of defensive measures against this mess: - Use an #error directive instead of a compile-time syntax error to halt compilation when _OPENMP is not defined. - For each option that might mean “enable OpenMP”, first do an AC_COMPILE_IFELSE to find out whether it really means that, and then an AC_LINK_IFELSE to find out whether it works. If the compilation succeeds but the link fails, bail out of the loop and declare OpenMP to be unsupported. - If a file named ‘mp’ or ‘openmp’ exists in configure’s working directory when AC_OPENMP begins, error out. This means it is safe to delete any file named ‘mp’ or ‘openmp’ that exists at the *end* of AC_OPENMP. - If a file named ‘mp’ or ‘openmp’ exists in the top level of the source tree with a configure.ac that uses AC_OPENMP, have autoconf error out, too. Fixes bug #110353. Problem reported by Dagobert Michelsen. * lib/autoconf/c.m4 (_AC_LANG_OPENMP(C)): Change ‘choke me’ to ‘#error "OpenMP not supported"’. (AC_OPENMP): AC_REQUIRE _AC_OPENMP_SAFE_WD. For each option, do both a compile test and a link test; if the compile test succeeds but the link fails, don’t go on to other candidate options. Delete files named ‘mp’ and ‘penmp’ after the loop. (_AC_OPENMP_SAFE_WD): New macro, subroutine of AC_OPENMP. If files named ‘mp’ or ‘penmp’ exist, error out both at autoconf time and at configure time. * tests/torture.at (Files clobbered by AC_OPENMP): New test. * doc/autoconf.texi: Document requirement not to have files named ‘mp’ or ‘penmp’ next to a configure.ac that uses AC_OPENMP.
Diffstat (limited to 'tests')
-rw-r--r--tests/torture.at51
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/torture.at b/tests/torture.at
index 76cddc65..a96af651 100644
--- a/tests/torture.at
+++ b/tests/torture.at
@@ -2061,3 +2061,54 @@ AT_CHECK([test -x build-aux/install-sh])
AT_CHECK_CONFIGURE
AT_CLEANUP
+
+## ------------------------------ ##
+## Files clobbered by AC_OPENMP. ##
+## ------------------------------ ##
+
+AT_SETUP([Files clobbered by AC_OPENMP])
+
+AT_CONFIGURE_AC(
+[[AC_PROG_CC
+AC_OPENMP
+]])
+
+AT_CHECK_AUTOHEADER
+
+# autoconf should bomb out if either 'mp' or 'openmp' exists in the
+# srcdir.
+AT_DATA([mp])
+AT_CHECK_AUTOCONF([], [1], [], [stderr])
+AT_CHECK([grep "clobbers files named 'mp' and 'penmp'" stderr],
+ [0], [ignore], [ignore])
+rm -f mp
+
+AT_DATA([penmp])
+AT_CHECK_AUTOCONF([], [1], [], [stderr])
+AT_CHECK([grep "clobbers files named 'mp' and 'penmp'" stderr],
+ [0], [ignore], [ignore])
+rm -f penmp
+
+# If neither of these files exist, autoconf should go through...
+AT_CHECK_AUTOCONF
+
+# ... but configure should bomb out, and *not* delete the files,
+# if they are added after autoconf is run.
+AT_DATA([mp])
+AT_CHECK_CONFIGURE([], [1], [], [stderr])
+AT_CHECK([test -e mp])
+AT_CHECK([grep "clobbers files named 'mp' and 'penmp'" stderr],
+ [0], [ignore], [ignore])
+rm -f mp
+
+AT_DATA([penmp])
+AT_CHECK_CONFIGURE([], [1], [], [stderr])
+AT_CHECK([test -e penmp])
+AT_CHECK([grep "clobbers files named 'mp' and 'penmp'" stderr],
+ [0], [ignore], [ignore])
+rm -f penmp
+
+AT_CHECK_CONFIGURE
+AT_CHECK_ENV
+
+AT_CLEANUP