Linker, initialization of global variables and the size of INIT segment
Hello, Thomas!
Thank you for answer.
Please, see my comments below.
"Thomas Maeder [TeamB]" <maeder@glue.ch> writes:
NM>> Whenever you are writing a big project using Borland C++ Builder (no
matter
NM>> which version) one day you will face the situation when some of global
NM>> variables constructors have never been called.
TM> Only if you use global variables of class type.
Yes, of course. What else type of variable needs constructor to be called?
NM>> I met various discussions on this issue. TeamB usually replies that the
NM>> problem is in the undefined order of initialization of modules. This is
NM>> obviously not true
TM> I can't remember somebody arguing that the reason for a global object
*never*
TM> to be constructed was the undefined order of initialization (without
being
TM> corrected, anyway).
Yes, you are right. Order of initialization can not be the reason. And
discussions that I've searched through never suggested this as the reason
for constructors never been called they only doubted that author of the
topic check construction in right way. You may find such discussions by
typing something like "global variables initialization borland". For
instance this is first that comes to my sight:
http://groups.google.com.ru/groups?q=global+variables+initialization+borland
&hl=ru&lr=&ie=UTF-8&oe=UTF-8&selm=3cebee5d%241_2%40dnews&rnum=5
TM> That order can certainly cause an object not yet to be constructed at a
TM> certain point during the execution of the program; but I don't think
that it
TM> can prevent an object from being constructed at all.
Yes, again, you are perfectly right.
NM>> since in accordance with do***entation order of
NM>> initialization is defined by linkage order or by dependency order if
NM>> "#pragma package" is used.
TM> Could you please indicate which part of the do***entation you write
about?
TM> I don't doubt what you write, but discussing is easier if both sides
discuss
TM> the same text.
Yes, of course. See Borland C++ Builder Help (version 5.0 or 6.0 - it doesn'
t matter) sections "Initialization order of OBJs" and "Initialization order
of units". Also I checked it by ****yzing RTL source code (see procedure
_init_exit_proc in initexit.c).
TM> This looks like the start of a reproducible test case. Does that number
96
TM> depend on the size of the modules, or can you demonstrate this behavior
TM> by any project of >96 modules, even if each just defines a global object
of
TM> class type?
Well, at that moment I can't introduce such test case. In fact I was too
angry when write the topic since I lost vast of time trying to understand
what's going wrong. The project that I worked on works well on several
platforms with many different compilers (gcc, msvc for example) and I was
really surprised by amount of workarounds that I had to implement to simply
compile it by BCB. I think that in a day or two I will prepare test project
that reproduces the issue and publish it.
TM> When you write "global object", do you mean "global" as in "global
namespace",
TM> or as in "defined in namespace scope"? I.e. does the problem also occur
if
TM> you have
Both the classes and instantiated objects were defined in certain namespace
(not global).
TM> I've just created these sources
(http://www.glue.ch/~maeder/linker-issue.zip)
TM> and built them with both gcc 3.3.2 (g++ main.cpp module*.cpp Object.cpp)
TM> and C++BuilderX (bcc32 main.cpp module*.cpp Object.cpp). Both
executables
TM> correctly printed the numbers 0 to 98 (in varying order). What do you
get
TM> with the C++ Builder version you are using?
I have BCB 5.0. Your example works perfectly. Now I work on reproducible
example.
TM> Again, please don't think that the fact that this reply comes from a
TeamB
TM> member causes it to be more valuable than a reply from somebody who
isn't.
TM> I'm just speculating and applying (what I think is) common sense.
There's
TM> no reason to assume that I'm better at this than anybody else.
TM>
TM> Please also note that I don't think it's ok for Borland not to fix
certain
TM> bugs. I'm just establishing a speculative list of reasons.
Ok, I understand.
|