Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re^9: Module::Install hacking

by syphilis (Chancellor)
on Sep 14, 2012 at 13:38 UTC ( #993722=note: print w/replies, xml ) Need Help??

in reply to Re^8: Module::Install hacking
in thread Module::Install hacking

If you know different, I defer; but that's my understanding at this point

I certainly don't claim to *know* a lot about this - but it was our (mine and aero's) experience that one of my past x64 builds of PDL wouldn't work (because of missing entry point) on x64 Strawberry unless we either:
a) Replaced Strawberry/c/bin/libgcc_s_sjlj-1.dll with my 4.7.0 version of the same file or
b) employed the current hack.

I did ask about this on the Strawberry list - and it was there that I was put on to the hack that I've used.

At the link you provided, I see:

If a DLL with the same module name is already loaded in memory, the system checks only for redirection and a manifest before resolving to the loaded DLL, no matter which directory it is in. The system does not search for the DLL.

There are no manifest files involved (afaik) ... and the quote I've just provided suggests to me that the already-loaded dll will therefore be used.
Admittedly I'm not sure what "redirection" is .... or what "resolving to the loaded DLL" exactly means. (What dictionary do they use in Redmond ?)

Thinking a bit more about it ... I guess that it could have been the case that the libgcc_s_sjlj-1.dll that I had provided from my 4.7.0 compiler was simply located in the wrong place. (But I think we checked that wasn't happening.)
I'll re-visit this tomorrow with a much simpler test case than PDL - just to be sure.


Replies are listed 'Best First'.
Re^10: Module::Install hacking
by BrowserUk (Pope) on Sep 15, 2012 at 00:10 UTC

    In theory, if a dll that is part of an XS module is dynamically loaded and has a dependency upon another dll that is already loaded (whether by the main perl.exe, perl5xx.dll, or some other previously loaded XS dll), then you can prevent that loaded dependency from being 'reused', by adding a xxx.dll.local file in the same directory as the xxx.dll.

    Hm. That's as clear as mud. I'l try again :)

    perl.exe uses perl5x.dll which uses dependee.dll.

    Module uses MyXS.dll uses dependee.dll. But it may need a different version of it to perl5x.dll.

    In the normal way of things, when MyXS.dll is runtime dynamically loaded as a result of use MyXS; statement, when the OS loader is loading MyXS.DLL, it sees it dependency upon dependee.dll, see that the process already has (a copy of) that loaded, and doesn't look further.

    However, if whilst loading MyXS.dll, it see a file MyXS.dll.local in the same directory, it *should* then ignore the existing in-memory copy of dependee.dll and look for (another copy) of it in the same directory as MyXS.dll, and use that for doing the fix-ups.

    That, by every interpretation I can find is what should happen. But ... I cannot make it work!

    myApp\myApp.c myApp\myApp.exe myApp\myDll.c myApp\myDLL.dll myApp\Dep.c myApp\Dep.dll myApp\Ext\ExtDll.c myApp\Ext\ExtDLL.dll myApp\Ext\ExtDLL.dll.local myApp\Ext\Dep.c myApp\Ext\Dep.dll

    MyApp.exe uses myDll.dll uses (myApp\)Dep.dll.

    At runtime, MyApp.exe LoadLibs Ext\ExtDll.dll which uses (myApp\Ext\)Dep.dll.

    The presence of myApp\Ext\ExtDLL.dll.local should force the OS loader to look in MyApp\Ext for Dep.dll when fixing up ExtDll.dll's dependencies. It doesn't:

    depends64 -c -ot:MyApp.depends -pb myapp.exe ext\ExtDLL.dll [... snip lots ...] Started "c:\test\myapp\MYAPP.EXE" (process 0x1194) at address 0x000000 +0140000000. Successfully hooked module. Loaded "c:\windows\system32\NTDLL.DLL" at address 0x0000000077A50000. + Successfully hooked module. Loaded "c:\windows\system32\KERNEL32.DLL" at address 0x000000007792000 +0. Successfully hooked module. Injected "c:\perl64\bin\DEPENDS.DLL" at address 0x0000000075030000. Loaded "c:\test\myapp\MYDLL.DLL" at address 0x0000000180000000. Succe +ssfully hooked module. Loaded "c:\test\myapp\DEP.DLL" at address 0x0000000000140000. Success +fully hooked module. Entrypoint reached. All implicit modules have been loaded. LoadLibraryExA("ext\ExtDLL.dll", 0x0000000000000000, 0x00000000) calle +d from "c:\test\myapp\MYAPP.EXE" at address 0x000000014000103F. Loaded "c:\test\myapp\ext\EXTDLL.DLL" at address 0x0000000000160000. +Successfully hooked module. LoadLibraryExA("ext\ExtDLL.dll", 0x0000000000000000, 0x00000000) retur +ned 0x0000000000160000. GetProcAddress(0x0000000000160000 [c:\test\myapp\ext\EXTDLL.DLL], "boo +t") called from "c:\test\myapp\MYAPP.EXE" at address 0x00000001400010 +92 and returned 0x0000000000161000. Exited "c:\test\myapp\MYAPP.EXE" (process 0x1194) with code 0 (0x0).

    The significant bit of that is that there is no Loaded "c:\test\myapp\Ext\DEP.DLL" ... line :( Which means that MS docs are either misleading or just outright wrong.

    It is also (theoretically) possible to attach a manifest to the XS dll that would force the OS loader to look for its dependencies in the same directory first. But the whole manifests thing just gives me a headache, so I haven't (re-)explored that this time.

    All of which means ... please forget I said anything and carry on as you were.

    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

    RIP Neil Armstrong

Re^10: Module::Install hacking
by bulk88 (Priest) on Sep 14, 2012 at 18:55 UTC
    Redirection is a ".local" file in the directory with that DLL. Only works if perl.exe does NOT have a manifest. (VC/AP 5.10 good, VC/AP 5.12 no).

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://993722]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2018-05-24 04:23 GMT
Find Nodes?
    Voting Booth?