This is the mail archive of the binutils@sourceware.org mailing list for the binutils 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]

another powerpc APUinfo patch


this is a followup to
2010-02-08  Nathan Sidwell  <nathan@codesourcery.com>

	* elf32-ppc.c (ppc_elf_begin_write_processing): Allow empty
	apuinfo sections, only scan input sections once and reuse the
	buffer.

I've now met a case where there were (only) multiple empty APUinfo sections in the input. In such a case we end up with an empty list of APU attributes and then consequently don't think we need to do anything special writing out the matching output section. We end up attempting to concatenate the input sections.

This patch adds an explicit boolean indicating that we met APUinfo sections in the input. If we do, we always synthesize an APUinfo output section even if it has not attributes (just the header). I didn't think it worth while optimizing the case I'd hit -- hey, if the producer can't be bothered, why try harder?

built and tested on powerpc-elf, ok?

nathan
--
Nathan Sidwell    ::   http://www.codesourcery.com   ::         CodeSourcery

2010-04-01  Nathan Sidwell  <nathan@codesourcery.com>

	bfd/
	* elf32-ppc.c (apuinfo_set): New static var.
	(ppc_elf_begin_write_processing): Set it here, always create an
	APUinfo section if there were any in the inputs.
	(ppc_elf_write_section): Check apuinfo_set.
	(ppc_elf_final_write_processing): Likewise.

	ld/testsuite/
	* ld-powerpc/apuinfo-nul.rd: New.
	* ld-powerpc/apuinfo-nul1.s: New.
	* ld-powerpc/powerpc.exp: Add it.

Index: bfd/elf32-ppc.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-ppc.c,v
retrieving revision 1.280
diff -c -3 -p -r1.280 elf32-ppc.c
*** bfd/elf32-ppc.c	26 Mar 2010 08:34:24 -0000	1.280
--- bfd/elf32-ppc.c	1 Apr 2010 08:18:04 -0000
*************** typedef struct apuinfo_list
*** 2077,2088 ****
  apuinfo_list;
  
  static apuinfo_list *head;
! 
  
  static void
  apuinfo_list_init (void)
  {
    head = NULL;
  }
  
  static void
--- 2077,2089 ----
  apuinfo_list;
  
  static apuinfo_list *head;
! static bfd_boolean apuinfo_set;
  
  static void
  apuinfo_list_init (void)
  {
    head = NULL;
+   apuinfo_set = FALSE;
  }
  
  static void
