This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc 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: PATCH: Support mixing .init_array.* and .ctors.* input sections


On Tue, Dec 14, 2010 at 09:55:42AM -0800, H.J. Lu wrote:
> bfd/
> 
> 2010-12-14  H.J. Lu  <hongjiu.lu@intel.com>
> 
> 	* elf.c (_bfd_elf_new_section_hook): Special handling for
> 	.init_array/.fini_array output sections.
> 
> ld/
> 
> 2010-12-13  H.J. Lu  <hongjiu.lu@intel.com>
> 
> 	* Makefile.am (GENSCRIPTS): Add @enable_initfini_array@.
> 
> 	* NEWS: Mention SORT_BY_INIT_PRIORITY.
> 
> 	* configure.in: Add AC_CANONICAL_BUILD.
> 	Add --enable-initfini-array.
> 
> 	* genscripts.sh (ENABLE_INITFINI_ARRAY): New.
> 
> 	* ld.h (sort_type): Add by_init_priority.
> 
> 	* ld.texinfo: Document SORT_BY_INIT_PRIORITY.
> 
> 	* ldgram.y (SORT_BY_INIT_PRIORITY): New.
> 	(wildcard_spec): Handle SORT_BY_INIT_PRIORITY.
> 
> 	* ldlang.c (get_init_priority): New.
> 	(compare_section): Use get_init_priority for by_init_priority.
> 
> 	* ldlex.l (SORT_BY_INIT_PRIORITY): New.
> 
> 	* scripttempl/elf.sc: Support ENABLE_INITFINI_ARRAY.
> 
> 	* Makefile.in: Regenerated.
> 	* aclocal.m4: Regenerated.
> 	* config.in: Likewise.
> 	* configure: Likewise.
> 
> ld/testsuite/
> 
> 2010-12-13  H.J. Lu  <hongjiu.lu@intel.com>
> 
> 	* ld-elf/elf.exp (array_tests): Add init-mixed.
> 	(array_tests_static): Likewise.
> 	Also delete tmpdir/init-mixed.
> 
> 	* ld-elf/init-mixed.c: New.
> 	* ld-elf/init-mixed.out: Likewise.

OK.  Except

> +static long int

unsigned long

> +get_init_priority (const char *name)
> +{
> +  char *end;
> +  long int init_priority;

unsigned long

> +
> +  /* GCC uses the following section names for the init_priority
> +     attribute with numerical values 101 and 65535 inclusive:
> +
> +     1: .init_array.NNNN/.fini_array.NNNN: Where NNNN is the
> +	decimal numerical value of the init_priority attribute.
> +     2: .ctors.NNNN/.ctors.NNNN: Where NNNN is 65535 minus the
> +	decimal numerical value of the init_priority attribute.
> +   */

I would like to see this comment expanded.  Specify what the
init_priority values mean, ie. a lower value means a higher priority.
Also specify the order of execution in .init_array and .fini_array.
>From memory .init_array is forward, .fini_array reverse, and just to
make things interesting .ctors/.dtors goes the other way, .ctors
reverse and .dtors forward.

> +  if (strncmp (name, ".init_array.", 12) == 0
> +      || strncmp (name, ".fini_array.", 12) == 0)
> +    {
> +      init_priority = strtoul (name + 12, &end, 10);
> +      return *end ? 0 : init_priority;
> +    }
> +  else if (strncmp (name, ".ctors.", 7) == 0
> +	   || strncmp (name, ".dtors.", 7) == 0)
> +    {
> +      init_priority = strtoul (name + 7, &end, 10);
> +      return *end ? 0 : 65535 - init_priority;
> +    }
> +
> +  return 0;
> +}
> +
>  /* Compare sections ASEC and BSEC according to SORT.  */
>  
>  static int
>  compare_section (sort_type sort, asection *asec, asection *bsec)
>  {
>    int ret;
> +  long int ainit_priority, binit_priority;

unsigned long


> @@ -247,19 +274,16 @@ CTOR=".ctors        ${CONSTRUCTING-0} :
>         linker won't look for a file to match a
>         wildcard.  The wildcard also means that it
>         doesn't matter which directory crtbegin.o
> -       is in.  */
> +       is in. 
>  
> -    KEEP (*crtbegin.o(.ctors))
> -    KEEP (*crtbegin?.o(.ctors))
> -
> -    /* We don't want to include the .ctor section from
> +       We don't want to include the .ctor section from
>         the crtend.o file until after the sorted ctors.
>         The .ctor section from the crtend file contains the
>         end of ctors marker and it must be last */
>  
> -    KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o $OTHER_EXCLUDE_FILES) .ctors))
> -    KEEP (*(SORT(.ctors.*)))
> -    KEEP (*(.ctors))
> +    KEEP (*crtbegin.o(.ctors))
> +    KEEP (*crtbegin?.o(.ctors))
> +    ${CTORS}
>      ${CONSTRUCTING+${CTOR_END}}
>    }"
>  DTOR=".dtors        ${CONSTRUCTING-0} :
> @@ -267,9 +291,7 @@ DTOR=".dtors        ${CONSTRUCTING-0} :
>      ${CONSTRUCTING+${DTOR_START}}
>      KEEP (*crtbegin.o(.dtors))
>      KEEP (*crtbegin?.o(.dtors))
> -    KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o $OTHER_EXCLUDE_FILES) .dtors))
> -    KEEP (*(SORT(.dtors.*)))
> -    KEEP (*(.dtors))
> +    ${DTORS}
>      ${CONSTRUCTING+${DTOR_END}}
>    }"

No need to make any changes to .ctors or .dtors.  If .init_array
and .fini_array match input .ctors or .dtors sections, then any later
match will simply be ignored.

-- 
Alan Modra
Australia Development Lab, IBM


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