/* x86 specific support for ELF
- Copyright (C) 2017-2018 Free Software Foundation, Inc.
+ Copyright (C) 2017-2019 Free Software Foundation, Inc.
This file is part of BFD, the Binary File Descriptor library.
if ((s->flags & SEC_HAS_CONTENTS) == 0)
continue;
+ /* NB: Initially, the iplt section has minimal alignment to
+ avoid moving dot of the following section backwards when
+ it is empty. Update its section alignment now since it
+ is non-empty. */
+ if (s == htab->elf.iplt)
+ bfd_set_section_alignment (s->owner, s,
+ htab->plt.iplt_alignment);
+
/* Allocate memory for the section contents. We use bfd_zalloc
here in case unused entries are not reclaimed before the
section's contents are written out. This should not happen,
{
elf_property *prop;
- switch (type)
+ if (type == GNU_PROPERTY_X86_COMPAT_ISA_1_USED
+ || type == GNU_PROPERTY_X86_COMPAT_ISA_1_NEEDED
+ || (type >= GNU_PROPERTY_X86_UINT32_AND_LO
+ && type <= GNU_PROPERTY_X86_UINT32_AND_HI)
+ || (type >= GNU_PROPERTY_X86_UINT32_OR_LO
+ && type <= GNU_PROPERTY_X86_UINT32_OR_HI)
+ || (type >= GNU_PROPERTY_X86_UINT32_OR_AND_LO
+ && type <= GNU_PROPERTY_X86_UINT32_OR_AND_HI))
{
- case GNU_PROPERTY_X86_ISA_1_USED:
- case GNU_PROPERTY_X86_ISA_1_NEEDED:
- case GNU_PROPERTY_X86_FEATURE_1_AND:
if (datasz != 4)
{
_bfd_error_handler
- ((type == GNU_PROPERTY_X86_ISA_1_USED
- ? _("error: %pB: <corrupt x86 ISA used size: 0x%x>")
- : (type == GNU_PROPERTY_X86_ISA_1_NEEDED
- ? _("error: %pB: <corrupt x86 ISA needed size: 0x%x>")
- : _("error: %pB: <corrupt x86 feature size: 0x%x>"))),
- abfd, datasz);
+ (_("error: %pB: <corrupt x86 property (0x%x) size: 0x%x>"),
+ abfd, type, datasz);
return property_corrupt;
}
prop = _bfd_elf_get_property (abfd, type, datasz);
- /* Combine properties of the same type. */
prop->u.number |= bfd_h_get_32 (abfd, ptr);
prop->pr_kind = property_number;
- break;
-
- default:
- return property_ignored;
+ return property_number;
}
- return property_number;
+ return property_ignored;
}
/* Merge x86 GNU property BPROP with APROP. If APROP isn't NULL,
bfd_boolean updated = FALSE;
unsigned int pr_type = aprop != NULL ? aprop->pr_type : bprop->pr_type;
- switch (pr_type)
+ if (pr_type == GNU_PROPERTY_X86_COMPAT_ISA_1_USED
+ || (pr_type >= GNU_PROPERTY_X86_UINT32_OR_AND_LO
+ && pr_type <= GNU_PROPERTY_X86_UINT32_OR_AND_HI))
{
- case GNU_PROPERTY_X86_ISA_1_USED:
if (aprop == NULL || bprop == NULL)
{
/* Only one of APROP and BPROP can be NULL. */
aprop->pr_kind = property_remove;
updated = TRUE;
}
- break;
}
- goto or_property;
-
- case GNU_PROPERTY_X86_ISA_1_NEEDED:
+ else
+ {
+ number = aprop->u.number;
+ aprop->u.number = number | bprop->u.number;
+ updated = number != (unsigned int) aprop->u.number;
+ }
+ return updated;
+ }
+ else if (pr_type == GNU_PROPERTY_X86_COMPAT_ISA_1_NEEDED
+ || (pr_type >= GNU_PROPERTY_X86_UINT32_OR_LO
+ && pr_type <= GNU_PROPERTY_X86_UINT32_OR_HI))
+ {
if (aprop != NULL && bprop != NULL)
{
-or_property:
number = aprop->u.number;
aprop->u.number = number | bprop->u.number;
/* Remove the property if all bits are empty. */
updated = bprop->u.number != 0;
}
}
- break;
-
- case GNU_PROPERTY_X86_FEATURE_1_AND:
+ return updated;
+ }
+ else if (pr_type >= GNU_PROPERTY_X86_UINT32_AND_LO
+ && pr_type <= GNU_PROPERTY_X86_UINT32_AND_HI)
+ {
/* Only one of APROP and BPROP can be NULL:
1. APROP & BPROP when both APROP and BPROP aren't NULL.
2. If APROP is NULL, remove x86 feature.
updated = TRUE;
}
}
- break;
-
- default:
+ return updated;
+ }
+ else
+ {
/* Never should happen. */
abort ();
}
const struct elf_backend_data *bed;
unsigned int class_align = ABI_64_P (info->output_bfd) ? 3 : 2;
unsigned int got_align;
- bfd_boolean has_text = FALSE;
features = 0;
if (info->ibt)
if (bfd_get_flavour (pbfd) == bfd_target_elf_flavour
&& bfd_count_sections (pbfd) != 0)
{
- if (!has_text)
- {
- /* Check if there is no non-empty text section. */
- sec = bfd_get_section_by_name (pbfd, ".text");
- if (sec != NULL && sec->size != 0)
- has_text = TRUE;
- }
-
ebfd = pbfd;
if (elf_properties (pbfd) != NULL)
prop->u.number |= features;
prop->pr_kind = property_number;
}
- else if (has_text
- && elf_properties (ebfd) == NULL
- && elf_tdata (info->output_bfd)->o->build_id.sec == NULL
- && !htab->elf.dynamic_sections_created
- && !info->traditional_format
- && (info->output_bfd->flags & D_PAGED) != 0
- && info->separate_code)
- {
- /* If the separate code program header is needed, make sure
- that the first read-only PT_LOAD segment has no code by
- adding a GNU_PROPERTY_X86_ISA_1_NEEDED note. */
- prop = _bfd_elf_get_property (ebfd,
- GNU_PROPERTY_X86_ISA_1_NEEDED,
- 4);
- prop->u.number = GNU_PROPERTY_X86_ISA_1_486;
- prop->pr_kind = property_number;
- }
/* Create the GNU property note section if needed. */
if (prop != NULL && pbfd == NULL)
}
}
- if (normal_target)
+ /* The .iplt section is used for IFUNC symbols in static
+ executables. */
+ sec = htab->elf.iplt;
+ if (sec != NULL)
{
- /* The .iplt section is used for IFUNC symbols in static
- executables. */
- sec = htab->elf.iplt;
- if (sec != NULL
- && !bfd_set_section_alignment (sec->owner, sec,
- plt_alignment))
+ /* NB: Delay setting its alignment until we know it is non-empty.
+ Otherwise an empty iplt section may change vma and lma of the
+ following sections, which triggers moving dot of the following
+ section backwards, resulting in a warning and section lma not
+ being set properly. It later leads to a "File truncated"
+ error. */
+ if (!bfd_set_section_alignment (sec->owner, sec, 0))
goto error_alignment;
+
+ htab->plt.iplt_alignment = (normal_target
+ ? plt_alignment
+ : bed->plt_alignment);
}
return pbfd;
}
+
+/* Fix up x86 GNU properties. */
+
+void
+_bfd_x86_elf_link_fixup_gnu_properties
+ (struct bfd_link_info *info ATTRIBUTE_UNUSED,
+ elf_property_list **listp)
+{
+ elf_property_list *p;
+
+ for (p = *listp; p; p = p->next)
+ {
+ unsigned int type = p->property.pr_type;
+ if (type == GNU_PROPERTY_X86_COMPAT_ISA_1_USED
+ || type == GNU_PROPERTY_X86_COMPAT_ISA_1_NEEDED
+ || (type >= GNU_PROPERTY_X86_UINT32_AND_LO
+ && type <= GNU_PROPERTY_X86_UINT32_AND_HI)
+ || (type >= GNU_PROPERTY_X86_UINT32_OR_LO
+ && type <= GNU_PROPERTY_X86_UINT32_OR_HI)
+ || (type >= GNU_PROPERTY_X86_UINT32_OR_AND_LO
+ && type <= GNU_PROPERTY_X86_UINT32_OR_AND_HI))
+ {
+ if (p->property.u.number == 0
+ && (type == GNU_PROPERTY_X86_COMPAT_ISA_1_NEEDED
+ || (type >= GNU_PROPERTY_X86_UINT32_AND_LO
+ && type <= GNU_PROPERTY_X86_UINT32_AND_HI)
+ || (type >= GNU_PROPERTY_X86_UINT32_OR_LO
+ && type <= GNU_PROPERTY_X86_UINT32_OR_HI)))
+ {
+ /* Remove empty property. */
+ *listp = p->next;
+ continue;
+ }
+
+ listp = &p->next;
+ }
+ else if (type > GNU_PROPERTY_HIPROC)
+ {
+ /* The property list is sorted in order of type. */
+ break;
+ }
+ }
+}