]> git.ipfire.org Git - thirdparty/autoconf.git/commit
AC_OPENMP: Avoid clobbering ‘mp’ and/or ‘penmp’ (#110353)
authorZack Weinberg <zackw@panix.com>
Mon, 2 Nov 2020 18:15:00 +0000 (13:15 -0500)
committerZack Weinberg <zackw@panix.com>
Mon, 2 Nov 2020 18:15:00 +0000 (13:15 -0500)
commitf1047b2e9656ba1cb3b672df22b2178ad0b38738
treeae091d8ded2e8d6e07227fbd8e60bf61970379a6
parent45f1c8ba95c84a2980aa2ed3d03f1674fcc114fa
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.
NEWS
doc/autoconf.texi
lib/autoconf/c.m4
tests/torture.at