2005-02-11 Paul Brook <paul@codesourcery.com>
authorPaul Brook <paul@codesourcery.com>
Fri, 11 Feb 2005 16:41:09 +0000 (16:41 +0000)
committerPaul Brook <paul@codesourcery.com>
Fri, 11 Feb 2005 16:41:09 +0000 (16:41 +0000)
* elf-bfd.h (struct elf_link_hash_table): Add
is_relocatable_executable.
* elf.c (_bfd_elf_link_hash_table_init): Initialize it.
* elflink.c (bfd_elf_link_record_dynamic_symbol): Create local dynamic
symbols in relocatable executables.
(bfd_elf_record_link_assignment): Create dynamic section symbols in
relocatable executables.
(_bfd_elf_link_renumber_dynsyms): Ditto.
(bfd_elf_final_link): Ditto.
* elf32-arm.c (elf32_arm_final_link_relocate): Copy absolute
relocations into relocatable executables.
(elf32_arm_check_relocs): Crate dynamic sections for relocatable
executables.  Also copy absolute relocations.
(elf32_arm_adjust_dynamic_symbol): Don't create copy relocations
in relocatable executables.
(allocate_dynrelocs): Copy relocations for relocatable executables.
Output dynamic symbols for symbols defined in linker scripts.

bfd/ChangeLog
bfd/elf-bfd.h
bfd/elf.c
bfd/elf32-arm.c
bfd/elflink.c

index 5e622c58ea1170a65cac977d0eaa063097cf43ea..590943be854e5b274be812436316dd45b9a4e92a 100644 (file)
@@ -1,3 +1,23 @@
+2005-02-11  Paul Brook  <paul@codesourcery.com>
+
+       * elf-bfd.h (struct elf_link_hash_table): Add
+       is_relocatable_executable.
+       * elf.c (_bfd_elf_link_hash_table_init): Initialize it.
+       * elflink.c (bfd_elf_link_record_dynamic_symbol): Create local dynamic
+       symbols in relocatable executables.
+       (bfd_elf_record_link_assignment): Create dynamic section symbols in
+       relocatable executables.
+       (_bfd_elf_link_renumber_dynsyms): Ditto.
+       (bfd_elf_final_link): Ditto.
+       * elf32-arm.c (elf32_arm_final_link_relocate): Copy absolute
+       relocations into relocatable executables.
+       (elf32_arm_check_relocs): Crate dynamic sections for relocatable
+       executables.  Also copy absolute relocations.
+       (elf32_arm_adjust_dynamic_symbol): Don't create copy relocations
+       in relocatable executables.
+       (allocate_dynrelocs): Copy relocations for relocatable executables.
+       Output dynamic symbols for symbols defined in linker scripts.
+
 2005-02-11  Nick Clifton  <nickc@redhat.com>
 
        * libbfd.c (read_signed_leb128): Use an unsigned type for 'shift'
index 42caa3ce868193a3eb14eada7e3cf972aeddda17..4676a272d8081c9773dffca781e68795e3d53dfc 100644 (file)
@@ -398,6 +398,10 @@ struct elf_link_hash_table
 
   /* A linked list of BFD's loaded in the link.  */
   struct elf_link_loaded_list *loaded;
+
+  /* True if this target has relocatable executables, so needs dynamic
+     section symbols.  */
+  bfd_boolean is_relocatable_executable;
 };
 
 /* Look up an entry in an ELF linker hash table.  */
index fb587d51281bf0933ee51886c948deaf0d86f1ca..2ab84e4581fe0f3188db65b74cd4ed658f063c1b 100644 (file)
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -1496,6 +1496,7 @@ _bfd_elf_link_hash_table_init
   table->tls_sec = NULL;
   table->tls_size = 0;
   table->loaded = NULL;
+  table->is_relocatable_executable = FALSE;
 
   ret = _bfd_link_hash_table_init (&table->root, abfd, newfunc);
   table->root.type = bfd_link_elf_hash_table;
index cc3249662795b744765fda83896b45d4dbd63522..660a9909dc04ae438a0ccae6d1e8e30dc9e0cf7d 100644 (file)
@@ -2350,9 +2350,10 @@ elf32_arm_final_link_relocate (reloc_howto_type *           howto,
                                           (bfd_vma) 0);
        }
 
