diff options
author | Mike McGaughey <mmcg@cs.monash.edu.au> | 2013-07-21 15:47:53 +0400 |
---|---|---|
committer | Ivan Maidanski <ivmai@mail.ru> | 2013-08-25 15:22:48 +0400 |
commit | 97d71091e67380b6812dd8673c337cbf20410996 (patch) | |
tree | 84d6bf1b0a945a4044b254716b0d106996b9e595 | |
parent | 4872305d33db1c36a1cf7bf4ee157810d34cb6aa (diff) | |
download | bdwgc-97d71091e67380b6812dd8673c337cbf20410996.tar.gz |
FreeBSD New ports collection for boehm-gc v7.1
(Imported from freebsd-ports/devel/boehm-gc)
(Apply commit 2cdf7ec from 'release-7_2' branch.)
* dbg_mlc.c (GC_caller_func_offset): New function (empty unless
FreeBSD).
* dbg_mlc.c (GC_debug_malloc, GC_debug_realloc): Invoke
GC_caller_func_offset if GC_ADD_CALLER.
* include/private/gc_priv.h (GC_DBG_RA): Define to GC_RETURN_ADDR_PARENT
(if the latter is defined).
* dbg_mlc.c (GC_debug_malloc_replacement,
GC_debug_realloc_replacement): Pass NULL (instead of "unknown") to
GC_debug_malloc/realloc.
* doc/gc.man: Add "PORT INFORMATION".
* dyn_load.c (ElfW): Define for FreeBSD.
* include/private/gcconfig.h (X86_64, IA64, POWERPC, ARM32,
mach_type_known, ALIGNMENT, OS_TYPE, DYNAMIC_LOADING, HEURISTIC2,
etext, SEARCH_FOR_DATA_START): Likewise.
* os_dep.c (old_bus_act): Likewise.
* include/gc.h (GC_RETURN_ADDR_PARENT): New macro.
* os_dep.c (GC_set_and_save_fault_handler): Invoke sigaction(SIGBUS)
for FreeBSD.
* os_dep.c (AIM): Define before include machine/trap.h if FreeBSD/ppc.
* os_dep.c (CODE_OK): Define to test "code" against EXC_DSI (instead
of BUS_PAGE_FAULT) if FreeBSD/ppc.
Conflicts:
Makefile.in
configure
dbg_mlc.c
include/gc.h
include/private/gcconfig.h
os_dep.c
-rw-r--r-- | dbg_mlc.c | 36 | ||||
-rw-r--r-- | doc/gc.man | 44 | ||||
-rw-r--r-- | dyn_load.c | 6 | ||||
-rw-r--r-- | include/gc_config_macros.h | 1 | ||||
-rw-r--r-- | include/private/gc_priv.h | 6 | ||||
-rw-r--r-- | include/private/gcconfig.h | 32 | ||||
-rw-r--r-- | os_dep.c | 17 |
7 files changed, 130 insertions, 12 deletions
@@ -485,6 +485,23 @@ GC_API void GC_CALL GC_debug_register_displacement(size_t offset) UNLOCK(); } +#if defined(__FreeBSD__) +#include <dlfcn.h> +static void GC_caller_func_offset(ad, symp, offp) +const GC_word ad; +const char **symp; +int *offp; +{ + Dl_info caller; + if (dladdr((const void *)ad, &caller) && caller.dli_sname != NULL) { + *symp = caller.dli_sname; + *offp = (const char *)ad - (const char *)caller.dli_saddr; + } +} +#else +#define GC_caller_func(ad, symp, offp) +#endif + GC_API void * GC_CALL GC_debug_malloc(size_t lb, GC_EXTRA_PARAMS) { void * result; @@ -493,6 +510,13 @@ GC_API void * GC_CALL GC_debug_malloc(size_t lb, GC_EXTRA_PARAMS) /* later be successfully passed to free(). We always do the latter. */ result = GC_malloc(lb + DEBUG_BYTES); +#ifdef GC_ADD_CALLER + if (s == NULL) { + GC_caller_func_offset(ra, &s, &i); + if (s == NULL) + s = "unknown"; + } +#endif if (result == 0) { GC_err_printf("GC_debug_malloc(%lu) returning NULL (%s:%d)\n", (unsigned long)lb, s, i); @@ -841,6 +865,14 @@ GC_API void * GC_CALL GC_debug_realloc(void * p, size_t lb, GC_EXTRA_PARAMS) void * base; void * result; hdr * hhdr; + +#ifdef GC_ADD_CALLER + if (s == NULL) { + GC_caller_func_offset(ra, &s, &i); + if (s == NULL) + s = "unknown"; + } +#endif if (p == 0) return(GC_debug_malloc(lb, OPT_RA s, i)); @@ -1177,10 +1209,10 @@ GC_API void GC_CALL GC_debug_register_finalizer_ignore_self GC_API void * GC_CALL GC_debug_malloc_replacement(size_t lb) { - return GC_debug_malloc(lb, GC_DBG_RA "unknown", 0); + return GC_debug_malloc(lb, GC_DBG_RA NULL, 0); } GC_API void * GC_CALL GC_debug_realloc_replacement(void *p, size_t lb) { - return GC_debug_realloc(p, lb, GC_DBG_RA "unknown", 0); + return GC_debug_realloc(p, lb, GC_DBG_RA NULL, 0); } @@ -11,7 +11,7 @@ void GC_free(void *ptr); void * GC_realloc(void *ptr, size_t size); .br .sp -cc ... gc.a +cc ... -lgc .LP .SH DESCRIPTION .I GC_malloc @@ -88,6 +88,48 @@ This may temporarily write protect pages in the heap. See the README file for m .LP Other facilities not discussed here include limited facilities to support incremental collection on machines without appropriate VM support, provisions for providing more explicit object layout information to the garbage collector, more direct support for ``weak'' pointers, support for ``abortable'' garbage collections during idle time, etc. .LP +.SH "PORT INFORMATION" +.LP +In this (FreeBSD package) installation, +.I gc.h +and +.I gc_cpp.h +will probably be found in +.I %%PREFIX%%/include, +and the library in +.I %%PREFIX%%/lib. +.LP +This library has been compiled as drop-in replacements +for malloc and free (which is to say, all malloc +calls will allocate garbage-collectable data). +There is no need to include "gc.h" in your C files unless you want +access to the debugging (and other) functions defined there, +or unless you want to explicitly use +.I GC_malloc_uncollectable +for some allocations. +Just link against them whenever you want either garbage +collection or leak detection. +.LP +The C++ header file, "gc_cpp.h", +.I is +necessary for C++ programs, to obtain the appropriate +definitions of the +.I new +and +.I delete +operators. +The comments in both of these header files presently +provide far better documentation +for the package than this man page; +look there for more information. +.LP +This library is compiled without (explicit) support +for the experimental +.I gc +extension of +.I g++. +This may or may not make a difference. +.LP .SH "SEE ALSO" The README and gc.h files in the distribution. More detailed definitions of the functions exported by the collector are given there. (The above list is not complete.) .LP @@ -130,6 +130,12 @@ STATIC GC_has_static_roots_func GC_has_static_roots = 0; # else # define ElfW(type) Elf64_##type # endif +# elif defined(__FreeBSD__) +# if __ELF_WORD_SIZE == 32 +# define ElfW(type) Elf32_##type +# else +# define ElfW(type) Elf64_##type +# endif # else # if !defined(ELF_CLASS) || ELF_CLASS == ELFCLASS32 # define ElfW(type) Elf32_##type diff --git a/include/gc_config_macros.h b/include/gc_config_macros.h index 42743d59..bdd25f36 100644 --- a/include/gc_config_macros.h +++ b/include/gc_config_macros.h @@ -323,6 +323,7 @@ /* gcc knows how to retrieve return address, but we don't know */ /* how to generate call stacks. */ # define GC_RETURN_ADDR (GC_word)__builtin_return_address(0) +# define GC_RETURN_ADDR_PARENT (GC_word)__builtin_return_address(1) # else /* Just pass 0 for gcc compatibility. */ # define GC_RETURN_ADDR 0 diff --git a/include/private/gc_priv.h b/include/private/gc_priv.h index 4380463b..a2795ff2 100644 --- a/include/private/gc_priv.h +++ b/include/private/gc_priv.h @@ -1807,7 +1807,11 @@ GC_INNER ptr_t GC_allocobj(size_t sz, int kind); /* head. Sz is in granules. */ #ifdef GC_ADD_CALLER -# define GC_DBG_RA GC_RETURN_ADDR, +# ifdef GC_RETURN_ADDR_PARENT +# define GC_DBG_RA GC_RETURN_ADDR_PARENT, +# else +# define GC_DBG_RA GC_RETURN_ADDR, +# endif #else # define GC_DBG_RA /* empty */ #endif diff --git a/include/private/gcconfig.h b/include/private/gcconfig.h index d2488d5c..8a86864a 100644 --- a/include/private/gcconfig.h +++ b/include/private/gcconfig.h @@ -91,9 +91,9 @@ # endif # if defined(__arm) || defined(__arm__) || defined(__thumb__) # define ARM32 -# if !defined(LINUX) && !defined(NETBSD) && !defined(OPENBSD) \ - && !defined(DARWIN) && !defined(_WIN32) && !defined(__CEGCC__) \ - && !defined(SYMBIAN) +# if !defined(LINUX) && !defined(NETBSD) && !defined(FREEBSD) \ + && !defined(OPENBSD) && !defined(DARWIN) \ + && !defined(_WIN32) && !defined(__CEGCC__) && !defined(SYMBIAN) # define NOSYS # define mach_type_known # endif @@ -397,10 +397,26 @@ # define X86_64 # define mach_type_known # endif +# if defined(__FreeBSD__) && defined(__amd64__) +# define X86_64 +# define mach_type_known +# endif +# if defined(__FreeBSD__) && defined(__ia64__) +# define IA64 +# define mach_type_known +# endif # if defined(FREEBSD) && defined(__sparc__) # define SPARC # define mach_type_known # endif +# if defined(FREEBSD) && defined(__powerpc__) +# define POWERPC +# define mach_type_known +# endif +# if defined(FREEBSD) && defined(__arm__) +# define ARM32 +# define mach_type_known +# endif # if defined(bsdi) && (defined(i386) || defined(__i386__)) # define I386 # define BSDI @@ -2054,6 +2070,16 @@ # define DATAEND ((ptr_t)(&_end)) # define DYNAMIC_LOADING # endif +# ifdef FREEBSD +# define ALIGNMENT 4 +# define OS_TYPE "FREEBSD" +# ifdef __ELF__ +# define DYNAMIC_LOADING +# endif +# define HEURISTIC2 + extern char etext[]; +# define SEARCH_FOR_DATA_START +# endif # ifdef NOSYS /* __data_start is usually defined in the target linker script. */ extern int __data_start[]; @@ -847,7 +847,7 @@ GC_INNER word GC_page_size = 0; || defined(HURD) || defined(NETBSD) static struct sigaction old_segv_act; # if defined(_sigargs) /* !Irix6.x */ \ - || defined(HURD) || defined(NETBSD) + || defined(HURD) || defined(NETBSD) || defined(FREEBSD) static struct sigaction old_bus_act; # endif # else @@ -860,7 +860,7 @@ GC_INNER word GC_page_size = 0; GC_INNER void GC_set_and_save_fault_handler(GC_fault_handler_t h) { # if defined(SUNOS5SIGS) || defined(IRIX5) \ - || defined(OSF1) || defined(HURD) || defined(NETBSD) + || defined(OSF1) || defined(HURD) || defined(NETBSD) || defined(FREEBSD) struct sigaction act; act.sa_handler = h; @@ -882,7 +882,7 @@ GC_INNER word GC_page_size = 0; # else (void) sigaction(SIGSEGV, &act, &old_segv_act); # if defined(IRIX5) && defined(_sigargs) /* Irix 5.x, not 6.x */ \ - || defined(HURD) || defined(NETBSD) + || defined(HURD) || defined(NETBSD) || defined(FREEBSD) /* Under Irix 5.x or HP/UX, we may get SIGBUS. */ /* Pthreads doesn't exist under Irix 5.x, so we */ /* don't have to worry in the threads case. */ @@ -3073,8 +3073,15 @@ GC_API GC_push_other_roots_proc GC_CALL GC_get_push_other_roots(void) # ifndef SEGV_ACCERR # define SEGV_ACCERR 2 # endif -# define CODE_OK (si -> si_code == BUS_PAGE_FAULT \ - || si -> si_code == SEGV_ACCERR) +# if defined(POWERPC) +# define AIM /* Pretend that we're AIM. */ +# include <machine/trap.h> +# define CODE_OK (si -> si_code == EXC_DSI \ + || si -> si_code == SEGV_ACCERR) +# else +# define CODE_OK (si -> si_code == BUS_PAGE_FAULT \ + || si -> si_code == SEGV_ACCERR) +# endif # elif defined(OSF1) # define CODE_OK (si -> si_code == 2 /* experimentally determined */) # elif defined(IRIX5) |