On Wednesday 28 August 2024 15:51:46 Jacek Caban wrote:
> On 27.08.2024 23:35, 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 a step backwards from UCRT point of view. Right now if user
> makes such a mistake, it gets diagnostics from the linker (an error with
> binutils or a warning with LLD), while with this patch it will be silently
> accepted.
Hm... it is correct that binutils linker in this throws a fatal error?
Anyway, I have tried to compile this simple program with msvc
__declspec(dllimport) int atexit(void (*function)(void));
static void func(void) {}
int main() { atexit(func); return 0; }
and cl/link successfully generated exe file. After inspecting import
table, I see that "_crt_atexit" is used. Which means that dllimported
atexit function was transformed into _crt_atexit symbol.
So if we want for gcc/ld to allow compiling code which also msvc accepts
then we need this atexit imp symbol for compatibility.
> I think that implementing local imports in binutils would be a
> better approach.
That would allow to remove lot of manually generated imp symbols from
all source files...
>
> Anyway, it's not a big deal, feel free to ignore.
>
>
> Jacek
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public