public inbox for gcc-prs@sourceware.org help / color / mirror / Atom feed
From: hablack@vt.edu To: gcc-gnats@gcc.gnu.org Subject: c++/7769: using static libraries sometimes loses static initialization Date: Thu, 29 Aug 2002 20:16:00 -0000 [thread overview] Message-ID: <20020830022936.13016.qmail@sources.redhat.com> (raw) >Number: 7769 >Category: c++ >Synopsis: using static libraries sometimes loses static initialization >Confidential: no >Severity: non-critical >Priority: medium >Responsible: unassigned >State: open >Class: wrong-code >Submitter-Id: net >Arrival-Date: Thu Aug 29 19:36:00 PDT 2002 >Closed-Date: >Last-Modified: >Originator: hablack@vt.edu >Release: version 2.96 20000731 >Organization: >Environment: Mandrake Linux 8.1 2.96-0.62mdk with binutils-2.11.90.0.8-5mdk ALSO Red Hat Linux 7.3 with gcc-2.96-110 and binutils-2.11.93.0.2-11 >Description: I instantiate a global/static variable call it "a" in one file (one.cc) I define main in another file (two.cc) Expected behavior: Constructor for "a" is called. Actual behavior: Constructor for "a" is sometimes called, sometimes not, depending on linking and libraries. Test 1: g++ 2 .o files Result: WORKS - Constructor called Test 2: g++ 2 .a files containing 1 .o file each Result: FAILS - Constructor not called Test 3: g++ 1 .a file containing 2 .o files Result: FAILS - Constructor not called Test 4: g++ 1 .a file containing 1 .o file (the .o file is obtained by concatenating one.cc and two.cc) Result: WORKS - Constructor called There is other bizarre behavior in more complicated examples (not included). In particular, this is puzzling because test 1 works - 2 .o files, and test 3 doesn't - 2 .o files inside a library. Shouldn't it not matter whether the input comes from a inside a .a or on the command line? Relevance: CppUnit, an LGPL C++ unit test framework, uses static initializers to automatically register test suites with the test registry, simplifying test writing. This is done using the CPPUNIT_TEST_SUITE_REGISTRATION macro, which evaluates to code similar to attached. See http://cppunit.sourceforge.net/cppunit_cookbook.html#cppunit_cookbook for more discussion. one.cc: #include <stdio.h> class A { public: A() { printf("Hello world!\n"); } }; A a; two:cc int main() {} >How-To-Repeat: untar attached file, make >Fix: n/a >Release-Note: >Audit-Trail: >Unformatted: ----gnatsweb-attachment---- Content-Type: application/gzip; name="static_init.tar.gz" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="static_init.tar.gz" H4sIAKjSbj0AA+2WzW7bMAzHc42egssaoE0RV7IkG3CKYbntsjcYViiKswhzrMJW1kORd59k16mL dcslTVeUv4NMkNQHTP0l1U45o29MadzV4IWgVNA0lf5LWSpZ/9sxoKnkXEoWcz6gjEnvAvlSC+qz rZ2qAAZrVfwz71D8jVL36v9V/cxXpsiPPQdllCaJ+Gv9JU979fd7gXHmXUCPvZDneOf1d3ntso0y JYPQxk3Lm1aQYXTVhDoj7gzeGYKMI5uNI63J8MflJUw1nF2TwizGkfJuS4b+51a/4Oxz8C+sW3u/ LfPIgruzT+PfSTPZ03AYtOeAqYV2Sc16Mj9TiCrwRkhQbY8/3F2/uOnHs3YlbXJrdxm8yRBhZG03 C1Pmy96oj64uXxBd5KrMyLDawHQFEx+aRG1sQl67vAfp6z/8Mq2PP8ch/bOYPehfJIz6e4LFMmGo /1Pw0ZS62C5zuK7d0tho/Yn4Da3qGuZwT263i8Jov7fn5xdwD7eVKd3qfPQlLwoLd7Yqlh++laOL GezIbkbmoGb//45H+vT1H07K19A/ZUmnf5HEIug/iSnq/xR4QTdXVdD3DsX77ujrf/+4OfIhcFD/ Quzvf8pZeP/LJEb9n4L9/T9qX38j8uhp74MRngoIgiAIgiAIgiAIgiAIgiAI8sb4DXGkm0QAKAAA
next reply other threads:[~2002-08-30 2:36 UTC|newest] Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top 2002-08-29 20:16 hablack [this message] 2002-09-12 18:06 Hal Black 2002-12-19 17:40 bangerth 2002-12-19 19:26 Hal Black 2002-12-20 8:46 Wolfgang Bangerth 2002-12-20 10:16 Hal Black
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=20020830022936.13016.qmail@sources.redhat.com \ --to=hablack@vt.edu \ --cc=gcc-gnats@gcc.gnu.org \ /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: linkBe 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).