*************** ppc_elf_begin_write_processing (bfd *abf
*** 2162,2168 ****
    char *buffer = NULL;
    bfd_size_type largest_input_size = 0;
    unsigned i;
-   unsigned num_entries;
    unsigned long length;
    const char *error_message = NULL;
  
--- 2163,2168 ----
*************** ppc_elf_begin_write_processing (bfd *abf
*** 2185,2190 ****
--- 2185,2191 ----
        if (length < 20)
  	goto fail;
  
+       apuinfo_set = TRUE;
        if (largest_input_size < asec->size)
  	{
  	  if (buffer)
*************** ppc_elf_begin_write_processing (bfd *abf
*** 2228,2240 ****
  
    error_message = NULL;
  
!   /* Compute the size of the output section.  */
!   num_entries = apuinfo_list_length ();
! 
!   if (num_entries)
      {
        /* Set the output section size, if it exists.  */
        asec = bfd_get_section_by_name (abfd, APUINFO_SECTION_NAME);
        if (asec && ! bfd_set_section_size (abfd, asec, 20 + num_entries * 4))
  	{
  	  ibfd = abfd;
--- 2229,2242 ----
  
    error_message = NULL;
  
!   if (apuinfo_set)
      {
+       /* Compute the size of the output section.  */
+       unsigned num_entries = apuinfo_list_length ();
+       
        /* Set the output section size, if it exists.  */
        asec = bfd_get_section_by_name (abfd, APUINFO_SECTION_NAME);
+ 
        if (asec && ! bfd_set_section_size (abfd, asec, 20 + num_entries * 4))
  	{
  	  ibfd = abfd;
*************** ppc_elf_write_section (bfd *abfd ATTRIBU
*** 2259,2266 ****
  		       asection *asec,
  		       bfd_byte *contents ATTRIBUTE_UNUSED)
  {
!   return (apuinfo_list_length ()
! 	  && strcmp (asec->name, APUINFO_SECTION_NAME) == 0);
  }
  
  /* Finally we can generate the output section.  */
--- 2261,2267 ----
  		       asection *asec,
  		       bfd_byte *contents ATTRIBUTE_UNUSED)
  {
!   return apuinfo_set && strcmp (asec->name, APUINFO_SECTION_NAME) == 0;
  }
  
  /* Finally we can generate the output section.  */
*************** ppc_elf_final_write_processing (bfd *abf
*** 2278,2284 ****
    if (asec == NULL)
      return;
  
!   if (apuinfo_list_length () == 0)
      return;
  
    length = asec->size;
--- 2279,2285 ----
    if (asec == NULL)
      return;
  
!   if (!apuinfo_set)
      return;
  
    length = asec->size;
Index: ld/testsuite/ld-powerpc/apuinfo-nul.rd
===================================================================
RCS file: ld/testsuite/ld-powerpc/apuinfo-nul.rd
diff -N ld/testsuite/ld-powerpc/apuinfo-nul.rd
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- ld/testsuite/ld-powerpc/apuinfo-nul.rd	1 Apr 2010 08:18:10 -0000
***************
*** 0 ****
--- 1,9 ----
+ #source: apuinfo-nul.s
+ #source: apuinfo-nul1.s
+ #as: -me500
+ #readelf: -x2
+ #target: powerpc-eabi*
+ 
+ Hex dump of section '.PPC.EMB.apuinfo':
+   0x00000000 00000008 00000000 00000002 41505569 ............APUi
+   0x00000010 6e666f00                            nfo.
Index: ld/testsuite/ld-powerpc/apuinfo-nul1.s
===================================================================
RCS file: ld/testsuite/ld-powerpc/apuinfo-nul1.s
diff -N ld/testsuite/ld-powerpc/apuinfo-nul1.s
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- ld/testsuite/ld-powerpc/apuinfo-nul1.s	1 Apr 2010 08:18:10 -0000
***************
*** 0 ****
--- 1,10 ----
+ 	.text
+ _start:	nop
+ 
+ 	# dummy empty apuinfo
+ 	# some other tools emit these
+ 	.section ".PPC.EMB.apuinfo"
+ 	.long 8
+ 	.long 0
+ 	.long 2
+ 	.asciz "APUinfo"
Index: ld/testsuite/ld-powerpc/powerpc.exp
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-powerpc/powerpc.exp,v
retrieving revision 1.30
diff -c -3 -p -r1.30 powerpc.exp
*** ld/testsuite/ld-powerpc/powerpc.exp	8 Feb 2010 07:09:39 -0000	1.30
--- ld/testsuite/ld-powerpc/powerpc.exp	1 Apr 2010 08:18:10 -0000
*************** set ppcelftests {
*** 103,108 ****
--- 103,111 ----
      {"APUinfo section processing" "-melf32ppc"
       "-a32 -me500" {apuinfo1.s apuinfo-nul.s apuinfo2.s}
      {{readelf -x2 apuinfo.rd}} "apuinfo"}
+     {"APUinfo NULL section processing" "-melf32ppc"
+      "-a32 -me500" {apuinfo-nul1.s apuinfo-nul.s}
+     {{readelf -x2 apuinfo-nul.rd}} "apuinfo"}
      {"TLS32 static exec" "-melf32ppc" "-a32"  {tls32.s tlslib32.s}
       {{objdump -dr tls32.d} {objdump -sj.got tls32.g}
        {objdump -sj.tdata tls32.t}}

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