]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
strip: don't corrupt PE binary's section/file alignment
authorJan Beulich <jbeulich@suse.com>
Fri, 21 Mar 2025 07:33:58 +0000 (08:33 +0100)
committerJan Beulich <jbeulich@suse.com>
Fri, 21 Mar 2025 07:33:58 +0000 (08:33 +0100)
Section and file alignment are supposed to remain unaltered when PE
binaries are stripped. While this is the case when they're strip-ed
individually, passing multiple such files to strip would reset the
two values to their defaults in all but the first of those binaries.

binutils/objcopy.c

index e2e6bd7ee832ad9d412b205eb28decde594730bb..572f22c9d365260a0d7c7b505b552e258ff05ad6 100644 (file)
@@ -2832,7 +2832,7 @@ copy_object (bfd *ibfd, bfd *obfd, const bfd_arch_info_type *input_arch)
 
       if (pe_file_alignment != (bfd_vma) -1)
        pe->pe_opthdr.FileAlignment = pe_file_alignment;
-      else
+      else if (!is_strip)
        pe_file_alignment = PE_DEF_FILE_ALIGNMENT;
 
       if (pe_heap_commit != (bfd_vma) -1)
@@ -2846,7 +2846,7 @@ copy_object (bfd *ibfd, bfd *obfd, const bfd_arch_info_type *input_arch)
 
       if (pe_section_alignment != (bfd_vma) -1)
        pe->pe_opthdr.SectionAlignment = pe_section_alignment;
-      else
+      else if (!is_strip)
        pe_section_alignment = PE_DEF_SECTION_ALIGNMENT;
 
       if (pe_stack_commit != (bfd_vma) -1)