bfd/
authorH.J. Lu <hjl.tools@gmail.com>
Wed, 23 Mar 2005 04:14:46 +0000 (04:14 +0000)
committerH.J. Lu <hjl.tools@gmail.com>
Wed, 23 Mar 2005 04:14:46 +0000 (04:14 +0000)
2005-03-22  H.J. Lu  <hongjiu.lu@intel.com>

* bfd-in.h (_bfd_elf_provide_symbol): New.
* bfd-in2.h: Regenerated.

* elf32-ppc.c (set_linker_sym): Moved to elflink.c.
(ppc_elf_set_sdata_syms): Call _bfd_elf_provide_symbol instead
of set_linker_sym.

* elflink.c (_bfd_elf_provide_symbol): New. Moved and renamed
from elf32-ppc.c.

ld/

2005-03-22  H.J. Lu  <hongjiu.lu@intel.com>

* emultempl/elf32.em (gld${EMULATION_NAME}_provide_bound_symbols): New
(gld${EMULATION_NAME}_finish): Call
gld${EMULATION_NAME}_provide_bound_symbols to provide
__preinit_array_start, __preinit_array_end, __init_array_start,
__init_array_end, __fini_array_start and __fini_array_end.

* scripttempl/elf.sc: Don't provide __preinit_array_start,
__preinit_array_end, __init_array_start, __init_array_end,
__fini_array_start nor __fini_array_end.

bfd/ChangeLog
bfd/bfd-in.h
bfd/bfd-in2.h
bfd/elf32-ppc.c
bfd/elflink.c
ld/ChangeLog
ld/emultempl/elf32.em
ld/scripttempl/elf.sc

index f02c6775dadccba20557449ab2d637781b7844d9..39200876081450b4f94951dde4632ebf5952b1f9 100644 (file)
@@ -1,3 +1,15 @@
+2005-03-22  H.J. Lu  <hongjiu.lu@intel.com>
+
+       * bfd-in.h (_bfd_elf_provide_symbol): New.
+       * bfd-in2.h: Regenerated.
+
+       * elf32-ppc.c (set_linker_sym): Moved to elflink.c.
+       (ppc_elf_set_sdata_syms): Call _bfd_elf_provide_symbol instead
+       of set_linker_sym.
+
+       * elflink.c (_bfd_elf_provide_symbol): New. Moved and renamed
+       from elf32-ppc.c.
+
 2005-03-22  Hans-Peter Nilsson  <hp@axis.com>
 
        * hash.c (strtab_hash_newfunc): Fix typo in allocated size.
index 37c6386632e163389bf6eaa5fded70218745f233..0222a4e24a66a268061bd4476c55370d9e2ad7d3 100644 (file)
@@ -694,6 +694,9 @@ extern int bfd_get_sign_extend_vma
 extern struct bfd_section *_bfd_elf_tls_setup
   (bfd *, struct bfd_link_info *);
 
+extern void _bfd_elf_provide_symbol
+  (struct bfd_link_info *, const char *, bfd_vma);
+
 extern bfd_boolean bfd_m68k_elf32_create_embedded_relocs
   (bfd *, struct bfd_link_info *, struct bfd_section *, struct bfd_section *, char **);
 
index 626e0661b4860700a94a3ca8bf999c577eba99ee..131bd833012e834090688b2786a65303faf44686 100644 (file)
@@ -701,6 +701,9 @@ extern int bfd_get_sign_extend_vma
 extern struct bfd_section *_bfd_elf_tls_setup
   (bfd *, struct bfd_link_info *);
 
+extern void _bfd_elf_provide_symbol
+  (struct bfd_link_info *, const char *, bfd_vma);
+
 extern bfd_boolean bfd_m68k_elf32_create_embedded_relocs
   (bfd *, struct bfd_link_info *, struct bfd_section *, struct bfd_section *, char **);
 
index 82de7df90799c7a68badf9e33618221cc38f9e31..f2a1d38eb27c57d5245baa892a1a987a9b4fd031 100644 (file)
@@ -4545,26 +4545,6 @@ ppc_elf_relax_section (bfd *abfd,
   return FALSE;
 }
 \f
