public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Takashi Yano <takashi.yano@nifty.ne.jp>
To: cygwin@cygwin.com
Subject: Re: segfault on 32bit cygwin snapshot
Date: Thu, 4 Mar 2021 18:05:34 +0900	[thread overview]
Message-ID: <20210304180534.7c3825e6ee989a2bf62f0652@nifty.ne.jp> (raw)
In-Reply-To: <YD9sSea32T7GqlJr@calimero.vinschen.de>

Hi Corinna,

On Wed, 3 Mar 2021 12:00:25 +0100
Corinna Vinschen wrote:
> [Ping Mark Geisert]
> 
> On Mar  3 18:56, Takashi Yano via Cygwin wrote:
> > Hi Corinna,
> > 
> > On Tue, 2 Mar 2021 16:48:45 +0100
> > Corinna Vinschen wrote:
> > > On Mar  2 20:03, Takashi Yano via Cygwin wrote:
> > > > > The following check code does not work as expected if
> > > > > newly build exe file is linked with old dll which calls
> > > > > uname() as in this case.
> > > > > 
> > > > >   if (CYGWIN_VERSION_CHECK_FOR_UNAME_X)
> > > > >     return uname_x (in_name);
> > > > > 
> > > > > Any idea?
> > > > 
> > > > Ping Corinna?
> > > 
> > > I have no idea how we could fix that, other than by rebuilding the DLLs
> > > which call uname, too.  We can't check the Cygwin build of all DLLs an
> > > executable is linked to.
> > 
> > I have checked all /usr/bin/*.dll in my cygwin installation and found
> > following dlls call uname() rather than uname_x().
> > [...]
> > Do you think rebuilding all of these (or maybe more) dlls is only
> > the solution? 
> 
> No, we could also drop the above code snippet.
> 
> Here's the problem: When we changed some datatypes in the early 2000s,
> the old entry points have been conserved for backward compatibility,
> while the new function using the new datatypes got a new name, e. g.,
> stat vs. _stat64.
> 
> Next, libcygwin.a gets changed so that a newly built executable (using
> the new datatypes as defined in the standard headers) calling stat is
> redirected to _stat64.
> 
> All is well for the next 15+ years or so.
> 
> Then we discover that the exact same mechanism fails to work for
> uname vs. the new uname_x in python.  What happened?
> 
> It turned out that python called uname dynamically Rather then just
> calling uname, it calls dlopen();dlsym("uname");
> 
> This actually fetches the symbol for uname, not the symbol for uname_x.
> The good old mechanism used for ages on standard function, fails as soon
> as the caller uses dynamic loading of symbols.  Surprise, surprise!
> It was just never taken into consideration that standard libc functions
> might be called dynamically, given it usually doesn't make sense.
> 
> Given that this affects *all* of these redirected functions, we're in a
> bit of a fix.  Fortunately, for all other functions this only affects 32
> bit Cygwin, because the 64 bit version never had this backward
> compatibility problem.
> 
> Therefore, uname vs. uname_x is the only function affecting 64 bit
> Cygwin as well, and that's why I added the above crude redirection only
> to uname in the first place.
> 
> So what we can do is this:
> 
> - Either all old DLLs calling uname must be rebuilt.
> 
> - Or we remove the above code snippet again and behave like for all
>   other redirected functions on 32 bit as well.  Python's os.uname is
>   broken, but all the affected DLL sstart working again.
> 
> Is there a way around that?  I'm not quite sure, so let's brain storm
> a bit, ok?
> 
> - One thing we could try is to remove the above code, but add a python
>   hack to dlsym instead.  This would let the "old" DLLs work again as
>   before and for python we could add a hack to dlsym, along these lines:
> 
>     if (CYGWIN_VERSION_CHECK_FOR_UNAME_X
>     	&& modulehandle == cygwin1.dll
> 	&& strcmp (symname, "uname"))
>       symname = "uname_x";
> 
> Thoughts?  Other ideas?

It sounds very reasonable to me to deal with it within dlsym(),
as the problem arises from the use of dlsym(). However, what
happens if newly built .exe is linked to old dll which calls
uname() via dlsym()? I am not sure whether there are such dlls.

-- 
Takashi Yano <takashi.yano@nifty.ne.jp>

  parent reply	other threads:[~2021-03-04  9:05 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-20 21:01 Marco Atzeri
2021-02-20 22:29 ` Takashi Yano
2021-02-28 18:48   ` Marco Atzeri
2021-03-01  0:55     ` Takashi Yano
2021-03-01  8:41       ` Takashi Yano
2021-03-01 11:26         ` Takashi Yano
2021-03-01 12:17           ` marco atzeri
2021-03-01 12:25       ` Takashi Yano
2021-03-02 11:03         ` Takashi Yano
2021-03-02 15:48           ` Corinna Vinschen
2021-03-03  9:56             ` Takashi Yano
2021-03-03 11:00               ` Corinna Vinschen
2021-03-04  9:05                 ` Mark Geisert
2021-03-04 16:11                   ` Corinna Vinschen
2021-03-05  9:18                     ` Mark Geisert
2021-03-05 14:37                       ` Corinna Vinschen
2021-03-04  9:05                 ` Takashi Yano [this message]
2021-03-04 11:11                   ` marco atzeri
2021-03-04 11:50                     ` Takashi Yano
2021-03-04 15:17                       ` Ken Brown
2021-03-04 15:54                         ` Corinna Vinschen
2021-03-04 20:17                         ` Marco Atzeri
2021-03-05  8:09                           ` Marco Atzeri
2021-03-05  9:11                             ` Mark Geisert
2021-03-05 14:42                               ` Corinna Vinschen
2021-03-05 16:30                                 ` Marco Atzeri
2021-03-06  1:45                                   ` Takashi Yano
2021-03-06 17:16                                     ` Ken Brown
2021-03-06 21:38                                       ` Mark Geisert
2021-03-05 22:55                                 ` Mark Geisert
2021-03-08 11:07                                   ` Mark Geisert
2021-03-08 14:01                                     ` Corinna Vinschen
2021-03-04 15:52                   ` Corinna Vinschen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210304180534.7c3825e6ee989a2bf62f0652@nifty.ne.jp \
    --to=takashi.yano@nifty.ne.jp \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).