RFC: Preserving order of functions and top-level asms via cgraph

Mark Mitchell mark@codesourcery.com
Mon Apr 11 00:34:00 GMT 2005


Jan Hubicka wrote:

> We might thing of something like this for -O0 or so and it might be
> fairly easy to implement if we still want to sick on this.

-O0 is not the right thing to control something like this; if turning 
on/off optimization changes the behavior of the program, and the 
programs is valid (including appropriate use of GNU extensions), then 
the compiler has a bug.

> Most common use are the function sections that we have attribute mechanizms
> for now, so hopefully there is not that much use for this...
> Problem is that attributes afaik does not work everywhere and we still
> use this asm trick while bulding runtime.

If you're referring to the stuff in crtstuff.c, there's really just no 
excuse for that code.  It could be written much more cleanly as a 
mixture of actual assembly files and C code.  The current stuff is hard 
to read, and plays tricks that we should not be encouraging, like:

/* Hack: force cc1 to switch to .data section early, so that assembling 

    __CTOR_LIST__ does not undo our behind-the-back change to .ctors.  */
static func_ptr force_to_data[1] __attribute__ ((__unused__)) = { };

I have absolutely no problem with making code like this not work. 
Targets that are currently using this code can simply define 
CTOR_LIST_BEGIN to do whatever they need to do to emit the __CTOR_LIST__ 
directly as assembly code, or, if that doesn't work, we can provide a 
way to do all the data declarations in that file as part of a separate 
assembly file to be provided by the target, or we can add 
attributes/extensions to do what this code is trying to do.  The last 
approach has the advantage that then the compiler really will know is 
going on, and can DTRT.

-- 
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com
(916) 791-8304



More information about the Gcc-patches mailing list