From: Pedro Alves <pedro@codesourcery.com>
To: gdb-patches@sourceware.org
Cc: Joel Brobecker <brobecker@adacore.com>,
John Spencer <maillist-gdbpatches@barfooze.de>
Subject: Re: [RFC] Crash sourcing Python script on Windows
Date: Thu, 29 Sep 2011 10:54:00 -0000 [thread overview]
Message-ID: <201109291151.30633.pedro@codesourcery.com> (raw)
In-Reply-To: <20110929040634.GD19246@adacore.com>
On Thursday 29 September 2011 05:06:34, Joel Brobecker wrote:
> > FILE is supposed to be an opaque type and as such noone except of
> > the libc which defines it is supposed to "poke" at its internals.
> > however it is common practice in GNU software to assume everybody
> > uses GLIBC and poke around in internal stuff thats not supposed to
> > be accessibly at all in userland.
>
> It could be something simpler than that. Python was built on one
> system, using an unknown build environment. when then use that
> library to link it against some code on a version of Windows that
> is most likely different, with a compiler that is also most likely
> different. If each compiler used a libc where the definition of
> that type is different, then we have an incompatibility.
It is much more likely that your python is linked with a C runtime,
while gdb is linked with another. Try "info sharedlibrary",
and you'll probably see both msvcrXX.dll and both msvcrt.dll loaded.
There's not a single/main C runtime on a Windows system. The C runtime on
Windows is not a central part of the whole system runtime like tradicionally
on Unix. The NT api (and Win32 on top) fills that central role.
There's msvcrt.dll, originally part of Visual C++, but which is bundled
in Windows nowadays (*), and then there's the msvcrtd.dll, the debug variant,
and then Visual Studio will default to link with a different C runtime, and
a different one for each version, going by msvcrXXX.dll names (with XXX
being 70, 80, 90, 100, etc.)
It is common to end up with more than one C runtime loaded
on Windows. Windows dlls are self contained, and all its symbols
must be defined at link-time. There's no symbol interposition
concept in PE.
If you have your application linked with, say, msvcrt.dll, which is
what mingw links with by default, and you load a Dll that was linked
with, say, msvcr70.dll, you'll end up with both C runtimes loaded
in the process. Each of the runtimes will have its own separate
internal state. That's the crux. Given that, you need to be careful to
not pass/use C runtime objects across dlls. E.g., if you malloc
in dll/executable A, you can pass that around to other dlls, but you should
`free' that memory back on dll/executable A, so that the proper runtime
is called. If you had free'd memory in dll B instead (which was linked
against a different runtime, hence you call a different `free' function), B's
C runtime would have no clue what that pointer was -- it's just gargabe from
its perpective, and you'd likely crash.
Same with FILE*, and file descriptions. Each runtime maintains its
own internal state for those.
In a nutshell, your patch is correct.
If such a fix is not always possible, then we'll have to make sure you link
the same runtime in all the offending dlls (those that pass around C
runtime objects).
--
Pedro Alves
next prev parent reply other threads:[~2011-09-29 10:51 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-09-28 23:24 Joel Brobecker
2011-09-29 2:00 ` Paul_Koning
2011-09-29 2:19 ` John Spencer
2011-09-29 4:47 ` Joel Brobecker
2011-09-29 7:30 ` Eli Zaretskii
2011-09-29 8:54 ` Kai Tietz
2011-09-29 9:48 ` Eli Zaretskii
2011-09-29 9:51 ` Kai Tietz
2011-09-29 10:54 ` Pedro Alves [this message]
2011-09-29 12:33 ` Eli Zaretskii
2011-09-29 12:48 ` Kai Tietz
2011-09-29 13:19 ` Pedro Alves
2011-09-29 7:26 ` Eli Zaretskii
2011-10-03 20:05 ` Tom Tromey
2011-09-29 7:20 ` Eli Zaretskii
2011-10-03 20:02 ` Tom Tromey
2011-10-03 20:53 ` Joel Brobecker
2011-10-04 17:08 ` Tom Tromey
2012-01-23 18:14 ` [patch] Do not open Python scripts twice #2 [Re: [RFC] Crash sourcing Python script on Windows] Jan Kratochvil
2012-01-23 18:41 ` Pedro Alves
2012-01-23 21:55 ` Jan Kratochvil
2012-01-23 22:08 ` Doug Evans
2012-01-23 22:47 ` Jan Kratochvil
2012-01-23 23:47 ` Doug Evans
2012-01-24 14:45 ` Jan Kratochvil
2012-01-24 18:56 ` Doug Evans
2012-01-24 19:41 ` Jan Kratochvil
2012-01-24 22:20 ` Doug Evans
2012-01-24 23:49 ` Jan Kratochvil
2012-01-25 22:30 ` Jan Kratochvil
2012-01-26 7:18 ` Joel Brobecker
2012-01-26 22:03 ` [commit] " Jan Kratochvil
2012-01-24 15:15 ` Pedro Alves
2012-01-23 19:57 ` Pedro Alves
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=201109291151.30633.pedro@codesourcery.com \
--to=pedro@codesourcery.com \
--cc=brobecker@adacore.com \
--cc=gdb-patches@sourceware.org \
--cc=maillist-gdbpatches@barfooze.de \
/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