[Gc] boehm-gc breakage between binutils 2.16.1 and 2.17 on FreeBSD [7.2]

Loren James Rittle rittle at latour.labs.mot.com
Mon Aug 31 12:20:43 PDT 2009


Problem: Static root registration fails on FreeBSD7+ when compiled
with a gcc using binutils 2.17+ for a reason described in a FIXME
comment in one version of GC_FirstDLOpenedLinkMap() in dyn_load.c.

I have developed this patch [1] against the gcc mainline source tree
copy of boehm-gc [~6.6] (for comments and/or consideration for the
official boehm-gc source tree).  Wherein, it was tested against the
current gcc mainline bootstrapped to use GNU binutils 2.19.1 on
FreeBSD 7.2 [1 test passed].  I have also tested it against boehm-gc
6.8 as otherwise patched and configured in the FreeBSD ports
collection (against both the system compiler/linker and the
aforementioned gcc bootstrap configuration) [All 2 tests passed].  The
patch [1] did not apply cleanly against gc-7.2alpha2 so patch [2] was
created and tested [All 6 tests passed].

First of all, I have seperated the macro check to decide whether we
HAVE_DL_ITERATE_PHDR from the code enabled.  This simplifies adding
checks for those systems (FYI, other non-linux, ELF systems besides
FreeBSD would likely benefit from a similar change) that don't have
the same complex glibc version dependencies.  Next, I add a check for
the point at which the FreeBSD system supports dl_iterate_phdr.

Please advise me if patch [2] can be accepted against gc-7.2/mainline.
I shall submit patch [1] to gcc-patches after I learn the disposition.

Regards,
Loren

2009-08-31  Loren J. Rittle  <ljrittle at acm.org>

	* dyn_load.c (HAVE_DL_ITERATE_PHDR): Break definition from use.
	Define for FreeBSD 7.0+.

[1]
Index: dyn_load.c
===================================================================
--- dyn_load.c	(revision 151243)
+++ dyn_load.c	(working copy)
@@ -400,7 +400,17 @@
 /* It may still not be available in the library on the target system.   */
 /* Thus we also treat it as a weak symbol.				*/
 #define HAVE_DL_ITERATE_PHDR
+#pragma weak dl_iterate_phdr
+#endif
 
+# if (defined(FREEBSD) && __FreeBSD__ >= 7)
+/* On the FreeBSD system, any target system at major version 7 shall    */
+/* have dl_iterate_phdr; therefore, we need not make it weak as above.  */
+#define HAVE_DL_ITERATE_PHDR
+#endif
+
+#if defined(HAVE_DL_ITERATE_PHDR)
+
 static int GC_register_dynlib_callback(info, size, ptr)
      struct dl_phdr_info * info;
      size_t size;
@@ -441,8 +451,6 @@
 
 /* Return TRUE if we succeed, FALSE if dl_iterate_phdr wasn't there. */
 
-#pragma weak dl_iterate_phdr
-
 GC_bool GC_register_dynamic_libraries_dl_iterate_phdr()
 {
   if (dl_iterate_phdr) {

[2]
--- dyn_load.c.orig	2009-06-04 22:32:39.000000000 -0500
+++ dyn_load.c	2009-08-31 13:56:14.000000000 -0500
@@ -374,6 +374,20 @@
 # if (defined(LINUX) || defined (__GLIBC__)) /* Are others OK here, too? */ \
      && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2) \
          || (__GLIBC__ == 2 && __GLIBC_MINOR__ == 2 && defined(DT_CONFIG))) 
+/* We have the header files for a glibc that includes dl_iterate_phdr.	*/
+/* It may still not be available in the library on the target system.   */
+/* Thus we also treat it as a weak symbol.				*/
+#define HAVE_DL_ITERATE_PHDR
+#pragma weak dl_iterate_phdr
+#endif
+
+# if (defined(FREEBSD) && __FreeBSD__ >= 7)
+/* On the FreeBSD system, any target system at major version 7 shall    */
+/* have dl_iterate_phdr; therefore, we need not make it weak as above.  */
+#define HAVE_DL_ITERATE_PHDR
+#endif
+
+#if defined(HAVE_DL_ITERATE_PHDR)
 
 # ifdef PT_GNU_RELRO
 
@@ -399,11 +413,6 @@
 
 # endif /* PT_GNU_RELRO */
 
-/* We have the header files for a glibc that includes dl_iterate_phdr.	*/
-/* It may still not be available in the library on the target system.   */
-/* Thus we also treat it as a weak symbol.				*/
-#define HAVE_DL_ITERATE_PHDR
-
 /* A user-supplied routine that is called to determine if a DSO must
    be scanned by the gc.  */
 static int (GC_CALLBACK * GC_has_static_roots)(const char *, void *, size_t);
@@ -489,8 +498,6 @@
 
 /* Return TRUE if we succeed, FALSE if dl_iterate_phdr wasn't there. */
 
-#pragma weak dl_iterate_phdr
-
 GC_bool GC_register_dynamic_libraries_dl_iterate_phdr(void)
 {
   if (dl_iterate_phdr) {


More information about the Gc mailing list