diff options
author | Alan Modra <amodra@gmail.com> | 2025-02-17 09:25:30 +1030 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2025-02-18 09:16:57 +1030 |
commit | 54746376570c34d063e570161453b86b5d854380 (patch) | |
tree | cbde2a9c8f41e876444d0879d5772de71bd3cecd | |
parent | d26161914cf286171b29767916a212685f9aadf3 (diff) | |
download | binutils-54746376570c34d063e570161453b86b5d854380.zip binutils-54746376570c34d063e570161453b86b5d854380.tar.gz binutils-54746376570c34d063e570161453b86b5d854380.tar.bz2 |
bfd_set_section_alignment errors
I noticed when making the change from "einfo" to "fatal" that the
alignment error in _bfd_elf_link_create_gnu_property_sec lacked a %P,
and then decided that a bfd_set_section_alignment that can't happen
does not merit a separate error message. elfxx-x86.c had copied the
same code, so fix that too. In fact, every bfd_set_section_alignment
call in elfxx-x86.c will always return true absent some future
programming error. This patch makes those that accompany making a
section lose their "failed to align " error and share the "failed to
create" error. Those that are changing alignment of a section created
elsewhere now abort on bfd_set_section_alignment returning false.
-rw-r--r-- | bfd/elf-properties.c | 11 | ||||
-rw-r--r-- | bfd/elfxx-x86.c | 56 |
2 files changed, 25 insertions, 42 deletions
diff --git a/bfd/elf-properties.c b/bfd/elf-properties.c index 39e0d4e..5c2dd01 100644 --- a/bfd/elf-properties.c +++ b/bfd/elf-properties.c @@ -636,13 +636,10 @@ _bfd_elf_link_create_gnu_property_sec (struct bfd_link_info *info, bfd *elf_bfd, | SEC_READONLY | SEC_HAS_CONTENTS | SEC_DATA)); - if (sec == NULL) - info->callbacks->fatal (_("%P: failed to create GNU property section\n")); - - if (!bfd_set_section_alignment (sec, - elfclass == ELFCLASS64 ? 3 : 2)) - info->callbacks->fatal (_("%pA: failed to align section\n"), - sec); + if (sec == NULL + || !bfd_set_section_alignment (sec, elfclass == ELFCLASS64 ? 3 : 2)) + info->callbacks->fatal (_("%P: failed to create %s\n"), + NOTE_GNU_PROPERTY_SECTION_NAME); elf_section_type (sec) = SHT_NOTE; return sec; diff --git a/bfd/elfxx-x86.c b/bfd/elfxx-x86.c index 5651400..3b25f83 100644 --- a/bfd/elfxx-x86.c +++ b/bfd/elfxx-x86.c @@ -2665,8 +2665,9 @@ _bfd_x86_elf_late_size_sections (bfd *output_bfd, 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, htab->plt.iplt_alignment); + if (s == htab->elf.iplt + && !bfd_set_section_alignment (s, htab->plt.iplt_alignment)) + abort (); /* Allocate memory for the section contents. We use bfd_zalloc here in case unused entries are not reclaimed before the @@ -4346,15 +4347,10 @@ _bfd_x86_elf_link_setup_gnu_properties | SEC_READONLY | SEC_HAS_CONTENTS | SEC_DATA)); - if (sec == NULL) - info->callbacks->fatal (_("%P: failed to create GNU property section\n")); - - if (!bfd_set_section_alignment (sec, class_align)) - { - error_alignment: - info->callbacks->fatal (_("%pA: failed to align section\n"), - sec); - } + if (sec == NULL + || !bfd_set_section_alignment (sec, class_align)) + info->callbacks->fatal (_("%P: failed to create %sn"), + NOTE_GNU_PROPERTY_SECTION_NAME); elf_section_type (sec) = SHT_NOTE; } @@ -4684,11 +4680,11 @@ _bfd_x86_elf_link_setup_gnu_properties properly aligned even if create_dynamic_sections isn't called. */ sec = htab->elf.sgot; if (!bfd_set_section_alignment (sec, got_align)) - goto error_alignment; + abort (); sec = htab->elf.sgotplt; if (!bfd_set_section_alignment (sec, got_align)) - goto error_alignment; + abort (); /* Create the ifunc sections here so that check_relocs can be simplified. */ @@ -4724,18 +4720,16 @@ _bfd_x86_elf_link_setup_gnu_properties sec = pltsec; if (!bfd_set_section_alignment (sec, plt_alignment)) - goto error_alignment; + abort (); /* Create the GOT procedure linkage table. */ sec = bfd_make_section_anyway_with_flags (dynobj, ".plt.got", pltflags); - if (sec == NULL) + if (sec == NULL + || !bfd_set_section_alignment (sec, non_lazy_plt_alignment)) info->callbacks->fatal (_("%P: failed to create GOT PLT section\n")); - if (!bfd_set_section_alignment (sec, non_lazy_plt_alignment)) - goto error_alignment; - htab->plt_got = sec; if (lazy_plt) @@ -4749,11 +4743,9 @@ _bfd_x86_elf_link_setup_gnu_properties sec = bfd_make_section_anyway_with_flags (dynobj, ".plt.sec", pltflags); - if (sec == NULL) + if (sec == NULL + || !bfd_set_section_alignment (sec, plt_alignment)) info->callbacks->fatal (_("%P: failed to create IBT-enabled PLT section\n")); - - if (!bfd_set_section_alignment (sec, plt_alignment)) - goto error_alignment; } htab->plt_second = sec; @@ -4769,12 +4761,10 @@ _bfd_x86_elf_link_setup_gnu_properties sec = bfd_make_section_anyway_with_flags (dynobj, ".eh_frame", flags); - if (sec == NULL) + if (sec == NULL + || !bfd_set_section_alignment (sec, class_align)) info->callbacks->fatal (_("%P: failed to create PLT .eh_frame section\n")); - if (!bfd_set_section_alignment (sec, class_align)) - goto error_alignment; - htab->plt_eh_frame = sec; if (htab->plt_got != NULL) @@ -4782,12 +4772,10 @@ _bfd_x86_elf_link_setup_gnu_properties sec = bfd_make_section_anyway_with_flags (dynobj, ".eh_frame", flags); - if (sec == NULL) + if (sec == NULL + || !bfd_set_section_alignment (sec, class_align)) info->callbacks->fatal (_("%P: failed to create GOT PLT .eh_frame section\n")); - if (!bfd_set_section_alignment (sec, class_align)) - goto error_alignment; - htab->plt_got_eh_frame = sec; } @@ -4796,12 +4784,10 @@ _bfd_x86_elf_link_setup_gnu_properties sec = bfd_make_section_anyway_with_flags (dynobj, ".eh_frame", flags); - if (sec == NULL) + if (sec == NULL + || !bfd_set_section_alignment (sec, class_align)) info->callbacks->fatal (_("%P: failed to create the second PLT .eh_frame section\n")); - if (!bfd_set_section_alignment (sec, class_align)) - goto error_alignment; - htab->plt_second_eh_frame = sec; } } @@ -4863,7 +4849,7 @@ _bfd_x86_elf_link_setup_gnu_properties being set properly. It later leads to a "File truncated" error. */ if (!bfd_set_section_alignment (sec, 0)) - goto error_alignment; + abort (); htab->plt.iplt_alignment = (normal_target ? plt_alignment |