public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: David Brown <david@westcontrol.com>
To: Andi Kleen <andi@firstfloor.org>
Cc: Andrew Pinski <pinskia@gmail.com>,
	 David Brown <david.brown@hesbynett.no>,
	Iain Buclaw <ibuclaw@ubuntu.com>,
	Ian Lance Taylor <iant@google.com>,
	 gcc@gcc.gnu.org
Subject: Re: Merging gdc (GNU D Compiler) into gcc
Date: Wed, 05 Oct 2011 14:44:00 -0000	[thread overview]
Message-ID: <4E8C3A66.30701@westcontrol.com> (raw)
In-Reply-To: <m2r52r4v2h.fsf@firstfloor.org>

On 05/10/2011 12:00, Andi Kleen wrote:
> David Brown<david@westcontrol.com>  writes:
>>
>> Some toolchains are configured to have a series of "init" sections at
>> startup (technically, that's a matter of the default linker scripts
>> and libraries rather than the compiler).  You can get code to run at
>> specific times during startup by placing the instructions directly
>> within these sections - but it must be "raw" instructions, not
>> function definitions (and definitely no "return" statement).
>
> Note that this only works with modern gcc with -fno-reorder-toplevel,
> which disables some optimizations, and is currently broken in several
> ways with LTO (in progress of being fixed)
>

You should not need to worry about re-ordering code within a module 
unless you have several pieces of code that have to be put into the same 
"initX" section in a specific order.  And if that's the case, then you 
can just put all that code within the one "naked" function.

Of course, you have to put the code in the right section.  An example 
(from the avr-libc documentation) is:

void my_init_portb (void) __attribute__ ((naked))
     __attribute__ ((section (".init3")));
void my_init_portb (void)
{
         PORTB = 0xff;
         DDRB = 0xff;
}


LTO might well remove that function unless you also use the "used" 
attribute - although hopefully the "Keep" directive in the linker script 
file will do the same thing.

But I can't see why the -fno-reorder-toplevel flag would be needed here.

> Normally you don't get any defined order in these sections, both
> unit-at-a-time and LTO do reorder. The linker may also in some
> circumstances.
>

You need a linker script that puts these sections in the right place, of 
course.

> So it's somewhat dangerous to rely on.
>
> -Andi
>

WARNING: multiple messages have this Message-ID
From: David Brown <david@westcontrol.com>
To: gcc@gcc.gnu.org
Cc: Andrew Pinski <pinskia@gmail.com>,
	 David Brown <david.brown@hesbynett.no>,
	Iain Buclaw <ibuclaw@ubuntu.com>,
	Ian Lance Taylor <iant@google.com>,
	 gcc@gcc.gnu.org
Subject: Re: Merging gdc (GNU D Compiler) into gcc
Date: Wed, 05 Oct 2011 14:59:00 -0000	[thread overview]
Message-ID: <4E8C3A66.30701@westcontrol.com> (raw)
Message-ID: <20111005145900.hBQhTAZvo4nMgHa2nNq0YcJInbhVwaTbUHIVHzdAGm4@z> (raw)
In-Reply-To: <m2r52r4v2h.fsf@firstfloor.org>

On 05/10/2011 12:00, Andi Kleen wrote:
> David Brown<david@westcontrol.com>  writes:
>>
>> Some toolchains are configured to have a series of "init" sections at
>> startup (technically, that's a matter of the default linker scripts
>> and libraries rather than the compiler).  You can get code to run at
>> specific times during startup by placing the instructions directly
>> within these sections - but it must be "raw" instructions, not
>> function definitions (and definitely no "return" statement).
>
> Note that this only works with modern gcc with -fno-reorder-toplevel,
> which disables some optimizations, and is currently broken in several
> ways with LTO (in progress of being fixed)
>

You should not need to worry about re-ordering code within a module 
unless you have several pieces of code that have to be put into the same 
"initX" section in a specific order.  And if that's the case, then you 
can just put all that code within the one "naked" function.

Of course, you have to put the code in the right section.  An example 
(from the avr-libc documentation) is:

void my_init_portb (void) __attribute__ ((naked))
     __attribute__ ((section (".init3")));
void my_init_portb (void)
{
         PORTB = 0xff;
         DDRB = 0xff;
}


LTO might well remove that function unless you also use the "used" 
attribute - although hopefully the "Keep" directive in the linker script 
file will do the same thing.

But I can't see why the -fno-reorder-toplevel flag would be needed here.

> Normally you don't get any defined order in these sections, both
> unit-at-a-time and LTO do reorder. The linker may also in some
> circumstances.
>

You need a linker script that puts these sections in the right place, of 
course.

> So it's somewhat dangerous to rely on.
>
> -Andi
>


  reply	other threads:[~2011-10-05 11:11 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-04  7:08 Iain Buclaw
2011-10-04  8:41 ` Andrew Haley
2011-10-04 18:19   ` Iain Buclaw
2011-10-06 15:15   ` Iain Buclaw
2011-10-04 14:03 ` Ian Lance Taylor
2011-10-04 19:30   ` Iain Buclaw
2011-10-04 19:37     ` Andrew Pinski
2011-10-04 20:13       ` Iain Buclaw
2011-10-04 23:11         ` Ian Lance Taylor
2011-10-04 21:41       ` David Brown
2011-10-04 21:47         ` David Brown
2011-10-04 22:51         ` Andrew Pinski
2011-10-05  9:31           ` David Brown
2011-10-05 10:00             ` David Brown
2011-10-05 12:49             ` Andi Kleen
2011-10-05 14:44               ` David Brown [this message]
2011-10-05 14:59                 ` David Brown
2011-10-04 20:41     ` Tom Tromey
2011-10-05  0:59     ` Ian Lance Taylor
2011-10-05  4:14       ` Iain Buclaw
2011-10-11 14:05         ` Dave Korn
2011-10-04 16:50 ` Joseph S. Myers
2011-10-04 19:45   ` Iain Buclaw
2011-10-04 19:56     ` Joseph S. Myers
2011-10-06  8:31 ` Walter Bright
2012-04-11 14:12 ` Iain Buclaw
2012-04-13 23:01   ` Dave Korn
2012-05-10  9:37   ` Iain Buclaw
2012-05-10  9:48     ` Richard Guenther
2012-05-10  9:53       ` Iain Buclaw
2012-05-10 11:51         ` Manuel López-Ibáñez
2012-07-21 20:00 ` Florian Weimer
2012-07-24 20:37   ` Iain Buclaw
  -- strict thread matches above, loose matches on Subject: below --
2010-11-08 23:13 Merging gdc (Gnu " Walter Bright
2010-11-09  1:14 ` Joseph S. Myers
2010-11-09  7:22   ` Walter Bright
2010-11-09 13:09     ` Andrew Haley
2010-11-09 13:57       ` Jakub Jelinek
2010-11-09 16:43         ` Joe Buck

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=4E8C3A66.30701@westcontrol.com \
    --to=david@westcontrol.com \
    --cc=andi@firstfloor.org \
    --cc=david.brown@hesbynett.no \
    --cc=gcc@gcc.gnu.org \
    --cc=iant@google.com \
    --cc=ibuclaw@ubuntu.com \
    --cc=pinskia@gmail.com \
    /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).