arnetheduck / nlvm

LLVM-based compiler for the Nim language
Other
712 stars 42 forks source link

Feature Request: Supporting dynlib for dynamic loading #26

Open NotoriousRebel opened 4 years ago

NotoriousRebel commented 4 years ago

Hello, I was wondering how hard it would be to support the dynlib pragma. I do a fair amount of development and that involves using the Windows API my favorite package is winim. For example with something such as OpenProcess we can see it is utilizing the dynlib pragma for dynamic loading via LoadLibraryA and GetProcAddress. If I wanted to use this with nlvm would the easiest way be to import dynlib instead and call loadlib and getsymaddr to invoke OpenProcess that way? I could copy kernel32.dll over to my setup with nlvm. However, that is not too feasible as there may be differences between the current Windows version I am using then running it on something such as Windows 7 or Windows 8.

P.S. This is an awesome project and is really useful for something I am working on.

arnetheduck commented 4 years ago

I'm not too sure, it's been a while since I did windows development so I don't quite remember how libraries are imported there - in general, nlvm probably doesn't work on windows, but on the other hand, the work to get there is probably very minor - windows generally uses a different integer size model so some minor adjustments might be needed here and there.

On unix, there's really very little advantage using dynlib and loading the symbols dynamically the way nim does it - you expose yourself to more hard-to-diagnose ABI issues and related tooling (debuggers etc) works worse. I imagine the situation is the same on windows, though I don't quite remember if linking there requires a .lib file for the dll or if the linker can do without it.