summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Maidanski <ivmai@mail.ru>2019-11-07 11:30:58 +0300
committerIvan Maidanski <ivmai@mail.ru>2019-11-07 11:39:24 +0300
commit3efd0bc4e443132653d42aca1a80b22b14930dd8 (patch)
tree273898bc8115ad060b6252297edae78663687eea
parent4dada595d172ba6bd8dd5be1d961d68f08c82058 (diff)
downloadbdwgc-3efd0bc4e443132653d42aca1a80b22b14930dd8.tar.gz
Build gctba library
Issue #268 (bdgwc). The library exports only GC_throw_bad_alloc C++ function. It is intended to solve "undefined reference to GC_throw_bad_alloc" linkage error when the client needs to avoid linking with gccpp library (to avoid "::new" redirection, in turn). * CMakeLists.txt (enable_throw_bad_alloc_library): New option (ON by default). * CMakeLists.txt [enable_cplusplus && enable_throw_bad_alloc_library] (gctba): New library. * Makefile.am [CPLUSPLUS && GC_TBA_LIBRARY] (lib_LTLIBRARIES): Add libgctba.la item. * Makefile.am [CPLUSPLUS && GC_TBA_LIBRARY] (libgctba_la_SOURCES, libgctba_la_LIBADD, libgctba_la_LDFLAGS): New variable. * Makefile.direct: Update head comment (mention gctba.a). * Makefile.direct (bsd-libgctba.a, gctba.a): New target. * NT_MAKEFILE (gctba.lib): Likewise. * WCC_MAKEFILE (gctba.lib): Likewise. * WCC_MAKEFILE [!ENABLE_STATIC] (gctba.dll): Likewise. * Makefile.direct (bsd-libgc.a): Move gctba.a to bsd-libgctba.a. * Makefile.direct (BSD-pkg-install): Copy bsd-libgctba.a; install libgctba.a. * Makefile.direct (c++): Add dependency on gc_badalc.o; call rus, $(AR) and $(RANLIB) for gctba.a. * NT_MAKEFILE (all): Add dependency on gctba.lib. * WCC_MAKEFILE (all): Likewise. * README.QUICK: Update information about "make c++" (reference libgctba.a, libgctba.so and doc/gcinterface.md). * configure.ac (throw-bad-alloc-library): Specify new AC_ARG_ENABLE. * configure.ac (GC_TBA_LIBRARY): New AM_CONDITIONAL. * doc/gcinterface.md (Class inheritance based interface): Add information about libgctba library; document GC_NEW_ABORTS_ON_OOM and GC_INCLUDE_NEW macros.
-rw-r--r--CMakeLists.txt6
-rw-r--r--Makefile.am8
-rw-r--r--Makefile.direct21
-rw-r--r--NT_MAKEFILE9
-rw-r--r--README.QUICK8
-rw-r--r--WCC_MAKEFILE27
-rw-r--r--configure.ac7
-rw-r--r--doc/gcinterface.md9
8 files changed, 83 insertions, 12 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index be083815..e9ed12e2 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -40,6 +40,7 @@ option(enable_threads "Support threads" ON)
option(enable_parallel_mark "Parallelize marking and free list construction" ON)
option(enable_thread_local_alloc "Turn on thread-local allocation optimization" ON)
option(enable_threads_discovery "Enable threads discovery in GC" ON)
+option(enable_throw_bad_alloc_library "Turn on C++ gctba library build" ON)
option(enable_gcj_support "Support for gcj" ON)
option(enable_sigrt_signals "Use SIGRTMIN-based signals for thread suspend/resume" OFF)
option(enable_gc_debug "Support for pointer back-tracing" OFF)
@@ -312,6 +313,11 @@ endif()
if (enable_cplusplus)
add_library(gccpp gc_badalc.cc gc_cpp.cc)
target_link_libraries(gccpp PRIVATE gc)
+ if (enable_throw_bad_alloc_library)
+ # The same as gccpp but contains only gc_badalc.
+ add_library(gctba gc_badalc.cc)
+ target_link_libraries(gctba PRIVATE gc)
+ endif(enable_throw_bad_alloc_library)
endif()
if (build_cord)
diff --git a/Makefile.am b/Makefile.am
index 14405162..4758a36e 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -138,6 +138,14 @@ include_HEADERS += include/extra/gc_cpp.h
libgccpp_la_SOURCES = gc_badalc.cc gc_cpp.cc
libgccpp_la_LIBADD = ./libgc.la
libgccpp_la_LDFLAGS = -version-info $(LIBGCCPP_VER_INFO) -no-undefined
+if GC_TBA_LIBRARY
+# The same as libgccpp but contains only gc_badalc.o.
+lib_LTLIBRARIES += libgctba.la
+libgctba_la_SOURCES = gc_badalc.cc
+libgctba_la_LIBADD = ./libgc.la
+# Set the same version as for libgccpp.
+libgctba_la_LDFLAGS = -version-info $(LIBGCCPP_VER_INFO) -no-undefined
+endif
endif
## FIXME: If Visual C++ users use Makefile.am, this should go into
diff --git a/Makefile.direct b/Makefile.direct
index db0c28a3..84082f3e 100644
--- a/Makefile.direct
+++ b/Makefile.direct
@@ -2,13 +2,13 @@
# to build the collector.
#
# Primary targets:
-# all - builds gc.a, gccpp.a and cord.a
+# all - builds gc.a, gccpp.a, gctba.a and cord.a
# base_lib - builds gc.a only (basic library)
-# c++ - builds gccpp.a only (C++ interface to library)
+# c++ - builds gccpp.a and gctba.a only (C++ interface to library)
# cords - builds cord.a only (heavyweight strings library)
# check - same as "all" but also prints porting information, and runs some
# tests of collector and cords
-# check-cpp - builds gc.a and gccpp.a, runs C++ only test
+# check-cpp - builds gc.a, gccpp.a and gctba.a, runs C++ only test
# cord/de - builds dumb editor based on cords.
ABI_FLAG=
@@ -156,10 +156,11 @@ LEAKFLAGS= $(CFLAGS) -DFIND_LEAK
BSD-pkg-all: bsd-libgc.a bsd-libleak.a
-bsd-libgc.a bsd-libgccpp.a:
+bsd-libgc.a bsd-libgccpp.a bsd-libgctba.a:
$(MAKE) -f Makefile.direct CFLAGS="$(CFLAGS)" clean c++-t
mv gc.a bsd-libgc.a
mv gccpp.a bsd-libgccpp.a
+ mv gctba.a bsd-libgctba.a
bsd-libleak.a:
$(MAKE) -f Makefile.direct CFLAGS="$(LEAKFLAGS)" clean c++-nt
@@ -170,12 +171,14 @@ BSD-pkg-install: BSD-pkg-all
${INSTALL_DATA} libgc.a ${PREFIX}/lib
${CP} bsd-libgccpp.a libgccpp.a
${INSTALL_DATA} libgccpp.a ${PREFIX}/lib
+ ${CP} bsd-libgctba.a libgctba.a
+ ${INSTALL_DATA} libgctba.a ${PREFIX}/lib
${INSTALL_DATA} gc.h gc_cpp.h ${PREFIX}/include
${INSTALL_MAN} doc/gc.man ${PREFIX}/man/man3/gc.3
pcr: PCR-Makefile include/private/gc_private.h include/private/gc_hdrs.h \
-include/private/gc_locks.h include/gc.h include/private/gcconfig.h \
-mach_dep.o $(SRCS)
+ include/private/gc_locks.h include/gc.h include/private/gcconfig.h \
+ mach_dep.o $(SRCS)
$(MAKE) -f PCR-Makefile depend
$(MAKE) -f PCR-Makefile
@@ -244,14 +247,18 @@ c++-t: c++ test_cpp$(EXEEXT)
c++-nt: c++
@echo "Use ./test_cpp 1 to test the leak library"
-c++ gccpp.a: gc_badalc.o gc_cpp.o $(UTILS)
+c++ gccpp.a gctba.a: gc_badalc.o gc_cpp.o $(UTILS)
rm -f dont_ar_4
./if_mach SPARC SOLARIS touch dont_ar_4
./if_mach SPARC SOLARIS $(AR) rus gccpp.a gc_badalc.o gc_cpp.o
+ ./if_mach SPARC SOLARIS $(AR) rus gctba.a gc_badalc.o
./if_mach M68K AMIGA touch dont_ar_4
./if_mach M68K AMIGA $(AR) -vrus gccpp.a gc_badalc.o gc_cpp.o
+ ./if_mach M68K AMIGA $(AR) -vrus gctba.a gc_badalc.o
./if_not_there dont_ar_4 || $(AR) ru gccpp.a gc_badalc.o gc_cpp.o
./if_not_there dont_ar_4 || $(RANLIB) gccpp.a || cat /dev/null
+ ./if_not_there dont_ar_4 || $(AR) ru gctba.a gc_badalc.o
+ ./if_not_there dont_ar_4 || $(RANLIB) gctba.a || cat /dev/null
echo > c++
dyn_load_sunos53.o: dyn_load.c
diff --git a/NT_MAKEFILE b/NT_MAKEFILE
index 628ca5ed..d725f925 100644
--- a/NT_MAKEFILE
+++ b/NT_MAKEFILE
@@ -98,7 +98,7 @@ OBJS= extra\gc.obj extra\msvc_dbg.obj
COBJS= cord\cordbscs.obj cord\cordxtra.obj cord\cordprnt.obj
-all: gc.lib cord.lib gccpp.lib
+all: gc.lib cord.lib gccpp.lib gctba.lib
check: gctest.exe test_cpp.exe cordtest.exe de.exe
gctest.exe
@@ -126,6 +126,10 @@ cord.lib: $(COBJS)
gccpp.lib: gc_badalc.obj gc_cpp.obj
lib /out:gccpp.lib /MACHINE:$(CPU) gc_badalc.obj gc_cpp.obj
+# The same as gccpp.lib but contains only gc_badalc.obj.
+gctba.lib: gc_badalc.obj
+ lib /out:gctba.lib /MACHINE:$(CPU) gc_badalc.obj
+
!ELSE
gc.lib: $(OBJS)
@@ -137,6 +141,9 @@ cord.lib: $(COBJS) gc.lib
gccpp.lib: gc_badalc.obj gc_cpp.obj gc.lib
$(link) $(ldebug) gc.lib /subsystem:windows /dll /INCREMENTAL:NO /pdb:"gccpp.pdb" /out:gccpp.dll /implib:gccpp.lib /MACHINE:$(CPU) gc_badalc.obj gc_cpp.obj
+gctba.lib: gc_badalc.obj gc.lib
+ $(link) $(ldebug) gc.lib /subsystem:windows /dll /INCREMENTAL:NO /pdb:"gctba.pdb" /out:gctba.dll /implib:gctba.lib /MACHINE:$(CPU) gc_badalc.obj
+
!ENDIF
gctest.exe: gc.lib tests\test.obj
diff --git a/README.QUICK b/README.QUICK
index b09f53ab..86638a9a 100644
--- a/README.QUICK
+++ b/README.QUICK
@@ -52,9 +52,11 @@ cordprnt.c is known to be less than perfectly portable. The rest of the
package should still work.) See include/cord.h for the API.
If you wish to use the collector from C++, type "make c++", or use
---enable-cplusplus with the configure script. With Makefile.direct,
-"make c++" creates gccpp.a file. With the alternate build process, this
-generates libgccpp.a and/or libgccpp.so. See include/gc_cpp.h.
+--enable-cplusplus with the configure script. With Makefile.direct,
+"make c++" creates gccpp.a and gctba.a files (you should link with either
+gccpp.a or gctba.a). With the alternate (preferred) build process, this
+generates libgccpp.a and libgctba.a, and/or libgccpp.so and libgctba.so.
+See include/gc_cpp.h and doc/gcinterface.md.
TYPICAL USE:
Include "gc.h" from the include subdirectory. Link against the
diff --git a/WCC_MAKEFILE b/WCC_MAKEFILE
index 612bd57f..c8657a55 100644
--- a/WCC_MAKEFILE
+++ b/WCC_MAKEFILE
@@ -78,7 +78,7 @@ TEST_CXXFLAGS= $(TEST_CFLAGS) -xs
COBJS= cordbscs.obj cordxtra.obj cordprnt.obj
-all: gc.lib gccpp.lib cord.lib
+all: gc.lib gccpp.lib gctba.lib cord.lib
check: gctest.exe test_cpp.exe cordtest.exe .SYMBOLIC
*gctest.exe
@@ -109,6 +109,12 @@ gccpp.lib: gc_badalc.obj gc_cpp.obj
@%append $*.lb1 +'gc_cpp.obj'
*wlib -b -c -n -p=512 $@ @$*.lb1
+# The same as gccpp.lib but contains only gc_badalc.obj.
+gctba.lib: gc_badalc.obj
+ @%create $*.lb1
+ @%append $*.lb1 +'gc_badalc.obj'
+ *wlib -b -c -n -p=512 $@ @$*.lb1
+
!else
gc.obj: extra\gc.c .AUTODEPEND
@@ -169,6 +175,25 @@ gccpp.dll: gc_badalc.obj gc_cpp.obj gc.lib .AUTODEPEND
@%append $*.lnk library wr7$(CALLING)dll.lib
*wlink @$*.lnk
+gctba.lib: gctba.dll
+ *wlib -b -c -n -p=512 $@ +gctba.dll
+
+gctba.dll: gc_badalc.obj gc.lib .AUTODEPEND
+ @%create $*.lnk
+!ifdef DOS4GW
+ @%append $*.lnk sys os2v2_dll
+!else ifdef MSWIN32
+ @%append $*.lnk sys nt_dll
+!else ifdef OS2
+ @%append $*.lnk sys os2v2_dll
+!endif
+ @%append $*.lnk op case
+ @%append $*.lnk name $*
+ @%append $*.lnk file 'gc_badalc.obj'
+ @%append $*.lnk library gc.lib
+ @%append $*.lnk library wr7$(CALLING)dll.lib
+ *wlink @$*.lnk
+
!endif
gctest.exe: test.obj gc.lib
diff --git a/configure.ac b/configure.ac
index 1625cbd3..9df8f444 100644
--- a/configure.ac
+++ b/configure.ac
@@ -494,6 +494,13 @@ esac
AM_CONDITIONAL(CPLUSPLUS, test "${enable_cplusplus}" = yes)
+AC_ARG_ENABLE(throw-bad-alloc-library,
+ [AC_HELP_STRING([--disable-throw-bad-alloc-library],
+ [do not build C++ gctba library])])
+AM_CONDITIONAL(GC_TBA_LIBRARY,
+ test "${enable_cplusplus}" = yes \
+ -a "${enable_throw_bad_alloc_library}" != no)
+
if test "$GCC" = yes; then
if test "${enable_cplusplus}" = yes; then
case "$host" in
diff --git a/doc/gcinterface.md b/doc/gcinterface.md
index cf648cc4..e21efbc9 100644
--- a/doc/gcinterface.md
+++ b/doc/gcinterface.md
@@ -209,6 +209,15 @@ Linking against `libgccpp` in addition to the `gc` library overrides `::new`
(and friends) to allocate traceable but uncollectible memory, making
it safe to refer to collectible objects from the resulting memory.
+If the user includes `gc_cpp.h` but `::new` should not be overridden then
+`libgctba` (in addition to the `gc`) library should be linked with to provide
+the definition of `GC_throw_bad_alloc` C++ function used by operator `new` of
+class `gc`. Alternatively, the client may define `GC_NEW_ABORTS_ON_OOM` macro
+before include of `gc_cpp.h` (this instructs `::new` to issue an abort instead
+of throwing an exception), or may define `GC_INCLUDE_NEW` one before include
+of `gc_cpp.h` (however, this might not compile or work as expected on some
+platforms).
+
## C interface
It is also possible to use the C interface from `gc.h` directly. On platforms