This is the mail archive of the mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: progamming with Cygwin GNU Readline Library

----- Original Message -----
From: "Charles Wilson" <>
> 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;
(* mypointertofoo)->bar=3;

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:
Bug reporting:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]