binutils: add missing patches...

+260
+99
pkgs/development/tools/misc/binutils/elf-check-orphan-input.patch
··· 1 + From a388b7afeffad6411686d39dc1c62294da48a814 Mon Sep 17 00:00:00 2001 2 + From: "H.J. Lu" <hjl.tools@gmail.com> 3 + Date: Wed, 2 Aug 2017 05:10:29 -0700 4 + Subject: [PATCH] Check ELF section header only for ELF output 5 + 6 + When placing an orphan input section, check ELF section header only for 7 + ELF output. 8 + 9 + PR ld/21884 10 + * emultempl/elf32.em (gld${EMULATION_NAME}_place_orphan): Check 11 + ELF section header only for ELF output. 12 + * testsuite/ld-elf/pr21884.d: New test. 13 + * testsuite/ld-elf/pr21884.t: Likewise. 14 + * testsuite/ld-elf/pr21884a.s: Likewise. 15 + * testsuite/ld-elf/pr21884b.s: Likewise. 16 + 17 + (cherry picked from commit db99ecc08f5b66fbe9cb72e90352c7f77ec71a6e) 18 + --- 19 + ld/ChangeLog | 10 ++++++++++ 20 + ld/emultempl/elf32.em | 3 ++- 21 + ld/testsuite/ld-elf/pr21884.d | 11 +++++++++++ 22 + ld/testsuite/ld-elf/pr21884.t | 7 +++++++ 23 + ld/testsuite/ld-elf/pr21884a.s | 5 +++++ 24 + ld/testsuite/ld-elf/pr21884b.s | 5 +++++ 25 + 6 files changed, 40 insertions(+), 1 deletion(-) 26 + create mode 100644 ld/testsuite/ld-elf/pr21884.d 27 + create mode 100644 ld/testsuite/ld-elf/pr21884.t 28 + create mode 100644 ld/testsuite/ld-elf/pr21884a.s 29 + create mode 100644 ld/testsuite/ld-elf/pr21884b.s 30 + 31 + diff --git a/ld/emultempl/elf32.em b/ld/emultempl/elf32.em 32 + index d2551b6..75ded12 100644 33 + --- a/ld/emultempl/elf32.em 34 + +++ b/ld/emultempl/elf32.em 35 + @@ -2136,7 +2136,8 @@ gld${EMULATION_NAME}_place_orphan (asection *s, 36 + } 37 + 38 + /* Look through the script to see where to place this section. */ 39 + - if (constraint == 0) 40 + + if (constraint == 0 41 + + && link_info.output_bfd->xvec->flavour == bfd_target_elf_flavour) 42 + for (os = lang_output_section_find (secname); 43 + os != NULL; 44 + os = next_matching_output_section_statement (os, 0)) 45 + diff --git a/ld/testsuite/ld-elf/pr21884.d b/ld/testsuite/ld-elf/pr21884.d 46 + new file mode 100644 47 + index 0000000..52cd2c1 48 + --- /dev/null 49 + +++ b/ld/testsuite/ld-elf/pr21884.d 50 + @@ -0,0 +1,11 @@ 51 + +#source: pr21884a.s 52 + +#source: pr21884b.s 53 + +#ld: -T pr21884.t 54 + +#objdump: -b binary -s 55 + +#notarget: aarch64*-*-* arm*-*-* nds32*-*-* 56 + +# Skip targets which can't change output format to binary. 57 + + 58 + +.*: file format binary 59 + + 60 + +Contents of section .data: 61 + +#pass 62 + diff --git a/ld/testsuite/ld-elf/pr21884.t b/ld/testsuite/ld-elf/pr21884.t 63 + new file mode 100644 64 + index 0000000..d483911 65 + --- /dev/null 66 + +++ b/ld/testsuite/ld-elf/pr21884.t 67 + @@ -0,0 +1,7 @@ 68 + +OUTPUT_FORMAT("binary") 69 + + 70 + +ENTRY(_main); 71 + +SECTIONS { 72 + + . = 0; 73 + + .setup : { *(.setup) } 74 + +} 75 + diff --git a/ld/testsuite/ld-elf/pr21884a.s b/ld/testsuite/ld-elf/pr21884a.s 76 + new file mode 100644 77 + index 0000000..a3361b2 78 + --- /dev/null 79 + +++ b/ld/testsuite/ld-elf/pr21884a.s 80 + @@ -0,0 +1,5 @@ 81 + + .text 82 + + .globl _main 83 + + .type _main,%function 84 + +_main: 85 + + .dc.a bar 86 + diff --git a/ld/testsuite/ld-elf/pr21884b.s b/ld/testsuite/ld-elf/pr21884b.s 87 + new file mode 100644 88 + index 0000000..e533837 89 + --- /dev/null 90 + +++ b/ld/testsuite/ld-elf/pr21884b.s 91 + @@ -0,0 +1,5 @@ 92 + + .text 93 + + .globl bar 94 + + .type bar,%function 95 + +bar: 96 + + .byte 0 97 + -- 98 + 2.9.3 99 +
+161
pkgs/development/tools/misc/binutils/elf-check-orphan-placement.patch
··· 1 + From 36088682f447540fd8666a2c437fa232064044a7 Mon Sep 17 00:00:00 2001 2 + From: Alan Modra <amodra@gmail.com> 3 + Date: Thu, 3 Aug 2017 14:01:34 +0930 4 + Subject: [PATCH] ELF checks for orphan placement 5 + 6 + The loop checking for previous orphan placement should run even when 7 + the output is non-ELF. 8 + 9 + PR ld/21884 10 + * emultempl/elf32.em (gld${EMULATION_NAME}_place_orphan): Revert 11 + last change. Rename iself to elfinput. Expand comments. Condition 12 + ELF checks on having both input and output ELF files. Extract.. 13 + (elf_orphan_compatible): ..this new function. 14 + --- 15 + ld/ChangeLog | 8 ++++++ 16 + ld/emultempl/elf32.em | 76 +++++++++++++++++++++++++++++++-------------------- 17 + 2 files changed, 55 insertions(+), 29 deletions(-) 18 + 19 + diff --git a/ld/emultempl/elf32.em b/ld/emultempl/elf32.em 20 + index 75ded12..9ac1840 100644 21 + --- a/ld/emultempl/elf32.em 22 + +++ b/ld/emultempl/elf32.em 23 + @@ -2008,6 +2008,29 @@ output_rel_find (asection *sec, int isdyn) 24 + return last; 25 + } 26 + 27 + +/* Return whether IN is suitable to be part of OUT. */ 28 + + 29 + +static bfd_boolean 30 + +elf_orphan_compatible (asection *in, asection *out) 31 + +{ 32 + + /* Non-zero sh_info implies a section with SHF_INFO_LINK with 33 + + unknown semantics for the generic linker, or a SHT_REL/SHT_RELA 34 + + section where sh_info specifies a symbol table. (We won't see 35 + + SHT_GROUP, SHT_SYMTAB or SHT_DYNSYM sections here.) We clearly 36 + + can't merge SHT_REL/SHT_RELA using differing symbol tables, and 37 + + shouldn't merge sections with differing unknown semantics. */ 38 + + if (elf_section_data (out)->this_hdr.sh_info 39 + + != elf_section_data (in)->this_hdr.sh_info) 40 + + return FALSE; 41 + + /* We can't merge two sections with differing SHF_EXCLUDE when doing 42 + + a relocatable link. */ 43 + + if (bfd_link_relocatable (&link_info) 44 + + && ((elf_section_flags (out) ^ elf_section_flags (in)) & SHF_EXCLUDE) != 0) 45 + + return FALSE; 46 + + return _bfd_elf_match_sections_by_type (link_info.output_bfd, out, 47 + + in->owner, in); 48 + +} 49 + + 50 + /* Place an orphan section. We use this to put random SHF_ALLOC 51 + sections in the right segment. */ 52 + 53 + @@ -2064,8 +2087,9 @@ gld${EMULATION_NAME}_place_orphan (asection *s, 54 + lang_output_section_statement_type *os; 55 + lang_output_section_statement_type *match_by_name = NULL; 56 + int isdyn = 0; 57 + - int iself = s->owner->xvec->flavour == bfd_target_elf_flavour; 58 + - unsigned int sh_type = iself ? elf_section_type (s) : SHT_NULL; 59 + + int elfinput = s->owner->xvec->flavour == bfd_target_elf_flavour; 60 + + int elfoutput = link_info.output_bfd->xvec->flavour == bfd_target_elf_flavour; 61 + + unsigned int sh_type = elfinput ? elf_section_type (s) : SHT_NULL; 62 + flagword flags; 63 + asection *nexts; 64 + 65 + @@ -2073,7 +2097,7 @@ gld${EMULATION_NAME}_place_orphan (asection *s, 66 + && link_info.combreloc 67 + && (s->flags & SEC_ALLOC)) 68 + { 69 + - if (iself) 70 + + if (elfinput) 71 + switch (sh_type) 72 + { 73 + case SHT_RELA: 74 + @@ -2095,6 +2119,8 @@ gld${EMULATION_NAME}_place_orphan (asection *s, 75 + } 76 + 77 + if (!bfd_link_relocatable (&link_info) 78 + + && elfinput 79 + + && elfoutput 80 + && (s->flags & SEC_ALLOC) != 0 81 + && (elf_section_flags (s) & SHF_GNU_MBIND) != 0) 82 + { 83 + @@ -2135,9 +2161,11 @@ gld${EMULATION_NAME}_place_orphan (asection *s, 84 + secname = ".mbind.text"; 85 + } 86 + 87 + - /* Look through the script to see where to place this section. */ 88 + - if (constraint == 0 89 + - && link_info.output_bfd->xvec->flavour == bfd_target_elf_flavour) 90 + + /* Look through the script to see where to place this section. The 91 + + script includes entries added by previous lang_insert_orphan 92 + + calls, so this loop puts multiple compatible orphans of the same 93 + + name into a single output section. */ 94 + + if (constraint == 0) 95 + for (os = lang_output_section_find (secname); 96 + os != NULL; 97 + os = next_matching_output_section_statement (os, 0)) 98 + @@ -2146,29 +2174,19 @@ gld${EMULATION_NAME}_place_orphan (asection *s, 99 + lang_insert_orphan to create a new output section. */ 100 + constraint = SPECIAL; 101 + 102 + - /* SEC_EXCLUDE is cleared when doing a relocatable link. But 103 + - we can't merge 2 input sections with the same name when only 104 + - one of them has SHF_EXCLUDE. Don't merge 2 sections with 105 + - different sh_info. */ 106 + + /* Check to see if we already have an output section statement 107 + + with this name, and its bfd section has compatible flags. 108 + + If the section already exists but does not have any flags 109 + + set, then it has been created by the linker, possibly as a 110 + + result of a --section-start command line switch. */ 111 + if (os->bfd_section != NULL 112 + - && (elf_section_data (os->bfd_section)->this_hdr.sh_info 113 + - == elf_section_data (s)->this_hdr.sh_info) 114 + && (os->bfd_section->flags == 0 115 + - || ((!bfd_link_relocatable (&link_info) 116 + - || (iself && (((elf_section_flags (s) 117 + - ^ elf_section_flags (os->bfd_section)) 118 + - & SHF_EXCLUDE) == 0))) 119 + - && ((s->flags ^ os->bfd_section->flags) 120 + + || (((s->flags ^ os->bfd_section->flags) 121 + & (SEC_LOAD | SEC_ALLOC)) == 0 122 + - && _bfd_elf_match_sections_by_type (link_info.output_bfd, 123 + - os->bfd_section, 124 + - s->owner, s)))) 125 + + && (!elfinput 126 + + || !elfoutput 127 + + || elf_orphan_compatible (s, os->bfd_section))))) 128 + { 129 + - /* We already have an output section statement with this 130 + - name, and its bfd section has compatible flags. 131 + - If the section already exists but does not have any flags 132 + - set, then it has been created by the linker, probably as a 133 + - result of a --section-start command line switch. */ 134 + lang_add_section (&os->children, s, NULL, os); 135 + return os; 136 + } 137 + @@ -2244,8 +2262,8 @@ gld${EMULATION_NAME}_place_orphan (asection *s, 138 + else if ((flags & SEC_ALLOC) == 0) 139 + ; 140 + else if ((flags & SEC_LOAD) != 0 141 + - && ((iself && sh_type == SHT_NOTE) 142 + - || (!iself && CONST_STRNEQ (secname, ".note")))) 143 + + && ((elfinput && sh_type == SHT_NOTE) 144 + + || (!elfinput && CONST_STRNEQ (secname, ".note")))) 145 + place = &hold[orphan_interp]; 146 + else if ((flags & (SEC_LOAD | SEC_HAS_CONTENTS | SEC_THREAD_LOCAL)) == 0) 147 + place = &hold[orphan_bss]; 148 + @@ -2255,8 +2273,8 @@ gld${EMULATION_NAME}_place_orphan (asection *s, 149 + place = &hold[orphan_tdata]; 150 + else if ((flags & SEC_READONLY) == 0) 151 + place = &hold[orphan_data]; 152 + - else if (((iself && (sh_type == SHT_RELA || sh_type == SHT_REL)) 153 + - || (!iself && CONST_STRNEQ (secname, ".rel"))) 154 + + else if (((elfinput && (sh_type == SHT_RELA || sh_type == SHT_REL)) 155 + + || (!elfinput && CONST_STRNEQ (secname, ".rel"))) 156 + && (flags & SEC_LOAD) != 0) 157 + place = &hold[orphan_rel]; 158 + else if ((flags & SEC_CODE) == 0) 159 + -- 160 + 2.9.3 161 +