-/* Set SYM_NAME to VAL if the symbol exists and is undefined.  */
-
-static void
-set_linker_sym (struct ppc_elf_link_hash_table *htab,
-               const char *sym_name,
-               bfd_vma val)
-{
-  struct elf_link_hash_entry *h;
-  h = elf_link_hash_lookup (&htab->elf, sym_name, FALSE, FALSE, FALSE);
-  if (h != NULL && h->root.type == bfd_link_hash_undefined)
-    {
-      h->root.type = bfd_link_hash_defined;
-      h->root.u.def.section = bfd_abs_section_ptr;
-      h->root.u.def.value = val;
-      h->def_regular = 1;
-      h->type = STT_OBJECT;
-      h->other = STV_HIDDEN;
-    }
-}
-
 /* Set _SDA_BASE_, _SDA2_BASE, and sbss start and end syms.  They are
    set here rather than via PROVIDE in the default linker script,
    because using PROVIDE inside an output section statement results in
@@ -4599,19 +4579,19 @@ ppc_elf_set_sdata_syms (bfd *obfd, struct bfd_link_info *info)
        val = s->vma + 32768;
       lsect->sym_val = val;
 
-      set_linker_sym (htab, lsect->sym_name, val);
+      _bfd_elf_provide_symbol (info, lsect->sym_name, val);
     }
 
   s = bfd_get_section_by_name (obfd, ".sbss");
   val = 0;
   if (s != NULL)
     val = s->vma;
-  set_linker_sym (htab, "__sbss_start", val);
-  set_linker_sym (htab, "___sbss_start", val);
+  _bfd_elf_provide_symbol (info, "__sbss_start", val);
+  _bfd_elf_provide_symbol (info, "___sbss_start", val);
   if (s != NULL)
     val += s->size;
-  set_linker_sym (htab, "__sbss_end", val);
-  set_linker_sym (htab, "___sbss_end", val);
+  _bfd_elf_provide_symbol (info, "__sbss_end", val);
+  _bfd_elf_provide_symbol (info, "___sbss_end", val);
   return TRUE;
 }
 \f
index 783d9b9ea16b5bd7053aa00e4e5bd009a5785342..9792137d4fe53671e4c19a2225a53f8a0c8b233a 100644 (file)
@@ -9754,3 +9754,24 @@ _bfd_elf_section_already_linked (bfd *abfd, struct bfd_section * sec)
   /* This is the first section with this name.  Record it.  */
   bfd_section_already_linked_table_insert (already_linked_list, sec);
 }
+
+/* Set NAME to VAL if the symbol exists and is undefined.  */
+
+void
+_bfd_elf_provide_symbol (struct bfd_link_info *info, const char *name,
+                        bfd_vma val)
+{
+  struct elf_link_hash_entry *h;
+  h = elf_link_hash_lookup (elf_hash_table (info), name, FALSE, FALSE,
+                           FALSE);
+  if (h != NULL && h->root.type == bfd_link_hash_undefined)
+    {
+      h->root.type = bfd_link_hash_defined;
+      h->root.u.def.section = bfd_abs_section_ptr;
+      h->root.u.def.value = val;
+      h->def_regular = 1;
+      h->type = STT_OBJECT;
+      h->other = STV_HIDDEN | (h->other & ~ ELF_ST_VISIBILITY (-1));
+      h->forced_local = 1;
+    }
+}
index 1378cb53761f1ec32df9be0effe8b3dea699d448..49e0a0c6d0debb3f1c05ba141431c48bbba3af75 100644 (file)
@@ -1,3 +1,15 @@
+2005-03-22  H.J. Lu  <hongjiu.lu@intel.com>
+
+       * emultempl/elf32.em (gld${EMULATION_NAME}_provide_bound_symbols): New
+       (gld${EMULATION_NAME}_finish): Call
+       gld${EMULATION_NAME}_provide_bound_symbols to provide
+       __preinit_array_start, __preinit_array_end, __init_array_start,
+       __init_array_end, __fini_array_start and __fini_array_end.
+
+       * scripttempl/elf.sc: Don't provide __preinit_array_start,
+       __preinit_array_end, __init_array_start, __init_array_end,
+       __fini_array_start nor __fini_array_end.
+
 2005-03-23  Alan Modra  <amodra@bigpond.net.au>
 
        * emultempl/elf32.em (gld${EMULATION_NAME}_before_allocation): Set
