Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Use the C++ compiler for feature tests
Most of the configure test results will be used in C++ sources, so testing for
them with the C compiler might give wrong results.

I had to fix a few standard tests to work with the C++ compiler. There are
still a small number of tests that require the C compiler and should not be
checked with the C++ compiler. They either check features of the C compiler
or their results will only be used in C source files (by the C compiler).

This should fix issue #1572
  • Loading branch information
gonosztopi committed Sep 12, 2014
1 parent 97b6d81 commit 7a87cf9
Show file tree
Hide file tree
Showing 4 changed files with 232 additions and 53 deletions.
165 changes: 161 additions & 4 deletions acinclude.m4
Expand Up @@ -488,7 +488,7 @@ AC_DEFUN([MULE_CHECK_BFD],
#include <ansidecl.h>
#include <bfd.h>
]], [[
char *dummy = bfd_errmsg(bfd_get_error());
const char *dummy = bfd_errmsg(bfd_get_error());
]])
], [
result=yes
Expand Down Expand Up @@ -605,8 +605,8 @@ AC_DEFUN([MULE_CHECK_EXECINFO],
#include <execinfo.h>
]], [[
void *bt[1];
int n = backtrace(&bt, 1);
const char **bt_syms = backtrace_symbols(bt, n);
int n = backtrace((void **)&bt, 1);
char **bt_syms = backtrace_symbols(bt, n);
]])
], [
AH_TEMPLATE([HAVE_EXECINFO], [Define to 1 if you have the <execinfo.h> header which declares backtrace()])
Expand All @@ -617,6 +617,163 @@ AC_DEFUN([MULE_CHECK_EXECINFO],
])
])


