On Tue, 2009-12-29 at 16:28 +0000, Pedro Alves wrote:
> On Tuesday 29 December 2009 14:49:36, Danny Backx wrote:
> > Replacing the underlying function do_pseudo_reloc() by an empty one also
> > got the DLL to load. Adding MessageBoxW() calls to print the arguments
> > succeeds, until I try to print the value of the third argument "base".
> > 
> > This is (from src/mingw/pseudo-reloc.c) :
> >   do_pseudo_reloc (&__RUNTIME_PSEUDO_RELOC_LIST__,
> >                    &__RUNTIME_PSEUDO_RELOC_LIST_END__,
> >                     &__U(_image_base__));
> > 
> > I tried several versions :
> >    wsprintf(msg, L"do_pseudo_reloc(%p,%p)", start, end); // works
> >    wsprintf(msg, L"do_pseudo_reloc(%p)", base); // error 1114
[..]
> Does it fail to load, crashes, prints garbage, what?

Not sure. I am using a test program that uses LoadLibrary and
GetProcAddress, see tools/dll/testapi2.c . (Actually it's a variation of
the version in SVN that can also do a DLL function call, see below.)

It reports error 1114 after the LoadLibrary call. According to MSDN this
means that the DllMain has not returned with TRUE. (To be absolutely
clear: testapi2 doesn't crash, it continues to work as expected, just
reports the error in its log file.)

I'm guessing it crashes, and that the OS catches this and replaces the
crash with that error.

> To be clear, you're not supposed to read the contents of
> _image_base__.  This is a linker defined symbol.  Only it's
> address is important.  Can you try
> printing '&__U(_image_base__)' in the caller instead?

Your first statement is clear to me. I am not trying to follow the
pointer, just printing its value.

This symbols is obviously in the DLL, I was expecting to see its runtime
value printed out :

pavilion: {1757} fgrep _image_base__ lib5bb.objdump
[255](sec -1)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00010000 __image_base__

Printing the that value in the caller does the same thing as printing it
in the underlying function : the DLL doesn't work any more.

For the record, this is what I tested. Selecting the other wsprintf
statement makes the DLL fail :
void
_pei386_runtime_relocator ()
{
  static int was_init = 0;

  if (was_init)
    return;
  ++was_init;

  {
    wchar_t msg[64];
#if 0
    wsprintf(msg, L"Ptr %p", &__U(_image_base__));
#else
    wsprintf(msg, L"Ptrs %p %p", &__RUNTIME_PSEUDO_RELOC_LIST__,
      &__RUNTIME_PSEUDO_RELOC_LIST_END__);
#endif
    MessageBoxW(0, msg, L"_pei386_runtime_relocator", 0);
  }
#if 0
  do_pseudo_reloc (&__RUNTIME_PSEUDO_RELOC_LIST__,
                   &__RUNTIME_PSEUDO_RELOC_LIST_END__,
                    &__U(_image_base__));
#endif
}

The log file output of testapi2 shows this for a failure :

LoadLibrary(lib5bb.dll) : cannot load DLL -> error 1114

and this for a succesfull execution :

Started processing DLL(lib5bb.dll)
        lib5bb.dll doesn't know about open
        lib5bb.dll implements doit (0x7813108C)
        Trying to call doit()
        doit -> 0xdead0123
        lib5bb.dll doesn't know about getDLLValue

This is based on an input file that asks it to 
 - open the DLL
 - look for a function called "open"
 - look for a function called "doit", call it, and print
   the integer it returns
 - look for a function called getDLLValue

 Danny
-- 
Danny Backx ; danny.backx - at - scarlet.be ; http://danny.backx.info


------------------------------------------------------------------------------
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