[Mingw-users] btowc problem

Back to archive index
Eli Zaretskii eliz****@gnu*****
Fri Jul 3 21:51:52 JST 2020


> Date: Thu, 02 Jul 2020 05:41:46 +0300
> From: Eli Zaretskii <eliz****@gnu*****>
> 
> > > My suggestion was to add to 5.3.x libmingwex.a implementations of
> > > btowc etc. that simply call the corresponding __msvcrt_* functions, so
> > > that libraries compiled by older MinGW versions could still be happy
> > > when linked under the newer mingwrt.
> > 
> > No, that cannot work; it would create a recursive call loop with no
> > terminal condition, until the process runs out of stack space.
> 
> You are saying that __msvcrt_* functions call btowc etc.?  I thought
> they were doing that via a function pointer, which gets populated at
> run time?

I think I see what you were alluding to.  It's this code in the
__msvcrt_* functions:

  if(  (redirector_hook == NULL)
  &&  ((redirector_hook = dlsym( RTLD_DEFAULT, "btowc" )) == NULL)  )
  {
    /* ...but when no Microsoft implementation can be found, register
     * the MinGW fallback in its stead.
     */
    redirector_hook = __mingw_btowc_fallback;
  }

Since the dlsym call uses RTLD_DEFAULT, it will search the modules
that are already loaded into the program's address space, and will
thus find the implementation I proposed to put in libmingwex, which
then will cause it to call itself, recursively, this blowing up the
stack.  Not good.

But we could instead look for these functions explicitly in
MSVCRT.DLL, not in all of the loaded modules, couldn't we?

However, if this is not a good idea, then yes, I think having these
functions in libmingwex that redirect to __mingw_* replacements
unconditionally is a good-enough solution.



More information about the MinGW-Users mailing list
Back to archive index