return elf_tdata (abfd)->core != NULL;
}
-static char *
+char *
bfd_elf_get_str_section (bfd *abfd, unsigned int shindex)
{
Elf_Internal_Shdr **i_shdrp;
if (name == NULL)
name = "(null)";
else if (sym_sec && *name == '\0')
- name = bfd_section_name (abfd, sym_sec);
+ name = bfd_section_name (sym_sec);
return name;
}
return elf_next_in_group (sec) != NULL;
}
+const char *
+bfd_elf_group_name (bfd *abfd ATTRIBUTE_UNUSED, const asection *sec)
+{
+ if (elf_sec_group (sec) != NULL)
+ return elf_group_name (sec);
+ return NULL;
+}
+
static char *
convert_debug_to_zdebug (bfd *abfd, const char *name)
{
return new_name;
}
+/* This a copy of lto_section defined in GCC (lto-streamer.h). */
+
+struct lto_section
+{
+ int16_t major_version;
+ int16_t minor_version;
+ unsigned char slim_object;
+
+ /* Flags is a private field that is not defined publicly. */
+ uint16_t flags;
+};
+
/* Make a BFD section from an ELF section. We store a pointer to the
BFD section in the bfd_section field of the header. */
newsect->filepos = hdr->sh_offset;
- 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 (hdr->sh_addralign)))
+ if (!bfd_set_section_vma (newsect, hdr->sh_addr)
+ || !bfd_set_section_size (newsect, hdr->sh_size)
+ || !bfd_set_section_alignment (newsect, bfd_log2 (hdr->sh_addralign)))
return FALSE;
flags = SEC_NO_FLAGS;
if ((hdr->sh_flags & SHF_EXCLUDE) != 0)
flags |= SEC_EXCLUDE;
+ switch (elf_elfheader (abfd)->e_ident[EI_OSABI])
+ {
+ /* FIXME: We should not recognize SHF_GNU_MBIND for ELFOSABI_NONE,
+ but binutils as of 2019-07-23 did not set the EI_OSABI header
+ byte. */
+ case ELFOSABI_NONE:
+ case ELFOSABI_GNU:
+ case ELFOSABI_FREEBSD:
+ if ((hdr->sh_flags & SHF_GNU_MBIND) != 0)
+ elf_tdata (abfd)->has_gnu_osabi |= elf_gnu_osabi_mbind;
+ break;
+ }
+
if ((flags & SEC_ALLOC) == 0)
{
/* The debugging sections appear to be recognized only by name,
if (! bed->elf_backend_section_flags (&flags, hdr))
return FALSE;
- if (! bfd_set_section_flags (abfd, newsect, flags))
+ if (!bfd_set_section_flags (newsect, flags))
return FALSE;
/* We do not parse the PT_NOTE segments as we are interested even in the
char *new_name = convert_zdebug_to_debug (abfd, name);
if (new_name == NULL)
return FALSE;
- bfd_rename_section (abfd, newsect, new_name);
+ bfd_rename_section (newsect, new_name);
}
}
else
newsect->flags |= SEC_ELF_RENAME;
}
+ /* GCC uses .gnu.lto_.lto.<some_hash> as a LTO bytecode information
+ section. */
+ const char *lto_section_name = ".gnu.lto_.lto.";
+ if (strncmp (name, lto_section_name, strlen (lto_section_name)) == 0)
+ {
+ struct lto_section lsection;
+ if (bfd_get_section_contents (abfd, newsect, &lsection, 0,
+ sizeof (struct lto_section)))
+ abfd->lto_slim_object = lsection.slim_object;
+ }
+
return TRUE;
}
else
p_hdr = &esdt->rel.hdr;
- /* PR 17512: file: 0b4f81b7. */
+ /* PR 17512: file: 0b4f81b7.
+ Also see PR 24456, for a file which deliberately has two reloc
+ sections. */
if (*p_hdr != NULL)
- goto fail;
+ {
+ _bfd_error_handler
+ /* xgettext:c-format */
+ (_("%pB: warning: multiple relocation sections for section %pA \
+found - ignoring all but the first"),
+ abfd, target_sect);
+ goto success;
+ }
hdr2 = (Elf_Internal_Shdr *) bfd_alloc (abfd, sizeof (*hdr2));
if (hdr2 == NULL)
goto fail;
static const struct bfd_elf_special_section special_sections_c[] =
{
{ STRING_COMMA_LEN (".comment"), 0, SHT_PROGBITS, 0 },
+ { STRING_COMMA_LEN (".ctf"), 0, SHT_PROGBITS, 0 },
{ NULL, 0, 0, 0, 0 }
};
return (*bed->elf_backend_sym_is_global) (abfd, sym);
return ((sym->flags & (BSF_GLOBAL | BSF_WEAK | BSF_GNU_UNIQUE)) != 0
- || bfd_is_und_section (bfd_get_section (sym))
- || bfd_is_com_section (bfd_get_section (sym)));
+ || bfd_is_und_section (bfd_asymbol_section (sym))
+ || bfd_is_com_section (bfd_asymbol_section (sym)));
}
/* Filter global symbols of ABFD to include in the import library. All
bed = get_elf_backend_data (abfd);
- if ((abfd->flags & D_PAGED) != 0)
- {
- /* Add a PT_GNU_MBIND segment for each mbind section. */
- unsigned int page_align_power = bfd_log2 (bed->commonpagesize);
- for (s = abfd->sections; s != NULL; s = s->next)
- if (elf_section_flags (s) & SHF_GNU_MBIND)
- {
- if (elf_section_data (s)->this_hdr.sh_info
- > PT_GNU_MBIND_NUM)
- {
- _bfd_error_handler
- /* xgettext:c-format */
- (_("%pB: GNU_MBIN section `%pA' has invalid sh_info field: %d"),
- abfd, s, elf_section_data (s)->this_hdr.sh_info);
- continue;
- }
- /* Align mbind section to page size. */
- if (s->alignment_power < page_align_power)
- s->alignment_power = page_align_power;
- segs ++;
- }
- }
-
- /* Let the backend count up any program headers it might need. */
- if (bed->elf_backend_additional_program_headers)
+ if ((abfd->flags & D_PAGED) != 0
+ && (elf_tdata (abfd)->has_gnu_osabi & elf_gnu_osabi_mbind) != 0)
+ {
+ /* Add a PT_GNU_MBIND segment for each mbind section. */
+ unsigned int page_align_power = bfd_log2 (bed->commonpagesize);
+ for (s = abfd->sections; s != NULL; s = s->next)
+ if (elf_section_flags (s) & SHF_GNU_MBIND)
+ {
+ if (elf_section_data (s)->this_hdr.sh_info > PT_GNU_MBIND_NUM)
+ {
+ _bfd_error_handler
+ /* xgettext:c-format */
+ (_("%pB: GNU_MBIND section `%pA' has invalid "
+ "sh_info field: %d"),
+ abfd, s, elf_section_data (s)->this_hdr.sh_info);
+ continue;
+ }
+ /* Align mbind section to page size. */
+ if (s->alignment_power < page_align_power)
+ s->alignment_power = page_align_power;
+ segs ++;
+ }
+ }
+
+ /* Let the backend count up any program headers it might need. */
+ if (bed->elf_backend_additional_program_headers)
{
int a;
pm = &m->next;
}
- if (first_mbind && (abfd->flags & D_PAGED) != 0)
+ if (first_mbind
+ && (abfd->flags & D_PAGED) != 0
+ && (elf_tdata (abfd)->has_gnu_osabi & elf_gnu_osabi_mbind) != 0)
for (s = first_mbind; s != NULL; s = s->next)
if ((elf_section_flags (s) & SHF_GNU_MBIND) != 0
- && (elf_section_data (s)->this_hdr.sh_info
- <= PT_GNU_MBIND_NUM))
+ && elf_section_data (s)->this_hdr.sh_info <= PT_GNU_MBIND_NUM)
{
/* Mandated PF_R. */
unsigned long p_flags = PF_R;
{
unsigned int secalign;
- secalign = bfd_get_section_alignment (abfd, *secpp);
+ secalign = bfd_section_alignment (*secpp);
if (secalign > align_power)
align_power = secalign;
}
sec = *secpp;
this_hdr = &elf_section_data (sec)->this_hdr;
- align = (bfd_size_type) 1 << bfd_get_section_alignment (abfd, sec);
+ align = (bfd_size_type) 1 << bfd_section_alignment (sec);
if ((p->p_type == PT_LOAD
|| p->p_type == PT_TLS)
return TRUE;
}
-/* Assign file positions for the other sections. */
+/* Determine if a bfd is a debuginfo file. Unfortunately there
+ is no defined method for detecting such files, so we have to
+ use heuristics instead. */
+
+bfd_boolean
+is_debuginfo_file (bfd *abfd)
+{
+ if (abfd == NULL || bfd_get_flavour (abfd) != bfd_target_elf_flavour)
+ return FALSE;
+
+ Elf_Internal_Shdr **start_headers = elf_elfsections (abfd);
+ Elf_Internal_Shdr **end_headers = start_headers + elf_numsections (abfd);
+ Elf_Internal_Shdr **headerp;
+
+ for (headerp = start_headers; headerp < end_headers; headerp ++)
+ {
+ Elf_Internal_Shdr *header = * headerp;
+
+ /* Debuginfo files do not have any allocated SHT_PROGBITS sections.
+ The only allocated sections are SHT_NOBITS or SHT_NOTES. */
+ if ((header->sh_flags & SHF_ALLOC) == SHF_ALLOC
+ && header->sh_type != SHT_NOBITS
+ && header->sh_type != SHT_NOTE)
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+/* Assign file positions for the other sections, except for compressed debugging
+ and other sections assigned in _bfd_elf_assign_file_positions_for_non_load(). */
static bfd_boolean
assign_file_positions_for_non_load_sections (bfd *abfd,
BFD_ASSERT (hdr->sh_offset == hdr->bfd_section->filepos);
else if ((hdr->sh_flags & SHF_ALLOC) != 0)
{
- if (hdr->sh_size != 0)
+ if (hdr->sh_size != 0
+ /* PR 24717 - debuginfo files are known to be not strictly
+ compliant with the ELF standard. In particular they often
+ have .note.gnu.property sections that are outside of any
+ loadable segment. This is not a problem for such files,
+ so do not warn about them. */
+ && ! is_debuginfo_file (abfd))
_bfd_error_handler
/* xgettext:c-format */
(_("%pB: warning: allocated section `%s' not in segment"),
}
else if (((hdr->sh_type == SHT_REL || hdr->sh_type == SHT_RELA)
&& hdr->bfd_section == NULL)
+ /* We don't know the offset of these sections yet: their size has
+ not been decided. */
|| (hdr->bfd_section != NULL
- && (hdr->bfd_section->flags & SEC_ELF_COMPRESS))
- /* Compress DWARF debug sections. */
+ && (hdr->bfd_section->flags & SEC_ELF_COMPRESS
+ || (bfd_section_is_ctf (hdr->bfd_section)
+ && abfd->is_linker_output)))
|| hdr == i_shdrpp[elf_onesymtab (abfd)]
|| (elf_symtab_shndx_list (abfd) != NULL
&& hdr == i_shdrpp[elf_symtab_shndx_list (abfd)->ndx])
VMAs must be known before this is called.
Reloc sections come in two flavours: Those processed specially as
- "side-channel" data attached to a section to which they apply, and
- those that bfd doesn't process as relocations. The latter sort are
- stored in a normal bfd section by bfd_section_from_shdr. We don't
- consider the former sort here, unless they form part of the loadable
- image. Reloc sections not assigned here will be handled later by
+ "side-channel" data attached to a section to which they apply, and those that
+ bfd doesn't process as relocations. The latter sort are stored in a normal
+ bfd section by bfd_section_from_shdr. We don't consider the former sort
+ here, unless they form part of the loadable image. Reloc sections not
+ assigned here (and compressed debugging sections and CTF sections which
+ nothing else in the file can rely upon) will be handled later by
assign_file_positions_for_relocs.
We also don't set the positions of the .symtab and .strtab here. */
hdr = *hdrpp;
if (((hdr->sh_type == SHT_REL || hdr->sh_type == SHT_RELA)
&& hdr->bfd_section == NULL)
+ /* Do not assign offsets for these sections yet: we don't know
+ their sizes. */
|| (hdr->bfd_section != NULL
- && (hdr->bfd_section->flags & SEC_ELF_COMPRESS))
- /* Compress DWARF debug sections. */
+ && (hdr->bfd_section->flags & SEC_ELF_COMPRESS
+ || (bfd_section_is_ctf (hdr->bfd_section)
+ && abfd->is_linker_output)))
|| i == elf_onesymtab (abfd)
|| (elf_symtab_shndx_list (abfd) != NULL
&& hdr == i_shdrpp[elf_symtab_shndx_list (abfd)->ndx])
asection *sec = shdrp->bfd_section;
bfd_boolean is_rel = (shdrp->sh_type == SHT_REL
|| shdrp->sh_type == SHT_RELA);
+ bfd_boolean is_ctf = sec && bfd_section_is_ctf (sec);
if (is_rel
+ || is_ctf
|| (sec != NULL && (sec->flags & SEC_ELF_COMPRESS)))
{
- if (!is_rel)
+ if (!is_rel && !is_ctf)
{
const char *name = sec->name;
struct bfd_elf_section_data *d;
shdrp->contents = sec->contents;
shdrp->bfd_section->contents = NULL;
}
+ else if (is_ctf)
+ {
+ /* Update section size and contents. */
+ shdrp->sh_size = sec->size;
+ shdrp->contents = sec->contents;
+ }
+
off = _bfd_elf_assign_file_position_for_section (shdrp,
off,
TRUE);
|| !_bfd_elf_strtab_emit (abfd, elf_shstrtab (abfd))))
return FALSE;
- if (bed->elf_backend_final_write_processing)
- (*bed->elf_backend_final_write_processing) (abfd, elf_linker (abfd));
+ if (!(*bed->elf_backend_final_write_processing) (abfd))
+ return FALSE;
if (!bed->s->write_shdrs_and_ehdr (abfd))
return FALSE;
|| (segment->p_paddr \
? segment->p_paddr != section->lma \
: segment->p_vaddr != section->vma) \
- || (strcmp (bfd_get_section_name (ibfd, section), ".dynamic") \
- == 0)) \
+ || (strcmp (bfd_section_name (section), ".dynamic") == 0)) \
&& (segment->p_type != PT_LOAD || !section->segment_mark))
/* If the output section of a section in the input segment is NULL,
& (SHF_MASKOS | SHF_MASKPROC));
/* Copy sh_info from input for mbind section. */
- if (elf_section_flags (isec) & SHF_GNU_MBIND)
+ if ((elf_tdata (ibfd)->has_gnu_osabi & elf_gnu_osabi_mbind) != 0
+ && elf_section_flags (isec) & SHF_GNU_MBIND)
elf_section_data (osec)->this_hdr.sh_info
= elf_section_data (isec)->this_hdr.sh_info;
long symcount = bed->s->slurp_symbol_table (abfd, allocation, FALSE);
if (symcount >= 0)
- bfd_get_symcount (abfd) = symcount;
+ abfd->symcount = symcount;
return symcount;
}
long symcount = bed->s->slurp_symbol_table (abfd, allocation, TRUE);
if (symcount >= 0)
- bfd_get_dynamic_symcount (abfd) = symcount;
+ abfd->dynsymcount = symcount;
return symcount;
}
if (_bfd_dwarf2_find_nearest_line (abfd, symbols, NULL, section, offset,
filename_ptr, functionname_ptr,
line_ptr, discriminator_ptr,
- dwarf_debug_sections, 0,
+ dwarf_debug_sections,
&elf_tdata (abfd)->dwarf2_find_line_info)
|| _bfd_dwarf1_find_nearest_line (abfd, symbols, section, offset,
filename_ptr, functionname_ptr,
{
return _bfd_dwarf2_find_nearest_line (abfd, symbols, symbol, NULL, 0,
filename_ptr, NULL, line_ptr, NULL,
- dwarf_debug_sections, 0,
+ dwarf_debug_sections,
&elf_tdata (abfd)->dwarf2_find_line_info);
}
hdr = &elf_section_data (section)->this_hdr;
if (hdr->sh_offset == (file_ptr) -1)
{
+ if (bfd_section_is_ctf (section))
+ /* Nothing to do with this section: the contents are generated
+ later. */
+ return TRUE;
+
/* We must compress this section. Write output to the buffer. */
unsigned char *contents = hdr->contents;
if ((offset + count) > hdr->sh_size
"LARGE_COMMON", 0, SEC_IS_COMMON);
void
-_bfd_elf_post_process_headers (bfd * abfd,
- struct bfd_link_info * link_info ATTRIBUTE_UNUSED)
+_bfd_elf_post_process_headers (bfd *abfd ATTRIBUTE_UNUSED,
+ struct bfd_link_info *info ATTRIBUTE_UNUSED)
{
- Elf_Internal_Ehdr * i_ehdrp; /* ELF file header, internal form. */
+}
- i_ehdrp = elf_elfheader (abfd);
+bfd_boolean
+_bfd_elf_final_write_processing (bfd *abfd)
+{
+ Elf_Internal_Ehdr *i_ehdrp; /* ELF file header, internal form. */
- i_ehdrp->e_ident[EI_OSABI] = get_elf_backend_data (abfd)->elf_osabi;
+ i_ehdrp = elf_elfheader (abfd);
- /* To make things simpler for the loader on Linux systems we set the
- osabi field to ELFOSABI_GNU if the binary contains symbols of
- the STT_GNU_IFUNC type or STB_GNU_UNIQUE binding. */
- if (i_ehdrp->e_ident[EI_OSABI] == ELFOSABI_NONE
- && elf_tdata (abfd)->has_gnu_symbols)
- i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_GNU;
+ if (i_ehdrp->e_ident[EI_OSABI] == ELFOSABI_NONE)
+ i_ehdrp->e_ident[EI_OSABI] = get_elf_backend_data (abfd)->elf_osabi;
+
+ /* Set the osabi field to ELFOSABI_GNU if the binary contains
+ SHF_GNU_MBIND sections or symbols of STT_GNU_IFUNC type or
+ STB_GNU_UNIQUE binding. */
+ if (elf_tdata (abfd)->has_gnu_osabi != 0)
+ {
+ if (i_ehdrp->e_ident[EI_OSABI] == ELFOSABI_NONE)
+ i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_GNU;
+ else if (i_ehdrp->e_ident[EI_OSABI] != ELFOSABI_GNU
+ && i_ehdrp->e_ident[EI_OSABI] != ELFOSABI_FREEBSD)
+ {
+ if (elf_tdata (abfd)->has_gnu_osabi & elf_gnu_osabi_mbind)
+ _bfd_error_handler (_("GNU_MBIND section is unsupported"));
+ if (elf_tdata (abfd)->has_gnu_osabi & elf_gnu_osabi_ifunc)
+ _bfd_error_handler (_("symbol type STT_GNU_IFUNC is unsupported"));
+ if (elf_tdata (abfd)->has_gnu_osabi & elf_gnu_osabi_unique)
+ _bfd_error_handler (_("symbol binding STB_GNU_UNIQUE is unsupported"));
+ bfd_set_error (bfd_error_bad_value);
+ return FALSE;
+ }
+ }
+ return TRUE;
}