/* Allocate and clear an extra byte at the end, to prevent crashes
in case the string table is not terminated. */
- if (shstrtabsize + 1 == 0
+ if (shstrtabsize + 1 <= 1
|| (shstrtab = bfd_alloc (abfd, shstrtabsize + 1)) == NULL
|| bfd_seek (abfd, offset, SEEK_SET) != 0)
shstrtab = NULL;
if (bfd_get_error () != bfd_error_system_call)
bfd_set_error (bfd_error_file_truncated);
shstrtab = NULL;
+ /* Once we've failed to read it, make sure we don't keep
+ trying. Otherwise, we'll keep allocating space for
+ the string table over and over. */
+ i_shdrp[shindex]->sh_size = 0;
}
else
shstrtab[shstrtabsize] = '\0';
if (! bfd_set_section_vma (abfd, newsect, hdr->sh_addr)
|| ! bfd_set_section_size (abfd, newsect, hdr->sh_size)
|| ! bfd_set_section_alignment (abfd, newsect,
- bfd_log2 ((bfd_vma) hdr->sh_addralign)))
+ bfd_log2 (hdr->sh_addralign)))
return FALSE;
flags = SEC_NO_FLAGS;
{ NULL, 0 }, /* 'p' */
{ NULL, 0 }, /* 'q' */
{ NULL, 0 }, /* 'r' */
- { STRING_COMMA_LEN ("stab") } /* 's' */
+ { STRING_COMMA_LEN ("stab") }, /* 's' */
+ { NULL, 0 }, /* 't' */
+ { NULL, 0 }, /* 'u' */
+ { NULL, 0 }, /* 'v' */
+ { NULL, 0 }, /* 'w' */
+ { NULL, 0 }, /* 'x' */
+ { NULL, 0 }, /* 'y' */
+ { STRING_COMMA_LEN ("zdebug") } /* 'z' */
};
if (name [0] == '.')
if ((flags & SEC_ALLOC) != 0)
{
Elf_Internal_Phdr *phdr;
- unsigned int i;
+ unsigned int i, nload;
+
+ /* Some ELF linkers produce binaries with all the program header
+ p_paddr fields zero. If we have such a binary with more than
+ one PT_LOAD header, then leave the section lma equal to vma
+ so that we don't create sections with overlapping lma. */
+ phdr = elf_tdata (abfd)->phdr;
+ for (nload = 0, i = 0; i < elf_elfheader (abfd)->e_phnum; i++, phdr++)
+ if (phdr->p_paddr != 0)
+ break;
+ else if (phdr->p_type == PT_LOAD && phdr->p_memsz != 0)
+ ++nload;
+ if (i >= elf_elfheader (abfd)->e_phnum && nload > 1)
+ return TRUE;
- /* Look through the phdrs to see if we need to adjust the lma.
- If all the p_paddr fields are zero, we ignore them, since
- some ELF linkers produce such output. */
phdr = elf_tdata (abfd)->phdr;
for (i = 0; i < elf_elfheader (abfd)->e_phnum; i++, phdr++)
{
- if (phdr->p_paddr != 0)
- break;
- }
- if (i < elf_elfheader (abfd)->e_phnum)
- {
- phdr = elf_tdata (abfd)->phdr;
- for (i = 0; i < elf_elfheader (abfd)->e_phnum; i++, phdr++)
+ /* This section is part of this segment if its file
+ offset plus size lies within the segment's memory
+ span and, if the section is loaded, the extent of the
+ loaded data lies within the extent of the segment.
+
+ Note - we used to check the p_paddr field as well, and
+ refuse to set the LMA if it was 0. This is wrong
+ though, as a perfectly valid initialised segment can
+ have a p_paddr of zero. Some architectures, eg ARM,
+ place special significance on the address 0 and
+ executables need to be able to have a segment which
+ covers this address. */
+ if (phdr->p_type == PT_LOAD
+ && (bfd_vma) hdr->sh_offset >= phdr->p_offset
+ && (hdr->sh_offset + hdr->sh_size
+ <= phdr->p_offset + phdr->p_memsz)
+ && ((flags & SEC_LOAD) == 0
+ || (hdr->sh_offset + hdr->sh_size
+ <= phdr->p_offset + phdr->p_filesz)))
{
- /* This section is part of this segment if its file
- offset plus size lies within the segment's memory
- span and, if the section is loaded, the extent of the
- loaded data lies within the extent of the segment.
-
- Note - we used to check the p_paddr field as well, and
- refuse to set the LMA if it was 0. This is wrong
- though, as a perfectly valid initialised segment can
- have a p_paddr of zero. Some architectures, eg ARM,
- place special significance on the address 0 and
- executables need to be able to have a segment which
- covers this address. */
- if (phdr->p_type == PT_LOAD
- && (bfd_vma) hdr->sh_offset >= phdr->p_offset
- && (hdr->sh_offset + hdr->sh_size
- <= phdr->p_offset + phdr->p_memsz)
- && ((flags & SEC_LOAD) == 0
- || (hdr->sh_offset + hdr->sh_size
- <= phdr->p_offset + phdr->p_filesz)))
- {
- if ((flags & SEC_LOAD) == 0)
- newsect->lma = (phdr->p_paddr
- + hdr->sh_addr - phdr->p_vaddr);
- else
- /* We used to use the same adjustment for SEC_LOAD
- sections, but that doesn't work if the segment
- is packed with code from multiple VMAs.
- Instead we calculate the section LMA based on
- the segment LMA. It is assumed that the
- segment will contain sections with contiguous
- LMAs, even if the VMAs are not. */
- newsect->lma = (phdr->p_paddr
- + hdr->sh_offset - phdr->p_offset);
-
- /* With contiguous segments, we can't tell from file
- offsets whether a section with zero size should
- be placed at the end of one segment or the
- beginning of the next. Decide based on vaddr. */
- if (hdr->sh_addr >= phdr->p_vaddr
- && (hdr->sh_addr + hdr->sh_size
- <= phdr->p_vaddr + phdr->p_memsz))
- break;
- }
+ if ((flags & SEC_LOAD) == 0)
+ newsect->lma = (phdr->p_paddr
+ + hdr->sh_addr - phdr->p_vaddr);
+ else
+ /* We used to use the same adjustment for SEC_LOAD
+ sections, but that doesn't work if the segment
+ is packed with code from multiple VMAs.
+ Instead we calculate the section LMA based on
+ the segment LMA. It is assumed that the
+ segment will contain sections with contiguous
+ LMAs, even if the VMAs are not. */
+ newsect->lma = (phdr->p_paddr
+ + hdr->sh_offset - phdr->p_offset);
+
+ /* With contiguous segments, we can't tell from file
+ offsets whether a section with zero size should
+ be placed at the end of one segment or the
+ beginning of the next. Decide based on vaddr. */
+ if (hdr->sh_addr >= phdr->p_vaddr
+ && (hdr->sh_addr + hdr->sh_size
+ <= phdr->p_vaddr + phdr->p_memsz))
+ break;
}
}
}
fprintf (f, " %-20s ", name);
if (! stringp)
- fprintf (f, "0x%lx", (unsigned long) dyn.d_un.d_val);
+ {
+ fprintf (f, "0x");
+ bfd_fprintf_vma (abfd, f, dyn.d_un.d_val);
+ }
else
{
const char *string;
{ NULL, 0, 0, 0, 0 }
};
+static const struct bfd_elf_special_section special_sections_z[] =
+{
+ { STRING_COMMA_LEN (".zdebug_line"), 0, SHT_PROGBITS, 0 },
+ { STRING_COMMA_LEN (".zdebug_info"), 0, SHT_PROGBITS, 0 },
+ { STRING_COMMA_LEN (".zdebug_abbrev"), 0, SHT_PROGBITS, 0 },
+ { STRING_COMMA_LEN (".zdebug_aranges"), 0, SHT_PROGBITS, 0 },
+ { NULL, 0, 0, 0, 0 }
+};
+
static const struct bfd_elf_special_section *special_sections[] =
{
special_sections_b, /* 'b' */
special_sections_r, /* 'r' */
special_sections_s, /* 's' */
special_sections_t, /* 't' */
+ NULL, /* 'u' */
+ NULL, /* 'v' */
+ NULL, /* 'w' */
+ NULL, /* 'x' */
+ NULL, /* 'y' */
+ special_sections_z /* 'z' */
};
const struct bfd_elf_special_section *
return NULL;
i = sec->name[1] - 'b';
- if (i < 0 || i > 't' - 'b')
+ if (i < 0 || i > 'z' - 'b')
return NULL;
spec = special_sections[i];
rel_hdr->sh_entsize = (use_rela_p
? bed->s->sizeof_rela
: bed->s->sizeof_rel);
- rel_hdr->sh_addralign = 1 << bed->s->log_file_align;
+ rel_hdr->sh_addralign = (bfd_vma) 1 << bed->s->log_file_align;
rel_hdr->sh_flags = 0;
rel_hdr->sh_addr = 0;
rel_hdr->sh_size = 0;
this_hdr->sh_offset = 0;
this_hdr->sh_size = asect->size;
this_hdr->sh_link = 0;
- this_hdr->sh_addralign = 1 << asect->alignment_power;
+ this_hdr->sh_addralign = (bfd_vma) 1 << asect->alignment_power;
/* The sh_entsize and sh_info fields may have been set already by
copy_private_section_data. */
}
/* Don't output section symbols for sections that are not going to be
- output. Also, don't output section symbols for reloc and other
- special sections. */
+ output. */
static bfd_boolean
ignore_section_sym (bfd *abfd, asymbol *sym)
{
return ((sym->flags & BSF_SECTION_SYM) != 0
- && (sym->value != 0
- || (sym->section->owner != abfd
- && (sym->section->output_section->owner != abfd
- || sym->section->output_offset != 0))));
+ && !(sym->section->owner == abfd
+ || (sym->section->output_section->owner == abfd
+ && sym->section->output_offset == 0)));
}
static bfd_boolean
asymbol *sym = syms[idx];
if ((sym->flags & BSF_SECTION_SYM) != 0
+ && sym->value == 0
&& !ignore_section_sym (abfd, sym))
{
asection *sec = sym->section;
file_ptr offset,
bfd_boolean align)
{
- if (align)
- {
- unsigned int al;
-
- al = i_shdrp->sh_addralign;
- if (al > 1)
- offset = BFD_ALIGN (offset, al);
- }
+ if (align && i_shdrp->sh_addralign > 1)
+ offset = BFD_ALIGN (offset, i_shdrp->sh_addralign);
i_shdrp->sh_offset = offset;
if (i_shdrp->bfd_section != NULL)
i_shdrp->bfd_section->filepos = offset;
this_hdr = &elf_section_data (sec)->this_hdr;
align = (bfd_size_type) 1 << bfd_get_section_alignment (abfd, sec);
- if (p->p_type == PT_LOAD
- || p->p_type == PT_TLS)
- {
- bfd_signed_vma adjust = sec->lma - (p->p_paddr + p->p_memsz);
-
- if (this_hdr->sh_type != SHT_NOBITS
+ if ((p->p_type == PT_LOAD
+ || p->p_type == PT_TLS)
+ && (this_hdr->sh_type != SHT_NOBITS
|| ((this_hdr->sh_flags & SHF_ALLOC) != 0
&& ((this_hdr->sh_flags & SHF_TLS) == 0
- || p->p_type == PT_TLS)))
+ || p->p_type == PT_TLS))))
+ {
+ bfd_signed_vma adjust = sec->vma - (p->p_vaddr + p->p_memsz);
+
+ if (adjust < 0)
{
- if (adjust < 0)
- {
- (*_bfd_error_handler)
- (_("%B: section %A lma 0x%lx overlaps previous sections"),
- abfd, sec, (unsigned long) sec->lma);
- adjust = 0;
- }
- p->p_memsz += adjust;
+ (*_bfd_error_handler)
+ (_("%B: section %A vma 0x%lx overlaps previous sections"),
+ abfd, sec, (unsigned long) sec->lma);
+ adjust = 0;
+ }
+ p->p_memsz += adjust;
- if (this_hdr->sh_type != SHT_NOBITS)
- {
- off += adjust;
- p->p_filesz += adjust;
- }
+ if (this_hdr->sh_type != SHT_NOBITS)
+ {
+ off += adjust;
+ p->p_filesz += adjust;
}
}
unsigned int i;
unsigned int num_segments;
bfd_boolean phdr_included = FALSE;
+ bfd_boolean p_paddr_valid;
bfd_vma maxpagesize;
struct elf_segment_map *phdr_adjust_seg = NULL;
unsigned int phdr_adjust_num = 0;
for (section = ibfd->sections; section != NULL; section = section->next)
section->segment_mark = FALSE;
+ /* The Solaris linker creates program headers in which all the
+ p_paddr fields are zero. When we try to objcopy or strip such a
+ file, we get confused. Check for this case, and if we find it
+ don't set the p_paddr_valid fields. */
+ p_paddr_valid = FALSE;
+ for (i = 0, segment = elf_tdata (ibfd)->phdr;
+ i < num_segments;
+ i++, segment++)
+ if (segment->p_paddr != 0)
+ {
+ p_paddr_valid = TRUE;
+ break;
+ }
+
/* Scan through the segments specified in the program header
of the input BFD. For this first scan we look for overlaps
in the loadable segments. These can be created by weird
if (!first_section || first_section->output_section != NULL)
{
map->p_paddr = segment->p_paddr;
- map->p_paddr_valid = 1;
+ map->p_paddr_valid = p_paddr_valid;
}
/* Determine if this segment contains the ELF file header
pointers that we are interested in. As these sections get assigned
to a segment, they are removed from this array. */
- /* Gcc 2.96 miscompiles this code on mips. Don't do casting here
- to work around this long long bug. */
sections = bfd_malloc2 (section_count, sizeof (asection *));
if (sections == NULL)
return FALSE;
We try to catch that case here, and set it to the
correct value. Note - some backends require that
p_paddr be left as zero. */
- if (segment->p_paddr == 0
+ if (!p_paddr_valid
&& segment->p_vaddr != 0
&& !bed->want_p_paddr_set_to_zero
&& isec == 0
*pointer_to_map = map;
pointer_to_map = &map->next;
- if (!bed->want_p_paddr_set_to_zero
+ if (p_paddr_valid
+ && !bed->want_p_paddr_set_to_zero
&& matching_lma != map->p_paddr
- && !map->includes_filehdr && !map->includes_phdrs)
+ && !map->includes_filehdr
+ && !map->includes_phdrs)
/* There is some padding before the first section in the
segment. So, we must account for that in the output
segment's vma. */
map->p_flags = segment->p_flags;
map->p_flags_valid = 1;
map->p_paddr = suggested_lma;
- map->p_paddr_valid = 1;
+ map->p_paddr_valid = p_paddr_valid;
map->includes_filehdr = 0;
map->includes_phdrs = 0;
}
free (sections);
}
- /* The Solaris linker creates program headers in which all the
- p_paddr fields are zero. When we try to objcopy or strip such a
- file, we get confused. Check for this case, and if we find it
- reset the p_paddr_valid fields. */
- for (map = map_first; map != NULL; map = map->next)
- if (map->p_paddr != 0)
- break;
- if (map == NULL)
- for (map = map_first; map != NULL; map = map->next)
- map->p_paddr_valid = 0;
-
elf_tdata (obfd)->segment_map = map_first;
/* If we had to estimate the number of program headers that were
unsigned int i;
unsigned int num_segments;
bfd_boolean phdr_included = FALSE;
+ bfd_boolean p_paddr_valid;
iehdr = elf_elfheader (ibfd);
map_first = NULL;
pointer_to_map = &map_first;
+ /* If all the segment p_paddr fields are zero, don't set
+ map->p_paddr_valid. */
+ p_paddr_valid = FALSE;
num_segments = elf_elfheader (ibfd)->e_phnum;
+ for (i = 0, segment = elf_tdata (ibfd)->phdr;
+ i < num_segments;
+ i++, segment++)
+ if (segment->p_paddr != 0)
+ {
+ p_paddr_valid = TRUE;
+ break;
+ }
+
for (i = 0, segment = elf_tdata (ibfd)->phdr;
i < num_segments;
i++, segment++)
map->p_flags = segment->p_flags;
map->p_flags_valid = 1;
map->p_paddr = segment->p_paddr;
- map->p_paddr_valid = 1;
+ map->p_paddr_valid = p_paddr_valid;
map->p_align = segment->p_align;
map->p_align_valid = 1;
map->p_vaddr_offset = 0;
phdr_included = TRUE;
}
- if (!map->includes_phdrs && !map->includes_filehdr)
+ if (!map->includes_phdrs
+ && !map->includes_filehdr
+ && map->p_paddr_valid)
/* There is some other padding before the first section. */
map->p_vaddr_offset = ((lowest_section ? lowest_section->lma : 0)
- segment->p_paddr);
symtab_hdr->sh_entsize = bed->s->sizeof_sym;
symtab_hdr->sh_size = symtab_hdr->sh_entsize * (symcount + 1);
symtab_hdr->sh_info = elf_num_locals (abfd) + 1;
- symtab_hdr->sh_addralign = 1 << bed->s->log_file_align;
+ symtab_hdr->sh_addralign = (bfd_vma) 1 << bed->s->log_file_align;
symstrtab_hdr = &elf_tdata (abfd)->strtab_hdr;
symstrtab_hdr->sh_type = SHT_STRTAB;
ret = sizeof (arelent *);
for (s = abfd->sections; s != NULL; s = s->next)
- if ((s->flags & SEC_LOAD) != 0
- && elf_section_data (s)->this_hdr.sh_link == elf_dynsymtab (abfd)
+ if (elf_section_data (s)->this_hdr.sh_link == elf_dynsymtab (abfd)
&& (elf_section_data (s)->this_hdr.sh_type == SHT_REL
|| elf_section_data (s)->this_hdr.sh_type == SHT_RELA))
ret += ((s->size / elf_section_data (s)->this_hdr.sh_entsize)
ret = 0;
for (s = abfd->sections; s != NULL; s = s->next)
{
- if ((s->flags & SEC_LOAD) != 0
- && elf_section_data (s)->this_hdr.sh_link == elf_dynsymtab (abfd)
+ if (elf_section_data (s)->this_hdr.sh_link == elf_dynsymtab (abfd)
&& (elf_section_data (s)->this_hdr.sh_type == SHT_REL
|| elf_section_data (s)->this_hdr.sh_type == SHT_RELA))
{
note_name, NT_PPC_VMX, ppc_vmx, size);
}
+char *
+elfcore_write_register_note (bfd *abfd,
+ char *buf,
+ int *bufsiz,
+ const char *section,
+ const void *data,
+ int size)
+{
+ if (strcmp (section, ".reg2") == 0)
+ return elfcore_write_prfpreg (abfd, buf, bufsiz, data, size);
+ if (strcmp (section, ".reg-xfp") == 0)
+ return elfcore_write_prxfpreg (abfd, buf, bufsiz, data, size);
+ if (strcmp (section, ".reg-ppc-vmx") == 0)
+ return elfcore_write_ppc_vmx (abfd, buf, bufsiz, data, size);
+ return NULL;
+}
+
static bfd_boolean
elf_parse_notes (bfd *abfd, char *buf, size_t size, file_ptr offset)
{
count = relplt->size / hdr->sh_entsize;
size = count * sizeof (asymbol);
p = relplt->relocation;
- for (i = 0; i < count; i++, p++)
+ for (i = 0; i < count; i++, p += bed->s->int_rels_per_ext_rel)
size += strlen ((*p->sym_ptr_ptr)->name) + sizeof ("@plt");
s = *ret = bfd_malloc (size);
names = (char *) (s + count);
p = relplt->relocation;
n = 0;
- for (i = 0; i < count; i++, p++)
+ for (i = 0; i < count; i++, p += bed->s->int_rels_per_ext_rel)
{
size_t len;
bfd_vma addr;
we are defining a symbol, ensure one of them is set. */
if ((s->flags & BSF_LOCAL) == 0)
s->flags |= BSF_GLOBAL;
+ s->flags |= BSF_SYNTHETIC;
s->section = plt;
s->value = addr - plt->vma;
s->name = names;