This is the mail archive of the
mailing list for the Cygwin project.
Re: progamming with Cygwin GNU Readline Library
- From: "Robert Collins" <robert dot collins at itdomain dot com dot au>
- To: <cygwin at cygwin dot com>,"Hiroo Hayashi" <hiroo dot hayashi at computer dot org>
- Cc: <cygwin at cygwin dot com>
- Date: Mon, 7 Jan 2002 08:28:07 +1100
- Subject: Re: progamming with Cygwin GNU Readline Library
- References: <firstname.lastname@example.org> <3C38BE6C.email@example.com>
----- Original Message -----
From: "Charles Wilson" <firstname.lastname@example.org>
> Yep, this is a windows DLL problem. You can't use the address of an
> imported variable as a static initializer, because it isn't constant.
> It will depend on where the DLL is loaded into memory at each runtime.
> (I'm pretty sure of that; Corrections, anyone? Robert?)
Correct. Tech details follow.
Worse than that. The address of imported variables (without decoration)
is actually resolved to the address of the offset in the (IIRTC) IAT
(Import Address Table). So the _value_ that you'd read from that
variable would be equivalent to reading from a union of a void * and
your data type.
When you tell GCC to import a dll variable it internally considers that
to be a (<type of variable> *). I.e. if you are importing a "(struct
foo) *" from a .dll, then while your code shows
struct foo * mypointertofoo;
GCC translates this into something along the lines of
struct foo ** mypointertofoo;
And a corollary of this is that taking a static initializer is
impossible - what is the static value of "(* mypointertofoo)"? (When "*
mypointertofoo" is the value from the IAT + the loaded base address).
The only way around this that I know of is to assign the address to your
static pointer at the beginning of main.
And also, AFAIK auto-import cannot solve this, as while the value of the
statically initialised IAT member is resolveable, the application will
crash if/when the .dll relocates. I'm not sure if gcc detects this or
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Bug reporting: http://cygwin.com/bugs.html