[Gc] Dependency tracking for configuration macros

Petter Urkedal urkedal at nbi.dk
Wed May 20 12:18:25 PDT 2009


The attached patch adds AC_CONFIG_HEADER to configure.ac, so that the
command-line "-D"-options are replace by the conditional inclusion of a
generated config.h header.  The major part of the patch is the addition
of documentation to configuration macros.

I tested the patch on various configurations on Linux x86_64 and i386 by
diff-ing the disassembly of the object files before and after applying
the patch.

-----%<-----
Dependency tracking for configuration macros.

configure.ac, acinclude.m4:
        * Invoke AC_CONFIG_HEADER.
        * Added documentation of configuration macros.
        * Commented out the unused macros STACKBASE and DATASTART_IS_ETEXT.
configure.ac, Makefile.am:
        * Moved include paths to Makefile.am. 
        * Added include path for build directory.

include/gc_config_macros.h, include/private/gcconfig.h:
        * Conditionally include "private/config.h".
include/gc.h, include/private/gc_pmark.h,
backgraph.c, checksums.c, gcj_mlc.c, real_malloc.c, tests/test.c:
        * Minor adjustments to make sure that the config macros are
        defined before use.
-----%<-----
-------------- next part --------------
diff --git a/Makefile.am b/Makefile.am
index 7a20394..90c5845 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -32,6 +32,11 @@
 # endif
 SUBDIRS =
 
+AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_builddir)/include \
+	      -DGC_HAVE_PRIVATE_CONFIG_H
+# The GC_HAVE_PRIVATE_CONFIG_H is needed because it's unsafe to rely on
+# HAVE_CONFIG_H in the public gc_version.h header.
+
 # Initialize variables so that we can declare files locally.
 EXTRA_DIST = 
 lib_LTLIBRARIES =
