On Friday 01 January 2010 09:37:34, Danny Backx wrote:
> On Thu, 2009-12-31 at 19:01 +0000, Pedro Alves wrote:
> > With the patches pasted below, a dll linked with the full mingw
> > runtime loaded successfully for me.
> 
> My tests confirm this too, I've committed.

FYI, I hadn't applied the ld patch myself because I was
looking to confirm/hear if there's another cleaner way
to get at the image base, but I can't find one.  Anyway, I've
now commited the mingw/pseudo-reloc patch.  (A bit cleaned up from
yesterday's, reducing divergence from upstream mingw).

-- 
Pedro Alves

2010-01-01  Pedro Alves  <pedroal...@users.sourceforge.net>

        * pseudo-reloc.c (__text_start__): Declare.
        (_pei386_runtime_relocator): On CE, don't reference
        &__image_base__; get at the image base through __text_start__ -
        0x1000 instead.

---
 mingw/pseudo-reloc.c |   34 ++++++++++++++++++++++++++++++----
 1 file changed, 30 insertions(+), 4 deletions(-)

Index: src/mingw/pseudo-reloc.c
===================================================================
--- src.orig/mingw/pseudo-reloc.c       2009-12-31 18:52:36.000000000 +0000
+++ src/mingw/pseudo-reloc.c    2010-01-01 14:51:22.000000000 +0000
@@ -20,12 +20,12 @@
 #include <stdlib.h>
 #include <string.h>
 #include <assert.h>
-#include <stddef.h>
  
  extern char __RUNTIME_PSEUDO_RELOC_LIST__;
  extern char __RUNTIME_PSEUDO_RELOC_LIST_END__;
- extern char __U(_image_base__);
-
+ extern char _image_base__;
+ extern char __text_start__;
+ 
 typedef struct {
   DWORD addend;
   DWORD target;
@@ -172,10 +172,36 @@ void
  _pei386_runtime_relocator ()
 {
   static int was_init = 0;
+#ifdef UNDER_CE
+  static volatile void *text_start;
+  static volatile int pe_header_size;
+#endif
+  void *image_base;
   if (was_init)
     return;
   ++was_init;
+
+#ifndef UNDER_CE
+  image_base = _image_base__;
+#else
+  /* The loader of Windows Mobile 6.1 and above refuses to apply base
+     relocations if the resulting RVA falls out of the image.
+     __image_base__ happens to be one such symbol, as most other ld
+     magic symbols (__dll__, __major_image_version__, etc.).
+     Basically, symbols that end up on the absolute section.  As an
+     alternative to get at the image base, we relocate against the
+     __text_start__ symbol, and subtract the PE header from that.  In
+     practice, this gives us the image base.  We go through volatile
+     globals to make sure gcc doesn't fold the 0x1000 subtraction into
+     the relocatable address, as that would be the same as relocating
+     against __image_base__ in the first place, exactly what we need
+     to avoid.  */
+  text_start = &__text_start__;
+  pe_header_size = 0x1000;
+  image_base = (char *) text_start - pe_header_size;
+#endif
+
   do_pseudo_reloc (&__RUNTIME_PSEUDO_RELOC_LIST__,
                   &__RUNTIME_PSEUDO_RELOC_LIST_END__,
-                   &__U(_image_base__));
+                  image_base);
 }

------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev 
_______________________________________________
Cegcc-devel mailing list
Cegcc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/cegcc-devel

Reply via email to