-      /* When generating a shared object, these relocations are copied
-        into the output file to be resolved at run time.  */
-      if (info->shared
+      /* When generating a shared object or relocatable executable, these
+        relocations are copied into the output file to be resolved at
+        run time.  */
+      if ((info->shared || globals->root.is_relocatable_executable)
          && (input_section->flags & SEC_ALLOC)
          && (r_type != R_ARM_REL32
              || !SYMBOL_CALLS_LOCAL (info, h))
@@ -3986,6 +3987,15 @@ elf32_arm_check_relocs (bfd *abfd, struct bfd_link_info *info,
   htab = elf32_arm_hash_table (info);
   sreloc = NULL;
 
+  /* Create dynamic sections for relocatable executables so that we can
+     copy relocations.  */
+  if (htab->root.is_relocatable_executable
+      && ! htab->root.dynamic_sections_created)
+    {
+      if (! _bfd_elf_link_create_dynamic_sections (abfd, info))
+       return FALSE;
+    }
+
   dynobj = elf_hash_table (info)->dynobj;
   local_got_offsets = elf_local_got_offsets (abfd);
 
@@ -4106,11 +4116,11 @@ elf32_arm_check_relocs (bfd *abfd, struct bfd_link_info *info,
                  eh->plt_thumb_refcount += 1;
              }
 
-           /* If we are creating a shared library, and this is a reloc
-               against a global symbol, or a non PC relative reloc
-               against a local symbol, then we need to copy the reloc
-               into the shared library.  However, if we are linking with
-               -Bsymbolic, we do not need to copy a reloc against a
+           /* If we are creating a shared library or relocatable executable,
+              and this is a reloc against a global symbol, or a non PC
+              relative reloc against a local symbol, then we need to copy
+              the reloc into the shared library.  However, if we are linking
+              with -Bsymbolic, we do not need to copy a reloc against a
                global symbol which is defined in an object we are
                including in the link (i.e., DEF_REGULAR is set).  At
                this point we have not seen all the input files, so it is
@@ -4118,7 +4128,7 @@ elf32_arm_check_relocs (bfd *abfd, struct bfd_link_info *info,
                later (it is never cleared).  We account for that
                possibility below by storing information in the
                relocs_copied field of the hash table entry.  */
-           if (info->shared
+           if ((info->shared || htab->root.is_relocatable_executable)
                && (sec->flags & SEC_ALLOC) != 0
                && ((r_type != R_ARM_PC24
                     && r_type != R_ARM_PLT32
@@ -4378,7 +4388,9 @@ elf32_arm_adjust_dynamic_symbol (struct bfd_link_info * info,
   asection * s;
   unsigned int power_of_two;
   struct elf32_arm_link_hash_entry * eh;
+  struct elf32_arm_link_hash_table *globals;
 
+  globals = elf32_arm_hash_table (info);
   dynobj = elf_hash_table (info)->dynobj;
 
   /* Make sure we know what is going on here.  */
@@ -4443,8 +4455,10 @@ elf32_arm_adjust_dynamic_symbol (struct bfd_link_info * info,
   /* If we are creating a shared library, we must presume that the
      only references to the symbol are via the global offset table.
      For such cases we need not do anything here; the relocations will
-     be handled correctly by relocate_section.  */
-  if (info->shared)
+     be handled correctly by relocate_section.  Relocatable executables
+     can reference data in shared objects directly, so we don't need to
+     do anything here.  */
+  if (info->shared || globals->root.is_relocatable_executable)
     return TRUE;
 
   /* We must allocate the symbol in our .dynbss section, which will
@@ -4637,13 +4651,23 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf)
      space for pc-relative relocs that have become local due to symbol
      visibility changes.  */
 
-  if (info->shared)
+  if (info->shared || htab->root.is_relocatable_executable)
     {
       /* Discard relocs on undefined weak syms with non-default
          visibility.  */
       if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
          && h->root.type == bfd_link_hash_undefweak)
        eh->relocs_copied = NULL;
+      else if (htab->root.is_relocatable_executable && h->dynindx == -1
+              && h->root.type == bfd_link_hash_new)
+       {
+         /* Output absolute symbols so that we can create relocations
+            against them.  For normal symbols we output a relocation
+            against the section that contains them.  */
+         if (! bfd_elf_link_record_dynamic_symbol (info, h))
+           return FALSE;
+       }
+
     }
   else
     {
@@ -5846,6 +5870,7 @@ elf32_arm_symbian_link_hash_table_create (bfd *abfd)
       /* The PLT entries are each three instructions.  */
       htab->plt_entry_size = 4 * NUM_ELEM (elf32_arm_symbian_plt_entry);
       htab->symbian_p = 1;
+      htab->root.is_relocatable_executable = 1;
     }
   return ret;
 }     
index 4cbcc1bb7a3b7eea16bd3f7a793a384edd4587b5..16a368ef37f8c32867b5b5ecc9cef61db70703d1 100644 (file)
@@ -386,7 +386,8 @@ bfd_elf_link_record_dynamic_symbol (struct bfd_link_info *info,
              && h->root.type != bfd_link_hash_undefweak)
            {
              h->forced_local = 1;
-             return TRUE;
+             if (!elf_hash_table (info)->is_relocatable_executable)
+               return TRUE;
            }
 
        default:
@@ -494,7 +495,8 @@ bfd_elf_record_link_assignment (bfd *output_bfd ATTRIBUTE_UNUSED,
 
   if ((h->def_dynamic
        || h->ref_dynamic
-       || info->shared)
+       || info->shared
+       || (info->executable && elf_hash_table (info)->is_relocatable_executable))
       && h->dynindx == -1)
     {
       if (! bfd_elf_link_record_dynamic_symbol (info, h))
@@ -710,7 +712,7 @@ _bfd_elf_link_renumber_dynsyms (bfd *output_bfd, struct bfd_link_info *info)
 {
   unsigned long dynsymcount = 0;
 
-  if (info->shared)
+  if (info->shared || elf_hash_table (info)->is_relocatable_executable)
     {
       const struct elf_backend_data *bed = get_elf_backend_data (output_bfd);
       asection *p;
@@ -8167,7 +8169,7 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
       long last_local = 0;
 
       /* Write out the section symbols for the output sections.  */
-      if (info->shared)
+      if (info->shared || elf_hash_table (info)->is_relocatable_executable)
        {
          asection *s;
 
This page took 0.064783 seconds and 4 git commands to generate.