ocaml / flexdll

a dlopen-like API for Windows
Other
98 stars 30 forks source link

recognize data symbols inside import libraries #3

Closed fdopen closed 4 years ago

fdopen commented 9 years ago

I can't link to certain dlls, because flexlink can't resolve the used symbols (but the gcc toolchain can deal with them). The problem are some data symbols inside import libraries. They are prefixed with '_nm' and are therefore not found by flexlink.

libffi-6.dll:

LIBRARY "libffi-6.dll"
EXPORTS
ffi_call
ffi_call_win64
ffi_closure_alloc
ffi_closure_free
ffi_closure_win64
ffi_closure_win64_inner
ffi_prep_args
ffi_prep_cif
ffi_prep_cif_core
ffi_prep_cif_machdep
ffi_prep_cif_var
ffi_prep_closure
ffi_prep_closure_loc
ffi_type_double DATA
ffi_type_float DATA
ffi_type_longdouble DATA
ffi_type_pointer DATA
ffi_type_sint16 DATA
ffi_type_sint32 DATA
ffi_type_sint64 DATA
ffi_type_sint8 DATA
ffi_type_uint16 DATA
ffi_type_uint32 DATA
ffi_type_uint64 DATA
ffi_type_uint8 DATA
ffi_type_void DATA

x86_64-w64-mingw32-nm.exe libffi.dll.a:

[...]
d000014.o:
0000000000000000 i .idata$4
0000000000000000 i .idata$5
0000000000000000 i .idata$6
0000000000000000 i .idata$7
0000000000000000 t .text
0000000000000000 I __imp_ffi_type_double
0000000000000000 I __nm_ffi_type_double
                 U _head_libffi_6_dll
d000013.o:
[...]
d000012.o:
0000000000000000 i .idata$4
0000000000000000 i .idata$5
0000000000000000 i .idata$6
0000000000000000 i .idata$7
0000000000000000 t .text
0000000000000000 I __imp_ffi_prep_closure
                 U _head_libffi_6_dll
0000000000000000 T ffi_prep_closure

So flexlink can resolve ffi_prep_closure, but not to ffi_type_double. (Example error message: https://github.com/ocamllabs/ocaml-ctypes/issues/198 )

Similar case: libsqlite3.dll.a

d000173.o:
0000000000000000 i .idata$4
0000000000000000 i .idata$5
0000000000000000 i .idata$6
0000000000000000 i .idata$7
0000000000000000 t .text
0000000000000000 I __imp_sqlite3_temp_directory
0000000000000000 I __nm_sqlite3_temp_directory
                 U _head_libsqlite3_0_dll

d000172.o:

flexlink can't resolve sqlite3_temp_directory.

The supplied patch tells flexlink about the presence of the data symbols.

hcarty commented 7 years ago

@fdopen Are you still having this issue? I think I have run into this as well when using https://github.com/whitequark/opam-cross-windows.

fdopen commented 7 years ago

It's still reported in the issue tracker of ctypes from time to time, see eg.: https://github.com/ocamllabs/ocaml-ctypes/issues/435

dra27 commented 6 years ago

There's a similar patch used in Cygwin: https://github.com/cygwinports/flexdll/blob/master/0.35-data-auto-imports.patch

dra27 commented 4 years ago

@fdopen - would you be happy to rebase this, and it should then be merged. I'm happy to rebase it for you if you're very reasonably otherwise engaged at the moment!

dra27 commented 4 years ago

(I have personally be using a version of it rebased on top of the 0.37 tag at https://github.com/dra27/flexdll/commit/6d1062642a2f872c14956d6bbb55d9bb3e6bf4a6)

dra27 commented 4 years ago

Thanks, @fdopen!