This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Generalized init_priority attribute


Richard Henderson wrote:
> On Thu, Nov 25, 2004 at 10:54:45AM +1300, Danny Smith wrote:
>> void my_ctor (void) __attribute__ ((constructor,
>> init_priority(MAX_INIT_PRIORITY)));
>>
>> gets me:
>>
>>  error: can only use 'init_priority' attribute on file-scope
>> definitions of objects of class type
>
> Here is generalized support for init_priority in conjunction with
> the constructor and destructor attributes.  I don't recall if you
> are trying to fix regressions or not, and so don't know if this is
> appropriate for mainline at this time.
>

No,  lack of Dwarf2 support on windows32 is definitely not a regression.

The more  I think about the use of  MAX_INIT_PRIORITY ctor to act like
an .init section,  the more doubts I have.    Even if we put the DW2
unwind registratiion functions in a top priority ctor,  eg. by using

__attribute__ ((constructor, init_priority (0 /*
MAX_RESERVED_INIT_PRIORITY + 1 */)))

or putting something like this in crtend.c

/* These are defined in crtbegin.c  */
extern void __do_register_frame (void);
extern void __do_deregister_frame (void);

#ifndef MAX_PRIORITY_STRING
#define MAX_PRIORITY_STRING "65535"
#endif

__asm__(
  ".section\t.ctors." MAX_PRIORITY_STRING ",\"w\"\n\t"
  ".align 4\n\t"
   ".long\t___do_register_frame");

__asm__(
    ".section\t.dtors." MAX_PRIORITY_STRING ",\"w\"\n\t"
    ".align 4\n\t"
    ".long\t___do_deregister_frame");


There is nothing to stop a user from creating an even higher priority
like so

__asm__(
  ".section\t.ctors.ZZZZZZZ ,\"w\"\n\t"
  ".align 4\n\t"
   ".long\t_call_exception_throwing_function");

without a warning.

(GNU ld uses strcmp to SORT_BY_NAME).

I think it would be safer for my purpose to not assign a priority and
make the linker script
force crtend ctor to be run first, eg:

    ${CONSTRUCTING+ ___CTOR_LIST__ = .; __CTOR_LIST__ = . ;
                    LONG (-1);
                    *(EXCLUDE_FILE (*crtend.o) .ctors);
                    *(.ctor);
                    *(SORT(.ctors.*));
                    *crtend.o (.ctors);
                    LONG (0); }
    ${CONSTRUCTING+ ___DTOR_LIST__ = .; __DTOR_LIST__ = . ;
                    LONG (-1);
                    *(EXCLUDE_FILE (*crtend.o) .dtors);
                    *(.dtor);
                    *(SORT(.dtors.*));
                    *crtend.o (.dtors);
                    LONG (0); }


Since Dwarf2 unwind for windows will not be going into GCC 4.0, there is
time to get the ld support worked out first.
We also need linker script support for the .jcr section anyway.

Danny
>
> r~
>



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]