diff --git a/gcc/crtstuff.c b/gcc/crtstuff.c --- a/gcc/crtstuff.c +++ b/gcc/crtstuff.c @@ -53,6 +53,8 @@ see the files COPYING3 and COPYING.RUNTI identified the set of defines that need to go into auto-target.h, this will have to do. */ #include "auto-host.h" +#include + #undef pid_t #undef rlim_t #undef ssize_t @@ -563,8 +565,29 @@ static void __attribute__((used)) __do_global_ctors_aux (void) { func_ptr *p; - for (p = __CTOR_END__ - 1; *p != (func_ptr) -1; p--) + long top = 0; + long base = 0; + + for (p = __CTOR_END__ - 1; *p != (func_ptr) -1; p--) { + long value = (long)*p; + if (value) { + if (top == 0) { + top = ((value)/4096+1)*4096; + base = value; + } else if (value < base) + base = value; + } + } + + if (top) { + base = base/4096*4096; + int ret = madvise((void*)base, top - base, MADV_WILLNEED); + fprintf(stderr, "%x %x madvise:%d\n", base, top - base, ret); + } + + for (p++;p != __CTOR_END__;p++) { (*p) (); + } } /* Stick a call to __do_global_ctors_aux into the .init section. */