]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
bfd_set_section_alignment errors
authorAlan Modra <amodra@gmail.com>
Sun, 16 Feb 2025 22:55:30 +0000 (09:25 +1030)
committerAlan Modra <amodra@gmail.com>
Mon, 17 Feb 2025 22:46:57 +0000 (09:16 +1030)
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.

bfd/elf-properties.c
bfd/elfxx-x86.c

index 39e0d4ec456662b307e194c9a8f424708130457d..5c2dd018cc9f220eee4a2fe7b82fbbade856ec0c 100644 (file)
@@ -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;
index 56514000dc4de7b7ef2f8ecb8b1b57e6df3c58ca..3b25f832a9da2c89a565dc8df28cabcf4474be37 100644 (file)
@@ -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