public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "hubicka at ucw dot cz" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug other/46770] Replace .ctors/.dtors with .init_array/.fini_array on targets supporting them
Date: Thu, 19 Apr 2012 15:15:00 -0000	[thread overview]
Message-ID: <bug-46770-4-VcBGTKDTTl@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-46770-4@http.gcc.gnu.org/bugzilla/>

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46770

--- Comment #95 from Jan Hubicka <hubicka at ucw dot cz> 2012-04-19 15:07:27 UTC ---
> It is misleading to think that the linker accumulates code in translation unit
> order for a C++ program.  E.g., that is not what happens for template code or
> string constants.  And of course the placement of functions called in different
> translation units is arbitrary.
> 
> A lot of work was done in both GNU ld and gold to move constructors from .ctors
> to .init_array, all to improve startup latency for firefox.  If that same
> amount of work were done on better layout of initialization code, we would
> improve all programs.

I did some work on this, too.  GCC now identify the functions executed only at
startup and global destruction time and puts them into .text.startup
subsections.
This completely elliminate the problem for implicit constructors generated
by #include <iostream>. Those just calls libstdc++ constructor that checks
flags and does nothing most of time.

Sadly I think gold still ignore those, so the optimization works only with
GNU LD.

With more complex constructors this logic helps. It is however not resonable to
assume that ctors execute and access only stuff that can be recognized by
reachability analysis to be only used at startup (after all they are
constructing something).

It is resonable to assume that static constructor in translation unit X will
access functions and variables of unit X (because it is constructing them) + of
course some other common stuff needed to do its job that is shared across rest
of construction process.

For this it makes IMO a lot of sense to make the (implicit to user) order of
execution of constructors match the (impicit) order how sections are laid out.
Sure that there are counterexamples where this does not help, but it is good
heuristics and what we do by default now is almost always the slowest variant.

Firefox is really not a special case here. C++ makes it extremely easy to
introduce
static constructors and destructors and thus most large C++ programs expose
this
problems (at least I know that Chrome and OOo do).

I am not quite sure how linker ordering plugins and code layout is going to
help here better.

Some linkers do automatic reordering based on reconstructed callgraph.
I prototyped code layout pass (ipa-reorder) based on static analysis of the
callgraph at LTO. It works by clustering the callgraph/varpool nodes into
sequences based on the presence of references hoping to get related code
together.

In my tests it however reaches very mixed results on Mozilla, because 
static analysis quickly lose track of virtual calls and use of pointers.

It still seems to me that switching the default ctor execution order, at risk
of breaking non-conforming C++ programs, is a good idea here.  We get
measurable improvements for most of large C++ packages out there and 
hopefully the fallout is not going to be great - many other runtimes
already execute ctors in forwarding order.

We could get the static function/variable reordering pass into GCC,
implement in linker reordering and do reordering based on profile feedback,
but all those are rather ortogonal to the issue discussed here.

Honza


  parent reply	other threads:[~2012-04-19 15:15 UTC|newest]

