On 25/05/2024 22:55, Martin Wege via Cygwin wrote:
Hello,

Does Cygwin or Win32 have something like LD_PRELOAD, so I can
override/substitute functions in a DLL or EXE, like it is common for
UNIX/Linux ELF shared libraries?

This is not generally available on Win32, due to limitations of the PE file format.

(basically, the import table lists symbols which are imported, and where they are imported from, so the module (shared library or executable) which provides a given symbol is determined when the module is *linked*, not when it is loaded.


However, when googling "cygwin LD_PRELOAD" (which surely you must have done before asking this question?) I discover that there's some voodoo in the cygwin DLL (hookapi.cc) which claims to do something like that, but it seems (i) this requires the preloaded DLL to explicitly hook functions it's overriding, and (ii) maybe only works on functions imported by the running executable.

It would be nice to have some documentation for that, and/or a simple example which could serve as a testcase.

--
Problem reports:      https://cygwin.com/problems.html
FAQ:                  https://cygwin.com/faq/
Documentation:        https://cygwin.com/docs.html
Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple

Reply via email to