Skip to content

FFI: support symbol lookup without specifying lib on Windows #16351

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from

Conversation

cmb69
Copy link
Member

@cmb69 cmb69 commented Oct 10, 2024

This works similar to dlsym(RTLD_DEFAULT, …) with the caveat that symbols on Windows may not be unique, and are usually qualified by the module they are exported from. That means that wrong symbols may be fetched, potentially causing serious issues; therefore this usage is not recommended for production purposes, but is a nice simplification for quick experiments and the ext/ffi test suite.


Note that a particular example for where this shouldn't be used is gh14626.phpt which uses malloc() which is, contrary to skip reason, available on Windows easily multiple times (I had it in a debug build in ucrtbase.dll, ucrtbased.dll and msvcrt.dll at least).

This works similar to `dlsym(RTLD_DEFAULT, …)` with the caveat that
symbols on Windows may not be unique, and are usually qualified by the
module they are exported from.  That means that wrong symbols may be
fetched, potentially causing serious issues; therefore this usage is
not recommended for production purposes, but is a nice simplification
for quick experiments and the ext/ffi test suite.
Copy link
Member

@dstogov dstogov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!
See one minor comment.

@cmb69 cmb69 closed this in db991bc Oct 19, 2024
@cmb69 cmb69 deleted the cmb/ffi-dlsym-rtld-default-win branch October 19, 2024 13:37
cmb69 added a commit that referenced this pull request Oct 20, 2024
PR #16351 introduced `EnumProcessModules()` calls, but this function is
undefined; thus, the compiler mangles the name according to the default
calling convention.  This lets linking succeed for x64, but fail for
x86.

To properly fix this, we include <Psapi.h> where the function is
declared.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants