On Tue, 27 Aug 2024, Pali Rohár wrote:

On Tuesday 27 August 2024 23:20:23 Jacek Caban wrote:
On 27.08.2024 21:16, Pali Rohár wrote:
> +/* define just import symbol, function itself is in crtexe.c and crtdll.c 
files */
> +int (__cdecl *__MINGW_IMP_SYMBOL(atexit))(void (__cdecl *)(void)) = atexit;


The patch looks mostly good to me, but do we need this __imp_ symbol at all?
We already declare it without dllimport in the header.


Thanks,

Jacek

I thought that it is a good idea to provide __imp_ symbol for every
function which is originally available in DLL library. Reason is that it
is not required to use declarations from mingw-w64 header files and it is
possible to define own function declarations (with dllimport attribute)
or use object files compiled by msvc compiler.

When writing own declaration of function which is in external DLL
library, it is common to mark function as dllimport. And "atexit"
function looks like it can be in external DLL library.

In any case, this __imp_ symbol is in separate object file in .a
library, so should not cause any issues if the __imp_ symbol is not used
at all. Linker should not include it into final binary if is unused.

I think this is fine.

I wouldn't maybe go out and adding separate __imp_ symbols for exactly everything, if there are many symbols where we're missing it, if there's no specific use case for it. That the user could declare it themselves with a dllimport attribute isn't strictly a case I think we need to support (overall, our import libraries are meant to be used together with our headers), but for a single case like this one I don't mind.

While reading this patch, I was wondering if our existing UCRT _onexit -> _crt_atexit function was unused and could be removed now, but it seems to me that other CRT libraries export an _onexit function anyway, so I guess it makes sense to keep it, just for keeping the CRT library interface uniform.

// Martin

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

Reply via email to