diff --git a/acinclude.m4 b/acinclude.m4
index 97255c8..0c18172 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -37,10 +37,13 @@ AC_DEFUN([GC_SET_VERSION], [
     AC_MSG_ERROR([nonconforming PACKAGE_VERSION='$PACKAGE_VERSION'])
   fi
   
-  AC_DEFINE_UNQUOTED(GC_VERSION_MAJOR, $GC_VERSION_MAJOR)
-  AC_DEFINE_UNQUOTED(GC_VERSION_MINOR, $GC_VERSION_MINOR)
+  AC_DEFINE_UNQUOTED([GC_VERSION_MAJOR], $GC_VERSION_MAJOR,
+		     [The major version number of this GC release.])
+  AC_DEFINE_UNQUOTED([GC_VERSION_MINOR], $GC_VERSION_MINOR,
+		     [The minor version number of this GC release.])
   if test :$GC_ALPHA_VERSION: != :: ; then
-    AC_DEFINE_UNQUOTED(GC_ALPHA_VERSION, $GC_ALPHA_VERSION)
+    AC_DEFINE_UNQUOTED([GC_ALPHA_VERSION], $GC_ALPHA_VERSION,
+		       [The alpha version number, if applicable.])
   fi
   AC_MSG_RESULT(major=$GC_VERSION_MAJOR minor=$GC_VERSION_MINOR \
 ${GC_ALPHA_VERSION:+alpha=}$GC_ALPHA_VERSION)
diff --git a/backgraph.c b/backgraph.c
index 0ca0519..e81a03e 100644
--- a/backgraph.c
+++ b/backgraph.c
@@ -24,6 +24,8 @@
  * a growing space leak.
  */
 
+#include "gc_config_macros.h"
+
 #ifdef MAKE_BACK_GRAPH
 
 #define MAX_IN	10	/* Maximum in-degree we handle directly */
diff --git a/checksums.c b/checksums.c
index 91f3b28..52ce5e6 100644
--- a/checksums.c
+++ b/checksums.c
@@ -11,10 +11,11 @@
  * modified is included with the above copyright notice.
  */
 /* Boehm, March 29, 1995 12:51 pm PST */
-# ifdef CHECKSUMS
 
 # include "private/gc_priv.h"
 
+# ifdef CHECKSUMS
+
 /* This is debugging code intended to verify the results of dirty bit	*/
 /* computations. Works only in a single threaded environment.		*/
 /* We assume that stubborn objects are changed only when they are 	*/
diff --git a/configure.ac b/configure.ac
index c81a29e..190b228 100644
--- a/configure.ac
+++ b/configure.ac
@@ -25,6 +25,7 @@ AC_PREREQ(2.53)
 AC_REVISION($Revision: 1.42 $)
 GC_SET_VERSION
 AM_INIT_AUTOMAKE([foreign dist-bzip2 subdir-objects nostdinc])
+AM_CONFIG_HEADER([include/private/config.h])
 AM_MAINTAINER_MODE
 
 AC_SUBST(PACKAGE)
@@ -68,7 +69,31 @@ AC_ARG_ENABLE(parallel-mark,
 AC_ARG_ENABLE(cplusplus,
     [AC_HELP_STRING([--enable-cplusplus], [install C++ support])])
 
-INCLUDES=-I${srcdir}/include
+dnl Features which may be selected in the folliwng thread-detection switch.
+AH_TEMPLATE([PARALLEL_MARK], [Define to enable parallel marking.])
+AH_TEMPLATE([THREAD_LOCAL_ALLOC],
+	    [Define to enable thread-local allocation optimisation.])
+AH_TEMPLATE([USE_COMPILER_TLS],
+	    [Define to use of compiler-support for thread-local variables.])
+
+dnl Thread selection macros.
+AH_TEMPLATE([GC_AIX_THREADS],       [Define to support IBM AIX threads.])
+AH_TEMPLATE([GC_DARWIN_THREADS],    [Define to support Darwin pthreads.])
+AH_TEMPLATE([GC_FREEBSD_THREADS],   [Define to support FreeBSD pthreads.])
+AH_TEMPLATE([GC_GNU_THREADS],       [Define to support GNU pthreads.])
+AH_TEMPLATE([GC_HPUX_THREADS],      [Define to support HP/UX 11 pthreads.])
+AH_TEMPLATE([GC_IRIX_THREADS],      [Define to support Irix pthreads.])
+AH_TEMPLATE([GC_LINUX_THREADS],     [Define to support pthreads on Linux.])
+AH_TEMPLATE([GC_NETBSD_THREADS],    [Define to support NetBSD pthreads.])
+AH_TEMPLATE([GC_OSF1_THREADS],      [Define to support Tru64 pthreads.])
+AH_TEMPLATE([GC_SOLARIS_THREADS],   [Define to support Solaris pthreads.])
+AH_TEMPLATE([GC_WIN32_THREADS],     [Define to support win32 threads.])
+
+dnl System header feature requests.
+AH_TEMPLATE([_POSIX_C_SOURCE], [The POSIX feature macro.])
+AH_TEMPLATE([_PTHREADS], [Indicates the use of pthreads (NetBSD).])
+
+INCLUDES=
 THREADDLLIBS=
 need_atomic_ops_asm=false
 ## Libraries needed to support dynamic loading and/or threads.
@@ -189,7 +214,7 @@ case "$THREADS" in
     AC_DEFINE(GC_WIN32_THREADS)
     win32_threads=true
     dnl Wine getenv may not return NULL for missing entry
-    AC_DEFINE(NO_GETENV)
+    AC_DEFINE([NO_GETENV], 1, [Define to remove calls to getenv.])
     ;;
  dgux386)
     THREADS=dgux386
@@ -201,8 +226,10 @@ case "$THREADS" in
     fi
     AC_DEFINE(THREAD_LOCAL_ALLOC)
     AC_MSG_WARN("Explict GC_INIT() calls may be required.");
-    AC_DEFINE(GC_DGUX386_THREADS)
-    AC_DEFINE(DGUX_THREADS)
+    AC_DEFINE([GC_DGUX386_THREADS], 1,
+	      [Define to enable support for DB/UX threads on i386.])
+    AC_DEFINE([DGUX_THREADS], 1,
+	      [Define to enable support for DB/UX threads.])
     # Enable _POSIX4A_DRAFT10_SOURCE with flag -pthread
     INCLUDES="-pthread $INCLUDES"
     ;;
@@ -289,7 +316,7 @@ AC_MSG_RESULT($compiler_xlc)
 AM_CONDITIONAL(COMPILER_XLC,test $compiler_xlc = yes)
 if test $compiler_xlc = yes -a "$powerpc_darwin" = true; then
   # the darwin stack-frame-walking code is completely broken on xlc
-  AC_DEFINE(DARWIN_DONT_PARSE_STACK)
+  AC_DEFINE([DARWIN_DONT_PARSE_STACK], 1, [See Makefile.direct])
 fi
 
 # We never want libdl on darwin. It is a fake libdl that just ends up making
@@ -340,7 +367,7 @@ case "$TARGET_ECOS" in
    no)
       ;;
    *)
