* elflink.c (_bfd_elf_merge_symbol): Don't discard TLS symbols here.
[binutils-gdb.git] / bfd / elf32-rl78.c
index d40821856413635a8a2dbdb1fbcfa26977ece56d..ea9a0760d58ca570687fc7b10a2397689244ae0b 100644 (file)
@@ -1,5 +1,5 @@
 /* Renesas RL78 specific support for 32-bit ELF.
-   Copyright (C) 2011
+   Copyright (C) 2011, 2012
    Free Software Foundation, Inc.
 
    This file is part of BFD, the Binary File Descriptor library.
@@ -425,7 +425,7 @@ rl78_elf_relocate_section
   dynobj = elf_hash_table (info)->dynobj;
   splt = NULL;
   if (dynobj != NULL)
-    splt = bfd_get_section_by_name (dynobj, ".plt");
+    splt = bfd_get_linker_section (dynobj, ".plt");
 
   for (rel = relocs; rel < relend; rel ++)
     {
@@ -471,9 +471,9 @@ rl78_elf_relocate_section
          name = h->root.root.string;
        }
 
-      if (sec != NULL && elf_discarded_section (sec))
+      if (sec != NULL && discarded_section (sec))
        RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
-                                        rel, relend, howto, contents);
+                                        rel, 1, relend, howto, 0, contents);
 
       if (info->relocatable)
        {
@@ -497,8 +497,6 @@ rl78_elf_relocate_section
            else
              plt_offset = elf_local_got_offsets (input_bfd) + r_symndx;
 
-           /*      printf("%s: rel %x plt %d\n", h ? h->root.root.string : "(none)",
-                   relocation, *plt_offset);*/
            if (! valid_16bit_address (relocation))
              {
                /* If this is the first time we've processed this symbol,
@@ -651,16 +649,13 @@ rl78_elf_relocate_section
          break;
 
        case R_RL78_RH_SFR:
-         printf("SFR 0x%" BFD_VMA_FMT "x\n", relocation);
          RANGE (0xfff00, 0xfffff);
          OP (0) = relocation & 0xff;
          break;
 
        case R_RL78_RH_SADDR:
-         printf("SADDR 0x%" BFD_VMA_FMT "x\n", relocation);
          RANGE (0xffe20, 0xfff1f);
          OP (0) = relocation & 0xff;
-         printf(" - in\n");
          break;
 
          /* Complex reloc handling:  */
@@ -783,6 +778,8 @@ rl78_elf_relocate_section
                               + sec->output_section->vma
                               + sec->output_offset
                               + rel->r_addend);
+             else if (h->root.type == bfd_link_hash_undefweak)
+               RL78_STACK_PUSH (0);
              else
                _bfd_error_handler (_("Warning: RL78_SYM reloc with an unknown symbol"));
            }
@@ -1139,18 +1136,6 @@ rl78_dump_symtab (bfd * abfd, void * internal_syms, void * external_syms)
        case SHN_UNDEF: st_shndx_str = "SHN_UNDEF";
        default: st_shndx_str = "";
        }
-
-      printf ("isym = %p st_value = %lx st_size = %lx st_name = (%lu) %s "
-             "st_info = (%d) %s %s st_other = (%d) %s st_shndx = (%d) %s\n",
-             isym,
-             (unsigned long) isym->st_value,
-             (unsigned long) isym->st_size,
-             isym->st_name,
-             bfd_elf_string_from_elf_section (abfd, symtab_hdr->sh_link,
-                                              isym->st_name),
-             isym->st_info, st_info_str, st_info_stb_str,
-             isym->st_other, st_other_str,
-             isym->st_shndx, st_shndx_str);
     }
   if (free_internal)
     free (internal_syms);
@@ -1172,7 +1157,7 @@ rl78_get_reloc (long reloc)
 
 /* We support 16-bit pointers to code above 64k by generating a thunk
    below 64k containing a JMP instruction to the final address.  */
+
 static bfd_boolean
 rl78_elf_check_relocs
     (bfd *                     abfd,
@@ -1190,7 +1175,7 @@ rl78_elf_check_relocs
 
   if (info->relocatable)
     return TRUE;
+
   symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
   sym_hashes = elf_sym_hashes (abfd);
   local_plt_offsets = elf_local_got_offsets (abfd);
@@ -1203,7 +1188,7 @@ rl78_elf_check_relocs
       struct elf_link_hash_entry *h;
       unsigned long r_symndx;
       bfd_vma *offset;
+
       r_symndx = ELF32_R_SYM (rel->r_info);
       if (r_symndx < symtab_hdr->sh_info)
         h = NULL;
@@ -1214,7 +1199,7 @@ rl78_elf_check_relocs
                 || h->root.type == bfd_link_hash_warning)
            h = (struct elf_link_hash_entry *) h->root.u.i.link;
        }
