diff options
Diffstat (limited to 'meta-microblaze/recipes-devtools/binutils/binutils/0032-Patch-MicroBlaze-Double-free-with-ld-no-keep-memory.patch')
-rw-r--r-- | meta-microblaze/recipes-devtools/binutils/binutils/0032-Patch-MicroBlaze-Double-free-with-ld-no-keep-memory.patch | 195 |
1 files changed, 195 insertions, 0 deletions
diff --git a/meta-microblaze/recipes-devtools/binutils/binutils/0032-Patch-MicroBlaze-Double-free-with-ld-no-keep-memory.patch b/meta-microblaze/recipes-devtools/binutils/binutils/0032-Patch-MicroBlaze-Double-free-with-ld-no-keep-memory.patch new file mode 100644 index 00000000..e9556bf5 --- /dev/null +++ b/meta-microblaze/recipes-devtools/binutils/binutils/0032-Patch-MicroBlaze-Double-free-with-ld-no-keep-memory.patch | |||
@@ -0,0 +1,195 @@ | |||
1 | From 70268d8d38851d06bd66f9c7cc85865f2f3c0e48 Mon Sep 17 00:00:00 2001 | ||
2 | From: Mahesh Bodapati <mbodapat@xilinx.com> | ||
3 | Date: Mon, 24 Jan 2022 16:59:19 +0530 | ||
4 | Subject: [PATCH 32/34] [Patch,MicroBlaze] : Double free with ld | ||
5 | --no-keep-memory. Proposed patches from the community member | ||
6 | (dednev@rambler.ru) for 2021.1. [CR-1115233] | ||
7 | |||
8 | Conflicts: | ||
9 | bfd/elf32-microblaze.c | ||
10 | bfd/elf64-microblaze.c | ||
11 | --- | ||
12 | bfd/elf32-microblaze.c | 40 ++++++++++++++++++++++------------------ | ||
13 | bfd/elf64-microblaze.c | 38 ++++++++++++++++++++------------------ | ||
14 | 2 files changed, 42 insertions(+), 36 deletions(-) | ||
15 | |||
16 | diff --git a/bfd/elf32-microblaze.c b/bfd/elf32-microblaze.c | ||
17 | index 588367ebcbb..28589db662f 100644 | ||
18 | --- a/bfd/elf32-microblaze.c | ||
19 | +++ b/bfd/elf32-microblaze.c | ||
20 | @@ -1800,10 +1800,8 @@ microblaze_elf_relax_section (bfd *abfd, | ||
21 | { | ||
22 | Elf_Internal_Shdr *symtab_hdr; | ||
23 | Elf_Internal_Rela *internal_relocs; | ||
24 | - Elf_Internal_Rela *free_relocs = NULL; | ||
25 | Elf_Internal_Rela *irel, *irelend; | ||
26 | bfd_byte *contents = NULL; | ||
27 | - bfd_byte *free_contents = NULL; | ||
28 | int rel_count; | ||
29 | unsigned int shndx; | ||
30 | size_t i, sym_index; | ||
31 | @@ -1847,8 +1845,6 @@ microblaze_elf_relax_section (bfd *abfd, | ||
32 | internal_relocs = _bfd_elf_link_read_relocs (abfd, sec, NULL, NULL, link_info->keep_memory); | ||
33 | if (internal_relocs == NULL) | ||
34 | goto error_return; | ||
35 | - if (! link_info->keep_memory) | ||
36 | - free_relocs = internal_relocs; | ||
37 | |||
38 | sdata->relax_count = 0; | ||
39 | sdata->relax = (struct relax_table *) bfd_malloc ((sec->reloc_count + 1) | ||
40 | @@ -1876,7 +1872,6 @@ microblaze_elf_relax_section (bfd *abfd, | ||
41 | contents = (bfd_byte *) bfd_malloc (sec->size); | ||
42 | if (contents == NULL) | ||
43 | goto error_return; | ||
44 | - free_contents = contents; | ||
45 | |||
46 | if (!bfd_get_section_contents (abfd, sec, contents, | ||
47 | (file_ptr) 0, sec->size)) | ||
48 | @@ -2396,25 +2391,26 @@ microblaze_elf_relax_section (bfd *abfd, | ||
49 | } | ||
50 | |||
51 | elf_section_data (sec)->relocs = internal_relocs; | ||
52 | - free_relocs = NULL; | ||
53 | |||
54 | elf_section_data (sec)->this_hdr.contents = contents; | ||
55 | - free_contents = NULL; | ||
56 | |||
57 | symtab_hdr->contents = (bfd_byte *) isymbuf; | ||
58 | } | ||
59 | |||
60 | - free (free_relocs); | ||
61 | - free_relocs = NULL; | ||
62 | + if (internal_relocs != NULL | ||
63 | + && elf_section_data (sec)->relocs != internal_relocs) | ||
64 | + free (internal_relocs); | ||
65 | |||
66 | - if (free_contents != NULL) | ||
67 | - { | ||
68 | - if (!link_info->keep_memory) | ||
69 | - free (free_contents); | ||
70 | + if (contents != NULL | ||
71 | + && elf_section_data (sec)->this_hdr.contents != contents) | ||
72 | + { | ||
73 | + if (! link_info->keep_memory) | ||
74 | + free (contents); | ||
75 | else | ||
76 | - /* Cache the section contents for elf_link_input_bfd. */ | ||
77 | - elf_section_data (sec)->this_hdr.contents = contents; | ||
78 | - free_contents = NULL; | ||
79 | + { | ||
80 | + /* Cache the section contents for elf_link_input_bfd. */ | ||
81 | + elf_section_data (sec)->this_hdr.contents = contents; | ||
82 | + } | ||
83 | } | ||
84 | |||
85 | if (sdata->relax_count == 0) | ||
86 | @@ -2428,8 +2424,16 @@ microblaze_elf_relax_section (bfd *abfd, | ||
87 | return true; | ||
88 | |||
89 | error_return: | ||
90 | - free (free_relocs); | ||
91 | - free (free_contents); | ||
92 | + | ||
93 | + if (isymbuf != NULL | ||
94 | + && symtab_hdr->contents != (unsigned char *) isymbuf) | ||
95 | + free (isymbuf); | ||
96 | + if (internal_relocs != NULL | ||
97 | + && elf_section_data (sec)->relocs != internal_relocs) | ||
98 | + free (internal_relocs); | ||
99 | + if (contents != NULL | ||
100 | + && elf_section_data (sec)->this_hdr.contents != contents) | ||
101 | + free (contents); | ||
102 | free (sdata->relax); | ||
103 | sdata->relax = NULL; | ||
104 | sdata->relax_count = 0; | ||
105 | diff --git a/bfd/elf64-microblaze.c b/bfd/elf64-microblaze.c | ||
106 | index 76aec43ec7a..77872cef1ab 100644 | ||
107 | --- a/bfd/elf64-microblaze.c | ||
108 | +++ b/bfd/elf64-microblaze.c | ||
109 | @@ -1840,10 +1840,8 @@ microblaze_elf_relax_section (bfd *abfd, | ||
110 | { | ||
111 | Elf_Internal_Shdr *symtab_hdr; | ||
112 | Elf_Internal_Rela *internal_relocs; | ||
113 | - Elf_Internal_Rela *free_relocs = NULL; | ||
114 | Elf_Internal_Rela *irel, *irelend; | ||
115 | bfd_byte *contents = NULL; | ||
116 | - bfd_byte *free_contents = NULL; | ||
117 | int rel_count; | ||
118 | unsigned int shndx; | ||
119 | size_t i, sym_index; | ||
120 | @@ -1887,8 +1885,6 @@ microblaze_elf_relax_section (bfd *abfd, | ||
121 | internal_relocs = _bfd_elf_link_read_relocs (abfd, sec, NULL, NULL, link_info->keep_memory); | ||
122 | if (internal_relocs == NULL) | ||
123 | goto error_return; | ||
124 | - if (! link_info->keep_memory) | ||
125 | - free_relocs = internal_relocs; | ||
126 | |||
127 | sdata->relax_count = 0; | ||
128 | sdata->relax = (struct relax_table *) bfd_malloc ((sec->reloc_count + 1) | ||
129 | @@ -1916,8 +1912,6 @@ microblaze_elf_relax_section (bfd *abfd, | ||
130 | contents = (bfd_byte *) bfd_malloc (sec->size); | ||
131 | if (contents == NULL) | ||
132 | goto error_return; | ||
133 | - free_contents = contents; | ||
134 | - | ||
135 | if (!bfd_get_section_contents (abfd, sec, contents, | ||
136 | (file_ptr) 0, sec->size)) | ||
137 | goto error_return; | ||
138 | @@ -2449,25 +2443,26 @@ microblaze_elf_relax_section (bfd *abfd, | ||
139 | } | ||
140 | |||
141 | elf_section_data (sec)->relocs = internal_relocs; | ||
142 | - free_relocs = NULL; | ||
143 | |||
144 | elf_section_data (sec)->this_hdr.contents = contents; | ||
145 | - free_contents = NULL; | ||
146 | |||
147 | symtab_hdr->contents = (bfd_byte *) isymbuf; | ||
148 | } | ||
149 | |||
150 | - free (free_relocs); | ||
151 | - free_relocs = NULL; | ||
152 | + if (internal_relocs != NULL | ||
153 | + && elf_section_data (sec)->relocs != internal_relocs) | ||
154 | + free (internal_relocs); | ||
155 | |||
156 | - if (free_contents != NULL) | ||
157 | + if (contents != NULL | ||
158 | + && elf_section_data (sec)->this_hdr.contents != contents) | ||
159 | { | ||
160 | - if (!link_info->keep_memory) | ||
161 | - free (free_contents); | ||
162 | + if (! link_info->keep_memory) | ||
163 | + free (contents); | ||
164 | else | ||
165 | - /* Cache the section contents for elf_link_input_bfd. */ | ||
166 | - elf_section_data (sec)->this_hdr.contents = contents; | ||
167 | - free_contents = NULL; | ||
168 | + { | ||
169 | + /* Cache the section contents for elf_link_input_bfd. */ | ||
170 | + elf_section_data (sec)->this_hdr.contents = contents; | ||
171 | + } | ||
172 | } | ||
173 | |||
174 | if (sdata->relax_count == 0) | ||
175 | @@ -2481,8 +2476,15 @@ microblaze_elf_relax_section (bfd *abfd, | ||
176 | return true; | ||
177 | |||
178 | error_return: | ||
179 | - free (free_relocs); | ||
180 | - free (free_contents); | ||
181 | + if (isymbuf != NULL | ||
182 | + && symtab_hdr->contents != (unsigned char *) isymbuf) | ||
183 | + free (isymbuf); | ||
184 | + if (internal_relocs != NULL | ||
185 | + && elf_section_data (sec)->relocs != internal_relocs) | ||
186 | + free (internal_relocs); | ||
187 | + if (contents != NULL | ||
188 | + && elf_section_data (sec)->this_hdr.contents != contents) | ||
189 | + free (contents); | ||
190 | free (sdata->relax); | ||
191 | sdata->relax = NULL; | ||
192 | sdata->relax_count = 0; | ||
193 | -- | ||
194 | 2.37.1 (Apple Git-137.1) | ||
195 | |||