index 00805d53d560e79c18799838f71e5e4cdf53d5c5..b2d2a7c399c92b0fd7e10b16a0a0786f8adc061b 100644 (file)
@@ -1427,6 +1427,29 @@ fi
 if test x"$LDEMUL_FINISH" != xgld"$EMULATION_NAME"_finish; then
 cat >>e${EMULATION_NAME}.c <<EOF
 
+static void
+gld${EMULATION_NAME}_provide_bound_symbols (const char *sec,
+                                           const char *start,
+                                           const char *end)
+{
+  asection *s;
+  bfd_vma start_val, end_val;
+
+  s = bfd_get_section_by_name (output_bfd, sec);
+  if (s != NULL)
+    {
+      start_val = s->vma;
+      end_val = start_val + s->size;
+    }
+  else
+    {
+      start_val = 0;
+      end_val = 0;
+    }
+  _bfd_elf_provide_symbol (&link_info, start, start_val);
+  _bfd_elf_provide_symbol (&link_info, end, end_val);
+}
+
 static void
 gld${EMULATION_NAME}_finish (void)
 {
@@ -1472,6 +1495,34 @@ gld${EMULATION_NAME}_finish (void)
                  }
            }
        }
+
+      /* If not building shared library, provide
+
+        __preinit_array_start
+        __preinit_array_end
+        __init_array_start
+        __init_array_end
+        __fini_array_start
+        __fini_array_end
+
+        They are set here rather than via PROVIDE in the linker
+        script, because using PROVIDE inside an output section
+        statement results in unnecessary output sections.  Using
+        PROVIDE outside an output section statement runs the risk of
+        section alignment affecting where the section starts.  */
+
+      if (!link_info.shared)
+       {
+         gld${EMULATION_NAME}_provide_bound_symbols
+           (".preinit_array", "__preinit_array_start",
+            "__preinit_array_end");
+         gld${EMULATION_NAME}_provide_bound_symbols
+           (".init_array", "__init_array_start",
+            "__init_array_end");
+         gld${EMULATION_NAME}_provide_bound_symbols
+           (".fini_array", "__fini_array_start",
+            "__fini_array_end");
+       }
     }
 }
 EOF
index 4ff6467a0bbe2856d050d835fa03c0483c2837f4..a6c0a63d7253b0aef0a156df44cfbdd82f969c8e 100644 (file)
@@ -333,22 +333,9 @@ cat <<EOF
   .tdata       ${RELOCATING-0} : { *(.tdata${RELOCATING+ .tdata.* .gnu.linkonce.td.*}) }
   .tbss                ${RELOCATING-0} : { *(.tbss${RELOCATING+ .tbss.* .gnu.linkonce.tb.*})${RELOCATING+ *(.tcommon)} }
 
-  /* Ensure the __preinit_array_start label is properly aligned.  We
-     could instead move the label definition inside the section, but
-     the linker would then create the section even if it turns out to
-     be empty, which isn't pretty.  */
-  ${RELOCATING+. = ALIGN(${ALIGNMENT});}
-  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__preinit_array_start = .);}}
   .preinit_array   ${RELOCATING-0} : { KEEP (*(.preinit_array)) }
-  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__preinit_array_end = .);}}
-
-  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__init_array_start = .);}}
   .init_array   ${RELOCATING-0} : { KEEP (*(.init_array)) }
-  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__init_array_end = .);}}
-
-  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__fini_array_start = .);}}
   .fini_array   ${RELOCATING-0} : { KEEP (*(.fini_array)) }
-  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__fini_array_end = .);}}
 
   ${SMALL_DATA_CTOR-${RELOCATING+${CTOR}}}
   ${SMALL_DATA_DTOR-${RELOCATING+${DTOR}}}