-      AC_DEFINE(ECOS)
+      AC_DEFINE(ECOS, 1, [Define to enable eCos target support.])
       CXXINCLUDES="-I${TARGET_ECOS}/include"
       addobjs="$addobjs ecos.lo"
       ;;
@@ -383,12 +410,12 @@ case "$host" in
     machdep="mach_dep.lo"
     ;;
  i?86-*-solaris2.[[89]] | i?86-*-solaris2.1?)
-    AC_DEFINE(SOLARIS25_PROC_VDB_BUG_FIXED)
+    AC_DEFINE(SOLARIS25_PROC_VDB_BUG_FIXED, 1, [See gcconfig.h])
     ;;
  mipstx39-*-elf*)
     machdep="mach_dep.lo"
-    AC_DEFINE(STACKBASE, __stackbase)
-    AC_DEFINE(DATASTART_IS_ETEXT)
+    dnl AC_DEFINE(STACKBASE, __stackbase)
+    dnl AC_DEFINE(DATASTART_IS_ETEXT)
     ;;
  mips-dec-ultrix*)
     machdep="mach-dep.lo"
@@ -414,7 +441,8 @@ case "$host" in
     ;;
  sparc-sun-solaris2.3)
     machdep="mach_dep.lo sparc_mach_dep.lo"
-    AC_DEFINE(SUNOS53_SHARED_LIB)
+    AC_DEFINE(SUNOS53_SHARED_LIB, 1,
+	      [Define to work around a Solaris 5.3 bug (see dyn_load.c).])
     ;;
  sparc*-sun-solaris2*)
     machdep="mach_dep.lo sparc_mach_dep.lo"
@@ -500,8 +528,10 @@ esac
 
 dnl Include defines that have become de facto standard.
 dnl ALL_INTERIOR_POINTERS can be overridden in startup code.
-AC_DEFINE(NO_EXECUTE_PERMISSION)
-AC_DEFINE(ALL_INTERIOR_POINTERS)
+AC_DEFINE([NO_EXECUTE_PERMISSION], [1],
+	  [Define to allow the collector to disable execute permission of heap objects.])
+AC_DEFINE([ALL_INTERIOR_POINTERS], [1],
+	  [Define to recognise all pointers to the interior of objects.])
 
 
 dnl Interface Selection
@@ -521,14 +551,22 @@ fi
 dnl Debugging
 dnl ---------
 
