+2016-03-11 Dan Gissel <dgisselq@ieee.org>
+
+ PR 19713
+ * elf.c (_bfd_elf_section_offset): Ensure that the returned offset
+ uses bytes not octets.
+ * elflink.c (resolve_section): Likewise.
+ Add a bfd parameter.
+ (eval_section): Pass the input_bfd to resolve_section.
+ (bfd_elf_perform_complex_relocation): Convert byte offset to
+ octets before read and writing values.
+ (elf_link_input_bfd): Add byte to octet conversions.
+ (elf_reloc_link_order): Likewise.
+ (elf_fixup_link_order): Likewise.
+ (bfd_elf_final_link): Likewise.
+ * reloc.c (_bfd_final_link_relocate): Likewise.
+ * syms.c (_bfd_stab_section_find_nearest_line): Likewise.
+
2016-03-10 Nick Clifton <nickc@redhat.com>
* config.bfd: Mark the i370 target as obsolete.
sym->st_value + addend);
}
+/* Adjust an address within a section. Given OFFSET within SEC, return
+ the new offset within the section, based upon changes made to the
+ section. Returns -1 if the offset is now invalid.
+ The offset (in abnd out) is in target sized bytes, however big a
+ byte may be. */
+
bfd_vma
_bfd_elf_section_offset (bfd *abfd,
struct bfd_link_info *info,
offset);
case SEC_INFO_TYPE_EH_FRAME:
return _bfd_elf_eh_frame_section_offset (abfd, info, sec, offset);
+
default:
if ((sec->flags & SEC_ELF_REVERSE_COPY) != 0)
{
+ /* Reverse the offset. */
const struct elf_backend_data *bed = get_elf_backend_data (abfd);
bfd_size_type address_size = bed->s->arch_size / 8;
- offset = sec->size - offset - address_size;
+
+ /* address_size and sec->size are in octets. Convert
+ to bytes before subtracting the original offset. */
+ offset = (sec->size - address_size) / bfd_octets_per_byte (abfd) - offset;
}
return offset;
}
return FALSE;
}
+/* Looks up NAME in SECTIONS. If found sets RESULT to NAME's address (in
+ bytes) and returns TRUE, otherwise returns FALSE. Accepts pseudo-section
+ names like "foo.end" which is the end address of section "foo". */
+
static bfd_boolean
resolve_section (const char *name,
asection *sections,
- bfd_vma *result)
+ bfd_vma *result,
+ bfd * abfd)
{
asection *curr;
unsigned int len;
}
/* Hmm. still haven't found it. try pseudo-section names. */
+ /* FIXME: This could be coded more efficiently... */
for (curr = sections; curr; curr = curr->next)
{
len = strlen (curr->name);
{
if (strncmp (".end", name + len, 4) == 0)
{
- *result = curr->vma + curr->size;
+ *result = curr->vma + curr->size / bfd_octets_per_byte (abfd);
return TRUE;
}
if (symbol_is_section)
{
- if (!resolve_section (symbuf, flinfo->output_bfd->sections, result)
+ if (!resolve_section (symbuf, flinfo->output_bfd->sections, result, input_bfd)
&& !resolve_symbol (symbuf, input_bfd, flinfo, result,
isymbuf, locsymcount))
{
if (!resolve_symbol (symbuf, input_bfd, flinfo, result,
isymbuf, locsymcount)
&& !resolve_section (symbuf, flinfo->output_bfd->sections,
- result))
+ result, input_bfd))
{
undefined_reference ("symbol", symbuf);
return FALSE;
else
shift = (8 * wordsz) - (start + len);
- /* FIXME: octets_per_byte. */
- x = get_value (wordsz, chunksz, input_bfd, contents + rel->r_offset);
+ x = get_value (wordsz, chunksz, input_bfd,
+ contents + rel->r_offset * bfd_octets_per_byte (input_bfd));
#ifdef DEBUG
printf ("Doing complex reloc: "
(unsigned long) relocation, (unsigned long) (mask << shift),
(unsigned long) ((relocation & mask) << shift), (unsigned long) x);
#endif
- /* FIXME: octets_per_byte. */
- put_value (wordsz, chunksz, input_bfd, x, contents + rel->r_offset);
+ put_value (wordsz, chunksz, input_bfd, x,
+ contents + rel->r_offset * bfd_octets_per_byte (input_bfd));
return r;
}
break;
default:
{
- /* FIXME: octets_per_byte. */
if (! (o->flags & SEC_EXCLUDE))
{
file_ptr offset = (file_ptr) o->output_offset;
bfd_size_type todo = o->size;
+
+ offset *= bfd_octets_per_byte (output_bfd);
+
if ((o->flags & SEC_ELF_REVERSE_COPY))
{
/* Reverse-copy input section to output. */
}
break;
}
+
ok = bfd_set_section_contents (output_bfd, output_section, buf,
- link_order->offset, size);
+ link_order->offset
+ * bfd_octets_per_byte (output_bfd),
+ size);
free (buf);
if (! ok)
return FALSE;
{
s = sections[n]->u.indirect.section;
offset &= ~(bfd_vma) 0 << s->alignment_power;
- s->output_offset = offset;
+ s->output_offset = offset / bfd_octets_per_byte (abfd);
sections[n]->offset = offset;
- /* FIXME: octets_per_byte. */
offset += sections[n]->size;
}
continue;
if (strcmp (o->name, ".dynstr") != 0)
{
- /* FIXME: octets_per_byte. */
if (! bfd_set_section_contents (abfd, o->output_section,
o->contents,
- (file_ptr) o->output_offset,
+ (file_ptr) o->output_offset
+ * bfd_octets_per_byte (abfd),
o->size))
goto error_return;
}