public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Alexandre Oliva <aoliva@redhat.com>
To: Hal Black <black@ieee.org>
Cc: binutils <binutils@sources.redhat.com>
Subject: Re: [BUG] ld behavior varies for C++ static initializer depending on .a or .o input
Date: Mon, 14 Apr 2003 18:41:00 -0000	[thread overview]
Message-ID: <oru1d0udk1.fsf@free.redhat.lsd.ic.unicamp.br> (raw)
In-Reply-To: <3E98C756.30005@ieee.org>

On Apr 12, 2003, Hal Black <black@ieee.org> wrote:

> I'm not an expert on g++ symbols, but I'm assuming the static
> intializer of the sort I'm talking about is is named
> __static_initialization_and_detruction.* because that's what nm
> reports for my test program.

Watch out for .ctor, .init or .init_array sections as well.

> I just hadn't heard any valid reasons against having it be as I
> describe, and it seems like the correct interpretation of the spec.

I disagree.  The compiler, which is the entity that deals with
translation units, isn't dropping any initializers, just like mandated
by the spec.  Now, by the Standard, a program is one or more
translation units linked together [basic.link], and that's it.
Nowhere does it get into details of what a linker is, nevermind how
static archives should behave, since this is all far beyond the scope
of the C++ Standard.

Your point that archives should be scanned for initializers would be
perfectly reasonable, except for the bloat one wouldn't be able to
avoid, but, like Ian says, this is not the way linkers have dealt with
archives in the past and, barring a strong reason to change, they
should change.  Standard compliance is not such a reason, because the
nowhere does the standard determine how to select the translation
units that go into a program.  

> Based on an earlier portion of your reply, I am taking your
> interpretation to mean that a static initializer in a library is only
> called when something references an instance of its class or members,
> but not otherwise.  I don't believe this is a valid view from reading
> the C++ spec.

My interpretation is that a static initializer in a translation unit
is only executed if the translation unit makes it to the program.  The
point under debate is whether the translation unit must make it to the
program in spite of not being referenced by any other translation unit
listed in the program.  If you have such requirements, using an
archive is the wrong approach: you want to list the object files
instead.

-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                 aoliva@{redhat.com, gcc.gnu.org}
CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist                Professional serial bug killer

  reply	other threads:[~2003-04-14 18:41 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-04-11  3:43 Hal Black
2003-04-11  4:47 ` Alexandre Oliva
2003-04-12  4:01   ` Hal Black
2003-04-12  5:43     ` Alexandre Oliva
2003-04-12 14:24       ` Hal Black
2003-04-12 16:52         ` Ian Lance Taylor
2003-04-12 18:01           ` Hal Black
2003-04-12 20:45             ` Alexandre Oliva
2003-04-13  2:11               ` Hal Black
2003-04-14 18:41                 ` Alexandre Oliva [this message]
2003-04-13 22:55             ` Ian Lance Taylor
2003-04-13 23:07               ` Zack Weinberg
2003-04-13 23:15                 ` Ian Lance Taylor
2003-04-13 23:26                 ` Ulrich Drepper
2003-04-14  5:14               ` Hal Black
2003-04-14  5:30                 ` Ian Lance Taylor
2003-04-11  8:16 ` Alan Modra

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=oru1d0udk1.fsf@free.redhat.lsd.ic.unicamp.br \
    --to=aoliva@redhat.com \
    --cc=binutils@sources.redhat.com \
    --cc=black@ieee.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: 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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).