diff --git a/backport-AArch64-Add-support-for-AArch64-EFI-efi-aarch64.patch b/backport-AArch64-Add-support-for-AArch64-EFI-efi-aarch64.patch new file mode 100644 index 0000000000000000000000000000000000000000..2cbd10da4acc8e31adcc2ea8d39981b93c3575f9 --- /dev/null +++ b/backport-AArch64-Add-support-for-AArch64-EFI-efi-aarch64.patch @@ -0,0 +1,179 @@ +From 4b6391170a7c3a70946501fb51606c95827ed9cb Mon Sep 17 00:00:00 2001 +From: Alan Modra +Date: Thu, 25 Nov 2021 14:26:51 +1030 +Subject: [PATCH 1/3] AArch64: Add support for AArch64 EFI (efi-*-aarch64) + +Commit b69c9d41e8 edited bfd/Makefile.in rather than using automake, +which meant a typo in Makefile.am was not discovered and other +differences in Makefile.in are seen with a proper regeneration. One +difference was lack of an empty line between the pe-aarch64igen.c rule +and the following $(BFD32_LIBS) etc. dependency rule, in the +regenerated file. Not that it matters for proper "make" behaviour, +but it's nicer with a line between those rules. Moving the rule +earlier seems to cure the missing empty line. + + * Makefile.am (BFD64_BACKENDS): Correct typo. + (BFD_H_DEPS, LOCAL_H_DEPS): Move earlier. Move rule using these + deps earlier too. + * Makefile.in: Regenerate. + * po/BLD-POTFILES.in: Regenerate. + * po/SRC-POTFILES.in: Regenerate. + +References: bsn#351 +Signed-off-by: Chenxi Mao +--- + bfd/Makefile.am | 20 ++++++++++---------- + bfd/Makefile.in | 21 ++++++++++----------- + bfd/po/BLD-POTFILES.in | 1 + + bfd/po/SRC-POTFILES.in | 1 + + 4 files changed, 22 insertions(+), 21 deletions(-) + +diff --git a/bfd/Makefile.am b/bfd/Makefile.am +index a4e84a1d..7c859428 100644 +--- a/bfd/Makefile.am ++++ b/bfd/Makefile.am +@@ -569,7 +569,7 @@ BFD64_BACKENDS = \ + mmo.lo \ + pe-aarch64igen.lo \ + pe-x86_64.lo \ +- pei-aarch64lo \ ++ pei-aarch64.lo \ + pei-ia64.lo \ + pei-x86_64.lo \ + pepigen.lo \ +@@ -710,6 +710,15 @@ BUILT_SOURCES = $(BUILD_HFILES) + + HFILES = $(SOURCE_HFILES) $(BUILD_HFILES) + ++BFD_H_DEPS = $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h $(INCDIR)/diagnostics.h ++LOCAL_H_DEPS = libbfd.h sysdep.h config.h ++$(BFD32_LIBS) \ ++ $(BFD64_LIBS) \ ++ $(ALL_MACHINES) \ ++ $(BFD32_BACKENDS) \ ++ $(BFD64_BACKENDS) \ ++ $(OPTIONAL_BACKENDS): $(BFD_H) $(BFD_H_DEPS) $(LOCAL_H_DEPS) ++ + SRC_POTFILES = $(SOURCE_CFILES) $(SOURCE_HFILES) + BLD_POTFILES = $(BUILD_CFILES) $(BUILD_HFILES) + +@@ -869,15 +878,6 @@ pe-aarch64igen.c: peXXigen.c + echo "#line 1 \"peXXigen.c\"" > $@ + $(SED) -e s/XX/peAArch64/g < $< >> $@ + +-BFD_H_DEPS= $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h $(INCDIR)/diagnostics.h +-LOCAL_H_DEPS= libbfd.h sysdep.h config.h +-$(BFD32_LIBS) \ +- $(BFD64_LIBS) \ +- $(ALL_MACHINES) \ +- $(BFD32_BACKENDS) \ +- $(BFD64_BACKENDS) \ +- $(OPTIONAL_BACKENDS): $(BFD_H) $(BFD_H_DEPS) $(LOCAL_H_DEPS) +- + host-aout.lo: Makefile + + # The following program can be used to generate a simple config file +diff --git a/bfd/Makefile.in b/bfd/Makefile.in +index dd029f68..66fa92c1 100644 +--- a/bfd/Makefile.in ++++ b/bfd/Makefile.in +@@ -1131,6 +1131,8 @@ BUILD_HFILES = \ + # Ensure they are built early: + BUILT_SOURCES = $(BUILD_HFILES) + HFILES = $(SOURCE_HFILES) $(BUILD_HFILES) ++BFD_H_DEPS = $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h $(INCDIR)/diagnostics.h ++LOCAL_H_DEPS = libbfd.h sysdep.h config.h + SRC_POTFILES = $(SOURCE_CFILES) $(SOURCE_HFILES) + BLD_POTFILES = $(BUILD_CFILES) $(BUILD_HFILES) + +@@ -1156,8 +1158,6 @@ libbfd_la_LIBADD = `cat ofiles` @SHARED_LIBADD@ $(LIBDL) $(ZLIB) + # everything else starts using libtool. FIXME. + noinst_LIBRARIES = libbfd.a + libbfd_a_SOURCES = +-BFD_H_DEPS = $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h $(INCDIR)/diagnostics.h +-LOCAL_H_DEPS = libbfd.h sysdep.h config.h + BFD_H_FILES = bfd-in.h init.c opncls.c libbfd.c \ + bfdio.c bfdwin.c section.c archures.c reloc.c \ + syms.c bfd.c archive.c corefile.c targets.c format.c \ +@@ -1540,6 +1540,7 @@ distclean-compile: + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/osf-core.Plo@am__quote@ + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pc532-mach.Plo@am__quote@ + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pdp11.Plo@am__quote@ ++@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pe-aarch64igen.Plo@am__quote@ + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pe-arm-wince.Plo@am__quote@ + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pe-arm.Plo@am__quote@ + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pe-i386.Plo@am__quote@ +@@ -1547,6 +1548,7 @@ distclean-compile: + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pe-sh.Plo@am__quote@ + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pe-x86_64.Plo@am__quote@ + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pef.Plo@am__quote@ ++@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pei-aarch64.Plo@am__quote@ + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pei-arm-wince.Plo@am__quote@ + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pei-arm.Plo@am__quote@ + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pei-i386.Plo@am__quote@ +@@ -1554,11 +1556,9 @@ distclean-compile: + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pei-mcore.Plo@am__quote@ + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pei-sh.Plo@am__quote@ + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pei-x86_64.Plo@am__quote@ +-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pei-aarch64.Plo@am__quote@ + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/peigen.Plo@am__quote@ + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pepigen.Plo@am__quote@ + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pex64igen.Plo@am__quote@ +-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pe-aarch64igen.Plo@am__quote@ + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/plugin.Plo@am__quote@ + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ppcboot.Plo@am__quote@ + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/reloc.Plo@am__quote@ +@@ -1884,6 +1884,12 @@ uninstall-am: uninstall-bfdincludeHEADERS uninstall-bfdlibLTLIBRARIES + + .PRECIOUS: Makefile + ++$(BFD32_LIBS) \ ++ $(BFD64_LIBS) \ ++ $(ALL_MACHINES) \ ++ $(BFD32_BACKENDS) \ ++ $(BFD64_BACKENDS) \ ++ $(OPTIONAL_BACKENDS): $(BFD_H) $(BFD_H_DEPS) $(LOCAL_H_DEPS) + + po/SRC-POTFILES.in: @MAINT@ Makefile $(SRC_POTFILES) + for file in $(SRC_POTFILES); do echo $$file; done \ +@@ -2001,13 +2007,6 @@ pe-aarch64igen.c: peXXigen.c + echo "#line 1 \"peXXigen.c\"" > $@ + $(SED) -e s/XX/peAArch64/g < $< >> $@ + +-$(BFD32_LIBS) \ +- $(BFD64_LIBS) \ +- $(ALL_MACHINES) \ +- $(BFD32_BACKENDS) \ +- $(BFD64_BACKENDS) \ +- $(OPTIONAL_BACKENDS): $(BFD_H) $(BFD_H_DEPS) $(LOCAL_H_DEPS) +- + host-aout.lo: Makefile + + # The following program can be used to generate a simple config file +diff --git a/bfd/po/BLD-POTFILES.in b/bfd/po/BLD-POTFILES.in +index f81e2b40..f0a870df 100644 +--- a/bfd/po/BLD-POTFILES.in ++++ b/bfd/po/BLD-POTFILES.in +@@ -7,6 +7,7 @@ elf64-aarch64.c + elf64-ia64.c + elf64-riscv.c + elf64-target.h ++pe-aarch64igen.c + peigen.c + pepigen.c + pex64igen.c +diff --git a/bfd/po/SRC-POTFILES.in b/bfd/po/SRC-POTFILES.in +index c83b86cd..10de7bc0 100644 +--- a/bfd/po/SRC-POTFILES.in ++++ b/bfd/po/SRC-POTFILES.in +@@ -320,6 +320,7 @@ pe-x86_64.c + pef-traceback.h + pef.c + pef.h ++pei-aarch64.c + pei-arm-wince.c + pei-arm.c + pei-i386.c +-- +2.30.2 + diff --git a/backport-Add-support-for-AArch64-EFI-efi-aarch64.patch b/backport-Add-support-for-AArch64-EFI-efi-aarch64.patch new file mode 100644 index 0000000000000000000000000000000000000000..937aa53101719b49c3e2cf6897364ae6a859d689 --- /dev/null +++ b/backport-Add-support-for-AArch64-EFI-efi-aarch64.patch @@ -0,0 +1,158 @@ +From fd932228d9104001abbf6a1c8ef1bb030ab7a21d Mon Sep 17 00:00:00 2001 +From: Alan Modra +Date: Tue, 7 Dec 2021 12:36:31 +1030 +Subject: [PATCH 2/3] Add support for AArch64 EFI (efi-*-aarch64) + +Commit b69c9d41e8 was broken in multiple ways regarding the realloc +of the target string, most notably in that "-little" wasn't actually +appended to the input_target or output_target. This caused asan +errors and "FAIL: Check if efi app format is recognized". I also +noticed that the input_target string wasn't being copied but rather +the output_target when dealing with the input target. Fix that too. + + PR 26206 + * objcopy.c (convert_efi_target): Rewrite. Allocate modified + target strings here.. + (copy_main): ..rather than here. Do handle input_target, + not output_target for input. + +References: bsn#351 +Signed-off-by: Chenxi Mao +--- + binutils/objcopy.c | 86 +++++++++++++++++++++------------------------- + 1 file changed, 40 insertions(+), 46 deletions(-) + +diff --git a/binutils/objcopy.c b/binutils/objcopy.c +index 242b1052..cbff93b3 100644 +--- a/binutils/objcopy.c ++++ b/binutils/objcopy.c +@@ -4969,32 +4969,55 @@ set_pe_subsystem (const char *s) + + /* Convert EFI target to PEI target. */ + +-static void +-convert_efi_target (char *efi) ++static int ++convert_efi_target (char **targ) + { +- efi[0] = 'p'; +- efi[1] = 'e'; +- efi[2] = 'i'; ++ size_t len; ++ char *pei; ++ char *efi = *targ + 4; ++ int subsys = -1; ++ ++ if (startswith (efi, "app-")) ++ subsys = IMAGE_SUBSYSTEM_EFI_APPLICATION; ++ else if (startswith (efi, "bsdrv-")) ++ { ++ subsys = IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER; ++ efi += 2; ++ } ++ else if (startswith (efi, "rtdrv-")) ++ { ++ subsys = IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER; ++ efi += 2; ++ } ++ else ++ return subsys; ++ ++ len = strlen (efi); ++ pei = xmalloc (len + sizeof ("-little")); ++ memcpy (pei, efi, len + 1); ++ pei[0] = 'p'; ++ pei[1] = 'e'; ++ pei[2] = 'i'; + + if (strcmp (efi + 4, "ia32") == 0) + { + /* Change ia32 to i386. */ +- efi[5]= '3'; +- efi[6]= '8'; +- efi[7]= '6'; ++ pei[5]= '3'; ++ pei[6]= '8'; ++ pei[7]= '6'; + } + else if (strcmp (efi + 4, "x86_64") == 0) + { + /* Change x86_64 to x86-64. */ +- efi[7] = '-'; ++ pei[7] = '-'; + } + else if (strcmp (efi + 4, "aarch64") == 0) + { + /* Change aarch64 to aarch64-little. */ +- efi = (char *) xrealloc (efi, strlen (efi) + 7); +- char *t = "aarch64-little"; +- strcpy (efi + 4, t); ++ memcpy (pei + 4 + sizeof ("aarch64") - 1, "-little", sizeof ("-little")); + } ++ *targ = pei; ++ return subsys; + } + + /* Allocate and return a pointer to a struct section_add, initializing the +@@ -5877,53 +5900,24 @@ copy_main (int argc, char *argv[]) + if (input_target != NULL + && startswith (input_target, "efi-")) + { +- char *efi; +- +- efi = xstrdup (output_target + 4); +- if (startswith (efi, "bsdrv-") +- || startswith (efi, "rtdrv-")) +- efi += 2; +- else if (!startswith (efi, "app-")) ++ if (convert_efi_target (&input_target) < 0) + fatal (_("unknown input EFI target: %s"), input_target); +- +- input_target = efi; +- convert_efi_target (efi); + } + + /* Convert output EFI target to PEI target. */ + if (output_target != NULL + && startswith (output_target, "efi-")) + { +- char *efi; ++ int subsys = convert_efi_target (&output_target); + +- efi = xstrdup (output_target + 4); +- if (startswith (efi, "app-")) +- { +- if (pe_subsystem == -1) +- pe_subsystem = IMAGE_SUBSYSTEM_EFI_APPLICATION; +- } +- else if (startswith (efi, "bsdrv-")) +- { +- if (pe_subsystem == -1) +- pe_subsystem = IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER; +- efi += 2; +- } +- else if (startswith (efi, "rtdrv-")) +- { +- if (pe_subsystem == -1) +- pe_subsystem = IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER; +- efi += 2; +- } +- else ++ if (subsys < 0) + fatal (_("unknown output EFI target: %s"), output_target); +- ++ if (pe_subsystem == -1) ++ pe_subsystem = subsys; + if (pe_file_alignment == (bfd_vma) -1) + pe_file_alignment = PE_DEF_FILE_ALIGNMENT; + if (pe_section_alignment == (bfd_vma) -1) + pe_section_alignment = PE_DEF_SECTION_ALIGNMENT; +- +- output_target = efi; +- convert_efi_target (efi); + } + + /* If there is no destination file, or the source and destination files +-- +2.30.2 + diff --git a/backport-don-t-over-align-file-positions-of-PE-executable-sec.patch b/backport-don-t-over-align-file-positions-of-PE-executable-sec.patch new file mode 100644 index 0000000000000000000000000000000000000000..f871ecf82f653f560aae0821be2fe7382989058b --- /dev/null +++ b/backport-don-t-over-align-file-positions-of-PE-executable-sec.patch @@ -0,0 +1,111 @@ +From 5bb067dba365e713bf988a06f7ed1c352aab52c4 Mon Sep 17 00:00:00 2001 +From: Jan Beulich +Date: Thu, 19 May 2022 12:43:10 +0200 +Subject: [PATCH 3/3] don't over-align file positions of PE executable sections + +When a sufficiently small alignment was specified via --file-alignment, +individual section alignment shouldn't affect placement within the file. +This involves first of all clearing D_PAGED for images when section and +file alignment together don't permit paging of the image. The involved +comparison against COFF_PAGE_SIZE in turn helped point out (through a +compiler warning) that 'page_size' should be of unsigned type (as in +particular FileAlignment is). This yet in turn pointed out a dubious +error condition (which is being deleted). + +For the D_PAGED case I think the enforced file alignment may still be +too high, but I'm wary of changing that logic without knowing of +possible corner cases. + +Furthermore file positions in PE should be independent of the alignment +recorded in section headers anyway. Otherwise there are e.g. anomalies +following commit 6f8f6017a0c4 ("PR27567, Linking PE files adds alignment +section flags to executables") in that linking would use information a +subsequent processing step (e.g. stripping) wouldn't have available +anymore, and hence a binary could change in that 2nd step for no actual +reason. (Similarly stripping a binary linked with a linker pre-dating +that commit would change the binary again when stripping it a 2nd time.) + +References: bsn#351 +Signed-off-by: Chenxi Mao +--- + bfd/coffcode.h | 29 ++++++++++++++--------------- + 1 file changed, 14 insertions(+), 15 deletions(-) + +diff --git a/bfd/coffcode.h b/bfd/coffcode.h +index a5a4979f..d222c88d 100644 +--- a/bfd/coffcode.h ++++ b/bfd/coffcode.h +@@ -2952,7 +2952,7 @@ coff_compute_section_file_positions (bfd * abfd) + #endif + + #ifdef COFF_IMAGE_WITH_PE +- int page_size; ++ unsigned int page_size; + + if (coff_data (abfd)->link_info + || (pe_data (abfd) && pe_data (abfd)->pe_opthdr.FileAlignment)) +@@ -2963,22 +2963,12 @@ coff_compute_section_file_positions (bfd * abfd) + This repairs 'ld -r' for arm-wince-pe target. */ + if (page_size == 0) + page_size = 1; +- +- /* PR 17512: file: 0ac816d3. */ +- if (page_size < 0) +- { +- bfd_set_error (bfd_error_file_too_big); +- _bfd_error_handler +- /* xgettext:c-format */ +- (_("%pB: page size is too large (0x%x)"), abfd, page_size); +- return false; +- } + } + else + page_size = PE_DEF_FILE_ALIGNMENT; + #else + #ifdef COFF_PAGE_SIZE +- int page_size = COFF_PAGE_SIZE; ++ unsigned int page_size = COFF_PAGE_SIZE; + #endif + #endif + +@@ -3060,9 +3050,10 @@ coff_compute_section_file_positions (bfd * abfd) + bfd_size_type amt; + + #ifdef COFF_PAGE_SIZE +- /* Clear D_PAGED if section alignment is smaller than +- COFF_PAGE_SIZE. */ +- if (pe_data (abfd)->pe_opthdr.SectionAlignment < COFF_PAGE_SIZE) ++ /* Clear D_PAGED if section / file alignment aren't suitable for ++ paging at COFF_PAGE_SIZE granularity. */ ++ if (pe_data (abfd)->pe_opthdr.SectionAlignment < COFF_PAGE_SIZE ++ || page_size < COFF_PAGE_SIZE) + abfd->flags &= ~D_PAGED; + #endif + +@@ -3183,7 +3174,11 @@ coff_compute_section_file_positions (bfd * abfd) + padding the previous section up if necessary. */ + old_sofar = sofar; + ++#ifdef COFF_IMAGE_WITH_PE ++ sofar = BFD_ALIGN (sofar, page_size); ++#else + sofar = BFD_ALIGN (sofar, 1 << current->alignment_power); ++#endif + + #ifdef RS6000COFF_C + /* Make sure the file offset and the vma of .text/.data are at the +@@ -3259,7 +3254,11 @@ coff_compute_section_file_positions (bfd * abfd) + else + { + old_sofar = sofar; ++#ifdef COFF_IMAGE_WITH_PE ++ sofar = BFD_ALIGN (sofar, page_size); ++#else + sofar = BFD_ALIGN (sofar, 1 << current->alignment_power); ++#endif + align_adjust = sofar != old_sofar; + current->size += sofar - old_sofar; + } +-- +2.30.2 + diff --git a/binutils.spec b/binutils.spec index 7214eba2f330d9c0c36d4f4a8f87f83da5d9da82..60668771df41762ad6180f5be1bb36919300bdee 100644 --- a/binutils.spec +++ b/binutils.spec @@ -1,7 +1,7 @@ Summary: Binary utilities Name: binutils Version: 2.37 -Release: 9 +Release: 10 License: GPLv3+ URL: https://sourceware.org/binutils @@ -33,6 +33,9 @@ Patch10: bfd-Close-the-file-descriptor-if-there-is-no-archive.patch Patch11: binutils-AArch64-EFI.patch Patch12: backport-0001-PR28391-strip-objcopy-preserve-dates-.a-cannot-set-t.patch Patch13: backport-0001-texi2pod.pl-add-no-op-no-split-option-support-PR2814.patch +Patch14: backport-AArch64-Add-support-for-AArch64-EFI-efi-aarch64.patch +Patch15: backport-Add-support-for-AArch64-EFI-efi-aarch64.patch +Patch16: backport-don-t-over-align-file-positions-of-PE-executable-sec.patch Provides: bundled(libiberty) @@ -356,6 +359,9 @@ fi %{_infodir}/bfd*info* %changelog +* Sat Oct 08 2022 Chenxi Mao - 2.37-10 +- Fix Aarch64 EFI PE section address overlap issue. + * Fri Sep 02 2022 Wei, Qiang - 2.37-9 - Fix man page empty issue