+
       switch (ELF32_R_TYPE (rel->r_info))
         {
          /* This relocation describes a 16-bit pointer to a function.
@@ -1225,13 +1210,14 @@ rl78_elf_check_relocs
            elf_hash_table (info)->dynobj = dynobj = abfd;
          if (splt == NULL)
            {
-             splt = bfd_get_section_by_name (dynobj, ".plt");
+             splt = bfd_get_linker_section (dynobj, ".plt");
              if (splt == NULL)
                {
                  flagword flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS
                                    | SEC_IN_MEMORY | SEC_LINKER_CREATED
                                    | SEC_READONLY | SEC_CODE);
-                 splt = bfd_make_section_with_flags (dynobj, ".plt", flags);
+                 splt = bfd_make_section_anyway_with_flags (dynobj, ".plt",
+                                                            flags);
                  if (splt == NULL
                      || ! bfd_set_section_alignment (dynobj, splt, 1))
                    return FALSE;
@@ -1267,7 +1253,7 @@ rl78_elf_check_relocs
          break;
         }
     }
+
   return TRUE;
 }
 
@@ -1289,7 +1275,7 @@ rl78_elf_finish_dynamic_sections (bfd *abfd ATTRIBUTE_UNUSED,
   if (info->relax_trip > 0)
     {
       if ((dynobj = elf_hash_table (info)->dynobj) != NULL
-         && (splt = bfd_get_section_by_name (dynobj, ".plt")) != NULL)
+         && (splt = bfd_get_linker_section (dynobj, ".plt")) != NULL)
        {
          bfd_byte *contents = splt->contents;
          unsigned int i, size = splt->size;
@@ -1318,7 +1304,7 @@ rl78_elf_always_size_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
   if (dynobj == NULL)
     return TRUE;
 
-  splt = bfd_get_section_by_name (dynobj, ".plt");
+  splt = bfd_get_linker_section (dynobj, ".plt");
   BFD_ASSERT (splt != NULL);
 
   splt->contents = (bfd_byte *) bfd_zalloc (dynobj, splt->size);
@@ -1342,8 +1328,7 @@ struct relax_plt_data
 };
 
 static bfd_boolean
-rl78_relax_plt_check (struct elf_link_hash_entry *h,
-                      PTR xdata)
+rl78_relax_plt_check (struct elf_link_hash_entry *h, void * xdata)
 {
   struct relax_plt_data *data = (struct relax_plt_data *) xdata;
 
@@ -1374,8 +1359,7 @@ rl78_relax_plt_check (struct elf_link_hash_entry *h,
    previously had a plt entry, give it a new entry offset.  */
 
 static bfd_boolean
-rl78_relax_plt_realloc (struct elf_link_hash_entry *h,
-                        PTR xdata)
+rl78_relax_plt_realloc (struct elf_link_hash_entry *h, void * xdata)
 {
   bfd_vma *entry = (bfd_vma *) xdata;
 
@@ -1749,7 +1733,7 @@ rl78_offset_for_reloc (bfd *                    abfd,
          if (ssec)
            {
              if ((ssec->flags & SEC_MERGE)
-                 && ssec->sec_info_type == ELF_INFO_TYPE_MERGE)
+                 && ssec->sec_info_type == SEC_INFO_TYPE_MERGE)
                symval = _bfd_merged_section_offset (abfd, & ssec,
                                                     elf_section_data (ssec)->sec_info,
                                                     symval);
@@ -1989,7 +1973,7 @@ struct {
   { 0x71, 0x58, 0x53, 0x5b },  /* CLR1 !addr16.0 */
   { 0x71, 0x68, 0x63, 0x6b },  /* CLR1 !addr16.0 */
   { 0x71, 0x78, 0x73, 0x7b },  /* CLR1 !addr16.0 */
-  
+
   { -1, -1, -1, -1 }
 };
 
@@ -2072,14 +2056,14 @@ rl78_elf_relax_section
       if (shndx_buf == NULL)
        goto error_return;
       if (bfd_seek (abfd, shndx_hdr->sh_offset, SEEK_SET) != 0
-         || bfd_bread ((PTR) shndx_buf, amt, abfd) != amt)
+         || bfd_bread (shndx_buf, amt, abfd) != amt)
        goto error_return;
       shndx_hdr->contents = (bfd_byte *) shndx_buf;
     }
 
   /* Get a copy of the native relocations.  */
   internal_relocs = (_bfd_elf_link_read_relocs
-                    (abfd, sec, (PTR) NULL, (Elf_Internal_Rela *) NULL,
+                    (abfd, sec, NULL, (Elf_Internal_Rela *) NULL,
                      link_info->keep_memory));
   if (internal_relocs == NULL)
     goto error_return;
@@ -2366,7 +2350,7 @@ rl78_elf_relax_section
                }
              break;
            }
-         
+
        }
 
       if (irel->r_addend & RL78_RELAXA_ADDR16)
@@ -2396,10 +2380,6 @@ rl78_elf_relax_section
 
          GET_RELOC;
 
-         printf ("relax_addr16 detected, "
-                 "symval 0x%" BFD_VMA_FMT "x %02x %02x\n",
-                 symval, insn[0], insn[1]);
-
          if (0xffe20 <= symval && symval <= 0xfffff)
            {
 
@@ -2429,16 +2409,14 @@ rl78_elf_relax_section
                    {
                      insn[poff] = relax_addr16[idx].insn_for_sfr;
                      SNIP (poff+2, 1, R_RL78_RH_SFR);
-                     printf(" - replaced by SFR\n");
                    }
 
                  else if  (is_saddr && relax_addr16[idx].insn_for_saddr != -1)
                    {
                      insn[poff] = relax_addr16[idx].insn_for_saddr;
                      SNIP (poff+2, 1, R_RL78_RH_SADDR);
-                     printf(" - replaced by SADDR\n");
                    }
-               
+
                }
            }
        }