+ bfd_boolean warned;
+
+ RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
+ r_symndx, symtab_hdr, sym_hashes,
+ h, sec, relocation,
+ unresolved_reloc, warned);
+ }
+
+ if (sec != NULL && elf_discarded_section (sec))
+ RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
+ rel, relend, howto, contents);
+
+ if (info->relocatable)
+ {
+ if (is_rel
+ && sym != NULL
+ && ELF_ST_TYPE (sym->st_info) == STT_SECTION)
+ {
+ rel->r_addend = 0;
+ relocation = sec->output_offset + sym->st_value;
+ r = _bfd_relocate_contents (howto, input_bfd, relocation,
+ contents + rel->r_offset);
+ goto done_reloc;
+ }
+ continue;
+ }
+
+ switch (r_type)
+ {
+ case R_C6000_NONE:
+ case R_C6000_ALIGN:
+ case R_C6000_FPHEAD:
+ case R_C6000_NOCMP:
+ /* No action needed. */
+ continue;
+
+ case R_C6000_PCR_S21:
+ /* A branch to an undefined weak symbol is turned into a
+ "b .s2 B3" instruction if the existing insn is of the
+ form "b .s2 symbol". */
+ if (h ? h->root.type == bfd_link_hash_undefweak
+ && (htab->elf.splt == NULL || h->plt.offset == (bfd_vma) -1)
+ : r_symndx != STN_UNDEF && bfd_is_und_section (sec))
+ {
+ unsigned long oldval;
+ oldval = bfd_get_32 (input_bfd, contents + rel->r_offset);
+
+ if ((oldval & 0x7e) == 0x12)
+ {
+ oldval &= 0xF0000001;
+ bfd_put_32 (input_bfd, oldval | 0x000c0362,
+ contents + rel->r_offset);
+ r = bfd_reloc_ok;
+ goto done_reloc;
+ }
+ }
+
+ case R_C6000_PCR_S12:
+ case R_C6000_PCR_S10:
+ case R_C6000_PCR_S7:
+ if (h != NULL
+ && h->plt.offset != (bfd_vma) -1
+ && htab->elf.splt != NULL)
+ {
+ relocation = (htab->elf.splt->output_section->vma
+ + htab->elf.splt->output_offset
+ + h->plt.offset);
+ }
+
+ /* Generic PC-relative handling produces a value relative to
+ the exact location of the relocation. Adjust it to be
+ relative to the start of the fetch packet instead. */
+ relocation += (input_section->output_section->vma
+ + input_section->output_offset
+ + rel->r_offset) & 0x1f;
+ unresolved_reloc = FALSE;
+ break;
+
+ case R_C6000_DSBT_INDEX:
+ relocation = elf32_tic6x_hash_table (info)->params.dsbt_index;
+ if (!info->shared || relocation != 0)
+ break;
+
+ /* fall through */
+ case R_C6000_ABS32:
+ case R_C6000_ABS16:
+ case R_C6000_ABS8:
+ case R_C6000_ABS_S16:
+ case R_C6000_ABS_L16:
+ case R_C6000_ABS_H16:
+ /* 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 || elf32_tic6x_using_dsbt (output_bfd))
+ && (input_section->flags & SEC_ALLOC)
+ && (h == NULL
+ || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
+ || h->root.type != bfd_link_hash_undefweak))
+ {
+ Elf_Internal_Rela outrel;
+ bfd_boolean skip, relocate;
+ asection *sreloc;
+
+ unresolved_reloc = FALSE;
+
+ sreloc = elf_section_data (input_section)->sreloc;
+ BFD_ASSERT (sreloc != NULL && sreloc->contents != NULL);
+
+ skip = FALSE;
+ relocate = FALSE;
+
+ outrel.r_offset =
+ _bfd_elf_section_offset (output_bfd, info, input_section,
+ rel->r_offset);
+ if (outrel.r_offset == (bfd_vma) -1)
+ skip = TRUE;
+ else if (outrel.r_offset == (bfd_vma) -2)
+ skip = TRUE, relocate = TRUE;
+ outrel.r_offset += (input_section->output_section->vma
+ + input_section->output_offset);
+
+ if (skip)
+ memset (&outrel, 0, sizeof outrel);
+ else if (h != NULL
+ && h->dynindx != -1
+ && (!info->shared
+ || !info->symbolic
+ || !h->def_regular))
+ {
+ outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
+ outrel.r_addend = rel->r_addend;
+ }
+ else
+ {
+ long indx;
+
+ outrel.r_addend = relocation + rel->r_addend;
+
+ if (bfd_is_abs_section (sec))
+ indx = 0;
+ else if (sec == NULL || sec->owner == NULL)
+ {
+ bfd_set_error (bfd_error_bad_value);
+ return FALSE;
+ }
+ else
+ {
+ asection *osec;
+
+ osec = sec->output_section;
+ indx = elf_section_data (osec)->dynindx;
+ outrel.r_addend -= osec->vma;
+ BFD_ASSERT (indx != 0);
+ }
+
+ outrel.r_info = ELF32_R_INFO (indx, r_type);
+ }
+
+ elf32_tic6x_install_rela (output_bfd, sreloc, &outrel);
+
+ /* If this reloc is against an external symbol, we do not want to
+ fiddle with the addend. Otherwise, we need to include the symbol
+ value so that it becomes an addend for the dynamic reloc. */
+ if (! relocate)
+ continue;
+ }
+
+ /* Generic logic OK. */
+ break;
+
+ case R_C6000_SBR_U15_B:
+ case R_C6000_SBR_U15_H:
+ case R_C6000_SBR_U15_W:
+ case R_C6000_SBR_S16:
+ case R_C6000_SBR_L16_B:
+ case R_C6000_SBR_L16_H:
+ case R_C6000_SBR_L16_W:
+ case R_C6000_SBR_H16_B:
+ case R_C6000_SBR_H16_H:
+ case R_C6000_SBR_H16_W:
+ sbh = bfd_link_hash_lookup (info->hash, "__c6xabi_DSBT_BASE",
+ FALSE, FALSE, TRUE);
+ if (sbh != NULL
+ && (sbh->type == bfd_link_hash_defined
+ || sbh->type == bfd_link_hash_defweak))
+ {
+ if (h ? (h->root.type == bfd_link_hash_undefweak
+ && (htab->elf.splt == NULL
+ || h->plt.offset == (bfd_vma) -1))
+ : r_symndx != STN_UNDEF && bfd_is_und_section (sec))
+ relocation = 0;
+ else
+ relocation -= (sbh->u.def.value
+ + sbh->u.def.section->output_section->vma
+ + sbh->u.def.section->output_offset);
+ }
+ else
+ {
+ (*_bfd_error_handler) (_("%B: SB-relative relocation but "
+ "__c6xabi_DSBT_BASE not defined"),
+ input_bfd);
+ ok = FALSE;
+ continue;
+ }
+ break;
+
+ case R_C6000_SBR_GOT_U15_W:
+ case R_C6000_SBR_GOT_L16_W:
+ case R_C6000_SBR_GOT_H16_W:
+ case R_C6000_EHTYPE:
+ /* Relocation is to the entry for this symbol in the global
+ offset table. */
+ if (htab->elf.sgot == NULL)
+ abort ();
+
+ if (h != NULL)
+ {
+ bfd_boolean dyn;
+
+ off = h->got.offset;
+ dyn = htab->elf.dynamic_sections_created;
+ if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
+ || (info->shared
+ && SYMBOL_REFERENCES_LOCAL (info, h))
+ || (ELF_ST_VISIBILITY (h->other)
+ && h->root.type == bfd_link_hash_undefweak))
+ {
+ /* This is actually a static link, or it is a
+ -Bsymbolic link and the symbol is defined
+ locally, or the symbol was forced to be local
+ because of a version file. We must initialize
+ this entry in the global offset table. Since the
+ offset must always be a multiple of 4, we use the
+ least significant bit to record whether we have
+ initialized it already.
+
+ When doing a dynamic link, we create a .rel.got
+ relocation entry to initialize the value. This
+ is done in the finish_dynamic_symbol routine. */
+ if ((off & 1) != 0)
+ off &= ~1;
+ else
+ {
+ bfd_put_32 (output_bfd, relocation,
+ htab->elf.sgot->contents + off);
+ h->got.offset |= 1;
+
+ if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared,
+ h)
+ && !(ELF_ST_VISIBILITY (h->other)
+ && h->root.type == bfd_link_hash_undefweak))
+ elf32_tic6x_make_got_dynreloc (output_bfd, htab, sec,
+ off);
+ }
+ }
+ else
+ unresolved_reloc = FALSE;
+ }
+ else
+ {
+ if (local_got_offsets == NULL)
+ abort ();
+
+ off = local_got_offsets[r_symndx];
+
+ /* The offset must always be a multiple of 4. We use
+ the least significant bit to record whether we have
+ already generated the necessary reloc. */
+ if ((off & 1) != 0)
+ off &= ~1;
+ else
+ {
+ bfd_put_32 (output_bfd, relocation,
+ htab->elf.sgot->contents + off);
+
+ if (info->shared || elf32_tic6x_using_dsbt (output_bfd))
+ elf32_tic6x_make_got_dynreloc (output_bfd, htab, sec, off);
+
+ local_got_offsets[r_symndx] |= 1;
+ }
+ }
+
+ if (off >= (bfd_vma) -2)
+ abort ();
+
+ if (htab->dsbt)
+ relocation = (htab->elf.sgot->output_section->vma
+ + htab->elf.sgot->output_offset + off
+ - htab->dsbt->output_section->vma
+ - htab->dsbt->output_offset);
+ else
+ relocation = (htab->elf.sgot->output_section->vma
+ + htab->elf.sgot->output_offset + off
+ - htab->elf.sgotplt->output_section->vma
+ - htab->elf.sgotplt->output_offset);
+
+ if (rel->r_addend != 0)
+ {
+ /* We can't do anything for a relocation which is against
+ a symbol *plus offset*. GOT holds relocations for
+ symbols. Make this an error; the compiler isn't
+ allowed to pass us these kinds of things. */
+ if (h == NULL)
+ (*_bfd_error_handler)
+ (_("%B, section %A: relocation %s with non-zero addend %d"
+ " against local symbol"),
+ input_bfd,
+ input_section,
+ elf32_tic6x_howto_table[r_type].name,
+ rel->r_addend);
+ else
+ (*_bfd_error_handler)
+ (_("%B, section %A: relocation %s with non-zero addend %d"
+ " against symbol `%s'"),
+ input_bfd,
+ input_section,
+ elf32_tic6x_howto_table[r_type].name,
+ rel->r_addend,
+ h->root.root.string[0] != '\0' ? h->root.root.string
+ : _("[whose name is lost]"));
+
+ bfd_set_error (bfd_error_bad_value);
+ return FALSE;
+ }
+ break;
+
+ case R_C6000_PREL31:
+ if (h != NULL
+ && h->plt.offset != (bfd_vma) -1
+ && htab->elf.splt != NULL)
+ {
+ relocation = (htab->elf.splt->output_section->vma
+ + htab->elf.splt->output_offset
+ + h->plt.offset);
+ }
+ break;
+
+ case R_C6000_COPY:
+ /* Invalid in relocatable object. */
+ default:
+ /* Unknown relocation. */
+ (*_bfd_error_handler) (_("%B: invalid relocation type %d"),
+ input_bfd, r_type);
+ ok = FALSE;
+ continue;
+ }
+
+ r = _bfd_final_link_relocate (howto, input_bfd, input_section,
+ contents, rel->r_offset,
+ relocation, rel->r_addend);
+
+ done_reloc:
+ if (r == bfd_reloc_ok
+ && howto->complain_on_overflow == complain_overflow_bitfield)
+ {
+ /* Generic overflow handling accepts cases the ABI says
+ should be rejected for R_C6000_ABS16 and
+ R_C6000_ABS8. */
+ bfd_vma value = (relocation + rel->r_addend) & 0xffffffff;
+ bfd_vma sbit = 1 << (howto->bitsize - 1);
+ bfd_vma sbits = (-(bfd_vma) sbit) & 0xffffffff;
+ bfd_vma value_sbits = value & sbits;
+
+ if (value_sbits != 0
+ && value_sbits != sbit
+ && value_sbits != sbits)
+ r = bfd_reloc_overflow;
+ }
+
+ if (r != bfd_reloc_ok)
+ {
+ const char *name;
+ const char *error_message;
+
+ if (h != NULL)
+ name = h->root.root.string;
+ else
+ {
+ name = bfd_elf_string_from_elf_section (input_bfd,
+ symtab_hdr->sh_link,
+ sym->st_name);
+ if (name == NULL)
+ return FALSE;
+ if (*name == '\0')
+ name = bfd_section_name (input_bfd, sec);
+ }
+
+ switch (r)
+ {
+ case bfd_reloc_overflow:
+ /* If the overflowing reloc was to an undefined symbol,
+ we have already printed one error message and there
+ is no point complaining again. */
+ if ((! h ||
+ h->root.type != bfd_link_hash_undefined)
+ && (!((*info->callbacks->reloc_overflow)
+ (info, (h ? &h->root : NULL), name, howto->name,
+ (bfd_vma) 0, input_bfd, input_section,
+ rel->r_offset))))
+ return FALSE;
+ break;
+
+ case bfd_reloc_undefined:
+ if (!((*info->callbacks->undefined_symbol)
+ (info, name, input_bfd, input_section,
+ rel->r_offset, TRUE)))
+ return FALSE;
+ break;
+
+ case bfd_reloc_outofrange:
+ error_message = _("out of range");
+ goto common_error;
+
+ case bfd_reloc_notsupported:
+ error_message = _("unsupported relocation");
+ goto common_error;
+
+ case bfd_reloc_dangerous:
+ error_message = _("dangerous relocation");
+ goto common_error;
+
+ default:
+ error_message = _("unknown error");
+ /* Fall through. */
+
+ common_error:
+ BFD_ASSERT (error_message != NULL);
+ if (!((*info->callbacks->reloc_dangerous)
+ (info, error_message, input_bfd, input_section,
+ rel->r_offset)))
+ return FALSE;
+ break;
+ }
+ }
+ }
+
+ return ok;
+}
+
+\f
+/* Look through the relocs for a section during the first phase, and
+ calculate needed space in the global offset table, procedure linkage
+ table, and dynamic reloc sections. */
+
+static bfd_boolean
+elf32_tic6x_check_relocs (bfd *abfd, struct bfd_link_info *info,
+ asection *sec, const Elf_Internal_Rela *relocs)
+{
+ struct elf32_tic6x_link_hash_table *htab;
+ Elf_Internal_Shdr *symtab_hdr;
+ struct elf_link_hash_entry **sym_hashes;
+ const Elf_Internal_Rela *rel;
+ const Elf_Internal_Rela *rel_end;
+ asection *sreloc;
+
+ if (info->relocatable)
+ return TRUE;
+
+ htab = elf32_tic6x_hash_table (info);
+ symtab_hdr = &elf_symtab_hdr (abfd);
+ sym_hashes = elf_sym_hashes (abfd);
+
+ /* Create dynamic sections for relocatable executables so that we can
+ copy relocations. */
+ if (elf32_tic6x_using_dsbt (abfd)
+ && ! htab->elf.dynamic_sections_created)
+ {
+ if (! _bfd_elf_link_create_dynamic_sections (abfd, info))
+ return FALSE;
+ }
+
+ sreloc = NULL;
+
+ rel_end = relocs + sec->reloc_count;
+ for (rel = relocs; rel < rel_end; rel++)
+ {
+ unsigned int r_type;
+ unsigned long r_symndx;
+ struct elf_link_hash_entry *h;
+ Elf_Internal_Sym *isym;
+
+ r_symndx = ELF32_R_SYM (rel->r_info);
+ r_type = ELF32_R_TYPE (rel->r_info);
+
+ if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr))
+ {
+ (*_bfd_error_handler) (_("%B: bad symbol index: %d"),
+ abfd,
+ r_symndx);
+ return FALSE;
+ }
+
+ if (r_symndx < symtab_hdr->sh_info)
+ {
+ /* A local symbol. */
+ isym = bfd_sym_from_r_symndx (&htab->sym_cache,
+ abfd, r_symndx);
+ if (isym == NULL)
+ return FALSE;
+ h = NULL;
+ }
+ else
+ {
+ isym = NULL;
+ h = sym_hashes[r_symndx - symtab_hdr->sh_info];
+ while (h->root.type == bfd_link_hash_indirect
+ || h->root.type == bfd_link_hash_warning)
+ h = (struct elf_link_hash_entry *) h->root.u.i.link;
+ }
+
+ switch (r_type)
+ {
+ case R_C6000_PCR_S21:
+ case R_C6000_PREL31:
+ /* This symbol requires a procedure linkage table entry. We
+ actually build the entry in adjust_dynamic_symbol,
+ because this might be a case of linking PIC code which is
+ never referenced by a dynamic object, in which case we
+ don't need to generate a procedure linkage table entry
+ after all. */
+
+ /* If this is a local symbol, we resolve it directly without
+ creating a procedure linkage table entry. */
+ if (h == NULL)
+ continue;
+
+ h->needs_plt = 1;
+ h->plt.refcount += 1;
+ break;
+
+ case R_C6000_SBR_GOT_U15_W:
+ case R_C6000_SBR_GOT_L16_W:
+ case R_C6000_SBR_GOT_H16_W:
+ case R_C6000_EHTYPE:
+ /* This symbol requires a global offset table entry. */
+ if (h != NULL)
+ {
+ h->got.refcount += 1;
+ }
+ else
+ {
+ bfd_signed_vma *local_got_refcounts;
+
+ /* This is a global offset table entry for a local symbol. */
+ local_got_refcounts = elf_local_got_refcounts (abfd);
+ if (local_got_refcounts == NULL)
+ {
+ bfd_size_type size;
+
+ size = symtab_hdr->sh_info;
+ size *= (sizeof (bfd_signed_vma)
+ + sizeof (bfd_vma) + sizeof(char));
+ local_got_refcounts = bfd_zalloc (abfd, size);
+ if (local_got_refcounts == NULL)
+ return FALSE;
+ elf_local_got_refcounts (abfd) = local_got_refcounts;
+ }
+ local_got_refcounts[r_symndx] += 1;
+ }
+
+ if (htab->elf.sgot == NULL)
+ {
+ if (htab->elf.dynobj == NULL)
+ htab->elf.dynobj = abfd;
+ if (!_bfd_elf_create_got_section (htab->elf.dynobj, info))
+ return FALSE;
+ }
+ break;
+
+ case R_C6000_DSBT_INDEX:
+ /* We'd like to check for nonzero dsbt_index here, but it's
+ set up only after check_relocs is called. Instead, we
+ store the number of R_C6000_DSBT_INDEX relocs in the
+ pc_count field, and potentially discard the extra space
+ in elf32_tic6x_allocate_dynrelocs. */
+ if (!info->shared)
+ break;
+
+ /* fall through */
+ case R_C6000_ABS32:
+ case R_C6000_ABS16:
+ case R_C6000_ABS8:
+ case R_C6000_ABS_S16:
+ case R_C6000_ABS_L16:
+ case R_C6000_ABS_H16:
+ /* 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
+ 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
+ possible that DEF_REGULAR is not set now but will be set
+ later (it is never cleared). In case of a weak definition,
+ DEF_REGULAR may be cleared later by a strong definition in
+ a shared library. We account for that possibility below by
+ storing information in the relocs_copied field of the hash
+ table entry. A similar situation occurs when creating
+ shared libraries and symbol visibility changes render the
+ symbol local.
+
+ If on the other hand, we are creating an executable, we
+ may need to keep relocations for symbols satisfied by a
+ dynamic library if we manage to avoid copy relocs for the
+ symbol. */
+ if ((info->shared || elf32_tic6x_using_dsbt (abfd))
+ && (sec->flags & SEC_ALLOC) != 0)
+ {
+ struct elf_dyn_relocs *p;
+ struct elf_dyn_relocs **head;
+
+ /* We must copy these reloc types into the output file.
+ Create a reloc section in dynobj and make room for
+ this reloc. */
+ if (sreloc == NULL)
+ {
+ if (htab->elf.dynobj == NULL)
+ htab->elf.dynobj = abfd;
+
+ sreloc = _bfd_elf_make_dynamic_reloc_section
+ (sec, htab->elf.dynobj, 2, abfd, /*rela? */ TRUE);
+
+ if (sreloc == NULL)
+ return FALSE;
+ }
+
+ /* If this is a global symbol, we count the number of
+ relocations we need for this symbol. */
+ if (h != NULL)
+ {
+ head = &((struct elf32_tic6x_link_hash_entry *) h)->dyn_relocs;
+ }
+ else
+ {
+ /* Track dynamic relocs needed for local syms too.
+ We really need local syms available to do this
+ easily. Oh well. */
+ void **vpp;
+ asection *s;
+
+ s = bfd_section_from_elf_index (abfd, isym->st_shndx);
+ if (s == NULL)
+ s = sec;
+
+ vpp = &elf_section_data (s)->local_dynrel;
+ head = (struct elf_dyn_relocs **)vpp;
+ }
+
+ p = *head;
+ if (p == NULL || p->sec != sec)
+ {
+ bfd_size_type amt = sizeof *p;
+ p = bfd_alloc (htab->elf.dynobj, amt);
+ if (p == NULL)
+ return FALSE;
+ p->next = *head;
+ *head = p;
+ p->sec = sec;
+ p->count = 0;
+ p->pc_count = 0;
+ }
+
+ p->count += 1;
+ if (r_type == R_C6000_DSBT_INDEX)
+ p->pc_count += 1;
+ }
+ break;
+
+ case R_C6000_SBR_U15_B:
+ case R_C6000_SBR_U15_H:
+ case R_C6000_SBR_U15_W:
+ case R_C6000_SBR_S16:
+ case R_C6000_SBR_L16_B:
+ case R_C6000_SBR_L16_H:
+ case R_C6000_SBR_L16_W:
+ case R_C6000_SBR_H16_B:
+ case R_C6000_SBR_H16_H:
+ case R_C6000_SBR_H16_W:
+ if (h != NULL && info->executable)
+ {
+ /* For B14-relative addresses, we might need a copy
+ reloc. */
+ h->non_got_ref = 1;
+ }
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ return TRUE;
+}
+
+static bfd_boolean
+elf32_tic6x_add_symbol_hook (bfd *abfd,
+ struct bfd_link_info *info ATTRIBUTE_UNUSED,
+ Elf_Internal_Sym *sym,
+ const char **namep ATTRIBUTE_UNUSED,
+ flagword *flagsp ATTRIBUTE_UNUSED,
+ asection **secp,
+ bfd_vma *valp)
+{
+ switch (sym->st_shndx)
+ {
+ case SHN_TIC6X_SCOMMON:
+ *secp = bfd_make_section_old_way (abfd, ".scommon");
+ (*secp)->flags |= SEC_IS_COMMON;
+ *valp = sym->st_size;
+ bfd_set_section_alignment (abfd, *secp, bfd_log2 (sym->st_value));
+ break;
+ }
+
+ return TRUE;
+}
+
+static void
+elf32_tic6x_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED, asymbol *asym)
+{
+ elf_symbol_type *elfsym;
+
+ elfsym = (elf_symbol_type *) asym;
+ switch (elfsym->internal_elf_sym.st_shndx)
+ {
+ case SHN_TIC6X_SCOMMON:
+ if (tic6x_elf_scom_section.name == NULL)
+ {
+ /* Initialize the small common section. */
+ tic6x_elf_scom_section.name = ".scommon";
+ tic6x_elf_scom_section.flags = SEC_IS_COMMON;
+ tic6x_elf_scom_section.output_section = &tic6x_elf_scom_section;
+ tic6x_elf_scom_section.symbol = &tic6x_elf_scom_symbol;
+ tic6x_elf_scom_section.symbol_ptr_ptr = &tic6x_elf_scom_symbol_ptr;
+ tic6x_elf_scom_symbol.name = ".scommon";
+ tic6x_elf_scom_symbol.flags = BSF_SECTION_SYM;
+ tic6x_elf_scom_symbol.section = &tic6x_elf_scom_section;
+ tic6x_elf_scom_symbol_ptr = &tic6x_elf_scom_symbol;
+ }
+ asym->section = &tic6x_elf_scom_section;
+ asym->value = elfsym->internal_elf_sym.st_size;
+ break;
+ }
+}
+
+static int
+elf32_tic6x_link_output_symbol_hook (struct bfd_link_info *info ATTRIBUTE_UNUSED,
+ const char *name ATTRIBUTE_UNUSED,
+ Elf_Internal_Sym *sym,
+ asection *input_sec,
+ struct elf_link_hash_entry *h ATTRIBUTE_UNUSED)
+{
+ /* If we see a common symbol, which implies a relocatable link, then
+ if a symbol was small common in an input file, mark it as small
+ common in the output file. */
+ if (sym->st_shndx == SHN_COMMON && strcmp (input_sec->name, ".scommon") == 0)
+ sym->st_shndx = SHN_TIC6X_SCOMMON;
+
+ return 1;
+}
+
+static bfd_boolean
+elf32_tic6x_section_from_bfd_section (bfd *abfd ATTRIBUTE_UNUSED,
+ asection *sec,
+ int *retval)
+{
+ if (strcmp (bfd_get_section_name (abfd, sec), ".scommon") == 0)
+ {
+ *retval = SHN_TIC6X_SCOMMON;
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+/* Allocate space in .plt, .got and associated reloc sections for
+ dynamic relocs. */
+
+static bfd_boolean
+elf32_tic6x_allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
+{
+ struct bfd_link_info *info;
+ struct elf32_tic6x_link_hash_table *htab;
+ struct elf32_tic6x_link_hash_entry *eh;
+ struct elf_dyn_relocs *p;
+
+ if (h->root.type == bfd_link_hash_indirect)
+ return TRUE;
+
+ if (h->root.type == bfd_link_hash_warning)
+ /* When warning symbols are created, they **replace** the "real"
+ entry in the hash table, thus we never get to see the real
+ symbol in a hash traversal. So look at it now. */
+ h = (struct elf_link_hash_entry *) h->root.u.i.link;
+ eh = (struct elf32_tic6x_link_hash_entry *) h;
+
+ info = (struct bfd_link_info *) inf;
+ htab = elf32_tic6x_hash_table (info);
+
+ if (htab->elf.dynamic_sections_created && h->plt.refcount > 0)
+ {
+ /* Make sure this symbol is output as a dynamic symbol.
+ Undefined weak syms won't yet be marked as dynamic. */
+ if (h->dynindx == -1 && !h->forced_local)
+ {
+ if (! bfd_elf_link_record_dynamic_symbol (info, h))
+ return FALSE;
+ }
+
+ if (info->shared
+ || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
+ {
+ asection *s = htab->elf.splt;
+
+ /* If this is the first .plt entry, make room for the special
+ first entry. */
+ if (s->size == 0)
+ s->size += PLT_ENTRY_SIZE;
+
+ h->plt.offset = s->size;
+
+ /* If this symbol is not defined in a regular file, and we are
+ not generating a shared library, then set the symbol to this
+ location in the .plt. This is required to make function
+ pointers compare as equal between the normal executable and
+ the shared library. */
+ if (! info->shared && !h->def_regular)
+ {
+ h->root.u.def.section = s;
+ h->root.u.def.value = h->plt.offset;
+ }
+
+ /* Make room for this entry. */
+ s->size += PLT_ENTRY_SIZE;
+ /* We also need to make an entry in the .got.plt section, which
+ will be placed in the .got section by the linker script. */
+ htab->elf.sgotplt->size += 4;
+ /* We also need to make an entry in the .rel.plt section. */
+ htab->elf.srelplt->size += sizeof (Elf32_External_Rela);
+ }
+ else
+ {
+ h->plt.offset = (bfd_vma) -1;
+ h->needs_plt = 0;
+ }
+ }
+ else
+ {
+ h->plt.offset = (bfd_vma) -1;
+ h->needs_plt = 0;
+ }
+
+ if (h->got.refcount > 0)
+ {
+ asection *s;
+
+ /* Make sure this symbol is output as a dynamic symbol.
+ Undefined weak syms won't yet be marked as dynamic. */
+ if (h->dynindx == -1
+ && !h->forced_local)
+ {
+ if (! bfd_elf_link_record_dynamic_symbol (info, h))
+ return FALSE;
+ }
+
+ s = htab->elf.sgot;
+ h->got.offset = s->size;
+ s->size += 4;
+
+ if (!(ELF_ST_VISIBILITY (h->other)
+ && h->root.type == bfd_link_hash_undefweak))
+ htab->elf.srelgot->size += sizeof (Elf32_External_Rela);
+ }
+ else
+ h->got.offset = (bfd_vma) -1;
+
+ if (eh->dyn_relocs == NULL)
+ return TRUE;
+
+ /* Discard relocs on undefined weak syms with non-default
+ visibility. */
+ if (info->shared || elf32_tic6x_using_dsbt (htab->obfd))
+ {
+ /* We use the pc_count field to hold the number of
+ R_C6000_DSBT_INDEX relocs. */
+ if (htab->params.dsbt_index != 0)
+ {
+ struct elf_dyn_relocs **pp;
+
+ for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
+ {
+ p->count -= p->pc_count;
+ p->pc_count = 0;
+ if (p->count == 0)
+ *pp = p->next;
+ else
+ pp = &p->next;
+ }
+ }
+
+ if (eh->dyn_relocs != NULL
+ && h->root.type == bfd_link_hash_undefweak)
+ {
+ if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
+ eh->dyn_relocs = NULL;
+
+ /* Make sure undefined weak symbols are output as a dynamic
+ symbol in PIEs. */
+ else if (h->dynindx == -1
+ && !h->forced_local)
+ {
+ if (! bfd_elf_link_record_dynamic_symbol (info, h))
+ return FALSE;
+ }
+ }
+ }
+
+ /* Finally, allocate space. */
+ for (p = eh->dyn_relocs; p != NULL; p = p->next)
+ {
+ asection *sreloc;
+
+ sreloc = elf_section_data (p->sec)->sreloc;
+
+ BFD_ASSERT (sreloc != NULL);
+ sreloc->size += p->count * sizeof (Elf32_External_Rela);
+ }
+
+ return TRUE;
+}
+
+/* Find any dynamic relocs that apply to read-only sections. */
+
+static bfd_boolean
+elf32_tic6x_readonly_dynrelocs (struct elf_link_hash_entry *h, void *inf)
+{
+ struct elf32_tic6x_link_hash_entry *eh;
+ struct elf_dyn_relocs *p;
+
+ if (h->root.type == bfd_link_hash_warning)
+ h = (struct elf_link_hash_entry *) h->root.u.i.link;
+
+ eh = (struct elf32_tic6x_link_hash_entry *) h;
+ for (p = eh->dyn_relocs; p != NULL; p = p->next)
+ {
+ asection *s = p->sec->output_section;
+
+ if (s != NULL && (s->flags & SEC_READONLY) != 0)
+ {
+ struct bfd_link_info *info = (struct bfd_link_info *) inf;
+
+ info->flags |= DF_TEXTREL;
+
+ /* Not an error, just cut short the traversal. */
+ return FALSE;
+ }
+ }
+ return TRUE;
+}
+
+/* Set the sizes of the dynamic sections. */
+
+static bfd_boolean
+elf32_tic6x_size_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
+{
+ struct elf32_tic6x_link_hash_table *htab;
+ bfd *dynobj;
+ asection *s;
+ bfd_boolean relocs;
+ bfd *ibfd;
+
+ htab = elf32_tic6x_hash_table (info);
+ dynobj = htab->elf.dynobj;
+ if (dynobj == NULL)
+ abort ();
+
+ if (htab->elf.dynamic_sections_created)
+ {
+ /* Set the contents of the .interp section to the interpreter. */
+ if (info->executable)
+ {
+ s = bfd_get_section_by_name (dynobj, ".interp");
+ if (s == NULL)
+ abort ();
+ s->size = sizeof ELF_DYNAMIC_INTERPRETER;
+ s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
+ }
+ }
+
+ /* Set up .got offsets for local syms, and space for local dynamic
+ relocs. */
+ for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
+ {
+ bfd_signed_vma *local_got;
+ bfd_signed_vma *end_local_got;
+ char *local_tls_type;
+ bfd_vma *local_tlsdesc_gotent;
+ bfd_size_type locsymcount;
+ Elf_Internal_Shdr *symtab_hdr;
+ asection *srel;
+
+ for (s = ibfd->sections; s != NULL; s = s->next)
+ {
+ struct elf_dyn_relocs *p;