summaryrefslogtreecommitdiff
path: root/bfd/elf32-sh.c
diff options
context:
space:
mode:
Diffstat (limited to 'bfd/elf32-sh.c')
-rw-r--r--bfd/elf32-sh.c162
1 files changed, 70 insertions, 92 deletions
diff --git a/bfd/elf32-sh.c b/bfd/elf32-sh.c
index 480fa4bea66..2e220a5f03d 100644
--- a/bfd/elf32-sh.c
+++ b/bfd/elf32-sh.c
@@ -1843,10 +1843,12 @@ sh_elf_reloc_loop (int r_type ATTRIBUTE_UNUSED, bfd *input_bfd,
bfd_byte *start_ptr, *ptr, *last_ptr;
int diff, cum_diff;
bfd_signed_vma x;
+ bfd_size_type sz;
int insn;
/* Sanity check the address. */
- if (addr > input_section->_raw_size)
+ sz = input_section->rawsize ? input_section->rawsize : input_section->size;
+ if (addr > sz)
return bfd_reloc_outofrange;
/* We require the start and end relocations to be processed consecutively -
@@ -1871,14 +1873,11 @@ sh_elf_reloc_loop (int r_type ATTRIBUTE_UNUSED, bfd *input_bfd,
contents = elf_section_data (symbol_section)->this_hdr.contents;
else
{
- contents = (bfd_byte *) bfd_malloc (symbol_section->_raw_size);
- if (contents == NULL)
- return bfd_reloc_outofrange;
- if (! bfd_get_section_contents (input_bfd, symbol_section, contents,
- (file_ptr) 0,
- symbol_section->_raw_size))
+ if (!bfd_malloc_and_get_section (input_bfd, symbol_section,
+ &contents))
{
- free (contents);
+ if (contents != NULL)
+ free (contents);
return bfd_reloc_outofrange;
}
}
@@ -2197,11 +2196,6 @@ sh_elf_relax_section (bfd *abfd, asection *sec,
}
#endif
- /* If this is the first time we have been called for this section,
- initialize the cooked size. */
- if (sec->_cooked_size == 0)
- sec->_cooked_size = sec->_raw_size;
-
symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
internal_relocs = (_bfd_elf_link_read_relocs
@@ -2233,12 +2227,7 @@ sh_elf_relax_section (bfd *abfd, asection *sec,
contents = elf_section_data (sec)->this_hdr.contents;
else
{
- contents = (bfd_byte *) bfd_malloc (sec->_raw_size);
- if (contents == NULL)
- goto error_return;
-
- if (! bfd_get_section_contents (abfd, sec, contents,
- (file_ptr) 0, sec->_raw_size))
+ if (!bfd_malloc_and_get_section (abfd, sec, &contents))
goto error_return;
}
}
@@ -2248,7 +2237,7 @@ sh_elf_relax_section (bfd *abfd, asection *sec,
computed as though it were a jump offset, which are based
from 4 bytes after the jump instruction. */
laddr = irel->r_offset + 4 + irel->r_addend;
- if (laddr >= sec->_raw_size)
+ if (laddr >= sec->size)
{
(*_bfd_error_handler) (_("%s: 0x%lx: warning: bad R_SH_USES offset"),
bfd_archive_filename (abfd),
@@ -2276,7 +2265,7 @@ sh_elf_relax_section (bfd *abfd, asection *sec,
paddr = insn & 0xff;
paddr *= 4;
paddr += (laddr + 4) &~ (bfd_vma) 3;
- if (paddr >= sec->_raw_size)
+ if (paddr >= sec->size)
{
((*_bfd_error_handler)
(_("%s: 0x%lx: warning: bad R_SH_USES load offset"),
@@ -2490,12 +2479,7 @@ sh_elf_relax_section (bfd *abfd, asection *sec,
contents = elf_section_data (sec)->this_hdr.contents;
else
{
- contents = (bfd_byte *) bfd_malloc (sec->_raw_size);
- if (contents == NULL)
- goto error_return;
-
- if (! bfd_get_section_contents (abfd, sec, contents,
- (file_ptr) 0, sec->_raw_size))
+ if (!bfd_malloc_and_get_section (abfd, sec, &contents))
goto error_return;
}
}
@@ -2587,7 +2571,7 @@ sh_elf_relax_delete_bytes (bfd *abfd, asection *sec, bfd_vma addr,
power larger than the number of bytes we are deleting. */
irelalign = NULL;
- toaddr = sec->_cooked_size;
+ toaddr = sec->size;
irel = elf_section_data (sec)->relocs;
irelend = irel + sec->reloc_count;
@@ -2607,7 +2591,7 @@ sh_elf_relax_delete_bytes (bfd *abfd, asection *sec, bfd_vma addr,
memmove (contents + addr, contents + addr + count,
(size_t) (toaddr - addr - count));
if (irelalign == NULL)
- sec->_cooked_size -= count;
+ sec->size -= count;
else
{
int i;
@@ -2908,13 +2892,13 @@ sh_elf_relax_delete_bytes (bfd *abfd, asection *sec, bfd_vma addr,
Perhaps, if info->keep_memory is FALSE, we
should free them, if we are permitted to,
when we leave sh_coff_relax_section. */
- ocontents = (bfd_byte *) bfd_malloc (o->_raw_size);
- if (ocontents == NULL)
- return FALSE;
- if (! bfd_get_section_contents (abfd, o, ocontents,
- (file_ptr) 0,
- o->_raw_size))
- return FALSE;
+ if (!bfd_malloc_and_get_section (abfd, o, &ocontents))
+ {
+ if (ocontents != NULL)
+ free (ocontents);
+ return FALSE;
+ }
+
elf_section_data (o)->this_hdr.contents = ocontents;
}
}
@@ -2966,13 +2950,13 @@ sh_elf_relax_delete_bytes (bfd *abfd, asection *sec, bfd_vma addr,
Perhaps, if info->keep_memory is FALSE, we
should free them, if we are permitted to,
when we leave sh_coff_relax_section. */
- ocontents = (bfd_byte *) bfd_malloc (o->_raw_size);
- if (ocontents == NULL)
- return FALSE;
- if (! bfd_get_section_contents (abfd, o, ocontents,
- (file_ptr) 0,
- o->_raw_size))
- return FALSE;
+ if (!bfd_malloc_and_get_section (abfd, o, &ocontents))
+ {
+ if (ocontents != NULL)
+ free (ocontents);
+ return FALSE;
+ }
+
elf_section_data (o)->this_hdr.contents = ocontents;
}
}
@@ -3089,7 +3073,7 @@ sh_elf_align_loads (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
if (irel < irelend)
stop = irel->r_offset;
else
- stop = sec->_cooked_size;
+ stop = sec->size;
if (! _bfd_sh_align_load_span (abfd, sec, contents, sh_elf_swap_insns,
internal_relocs, &label,
@@ -4140,7 +4124,7 @@ sh_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
srel = htab->srelbss;
BFD_ASSERT (srel != NULL);
- srel->_raw_size += sizeof (Elf32_External_Rela);
+ srel->size += sizeof (Elf32_External_Rela);
h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_COPY;
}
@@ -4151,7 +4135,7 @@ sh_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
power_of_two = 3;
/* Apply the required alignment. */
- s->_raw_size = BFD_ALIGN (s->_raw_size, (bfd_size_type) (1 << power_of_two));
+ s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two));
if (power_of_two > bfd_get_section_alignment (htab->root.dynobj, s))
{
if (! bfd_set_section_alignment (htab->root.dynobj, s, power_of_two))
@@ -4160,10 +4144,10 @@ sh_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
/* Define the symbol as being at this point in the section. */
h->root.u.def.section = s;
- h->root.u.def.value = s->_raw_size;
+ h->root.u.def.value = s->size;
/* Increment the section size to make room for the symbol. */
- s->_raw_size += h->size;
+ s->size += h->size;
return TRUE;
}
@@ -4224,10 +4208,10 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
/* If this is the first .plt entry, make room for the special
first entry. */
- if (s->_raw_size == 0)
- s->_raw_size += PLT_ENTRY_SIZE;
+ if (s->size == 0)
+ s->size += PLT_ENTRY_SIZE;
- h->plt.offset = s->_raw_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
@@ -4242,14 +4226,14 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
}
/* Make room for this entry. */
- s->_raw_size += PLT_ENTRY_SIZE;
+ 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->sgotplt->_raw_size += 4;
+ htab->sgotplt->size += 4;
/* We also need to make an entry in the .rel.plt section. */
- htab->srelplt->_raw_size += sizeof (Elf32_External_Rela);
+ htab->srelplt->size += sizeof (Elf32_External_Rela);
}
else
{
@@ -4279,24 +4263,24 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
}
s = htab->sgot;
- h->got.offset = s->_raw_size;
- s->_raw_size += 4;
+ h->got.offset = s->size;
+ s->size += 4;
/* R_SH_TLS_GD needs 2 consecutive GOT slots. */
if (tls_type == GOT_TLS_GD)
- s->_raw_size += 4;
+ s->size += 4;
dyn = htab->root.dynamic_sections_created;
/* R_SH_TLS_IE_32 needs one dynamic relocation if dynamic,
R_SH_TLS_GD needs one if local symbol and two if global. */
if ((tls_type == GOT_TLS_GD && h->dynindx == -1)
|| (tls_type == GOT_TLS_IE && dyn))
- htab->srelgot->_raw_size += sizeof (Elf32_External_Rela);
+ htab->srelgot->size += sizeof (Elf32_External_Rela);
else if (tls_type == GOT_TLS_GD)
- htab->srelgot->_raw_size += 2 * sizeof (Elf32_External_Rela);
+ htab->srelgot->size += 2 * sizeof (Elf32_External_Rela);
else if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
|| h->root.type != bfd_link_hash_undefweak)
&& (info->shared
|| WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
- htab->srelgot->_raw_size += sizeof (Elf32_External_Rela);
+ htab->srelgot->size += sizeof (Elf32_External_Rela);
}
else
h->got.offset = (bfd_vma) -1;
@@ -4317,11 +4301,11 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
}
s = htab->sgot;
- eh->datalabel_got.offset = s->_raw_size;
- s->_raw_size += 4;
+ eh->datalabel_got.offset = s->size;
+ s->size += 4;
dyn = htab->root.dynamic_sections_created;
if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h))
- htab->srelgot->_raw_size += sizeof (Elf32_External_Rela);
+ htab->srelgot->size += sizeof (Elf32_External_Rela);
}
else
eh->datalabel_got.offset = (bfd_vma) -1;
@@ -4396,7 +4380,7 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
for (p = eh->dyn_relocs; p != NULL; p = p->next)
{
asection *sreloc = elf_section_data (p->sec)->sreloc;
- sreloc->_raw_size += p->count * sizeof (Elf32_External_Rela);
+ sreloc->size += p->count * sizeof (Elf32_External_Rela);
}
return TRUE;
@@ -4454,7 +4438,7 @@ sh_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
{
s = bfd_get_section_by_name (dynobj, ".interp");
BFD_ASSERT (s != NULL);
- s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER;
+ s->size = sizeof ELF_DYNAMIC_INTERPRETER;
s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
}
}
@@ -4493,7 +4477,7 @@ sh_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
else if (p->count != 0)
{
srel = elf_section_data (p->sec)->sreloc;
- srel->_raw_size += p->count * sizeof (Elf32_External_Rela);
+ srel->size += p->count * sizeof (Elf32_External_Rela);
if ((p->sec->output_section->flags & SEC_READONLY) != 0)
info->flags |= DF_TEXTREL;
}
@@ -4518,12 +4502,12 @@ sh_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
{
if (*local_got > 0)
{
- *local_got = s->_raw_size;
- s->_raw_size += 4;
+ *local_got = s->size;
+ s->size += 4;
if (*local_tls_type == GOT_TLS_GD)
- s->_raw_size += 4;
+ s->size += 4;
if (info->shared)
- srel->_raw_size += sizeof (Elf32_External_Rela);
+ srel->size += sizeof (Elf32_External_Rela);
}
else
*local_got = (bfd_vma) -1;
@@ -4535,9 +4519,9 @@ sh_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
{
/* Allocate 2 got entries and 1 dynamic reloc for R_SH_TLS_LD_32
relocs. */
- htab->tls_ldm_got.offset = htab->sgot->_raw_size;
- htab->sgot->_raw_size += 8;
- htab->srelgot->_raw_size += sizeof (Elf32_External_Rela);
+ htab->tls_ldm_got.offset = htab->sgot->size;
+ htab->sgot->size += 8;
+ htab->srelgot->size += sizeof (Elf32_External_Rela);
}
else
htab->tls_ldm_got.offset = -1;
@@ -4563,7 +4547,7 @@ sh_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
}
else if (strncmp (bfd_get_section_name (dynobj, s), ".rela", 5) == 0)
{
- if (s->_raw_size != 0 && s != htab->srelplt)
+ if (s->size != 0 && s != htab->srelplt)
relocs = TRUE;
/* We use the reloc_count field as a counter if we need
@@ -4576,7 +4560,7 @@ sh_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
continue;
}
- if (s->_raw_size == 0)
+ if (s->size == 0)
{
/* If we don't need this section, strip it from the
output file. This is mostly to handle .rela.bss and
@@ -4597,7 +4581,7 @@ sh_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
section's contents are written out. This should not happen,
but this way if it does, we get a R_SH_NONE reloc instead
of garbage. */
- s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->_raw_size);
+ s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
if (s->contents == NULL)
return FALSE;
}
@@ -4618,7 +4602,7 @@ sh_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
return FALSE;
}
- if (htab->splt->_raw_size != 0)
+ if (htab->splt->size != 0)
{
if (! add_dynamic_entry (DT_PLTGOT, 0)
|| ! add_dynamic_entry (DT_PLTRELSZ, 0)
@@ -5925,7 +5909,7 @@ sh_elf_get_relocated_section_contents (bfd *output_bfd,
symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
memcpy (data, elf_section_data (input_section)->this_hdr.contents,
- (size_t) input_section->_raw_size);
+ (size_t) input_section->size);
if ((input_section->flags & SEC_RELOC) != 0
&& input_section->reloc_count > 0)
@@ -7242,7 +7226,7 @@ sh_elf_finish_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
BFD_ASSERT (sgot != NULL && sdyn != NULL);
dyncon = (Elf32_External_Dyn *) sdyn->contents;
- dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->_raw_size);
+ dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
for (; dyncon < dynconend; dyncon++)
{
Elf_Internal_Dyn dyn;
@@ -7296,10 +7280,7 @@ sh_elf_finish_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
case DT_PLTRELSZ:
s = htab->srelplt->output_section;
BFD_ASSERT (s != NULL);
- if (s->_cooked_size != 0)
- dyn.d_un.d_val = s->_cooked_size;
- else
- dyn.d_un.d_val = s->_raw_size;
+ dyn.d_un.d_val = s->size;
bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
break;
@@ -7316,10 +7297,7 @@ sh_elf_finish_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
if (htab->srelplt != NULL)
{
s = htab->srelplt->output_section;
- if (s->_cooked_size != 0)
- dyn.d_un.d_val -= s->_cooked_size;
- else
- dyn.d_un.d_val -= s->_raw_size;
+ dyn.d_un.d_val -= s->size;
}
bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
break;
@@ -7328,7 +7306,7 @@ sh_elf_finish_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
/* Fill in the first entry in the procedure linkage table. */
splt = htab->splt;
- if (splt && splt->_raw_size > 0)
+ if (splt && splt->size > 0)
{
if (info->shared)
{
@@ -7373,7 +7351,7 @@ sh_elf_finish_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
}
/* Fill in the first three entries in the global offset table. */
- if (sgot && sgot->_raw_size > 0)
+ if (sgot && sgot->size > 0)
{
if (sdyn == NULL)
bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
@@ -7411,7 +7389,7 @@ static bfd_boolean
elf32_shlin_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
{
int offset;
- unsigned int raw_size;
+ unsigned int size;
switch (note->descsz)
{
@@ -7427,14 +7405,14 @@ elf32_shlin_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
/* pr_reg */
offset = 72;
- raw_size = 92;
+ size = 92;
break;
}
/* Make a ".reg/999" section. */
return _bfd_elfcore_make_pseudosection (abfd, ".reg",
- raw_size, note->descpos + offset);
+ size, note->descpos + offset);
}
static bfd_boolean