aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Beulich <jbeulich@suse.com>2025-04-04 10:24:56 +0200
committerJan Beulich <jbeulich@suse.com>2025-04-04 10:24:56 +0200
commit43ea7d00a76eb3a8e30aa91657e535f86e8658c4 (patch)
treeaf1c171a556b7ca440936c2c332152f5d45bbc41
parentcc0693d394692261e03651325c9ae986ae579296 (diff)
downloadbinutils-43ea7d00a76eb3a8e30aa91657e535f86e8658c4.zip
binutils-43ea7d00a76eb3a8e30aa91657e535f86e8658c4.tar.gz
binutils-43ea7d00a76eb3a8e30aa91657e535f86e8658c4.tar.bz2
objcopy: constrain --section-alignment to PE binaries again
PR binutils/32732 The --set-section-alignment option is what ought to be used on object files; --section-alignment should be affecting PE binaries only, and only the value stored in the header. Sections don't individually have alignment recorded there; see 6f8f6017a0c4 ("PR27567, Linking PE files adds alignment section flags to executables"). Undo the core part of 121a3f4b4f4a ("Update objcopy's --section-alignment option so that it sets the alignment flag on..."), which includes removing the testcase again, while leaving all secondary changes in place. (Note that the testcase did fail anyway for i?86-interix, with objdump saying "option -P/--private not supported by this file".)
-rw-r--r--binutils/doc/binutils.texi3
-rw-r--r--binutils/objcopy.c44
-rw-r--r--binutils/testsuite/binutils-all/objcopy.exp1
-rw-r--r--binutils/testsuite/binutils-all/section-alignment.d9
4 files changed, 3 insertions, 54 deletions
diff --git a/binutils/doc/binutils.texi b/binutils/doc/binutils.texi
index 5bf5d80..b291670 100644
--- a/binutils/doc/binutils.texi
+++ b/binutils/doc/binutils.texi
@@ -2146,9 +2146,6 @@ Sets the section alignment field in the PE header - if one is present
in the binary. Sections in memory will always begin at addresses
which are a multiple of this number. Defaults to 0x1000.
-Note - this option will also set the alignment field in each section's
-flags.
-
Note - if a section's LMA or VMA addresses are no longer aligned, and
those addresses have not been set via the @option{--set-section-lma} or
@option{--set-section-vma} options, and the file has been fully
diff --git a/binutils/objcopy.c b/binutils/objcopy.c
index 5b4fa7c..5048648 100644
--- a/binutils/objcopy.c
+++ b/binutils/objcopy.c
@@ -4114,29 +4114,6 @@ power_of_two (bfd_vma val)
return result;
}
-static unsigned int
-image_scn_align (unsigned int alignment)
-{
- switch (alignment)
- {
- case 8192: return IMAGE_SCN_ALIGN_8192BYTES;
- case 4096: return IMAGE_SCN_ALIGN_4096BYTES;
- case 2048: return IMAGE_SCN_ALIGN_2048BYTES;
- case 1024: return IMAGE_SCN_ALIGN_1024BYTES;
- case 512: return IMAGE_SCN_ALIGN_512BYTES;
- case 256: return IMAGE_SCN_ALIGN_256BYTES;
- case 128: return IMAGE_SCN_ALIGN_128BYTES;
- case 64: return IMAGE_SCN_ALIGN_64BYTES;
- case 32: return IMAGE_SCN_ALIGN_32BYTES;
- case 16: return IMAGE_SCN_ALIGN_16BYTES;
- case 8: return IMAGE_SCN_ALIGN_8BYTES;
- case 4: return IMAGE_SCN_ALIGN_4BYTES;
- case 2: return IMAGE_SCN_ALIGN_2BYTES;
- case 1: return IMAGE_SCN_ALIGN_1BYTES;
- default: return 0;
- }
-}
-
/* Create a section in OBFD with the same
name and attributes as ISECTION in IBFD. */
@@ -4302,24 +4279,9 @@ setup_section (bfd *ibfd, sec_ptr isection, bfd *obfd)
if (p != NULL)
alignment = p->alignment;
else if (pe_section_alignment != (bfd_vma) -1
- && bfd_get_flavour (ibfd) == bfd_target_coff_flavour
- && bfd_get_flavour (obfd) == bfd_target_coff_flavour)
- {
- alignment = power_of_two (pe_section_alignment);
-
- if (coff_section_data (ibfd, isection))
- {
- struct pei_section_tdata * pei_data = pei_section_data (ibfd, isection);
-
- if (pei_data != NULL)
- {
- /* Set the alignment flag of the input section, which will
- be copied to the output section later on. */
- pei_data->pe_flags &= ~IMAGE_SCN_ALIGN_POWER_BIT_MASK;
- pei_data->pe_flags |= image_scn_align (pe_section_alignment);
- }
- }
- }
+ && bfd_get_flavour (obfd) == bfd_target_coff_flavour
+ && bfd_pei_p (obfd))
+ alignment = power_of_two (pe_section_alignment);
else
alignment = bfd_section_alignment (isection);
diff --git a/binutils/testsuite/binutils-all/objcopy.exp b/binutils/testsuite/binutils-all/objcopy.exp
index a706efb..ff93fea 100644
--- a/binutils/testsuite/binutils-all/objcopy.exp
+++ b/binutils/testsuite/binutils-all/objcopy.exp
@@ -1463,7 +1463,6 @@ if [is_elf_format] {
run_dump_test "pr23633"
run_dump_test "set-section-alignment"
-run_dump_test "section-alignment"
setup_xfail "hppa*-*-*"
setup_xfail "spu-*-*"
diff --git a/binutils/testsuite/binutils-all/section-alignment.d b/binutils/testsuite/binutils-all/section-alignment.d
deleted file mode 100644
index d62528c..0000000
--- a/binutils/testsuite/binutils-all/section-alignment.d
+++ /dev/null
@@ -1,9 +0,0 @@
-#source: pr23633.s
-#PROG: objcopy
-#objcopy: --section-alignment=512
-#objdump: -P sections
-#target: [is_pecoff_format]
-
-#...
-.* Align: 512.*
-#pass