From 0c35069f58e55d76eb86bf362725abed17981d08 Mon Sep 17 00:00:00 2001 From: Andy Wingo Date: Thu, 10 Apr 2025 12:13:48 +0200 Subject: [PATCH] Add autotools embedding files --- embed.am | 210 +++++++++++++++++++++++++++++++++++++++++++++++++++++ whippet.m4 | 181 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 391 insertions(+) create mode 100644 embed.am create mode 100644 whippet.m4 diff --git a/embed.am b/embed.am new file mode 100644 index 000000000..81f93d287 --- /dev/null +++ b/embed.am @@ -0,0 +1,210 @@ +# Automake snippet for embedding Whippet in an autotools project. +# +# The including Makefile.am needs to do this, assuming Whippet is in the +# whippet/ subdirectory: +# +# noinst_LTLIBRARIES = +# WHIPPET_EMBEDDER_CPPFLAGS = -include src/my-embedder.h +# include whippet/embed.am +# +# my-embedder.h should provide the various hooks that Whippet needs to +# specialize itself to the embedder's object representation. +# +# The result is a libwhippet.la. To compile and link against it: +# +# AM_CFLAGS = $(WHIPPET_CPPFLAGS) $(WHIPPET_CFLAGS) $(WHIPPET_TO_EMBEDDER_CPPFLAGS) +# LDADD = libwhippet.la +# AM_LDFLAGS = $(WHIPPET_TO_EMBEDDER_LDFLAGS) +# +# The assumption is that the embedder will build a single copy of +# Whippet, specialized against a single collector, a single set of +# embedder hooks, and a single target platform. The collector and +# platform should be chosen at configure-time. Because Automake really +# wants the set of source files to be visible to it at automake-time, we +# need to implement these conditions via AM_CONDITIONAL in a +# configure.ac. For example for a parallel-mmc configuration on +# gnu-linux, we would need: +# +# AM_SUBST(WHIPPET_COLLECTOR, parallel-mmc) +# AM_CONDITIONAL(WHIPPET_COLLECTOR_SEMI, 0) +# AM_CONDITIONAL(WHIPPET_COLLECTOR_PCC, 0) +# AM_CONDITIONAL(WHIPPET_COLLECTOR_BDW, 0) +# AM_CONDITIONAL(WHIPPET_COLLECTOR_MMC, 1) +# AM_CONDITIONAL(WHIPPET_PLATFORM_GNU_LINUX, 1) +# +# Then there are other conditionals for compilation options: +# +# AM_CONDITIONAL(WHIPPET_ENABLE_DEBUG, 0) +# AM_CONDITIONAL(WHIPPET_USE_LTTNG, 1) +# +# Finally, LTO should be enabled, for best performance. This should be +# added to CFLAGS at configure-time. +# +# Getting all of this in there is gnarly. See the example configure.ac +# for one take on the topic. + +noinst_LTLIBRARIES += libwhippet-common.la libwhippet.la + +libwhippet_common_la_SOURCES = \ + %D%/src/gc-options-internal.h \ + %D%/src/gc-options.c \ + %D%/src/gc-stack.c \ + %D%/src/gc-stack.h \ + %D%/src/gc-tracepoint.c + +if WHIPPET_PLATFORM_GNU_LINUX +libwhippet_common_la_SOURCES += %D%/src/gc-platform-gnu-linux.c +endif + +libwhippet_la_SOURCES = \ + %D%/src/adaptive-heap-sizer.h \ + %D%/src/address-hash.h \ + %D%/src/address-map.h \ + %D%/src/address-set.h \ + %D%/src/assert.h \ + %D%/src/background-thread.h \ + %D%/src/copy-space.h \ + %D%/src/debug.h \ + %D%/src/extents.h \ + %D%/src/field-set.h \ + %D%/src/freelist.h \ + %D%/src/gc-align.h \ + %D%/src/gc-ephemeron-internal.h \ + %D%/src/gc-ephemeron.c \ + %D%/src/gc-finalizer-internal.h \ + %D%/src/gc-finalizer.c \ + %D%/src/gc-internal.h \ + %D%/src/gc-lock.h \ + %D%/src/gc-platform.h \ + %D%/src/gc-trace.h \ + %D%/src/generational-roots.h \ + %D%/src/growable-heap-sizer.h \ + %D%/src/heap-sizer.h \ + %D%/src/large-object-space.h \ + %D%/src/local-worklist.h \ + %D%/src/nofl-space.h \ + %D%/src/nursery.h \ + %D%/src/parallel-tracer.h \ + %D%/src/remembered-edges.h \ + %D%/src/root.h \ + %D%/src/root-worklist.h \ + %D%/src/serial-tracer.h \ + %D%/src/shared-worklist.h \ + %D%/src/simple-worklist.h \ + %D%/src/spin.h \ + %D%/src/splay-tree.h \ + %D%/src/swar.h \ + %D%/src/tracer.h + +WHIPPET_CFLAGS_bdw = -DGC_CONSERVATIVE_ROOTS=1 -DGC_CONSERVATIVE_TRACE=1 +WHIPPET_CFLAGS_semi = -DGC_PRECISE_ROOTS=1 +WHIPPET_CFLAGS_pcc = -DGC_PRECISE_ROOTS=1 -DGC_PARALLEL=1 +WHIPPET_CFLAGS_generational_pcc = $(WHIPPET_CFLAGS_pcc) -DGC_GENERATIONAL=1 +WHIPPET_CFLAGS_mmc = \ + -DGC_PRECISE_ROOTS=1 +WHIPPET_CFLAGS_generational_mmc = \ + -DGC_PRECISE_ROOTS=1 -DGC_GENERATIONAL=1 +WHIPPET_CFLAGS_parallel_mmc = \ + -DGC_PRECISE_ROOTS=1 -DGC_PARALLEL=1 +WHIPPET_CFLAGS_parallel_generational_mmc = \ + -DGC_PRECISE_ROOTS=1 -DGC_GENERATIONAL=1 -DGC_PARALLEL=1 +WHIPPET_CFLAGS_stack_conservative_mmc = \ + -DGC_CONSERVATIVE_ROOTS=1 +WHIPPET_CFLAGS_stack_conservative_generational_mmc = \ + -DGC_CONSERVATIVE_ROOTS=1 -DGC_GENERATIONAL=1 +WHIPPET_CFLAGS_stack_conservative_parallel_mmc = \ + -DGC_CONSERVATIVE_ROOTS=1 -DGC_PARALLEL=1 +WHIPPET_CFLAGS_stack_conservative_parallel_generational_mmc = \ + -DGC_CONSERVATIVE_ROOTS=1 -DGC_GENERATIONAL=1 -DGC_PARALLEL=1 +WHIPPET_CFLAGS_heap_conservative_mmc = \ + -DGC_CONSERVATIVE_ROOTS=1 -DGC_CONSERVATIVE_TRACE=1 +WHIPPET_CFLAGS_heap_conservative_generational_mmc = \ + -DGC_CONSERVATIVE_ROOTS=1 -DGC_CONSERVATIVE_TRACE=1 -DGC_GENERATIONAL=1 +WHIPPET_CFLAGS_heap_conservative_parallel_mmc = \ + -DGC_CONSERVATIVE_ROOTS=1 -DGC_CONSERVATIVE_TRACE=1 -DGC_PARALLEL=1 +WHIPPET_CFLAGS_heap_conservative_parallel_generational_mmc = \ + -DGC_CONSERVATIVE_ROOTS=1 -DGC_CONSERVATIVE_TRACE=1 -DGC_GENERATIONAL=1 -DGC_PARALLEL=1 + +WHIPPET_CFLAGS = $(WHIPPET_CFLAGS_$(subst -,_,$(WHIPPET_COLLECTOR))) +WHIPPET_IMPL_CFLAGS = +WHIPPET_LIBS = -lm +WHIPPET_CPPFLAGS = -I%D%/api +WHIPPET_TO_EMBEDDER_CPPFLAGS = $(WHIPPET_CPPFLAGS) + +if WHIPPET_ENABLE_DEBUG +WHIPPET_CFLAGS += -DGC_DEBUG=1 +endif + +if WHIPPET_COLLECTOR_SEMI +libwhippet_la_SOURCES += %D%/src/semi.c +WHIPPET_TO_EMBEDDER_CPPFLAGS += -include %D%/api/semi-attrs.h +endif + +if WHIPPET_COLLECTOR_PCC +libwhippet_la_SOURCES += %D%/src/pcc.c +WHIPPET_TO_EMBEDDER_CPPFLAGS += -include %D%/api/pcc-attrs.h +endif + +if WHIPPET_COLLECTOR_BDW +libwhippet_la_SOURCES += %D%/src/bdw.c +WHIPPET_IMPL_CFLAGS += $(WHIPPET_BDW_CFLAGS) +WHIPPET_LIBS += $(WHIPPET_BDW_LIBS) +WHIPPET_TO_EMBEDDER_CPPFLAGS += -include %D%/api/bdw-attrs.h +endif + +if WHIPPET_COLLECTOR_MMC +libwhippet_la_SOURCES += %D%/src/mmc.c +WHIPPET_TO_EMBEDDER_CPPFLAGS += -include %D%/api/mmc-attrs.h +endif + +# add to cflags: -flto -fvisibility=hidden -fno-strict-aliasing + +libwhippet_common_la_CPPFLAGS = $(WHIPPET_CPPFLAGS) +libwhippet_common_la_CFLAGS = -Wall -Wno-unused $(CFLAGS) +libwhippet_common_la_CFLAGS += $(WHIPPET_CFLAGS) +libwhippet_common_la_LDFLAGS = -lpthread $(LDFLAGS) +libwhippet_common_la_LIBADD = $(LIBS) + +if WHIPPET_USE_LTTNG +libwhippet_common_la_CPPFLAGS += $(WHIPPET_LTTNG_CFLAGS) -DGC_TRACEPOINT_LTTNG=1 +WHIPPET_LIBS += $(WHIPPET_LTTNG_LIBS) +endif + +if !WHIPPET_ENABLE_DEBUG +libwhippet_common_la_CFLAGS += -DNDEBUG +endif + +libwhippet_la_CPPFLAGS = $(libwhippet_common_la_CPPFLAGS) $(WHIPPET_EMBEDDER_CPPFLAGS) +libwhippet_la_CFLAGS = $(libwhippet_common_la_CFLAGS) +libwhippet_la_CFLAGS += $(WHIPPET_IMPL_CFLAGS) +libwhippet_la_LDFLAGS = $(libwhippet_common_la_LDFLAGS) $(WHIPPET_LIBS) +libwhippet_la_LIBADD = libwhippet-common.la + +noinst_HEADERS = \ + %D%/api/bdw-attrs.h \ + %D%/api/gc-allocation-kind.h \ + %D%/api/gc-api.h \ + %D%/api/gc-assert.h \ + %D%/api/gc-attrs.h \ + %D%/api/gc-basic-stats.h \ + %D%/api/gc-collection-kind.h \ + %D%/api/gc-config.h \ + %D%/api/gc-conservative-ref.h \ + %D%/api/gc-edge.h \ + %D%/api/gc-embedder-api.h \ + %D%/api/gc-ephemeron.h \ + %D%/api/gc-event-listener-chain.h \ + %D%/api/gc-event-listener.h \ + %D%/api/gc-finalizer.h \ + %D%/api/gc-forwarding.h \ + %D%/api/gc-histogram.h \ + %D%/api/gc-inline.h \ + %D%/api/gc-lttng.h \ + %D%/api/gc-null-event-listener.h \ + %D%/api/gc-options.h \ + %D%/api/gc-ref.h \ + %D%/api/gc-tracepoint.h \ + %D%/api/gc-visibility.h \ + %D%/api/mmc-attrs.h \ + %D%/api/pcc-attrs.h \ + %D%/api/semi-attrs.h diff --git a/whippet.m4 b/whippet.m4 new file mode 100644 index 000000000..9cd5c3449 --- /dev/null +++ b/whippet.m4 @@ -0,0 +1,181 @@ +AC_DEFUN([WHIPPET_ENABLE_LTO], + [AC_REQUIRE([AC_PROG_CC]) + AC_MSG_CHECKING([whether the compiler supports -flto]) + old_CFLAGS="$CFLAGS" + LTO_CFLAGS="-flto" + CFLAGS="$CFLAGS $LTO_CFLAGS" + AC_LINK_IFELSE([AC_LANG_PROGRAM([int foo;], [])],, [LTO_CFLAGS=]) + CFLAGS="$old_CFLAGS" + if test -n "$LTO_CFLAGS"; then + AC_MSG_RESULT([yes]) + else + AC_MSG_RESULT([no]) + fi + + AC_ARG_ENABLE(lto, + [AS_HELP_STRING([--enable-lto] + [enable link-time optimization])], + [], + [if test -z "$LTO_CFLAGS"; then enable_lto=no; else enable_lto=yes; fi]) + case "$enable_lto" in + yes | y) + if test -z "$LTO_CFLAGS"; then + AC_MSG_ERROR([--enable-lto=$enable_lto unsupported for $CC]) + fi + CFLAGS="$CFLAGS $LTO_CFLAGS" + AC_MSG_CHECKING([for lto-specific prefix for ar, nm, objcopy, ranlib]) + if test "$GCC" = yes; then + TOOLCHAIN_PREFIX=gcc + else + # Assuming LLVM if not GCC. Probably won't hurt. + TOOLCHAIN_PREFIX=llvm + fi + AC_MSG_RESULT([$TOOLCHAIN_PREFIX]) + AC_CHECK_TOOLS([AR], [$TOOLCHAIN_PREFIX-ar ar]) + AC_CHECK_TOOLS([NM], [$TOOLCHAIN_PREFIX-nm nm]) + AC_CHECK_TOOLS([OBJCOPY], [$TOOLCHAIN_PREFIX-objcopy objcopy]) + AC_CHECK_TOOLS([RANLIB], [$TOOLCHAIN_PREFIX-ranlib ranlib]) + ;; + no | n) + ;; + *) + AC_MSG_ERROR([unexpected --enable-lto=$enable_lto]) + ;; + esac]) + +AC_DEFUN([WHIPPET_PKG_PLATFORM], + [# Detect the target system + AC_MSG_CHECKING([which platform support library the garbage collector should use]) + case "$host_os" in + *linux-gnu*) + AC_MSG_RESULT(gnu-linux) + whippet_platform=gnu-linux + ;; + *) + AC_MSG_ERROR([unsupported host OS: $host_os]) + ;; + esac + AM_CONDITIONAL(WHIPPET_PLATFORM_GNU_LINUX, [test "$whippet_platform" = gnu-linux])]) + +AC_DEFUN([WHIPPET_PKG_TRACING], + [WHIPPET_TRACING_DEFAULT="m4_default([$1], [auto])" + AC_ARG_WITH(gc-lttng, + AS_HELP_STRING([--with-gc-lttng], + [Compile GC library with LTTng tracing support (default: $WHIPPET_TRACING_DEFAULT)]), + [whippet_with_lttng=$withval], + [whippet_with_lttng=auto]) + PKG_CHECK_MODULES(WHIPPET_LTTNG, lttng-ust, + [whippet_have_lttng=yes], [whippet_have_lttng=no]) + AC_MSG_CHECKING(whether to compile GC library with LTTng tracing support) + if test "$whippet_with_lttng" = auto; then + if test "$whippet_have_lttng" = no; then + whippet_use_lttng=no + else + whippet_use_lttng=yes + fi + else + whippet_use_lttng=$whippet_with_lttng + fi + AC_MSG_RESULT($whippet_use_lttng) + + if test "$whippet_use_lttng" != no && test "$whippet_have_lttng" = no; then + AC_MSG_ERROR([LTTng support explicitly required, but lttng not found]) + fi + AM_CONDITIONAL(WHIPPET_USE_LTTNG, [test "$whippet_use_lttng" != no]) + AC_SUBST(WHIPPET_LTTNG_CFLAGS) + AC_SUBST(WHIPPET_LTTNG_LIBS)]) + +AC_DEFUN([WHIPPET_PKG_COLLECTOR], + [PKG_CHECK_MODULES(WHIPPET_BDW, bdw-gc, + [whippet_have_bdw=yes], [whippet_have_bdw=no]) + AC_SUBST(WHIPPET_BDW_CFLAGS) + AC_SUBST(WHIPPET_BDW_LIBS) + + WHIPPET_COLLECTOR_DEFAULT="m4_default([$1], [pcc])" + AC_ARG_WITH(gc, + AS_HELP_STRING([--with-gc], + [Select garbage collector implementation (see --with-gc=help)]), + [whippet_collector=$withval], + [whippet_collector=$WHIPPET_COLLECTOR_DEFAULT]) + + WHIPPET_ALL_COLLECTORS=$(echo <