summaryrefslogtreecommitdiff
path: root/dyn_load.c
diff options
context:
space:
mode:
authorivmai <ivmai>2010-09-11 12:38:25 +0200
committerIvan Maidanski <ivmai@mail.ru>2011-07-26 19:06:54 +0200
commit1a5caf2d9f6f7d42327a8e08c69cd27e96a0b8d5 (patch)
tree274b85536bb4b858b2dcfdc82283fa4e6e57393d /dyn_load.c
parent0201a5b78617a8b2a8d18f55165868c4ee958eb2 (diff)
2010-09-11 Ivan Maidanski <ivmai@mail.ru>
* dyn_load.c (DL_ITERATE_PHDR_STRONG): New macro (define for FreeBSD). * dyn_load.c (GC_register_main_static_data): Move the definition above GC_register_dynamic_libraries_dl_iterate_phdr one (FreeBSD case); unconditionally return FALSE if DL_ITERATE_PHDR_STRONG. * dyn_load.c (GC_register_dynamic_libraries_dl_iterate_phdr): Test GC_register_main_static_data() result (instead of direct testing of dl_iterate_phdr (to prevent a compiler warning). * os_dep.c (CODE_OK): Test si_code also for the value of 2 (FreeBSD case; required for FreeBSD v7+). * os_dep.c (CODE_OK): Properly use parentheses (HPUX case). * include/private/gcconfig.h (DATASTART): Cast etext argument in GC_FreeBSDGetDataStart() call; remove unnecessary "&" (FreeBSD case).
Diffstat (limited to 'dyn_load.c')
-rw-r--r--dyn_load.c89
1 files changed, 48 insertions, 41 deletions
diff --git a/dyn_load.c b/dyn_load.c
index eab59ff..8893d34 100644
--- a/dyn_load.c
+++ b/dyn_load.c
@@ -399,6 +399,7 @@ GC_INNER GC_bool GC_register_main_static_data(void)
/* 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
+#define DL_ITERATE_PHDR_STRONG
#endif
#if defined(HAVE_DL_ITERATE_PHDR)
@@ -508,59 +509,65 @@ STATIC int GC_register_dynlib_callback(struct dl_phdr_info * info,
}
}
- * (int *)ptr = 1; /* Signal that we were called */
+ *(int *)ptr = 1; /* Signal that we were called */
return 0;
}
-/* Return TRUE if we succeed, FALSE if dl_iterate_phdr wasn't there. */
+/* Do we need to separately register the main static data segment? */
+GC_INNER GC_bool GC_register_main_static_data(void)
+{
+# ifdef DL_ITERATE_PHDR_STRONG
+ /* If dl_iterate_phdr is not a weak symbol then don't test against */
+ /* zero (otherwise a compiler might issue a warning). */
+ return FALSE;
+# else
+ return (dl_iterate_phdr == 0);
+# endif
+}
+/* Return TRUE if we succeed, FALSE if dl_iterate_phdr wasn't there. */
STATIC GC_bool GC_register_dynamic_libraries_dl_iterate_phdr(void)
{
- if (dl_iterate_phdr) {
- int did_something = 0;
+ int did_something;
+ if (GC_register_main_static_data())
+ return FALSE;
+# ifdef PT_GNU_RELRO
+ {
+ static GC_bool excluded_segs = FALSE;
+ n_load_segs = 0;
+ if (!excluded_segs) {
+ GC_exclude_static_roots_inner((ptr_t)load_segs,
+ (ptr_t)load_segs + sizeof(load_segs));
+ excluded_segs = TRUE;
+ }
+ }
+# endif
+
+ did_something = 0;
+ dl_iterate_phdr(GC_register_dynlib_callback, &did_something);
+ if (did_something) {
# ifdef PT_GNU_RELRO
- static GC_bool excluded_segs = FALSE;
- n_load_segs = 0;
- if (!excluded_segs) {
- GC_exclude_static_roots_inner((ptr_t)load_segs,
- (ptr_t)load_segs + sizeof(load_segs));
- excluded_segs = TRUE;
- }
-# endif
- dl_iterate_phdr(GC_register_dynlib_callback, &did_something);
- if (did_something) {
-# ifdef PT_GNU_RELRO
- size_t i;
+ size_t i;
- for (i = 0; i < n_load_segs; ++i) {
- if (load_segs[i].end > load_segs[i].start) {
- GC_add_roots_inner(load_segs[i].start, load_segs[i].end, TRUE);
- }
- if (load_segs[i].end2 > load_segs[i].start2) {
- GC_add_roots_inner(load_segs[i].start2, load_segs[i].end2, TRUE);
- }
+ for (i = 0; i < n_load_segs; ++i) {
+ if (load_segs[i].end > load_segs[i].start) {
+ GC_add_roots_inner(load_segs[i].start, load_segs[i].end, TRUE);
}
-# endif
- } else {
- /* 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;
+ if (load_segs[i].end2 > load_segs[i].start2) {
+ GC_add_roots_inner(load_segs[i].start2, load_segs[i].end2, TRUE);
+ }
+ }
+# endif
} else {
- return FALSE;
+ /* 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
}
-}
-
-/* Do we need to separately register the main static data segment? */
-GC_INNER GC_bool GC_register_main_static_data(void)
-{
- return (dl_iterate_phdr == 0);
+ return TRUE;
}
#define HAVE_REGISTER_MAIN_STATIC_DATA