+AH_TEMPLATE([GC_HAVE_BUILTIN_BACKTRACE],
+	    [Define if backtrace information is supported.])
+AH_TEMPLATE([MAKE_BACK_GRAPH], [See Makefile.direct.])
+AH_TEMPLATE([SAVE_CALL_COUNT],
+	    [The number of caller frames saved when allocating with the
+	     debugging API.])
 UNWINDLIBS=
 AC_ARG_ENABLE(gc-debug,
 [AC_HELP_STRING([--enable-gc-debug],
     [include full support for pointer backtracing etc.])],
 [ if test "$enable_gc_debug" = "yes"; then
     AC_MSG_WARN("Should define GC_DEBUG and use debug alloc. in clients.")
-    AC_DEFINE(KEEP_BACK_PTRS)
-    AC_DEFINE(DBG_HDRS_ALL)
+    AC_DEFINE([KEEP_BACK_PTRS], 1,
+	      [Define to save back-pointers in debugging headers.])
+    AC_DEFINE([DBG_HDRS_ALL], 1,
+	      [Define to force debug headers on all objects.])
     case $host in
       ia64-*-linux* )
 	AC_DEFINE(MAKE_BACK_GRAPH)
@@ -554,7 +592,7 @@ AC_ARG_ENABLE(java-finalization,
     [AC_HELP_STRING([--disable-java-finalization],
 	[Disable support for java finalization.])])
 if test x"$enable_java_finalization" != xno; then
-    AC_DEFINE(JAVA_FINALIZATION)
+    AC_DEFINE([JAVA_FINALIZATION], 1, [See Makefile.direct.])
 fi
 
 AC_ARG_ENABLE(atomic-uncollectable,
@@ -571,13 +609,16 @@ AC_ARG_ENABLE(redirect-malloc,
 
 if test "${enable_redirect_malloc}" = yes; then
     if test "${enable_gc_debug}" = yes; then
-	AC_DEFINE(REDIRECT_MALLOC, GC_debug_malloc_replacement)
-	AC_DEFINE(REDIRECT_REALLOC, GC_debug_realloc_replacement)
-	AC_DEFINE(REDIRECT_FREE, GC_debug_free)
+	AC_DEFINE([REDIRECT_MALLOC], GC_debug_malloc_replacement,
+		  [If defined, redirect malloc to this function.])
+	AC_DEFINE([REDIRECT_REALLOC], GC_debug_realloc_replacement,
+		  [If defined, redirect GC_realloc to this function.])
+	AC_DEFINE([REDIRECT_FREE], GC_debug_free,
+		  [If defined, redirect free to this function.])
     else
 	AC_DEFINE(REDIRECT_MALLOC, GC_malloc)
     fi
-    AC_DEFINE(GC_USE_DLOPEN_WRAP)
+    AC_DEFINE([GC_USE_DLOPEN_WRAP], 1, [See Makefile.direct.])
 fi
 
 AC_ARG_ENABLE(large-config,
@@ -592,9 +633,11 @@ dnl This is something of a hack.  When cross-compiling we turn off
 dnl some functionality.  We also enable the "small" configuration.
 dnl These is only correct when targetting an embedded system.  FIXME.
 if test -n "${with_cross_host}"; then
-   AC_DEFINE(NO_CLOCK)
-   AC_DEFINE(SMALL_CONFIG)
-   AC_DEFINE(NO_DEBUGGING)
+   AC_DEFINE([NO_CLOCK], 1, [Define to not use system clock (cross compiling).])
+   AC_DEFINE([SMALL_CONFIG], 1,
+	     [Define to tune the collector for small heap sizes.])
+   AC_DEFINE([NO_DEBUGGING], 1,
+	     [Disable debugging, like GC_dump and its callees.])
 fi
 
 
@@ -604,7 +647,7 @@ AC_ARG_ENABLE(gc-assertions,
     [AC_HELP_STRING([--enable-gc-assertions],
 	[collector-internal assertion checking])])
 if test "${enable_gc_assertions}" = yes; then
-    AC_DEFINE(GC_ASSERTIONS)
+    AC_DEFINE([GC_ASSERTIONS], 1, [Define to enable internal debug assertions.])
 fi
 
 AC_ARG_ENABLE(munmap,
@@ -618,12 +661,16 @@ AC_ARG_ENABLE(munmap,
     esac]
    )
 if test "${enable_munmap}" != ""; then
-    AC_DEFINE(USE_MMAP)
-    AC_DEFINE(USE_MUNMAP)
+    AC_DEFINE([USE_MMAP], 1,
+	      [Define to use mmap instead of sbrk to expand the heap.])
+    AC_DEFINE([USE_MUNMAP], 1,
+	      [Define to return memory to OS with munmap calls.
+	       See Makefile.direct.])
     if test "${MUNMAP_THRESHOLD}" = "yes"; then
       MUNMAP_THRESHOLD=6
     fi
-    AC_DEFINE_UNQUOTED(MUNMAP_THRESHOLD, ${MUNMAP_THRESHOLD})
+    AC_DEFINE_UNQUOTED([MUNMAP_THRESHOLD], [${MUNMAP_THRESHOLD}],
+	[Number of GC cycles to wait before unmapping an unused block.])
 fi
 
 AM_CONDITIONAL(USE_LIBDIR, test -z "$with_cross_host")
diff --git a/gcj_mlc.c b/gcj_mlc.c
index 4755e18..bf51d34 100644
--- a/gcj_mlc.c
+++ b/gcj_mlc.c
@@ -14,6 +14,8 @@
  */
 /* Boehm, July 31, 1995 5:02 pm PDT */
 
+#include "gc_config_macros.h"
+
 #ifdef GC_GCJ_SUPPORT
 
 /*
diff --git a/include/gc.h b/include/gc.h
index ba4ca32..8aaa7c2 100644
--- a/include/gc.h
+++ b/include/gc.h
@@ -31,6 +31,8 @@
 
 # define _GC_H
 
+# include "gc_config_macros.h"
+
 # include "gc_version.h"
 	/* Define version numbers here to allow test on build machine	*/
 	/* for cross-builds.  Note that this defines the header		*/
@@ -38,8 +40,6 @@
 	/* dynamic library.  The GC_version variable can be used	*/
 	/* to obtain the latter.					*/
 
-# include "gc_config_macros.h"
-
 # ifdef __cplusplus
     extern "C" {
 # endif
diff --git a/include/gc_config_macros.h b/include/gc_config_macros.h
index ac56b71..caddfbd 100644
--- a/include/gc_config_macros.h
+++ b/include/gc_config_macros.h
@@ -5,6 +5,13 @@
  * Some tests for old macros.  These violate our namespace rules and will
  * disappear shortly.  Use the GC_ names.
  */
+
+/* When building from Makefile.am, include the Autoconf-generated header. */
+#if defined(GC_HAVE_PRIVATE_CONFIG_H) && !defined(GC_PRIVATE_CONFIG_H)
+#   define GC_PRIVATE_CONFIG_H 1
+#   include "private/config.h"
+#endif
+
 #if defined(SOLARIS_THREADS) || defined(_SOLARIS_THREADS) \
     || defined(_SOLARIS_PTHREADS) || defined(GC_SOLARIS_PTHREADS)
   /* We no longer support old style Solaris threads.		*/
diff --git a/include/private/gc_pmark.h b/include/private/gc_pmark.h
index 45346e2..f4a0247 100644
--- a/include/private/gc_pmark.h
+++ b/include/private/gc_pmark.h
@@ -25,15 +25,15 @@
 #ifndef GC_PMARK_H
 # define GC_PMARK_H
 
+# ifndef GC_PRIVATE_H
+#   include "gc_priv.h"
+# endif
 # if defined(KEEP_BACK_PTRS) || defined(PRINT_BLACK_LIST)
 #   include "dbg_mlc.h"
 # endif
 # ifndef GC_MARK_H
 #   include "../gc_mark.h"
 # endif
-# ifndef GC_PRIVATE_H
-#   include "gc_priv.h"
-# endif
 
 /* The real declarations of the following is in gc_priv.h, so that	*/
 /* we can avoid scanning the following table.				*/
diff --git a/include/private/gcconfig.h b/include/private/gcconfig.h
index bf5e739..4f26fe6 100644
--- a/include/private/gcconfig.h
+++ b/include/private/gcconfig.h
@@ -26,6 +26,11 @@
 
 # define GCCONFIG_H
 
+# if defined(GC_HAVE_PRIVATE_CONFIG_H) && !defined(GC_PRIVATE_CONFIG_H)
+#   define GC_PRIVATE_CONFIG_H
+#   include "private/config.h"
+# endif
+
 # ifndef GC_PRIVATE_H
     /* Fake ptr_t declaration, just to avoid compilation errors.	*/
     /* This avoids many instances if "ifndef GC_PRIVATE_H" below.	*/
diff --git a/real_malloc.c b/real_malloc.c
index 85befdc..3b68f6e 100644
--- a/real_malloc.c
+++ b/real_malloc.c
@@ -14,6 +14,8 @@
 /* Boehm, May 19, 1994 2:04 pm PDT */
 
 
+# include "gc_config_macros.h"
+
 # ifdef PCR
 /*
  * This definition should go in its own file that includes no other
diff --git a/tests/test.c b/tests/test.c
index a667d1d..1f3c26f 100644
--- a/tests/test.c
+++ b/tests/test.c
@@ -18,6 +18,7 @@
 /* GC.  It uses GC internals to allow more precise results	*/
 /* checking for some of the tests.				*/
 
+# include "gc_config_macros.h"
 # undef GC_BUILD
 
 #if (defined(DBG_HDRS_ALL) || defined(MAKE_BACK_GRAPH)) && !defined(GC_DEBUG)


More information about the Gc mailing list