aboutsummaryrefslogtreecommitdiff
path: root/bfd/elf.c
diff options
context:
space:
mode:
Diffstat (limited to 'bfd/elf.c')
-rw-r--r--bfd/elf.c80
1 files changed, 48 insertions, 32 deletions
diff --git a/bfd/elf.c b/bfd/elf.c
index 55bb091..1c77a79 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -1067,6 +1067,19 @@ _bfd_elf_make_section_from_shdr (bfd *abfd,
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,
@@ -4425,31 +4438,32 @@ get_program_header_size (bfd *abfd, struct bfd_link_info *info)
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;
@@ -5045,11 +5059,12 @@ _bfd_elf_map_sections_to_segments (bfd *abfd, struct bfd_link_info *info)
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;
@@ -7665,7 +7680,8 @@ _bfd_elf_init_private_section_data (bfd *ibfd,
& (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;
@@ -12118,9 +12134,9 @@ _bfd_elf_final_write_processing (bfd *abfd,
if (i_ehdrp->e_ident[EI_OSABI] == ELFOSABI_NONE)
i_ehdrp->e_ident[EI_OSABI] = get_elf_backend_data (abfd)->elf_osabi;
- /* 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. */
+ /* 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 (i_ehdrp->e_ident[EI_OSABI] == ELFOSABI_NONE
&& elf_tdata (abfd)->has_gnu_osabi)
i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_GNU;