Thread overview: 110+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-02 19:21 [Bug target/46770] New: " mh+gcc at glandium dot org
2010-12-02 19:24 ` [Bug target/46770] " mh+gcc at glandium dot org
2010-12-02 22:22 ` hubicka at gcc dot gnu.org
2010-12-02 23:01 ` hjl.tools at gmail dot com
2010-12-07 15:45 ` hjl.tools at gmail dot com
2010-12-07 15:45 ` hjl.tools at gmail dot com
2010-12-07 16:45 ` hjl.tools at gmail dot com
2010-12-09 17:55 ` hjl.tools at gmail dot com
2010-12-11 14:15 ` hubicka at gcc dot gnu.org
2010-12-11 14:28 ` hjl.tools at gmail dot com
2010-12-11 14:36 ` mh+gcc at glandium dot org
2010-12-11 15:01 ` hubicka at ucw dot cz
2010-12-11 15:34 ` hjl.tools at gmail dot com
2010-12-11 16:17 ` hubicka at ucw dot cz
2010-12-11 16:54 ` hjl.tools at gmail dot com
2010-12-11 18:33 ` mmitchel at gcc dot gnu.org
2010-12-11 18:47 ` hjl.tools at gmail dot com
2010-12-11 18:50 ` mark at codesourcery dot com
2010-12-11 19:02 ` hjl.tools at gmail dot com
2010-12-11 19:33 ` mark at codesourcery dot com
2010-12-11 19:44 ` hjl.tools at gmail dot com
2010-12-11 19:47 ` hjl.tools at gmail dot com
2010-12-11 19:48 ` mmitchel at gcc dot gnu.org
2010-12-11 19:51 ` hjl.tools at gmail dot com
2010-12-11 19:53 ` hjl.tools at gmail dot com
2010-12-11 19:57 ` mark at codesourcery dot com
2010-12-11 20:04 ` hjl.tools at gmail dot com
2010-12-11 20:17 ` hjl.tools at gmail dot com
2010-12-11 20:19 ` mark at codesourcery dot com
2010-12-11 21:01 ` hubicka at ucw dot cz
2010-12-11 21:07 ` hjl.tools at gmail dot com
2010-12-11 21:07 ` mark at codesourcery dot com
2010-12-11 22:57 ` hjl.tools at gmail dot com
2010-12-11 23:19 ` mark at codesourcery dot com
2010-12-11 23:28 ` hjl.tools at gmail dot com
2010-12-11 23:30 ` mark at codesourcery dot com
2010-12-11 23:48 ` hjl.tools at gmail dot com
2010-12-11 23:55 ` mark at codesourcery dot com
2010-12-12  0:01 ` hjl.tools at gmail dot com
2010-12-12  0:03 ` mark at codesourcery dot com
2010-12-12  0:08 ` hjl.tools at gmail dot com
2010-12-12  0:12 ` mark at codesourcery dot com
2010-12-12  0:20 ` hjl.tools at gmail dot com
2010-12-12  0:25 ` mark at codesourcery dot com
2010-12-12  0:25 ` hjl.tools at gmail dot com
2010-12-12  0:32 ` hjl.tools at gmail dot com
2010-12-12 15:54 ` hjl.tools at gmail dot com
2010-12-12 18:40 ` mark at codesourcery dot com
2010-12-13  2:30 ` ian at airs dot com
2010-12-13 18:08 ` joseph at codesourcery dot com
2010-12-13 19:41 ` hjl.tools at gmail dot com
2010-12-13 20:24 ` ccoutant at gcc dot gnu.org
2010-12-13 20:31 ` hjl.tools at gmail dot com
2010-12-13 20:42 ` ccoutant at gcc dot gnu.org
2010-12-13 20:48 ` hjl.tools at gmail dot com
2010-12-14  0:39 ` ian at airs dot com
2010-12-14  1:14 ` hjl.tools at gmail dot com
2010-12-14  1:24 ` ccoutant at gcc dot gnu.org
2010-12-14  1:32 ` hjl.tools at gmail dot com
2010-12-14 12:52 ` hubicka at gcc dot gnu.org
2010-12-14 13:17 ` paolo.carlini at oracle dot com
2010-12-14 13:26 ` hubicka at ucw dot cz
2010-12-14 13:33 ` paolo.carlini at oracle dot com
2010-12-14 15:17 ` mark at codesourcery dot com
2011-03-25 19:55 ` jakub at gcc dot gnu.org
2011-04-28 16:17 ` rguenth at gcc dot gnu.org
2011-05-09 10:11 ` amodra at gmail dot com
2011-06-23 16:22 ` ian at airs dot com
2011-06-23 23:17 ` hjl.tools at gmail dot com
2011-06-24 13:22 ` ian at airs dot com
2011-06-24 13:35 ` jakub at gcc dot gnu.org
2011-08-20 20:08 ` hjl at gcc dot gnu.org
2011-08-20 20:37 ` [Bug other/46770] " hjl.tools at gmail dot com
2012-02-18  6:05 ` jingyu at gcc dot gnu.org
2012-02-18  7:21 ` jingyu at gcc dot gnu.org
2012-02-22 22:28 ` jingyu at gcc dot gnu.org
2012-04-17  1:22 ` ccoutant at gcc dot gnu.org
2012-04-17 14:59 ` hjl.tools at gmail dot com
2012-04-17 15:30 ` ppluzhnikov at google dot com
2012-04-17 15:49 ` hjl.tools at gmail dot com
2012-04-17 17:18 ` ppluzhnikov at google dot com
2012-04-17 18:04 ` ccoutant at gcc dot gnu.org
2012-04-17 18:20 ` hjl.tools at gmail dot com
2012-04-17 18:54 ` ccoutant at google dot com
2012-04-17 19:04 ` hjl.tools at gmail dot com
2012-04-17 20:25 ` ccoutant at google dot com
2012-04-17 20:39 ` hjl.tools at gmail dot com
2012-04-17 21:12 ` ccoutant at google dot com
2012-04-17 21:34 ` hubicka at ucw dot cz
2012-04-17 22:00 ` ccoutant at google dot com
2012-04-17 22:27 ` hjl.tools at gmail dot com
2012-04-18  0:05 ` tglek at mozilla dot com
2012-04-18  0:51 ` ppluzhnikov at google dot com
2012-04-18  1:33 ` tglek at mozilla dot com
2012-04-18  3:53 ` ian at airs dot com
2012-04-18  4:58 ` tglek at mozilla dot com
2012-04-19  0:16 ` ian at airs dot com
2012-04-19 15:15 ` hubicka at ucw dot cz [this message]
2012-04-22  8:03 ` igodard at pacbell dot net
2012-04-22 17:04 ` ian at airs dot com
2012-04-22 17:47 ` igodard at pacbell dot net
2012-04-22 18:36 ` hubicka at ucw dot cz
2012-04-22 18:45 ` paolo.carlini at oracle dot com
2012-04-22 19:37 ` igodard at pacbell dot net
2012-04-22 21:19 ` ian at airs dot com
2012-04-22 21:53 ` igodard at pacbell dot net
2012-04-22 22:28 ` ian at airs dot com
2014-10-01 16:46 ` marcelo at brs dot ind.br
2014-10-01 18:16 ` marcelo at brs dot ind.br
2014-10-01 18:50 ` ian at airs dot com

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=bug-46770-4-VcBGTKDTTl@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@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: 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).