Pali Rohár <[email protected]> wrote:

> On Wednesday 17 June 2026 06:39:01 Kirill Makurin wrote:
>> Pali Rohár <[email protected]> wrote:
>> > Those ifdefs for library name is really ugly. I needed it more times and
>> > I was thinking about this idea:
>> >
>> > What about providing one specific symbol into every mingw-w64 CRT import
>> > library which would be a global char array with content of the library
>> > name?
> >
>> > With this, it would be needed just to reference that symbol (e.g.
>> > __mingw_crt_library_name) and could be used in any application which
>> > needs this.
>>
>> I agree that this is pretty ugly, but it was the best way to do it locally. 
>> I actually like your idea, except I would prefer to keep this stuff for 
>> internal use only.
>>
>> In posix32, I have function `p32_crt_handle`[1] which returns handle to CRT 
>> the library is linked against (or terminates the process if it failed); when 
>> linked against static CRT (MSVC with /MT switches), it returns zero to 
>> inidcate static CRT. We might as well do something similar.
>>
>> [1] 
>> https://github.com/maiddaisuki/posix32/blob/master/lib/posix32-core/src/crt.c
>>
>> > Another idea: Via WinAPI it is possible to get HMODULE from any passed
>> > address of function. So what about using address of exit function (which
>> > is available in every CRT library) then deduce HMODULE of it (which
>> > would be the currently linked CRT DLL library) and on that call
>> > GetProcAddress?
>>
>> I really forgot that it was an option. I think your idea above is generally 
>> better.
>
> I think that this is the best solution for runtime.
>
> But in my opinion this case is the "linking" problem because at the link
> time the linker knows to which library it is linking, so it could
> provide this information to application via link time symbol. And that
> was my idea above adding new "char __mingw_crt_library_name[]" symbol
> into every CRT import library.

I might have worded it poorly; I prefer the idea of providing per-library 
symbol which contains CRT library name.

- Kirill Makurin

_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to