bfd/
authorNathan Sidwell <nathan@codesourcery.com>
Thu, 1 Apr 2010 10:02:28 +0000 (10:02 +0000)
committerNathan Sidwell <nathan@codesourcery.com>
Thu, 1 Apr 2010 10:02:28 +0000 (10:02 +0000)
* 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.

bfd/ChangeLog
bfd/elf32-ppc.c
ld/testsuite/ChangeLog
ld/testsuite/ld-powerpc/apuinfo-nul.rd [new file with mode: 0644]
ld/testsuite/ld-powerpc/apuinfo-nul1.s [new file with mode: 0644]
ld/testsuite/ld-powerpc/powerpc.exp

index de1ed790eb0398634d49b25f0cd195729a10fe74..aa3214496d1aa558b44539a0e8601603b3ce7b20 100644 (file)
@@ -1,3 +1,11 @@
+2010-04-01  Nathan Sidwell  <nathan@codesourcery.com>
+
+       * 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.
+
 2010-04-01  Tristan Gingold  <gingold@adacore.com>
 
        * vms.h: Include time.h. Add prototypes for vms_get_module_name,
index 2c42464ee9d614a0d7465cc98c6f199bda09cd82..28274c40437bb031332426dc80123accc1ae51aa 100644 (file)
@@ -2077,12 +2077,13 @@ typedef struct apuinfo_list
 apuinfo_list;
 
 static apuinfo_list *head;
-
+static bfd_boolean apuinfo_set;
 
 static void
 apuinfo_list_init (void)
 {
   head = NULL;
+  apuinfo_set = FALSE;
 }
 
 static void
@@ -2162,7 +2163,6 @@ ppc_elf_begin_write_processing (bfd *abfd, struct bfd_link_info *link_info)
   char *buffer = NULL;
   bfd_size_type largest_input_size = 0;
   unsigned i;
-  unsigned num_entries;
   unsigned long length;
   const char *error_message = NULL;
 
@@ -2185,6 +2185,7 @@ ppc_elf_begin_write_processing (bfd *abfd, struct bfd_link_info *link_info)
       if (length < 20)
        goto fail;
 
+      apuinfo_set = TRUE;
       if (largest_input_size < asec->size)
        {
          if (buffer)
@@ -2228,13 +2229,14 @@ ppc_elf_begin_write_processing (bfd *abfd, struct bfd_link_info *link_info)
 
   error_message = NULL;
 
-  /* Compute the size of the output section.  */
-  num_entries = apuinfo_list_length ();
-
-  if (num_entries)
+  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;
@@ -2259,8 +2261,7 @@ ppc_elf_write_section (bfd *abfd ATTRIBUTE_UNUSED,
                       asection *asec,
                       bfd_byte *contents ATTRIBUTE_UNUSED)
 {
-  return (apuinfo_list_length ()
-         && strcmp (asec->name, APUINFO_SECTION_NAME) == 0);
+  return apuinfo_set && strcmp (asec->name, APUINFO_SECTION_NAME) == 0;
 }
 
 /* Finally we can generate the output section.  */
@@ -2278,7 +2279,7 @@ ppc_elf_final_write_processing (bfd *abfd, bfd_boolean linker ATTRIBUTE_UNUSED)
   if (asec == NULL)
     return;
 
-  if (apuinfo_list_length () == 0)
+  if (!apuinfo_set)
     return;
 
   length = asec->size;
index 3731c1f14b1ba1e862e9120d9e024aa0ae5ec640..97a39ec3abff35d469fe6625eca0f412786d48fa 100644 (file)
@@ -1,3 +1,9 @@
+2010-04-01  Nathan Sidwell  <nathan@codesourcery.com>
+
+       * ld-powerpc/apuinfo-nul.rd: New.
+       * ld-powerpc/apuinfo-nul1.s: New.
+       * ld-powerpc/powerpc.exp: Add it.
+
 2010-03-31  Kai TIetz  <kai.tietz@onevision.com>
 
        * ld-pe//pe-compile.exp (run_basefile_test): Trim result of wc
diff --git a/ld/testsuite/ld-powerpc/apuinfo-nul.rd b/ld/testsuite/ld-powerpc/apuinfo-nul.rd
new file mode 100644 (file)
index 0000000..c20fc5e
--- /dev/null
@@ -0,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.
diff --git a/ld/testsuite/ld-powerpc/apuinfo-nul1.s b/ld/testsuite/ld-powerpc/apuinfo-nul1.s
new file mode 100644 (file)
index 0000000..f415e71
--- /dev/null
@@ -0,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 4c0038aecd1cf5fbed25d36a37b3e710b5197c3c..9d0207f1c0c68b7497357785800f6cea14af6a33 100644 (file)
@@ -103,6 +103,9 @@ set ppcelftests {
     {"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}}