aboutsummaryrefslogtreecommitdiff
path: root/boehm-gc/dyn_load.c
diff options
context:
space:
mode:
Diffstat (limited to 'boehm-gc/dyn_load.c')
-rw-r--r--boehm-gc/dyn_load.c68
1 files changed, 52 insertions, 16 deletions
diff --git a/boehm-gc/dyn_load.c b/boehm-gc/dyn_load.c
index d3ef572be68..71ad5fb1d78 100644
--- a/boehm-gc/dyn_load.c
+++ b/boehm-gc/dyn_load.c
@@ -355,10 +355,6 @@ void GC_register_dynamic_libraries()
/* Stack mapping; discard */
continue;
}
- if (start <= datastart && end > datastart && maj_dev != 0) {
- /* Main data segment; discard */
- continue;
- }
# ifdef THREADS
if (GC_segment_is_thread_stack(start, end)) continue;
# endif
@@ -384,6 +380,13 @@ void GC_register_dynamic_libraries()
}
}
+/* We now take care of the main data segment ourselves: */
+GC_bool GC_register_main_static_data()
+{
+ return FALSE;
+}
+
+# define HAVE_REGISTER_MAIN_STATIC_DATA
//
// parse_map_entry parses an entry from /proc/self/maps so we can
// locate all writable data segments that belong to shared libraries.
@@ -469,13 +472,6 @@ static int GC_register_dynlib_callback(info, size, ptr)
+ sizeof (info->dlpi_phnum))
return -1;
- /* Skip the first object - it is the main program. */
- if (*(int *)ptr == 0)
- {
- *(int *)ptr = 1;
- return 0;
- }
-
p = info->dlpi_phdr;
for( i = 0; i < (int)(info->dlpi_phnum); ((i++),(p++)) ) {
switch( p->p_type ) {
@@ -491,6 +487,7 @@ static int GC_register_dynlib_callback(info, size, ptr)
}
}
+ * (int *)ptr = 1; /* Signal that we were called */
return 0;
}
@@ -500,16 +497,31 @@ static int GC_register_dynlib_callback(info, size, ptr)
GC_bool GC_register_dynamic_libraries_dl_iterate_phdr()
{
- int tmp = 0;
-
if (dl_iterate_phdr) {
- dl_iterate_phdr(GC_register_dynlib_callback, &tmp);
+ int did_something = 0;
+ dl_iterate_phdr(GC_register_dynlib_callback, &did_something);
+ if (!did_something) {
+ /* dl_iterate_phdr may forget the static data segment in */
+ /* statically linked executables. */
+ GC_add_roots_inner(DATASTART, (char *)(DATAEND), TRUE);
+# if defined(DATASTART2)
+ GC_add_roots_inner(DATASTART2, (char *)(DATAEND2), TRUE);
+# endif
+ }
return TRUE;
} else {
return FALSE;
}
}
+/* Do we need to separately register the main static data segment? */
+GC_bool GC_register_main_static_data()
+{
+ return (dl_iterate_phdr == 0);
+}
+
+#define HAVE_REGISTER_MAIN_STATIC_DATA
+
# else /* !LINUX || version(glibc) < 2.2.4 */
/* Dynamic loading code for Linux running ELF. Somewhat tested on
@@ -775,10 +787,23 @@ void GC_register_dynamic_libraries()
}
# endif
-# ifndef MSWINCE
+# ifdef MSWINCE
+ /* Do we need to separately register the main static data segment? */
+ GC_bool GC_register_main_static_data()
+ {
+ return FALSE;
+ }
+# else /* win32 */
extern GC_bool GC_no_win32_dlls;
-# endif
+
+ GC_bool GC_register_main_static_data()
+ {
+ return GC_no_win32_dlls;
+ }
+# endif /* win32 */
+# define HAVE_REGISTER_MAIN_STATIC_DATA
+
void GC_register_dynamic_libraries()
{
MEMORY_BASIC_INFORMATION buf;
@@ -1079,4 +1104,15 @@ void GC_register_dynamic_libraries(){}
int GC_no_dynamic_loading;
#endif /* !PCR */
+
#endif /* !DYNAMIC_LOADING */
+
+#ifndef HAVE_REGISTER_MAIN_STATIC_DATA
+
+/* Do we need to separately register the main static data segment? */
+GC_bool GC_register_main_static_data()
+{
+ return TRUE;
+}
+#endif /* HAVE_REGISTER_MAIN_STATIC_DATA */
+