dnl ---------------------------------------------------------------------------
dnl MULE_FUNC_MMAP
dnl
dnl This function is copied over from autoconf sources, but fixed to work with
dnl C++.
dnl ---------------------------------------------------------------------------
AC_DEFUN([MULE_FUNC_MMAP],
[AC_CHECK_HEADERS_ONCE([stdlib.h unistd.h sys/param.h])
AC_CHECK_FUNCS([getpagesize])
AC_CACHE_CHECK([for working mmap], [ac_cv_func_mmap_fixed_mapped],
[AC_RUN_IFELSE([AC_LANG_SOURCE([AC_INCLUDES_DEFAULT]
[[/* malloc might have been renamed as rpl_malloc. */
#undef malloc
/* Thanks to Mike Haertel and Jim Avera for this test.
Here is a matrix of mmap possibilities:
mmap private not fixed
mmap private fixed at somewhere currently unmapped
mmap private fixed at somewhere already mapped
mmap shared not fixed
mmap shared fixed at somewhere currently unmapped
mmap shared fixed at somewhere already mapped
For private mappings, we should verify that changes cannot be read()
back from the file, nor mmap's back from the file at a different
address. (There have been systems where private was not correctly
implemented like the infamous i386 svr4.0, and systems where the
VM page cache was not coherent with the file system buffer cache
like early versions of FreeBSD and possibly contemporary NetBSD.)
For shared mappings, we should conversely verify that changes get
propagated back to all the places they're supposed to be.
Grep wants private fixed already mapped.
The main things grep needs to know about mmap are:
* does it exist and is it safe to write into the mmap'd area
* how to use it (BSD variants) */
#include <fcntl.h>
#include <sys/mman.h>
#if !defined STDC_HEADERS && !defined HAVE_STDLIB_H
char *malloc ();
#endif
/* This mess was copied from the GNU getpagesize.h. */
#ifndef HAVE_GETPAGESIZE
# ifdef _SC_PAGESIZE
# define getpagesize() sysconf(_SC_PAGESIZE)
# else /* no _SC_PAGESIZE */
# ifdef HAVE_SYS_PARAM_H
# include <sys/param.h>
# ifdef EXEC_PAGESIZE
# define getpagesize() EXEC_PAGESIZE
# else /* no EXEC_PAGESIZE */
# ifdef NBPG
# define getpagesize() NBPG * CLSIZE
# ifndef CLSIZE
# define CLSIZE 1
# endif /* no CLSIZE */
# else /* no NBPG */
# ifdef NBPC
# define getpagesize() NBPC
# else /* no NBPC */
# ifdef PAGESIZE
# define getpagesize() PAGESIZE
# endif /* PAGESIZE */
# endif /* no NBPC */
# endif /* no NBPG */
# endif /* no EXEC_PAGESIZE */
# else /* no HAVE_SYS_PARAM_H */
# define getpagesize() 8192 /* punt totally */
# endif /* no HAVE_SYS_PARAM_H */
# endif /* no _SC_PAGESIZE */
#endif /* no HAVE_GETPAGESIZE */
int
main ()
{
char *data, *data2, *data3;
int i, pagesize;
int fd, fd2;
pagesize = getpagesize ();
/* First, make a file with some known garbage in it. */
data = (char *) malloc (pagesize);
if (!data)
return 1;
for (i = 0; i < pagesize; ++i)
*(data + i) = rand ();
umask (0);
fd = creat ("conftest.mmap", 0600);
if (fd < 0)
return 2;
if (write (fd, data, pagesize) != pagesize)
return 3;
close (fd);
/* Next, check that the tail of a page is zero-filled. File must have
non-zero length, otherwise we risk SIGBUS for entire page. */
fd2 = open ("conftest.txt", O_RDWR | O_CREAT | O_TRUNC, 0600);
if (fd2 < 0)
return 4;
data2 = (char *) "";
if (write (fd2, data2, 1) != 1)
return 5;
data2 = (char *) mmap (0, pagesize, PROT_READ | PROT_WRITE, MAP_SHARED, fd2, 0L);
if (data2 == MAP_FAILED)
return 6;
for (i = 0; i < pagesize; ++i)
if (*(data2 + i))
return 7;
close (fd2);
if (munmap (data2, pagesize))
return 8;
/* Next, try to mmap the file at a fixed address which already has
something else allocated at it. If we can, also make sure that
we see the same garbage. */
fd = open ("conftest.mmap", O_RDWR);
if (fd < 0)
return 9;
if (data2 != mmap (data2, pagesize, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_FIXED, fd, 0L))
return 10;
for (i = 0; i < pagesize; ++i)
if (*(data + i) != *(data2 + i))
return 11;
/* Finally, make sure that changes to the mapped area do not
percolate back to the file as seen by read(). (This is a bug on
some variants of i386 svr4.0.) */
for (i = 0; i < pagesize; ++i)
*(data2 + i) = *(data2 + i) + 1;
data3 = (char *) malloc (pagesize);
if (!data3)
return 12;
if (read (fd, data3, pagesize) != pagesize)
return 13;
for (i = 0; i < pagesize; ++i)
if (*(data + i) != *(data3 + i))
return 14;
close (fd);
return 0;
}]])],
[ac_cv_func_mmap_fixed_mapped=yes],
[ac_cv_func_mmap_fixed_mapped=no],
[ac_cv_func_mmap_fixed_mapped=no])])
if test $ac_cv_func_mmap_fixed_mapped = yes; then
AC_DEFINE([HAVE_MMAP], [1],
[Define to 1 if you have a working `mmap' system call.])
fi
rm -f conftest.mmap conftest.txt
])


dnl ---------------------------------------------------------------------------
dnl MULE_CHECK_MMAP
dnl
Expand All @@ -628,7 +785,7 @@ AC_DEFUN([MULE_CHECK_MMAP],
MULE_IF_ENABLED([mmap], [
AC_CHECK_HEADERS([sys/mman.h])
AC_FUNC_MMAP
MULE_FUNC_MMAP
AC_CHECK_FUNCS([munmap sysconf])
AS_IF([test $ac_cv_func_sysconf = yes], [
AC_MSG_CHECKING([for pagesize constant for sysconf])
Expand Down

0 comments on commit 7a87cf9

Please sign in to comment.