summaryrefslogtreecommitdiffstats
path: root/meta-microblaze/recipes-devtools/binutils/binutils/0033-Patch-MB-MB-binutils-Upstream-port-issues.patch
diff options
context:
space:
mode:
Diffstat (limited to 'meta-microblaze/recipes-devtools/binutils/binutils/0033-Patch-MB-MB-binutils-Upstream-port-issues.patch')
-rw-r--r--meta-microblaze/recipes-devtools/binutils/binutils/0033-Patch-MB-MB-binutils-Upstream-port-issues.patch536
1 files changed, 536 insertions, 0 deletions
diff --git a/meta-microblaze/recipes-devtools/binutils/binutils/0033-Patch-MB-MB-binutils-Upstream-port-issues.patch b/meta-microblaze/recipes-devtools/binutils/binutils/0033-Patch-MB-MB-binutils-Upstream-port-issues.patch
new file mode 100644
index 00000000..f70ca3f2
--- /dev/null
+++ b/meta-microblaze/recipes-devtools/binutils/binutils/0033-Patch-MB-MB-binutils-Upstream-port-issues.patch
@@ -0,0 +1,536 @@
1From 5b79b9fe7da091664680b86e3b09bc4b926e2e61 Mon Sep 17 00:00:00 2001
2From: Mahesh Bodapati <mbodapat@xilinx.com>
3Date: Sun, 28 Nov 2021 17:17:15 +0530
4Subject: [PATCH 33/34] [Patch,MB]: MB binutils Upstream port issues.
5
6It's resolving the seg faults with ADDLIK
7Conflicts:
8 bfd/elf64-microblaze.c
9---
10 bfd/elf64-microblaze.c | 248 ++++++++++++++++++++++++++++---------
11 gas/config/tc-microblaze.c | 2 +-
12 opcodes/microblaze-dis.c | 12 +-
13 opcodes/microblaze-opc.h | 2 +-
14 4 files changed, 197 insertions(+), 67 deletions(-)
15
16diff --git a/bfd/elf64-microblaze.c b/bfd/elf64-microblaze.c
17index 77872cef1ab..119d266f95a 100644
18--- a/bfd/elf64-microblaze.c
19+++ b/bfd/elf64-microblaze.c
20@@ -807,12 +807,35 @@ microblaze_elf_is_local_label_name (bfd *abfd, const char *name)
21 return _bfd_elf_is_local_label_name (abfd, name);
22 }
23
24+/* The microblaze linker (like many others) needs to keep track of
25+ the number of relocs that it decides to copy as dynamic relocs in
26+ check_relocs for each symbol. This is so that it can later discard
27+ them if they are found to be unnecessary. We store the information
28+ in a field extending the regular ELF linker hash table. */
29+
30+struct elf64_mb_dyn_relocs
31+{
32+ struct elf64_mb_dyn_relocs *next;
33+
34+ /* The input section of the reloc. */
35+ asection *sec;
36+
37+ /* Total number of relocs copied for the input section. */
38+ bfd_size_type count;
39+
40+ /* Number of pc-relative relocs copied for the input section. */
41+ bfd_size_type pc_count;
42+};
43+
44 /* ELF linker hash entry. */
45
46 struct elf64_mb_link_hash_entry
47 {
48 struct elf_link_hash_entry elf;
49
50+ /* Track dynamic relocs copied for this symbol. */
51+ struct elf64_mb_dyn_relocs *dyn_relocs;
52+
53 /* TLS Reference Types for the symbol; Updated by check_relocs */
54 #define TLS_GD 1 /* GD reloc. */
55 #define TLS_LD 2 /* LD reloc. */
56@@ -836,6 +859,18 @@ struct elf64_mb_link_hash_table
57 {
58 struct elf_link_hash_table elf;
59
60+ /* Short-cuts to get to dynamic linker sections. */
61+ asection *sgot;
62+ asection *sgotplt;
63+ asection *srelgot;
64+ asection *splt;
65+ asection *srelplt;
66+ asection *sdynbss;
67+ asection *srelbss;
68+
69+ /* Small local sym to section mapping cache. */
70+ struct sym_cache sym_sec;
71+
72 /* TLS Local Dynamic GOT Entry */
73 union {
74 bfd_signed_vma refcount;
75@@ -1376,8 +1411,7 @@ microblaze_elf_relocate_section (bfd *output_bfd,
76 /* Need to generate relocs ? */
77 if ((bfd_link_pic (info) || indx != 0)
78 && (h == NULL
79- || (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
80- && !resolved_to_zero)
81+ || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
82 || h->root.type != bfd_link_hash_undefweak))
83 need_relocs = true;
84
85@@ -1564,13 +1598,11 @@ microblaze_elf_relocate_section (bfd *output_bfd,
86 contents + offset + endian);
87 }
88 else
89- {
90- bfd_put_16 (input_bfd, (relocation >> 16) & 0xffff,
91- contents + offset + endian);
92- bfd_put_16 (input_bfd, relocation & 0xffff,
93- contents + offset + endian + INST_WORD_SIZE);
94+ bfd_put_16 (input_bfd, (relocation >> 16) & 0xffff,
95+ contents + offset + endian);
96+ bfd_put_16 (input_bfd, relocation & 0xffff,
97+ contents + offset + endian + INST_WORD_SIZE);
98 }
99- }
100 break;
101 }
102
103@@ -1660,9 +1692,16 @@ microblaze_elf_relocate_section (bfd *output_bfd,
104 else
105 {
106 if (r_type == R_MICROBLAZE_64_PCREL)
107+ {
108+ if (!input_section->output_section->vma &&
109+ !input_section->output_offset && !offset)
110+ relocation -= (input_section->output_section->vma
111+ + input_section->output_offset
112+ + offset);
113+ else
114 relocation -= (input_section->output_section->vma
115- + input_section->output_offset
116- + offset + INST_WORD_SIZE);
117+ + input_section->output_offset + offset + INST_WORD_SIZE);
118+ }
119 else if (r_type == R_MICROBLAZE_TEXTREL_64
120 || r_type == R_MICROBLAZE_TEXTREL_32_LO)
121 relocation -= input_section->output_section->vma;
122@@ -1681,14 +1720,11 @@ microblaze_elf_relocate_section (bfd *output_bfd,
123 contents + offset + endian);
124 }
125 else
126- {
127- bfd_put_16 (input_bfd, (relocation >> 16) & 0xffff,
128- contents + offset + endian);
129- bfd_put_16 (input_bfd, relocation & 0xffff,
130- contents + offset + endian
131- + INST_WORD_SIZE);
132- }
133- }
134+ bfd_put_16 (input_bfd, (relocation >> 16) & 0xffff,
135+ contents + offset + endian);
136+ bfd_put_16 (input_bfd, relocation & 0xffff,
137+ contents + offset + endian + INST_WORD_SIZE);
138+ }
139 break;
140 }
141 }
142@@ -1759,6 +1795,21 @@ microblaze_elf_relocate_section (bfd *output_bfd,
143
144 return ret;
145 }
146+
147+/* Merge backend specific data from an object file to the output
148+ object file when linking.
149+
150+ Note: We only use this hook to catch endian mismatches. */
151+static bool
152+microblaze_elf_merge_private_bfd_data (bfd * ibfd, bfd * obfd)
153+{
154+ /* Check if we have the same endianess. */
155+ if (! _bfd_generic_verify_endian_match (ibfd, obfd))
156+ return false;
157+
158+ return true;
159+}
160+
161
162 /* Calculate fixup value for reference. */
163
164@@ -2512,6 +2563,17 @@ microblaze_elf_gc_mark_hook (asection *sec,
165 return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
166 }
167
168+/* Update the got entry reference counts for the section being removed. */
169+
170+static bool
171+microblaze_elf_gc_sweep_hook (bfd * abfd ATTRIBUTE_UNUSED,
172+ struct bfd_link_info * info ATTRIBUTE_UNUSED,
173+ asection * sec ATTRIBUTE_UNUSED,
174+ const Elf_Internal_Rela * relocs ATTRIBUTE_UNUSED)
175+{
176+ return true;
177+}
178+
179 /* PIC support. */
180
181 #define PLT_ENTRY_SIZE 16
182@@ -2718,14 +2780,14 @@ microblaze_elf_check_relocs (bfd * abfd,
183 && (! info->symbolic
184 || h->root.type == bfd_link_hash_defweak
185 || !h->def_regular))))
186- || (!bfd_link_pic (info)
187- && (sec->flags & SEC_ALLOC) != 0
188- && h != NULL
189- && (h->root.type == bfd_link_hash_defweak
190- || !h->def_regular)))
191- {
192- struct elf_dyn_relocs *p;
193- struct elf_dyn_relocs **head;
194+ || (!bfd_link_pic (info)
195+ && (sec->flags & SEC_ALLOC) != 0
196+ && h != NULL
197+ && (h->root.type == bfd_link_hash_defweak
198+ || !h->def_regular)))
199+ {
200+ struct elf64_mb_dyn_relocs *p;
201+ struct elf64_mb_dyn_relocs **head;
202
203 /* When creating a shared object, we must copy these
204 relocs into the output file. We create a reloc
205@@ -2769,14 +2831,14 @@ microblaze_elf_check_relocs (bfd * abfd,
206 return false;
207
208 vpp = &elf_section_data (s)->local_dynrel;
209- head = (struct elf_dyn_relocs **) vpp;
210+ head = (struct elf64_mb_dyn_relocs **) vpp;
211 }
212
213 p = *head;
214 if (p == NULL || p->sec != sec)
215 {
216 size_t amt = sizeof *p;
217- p = ((struct elf_dyn_relocs *)
218+ p = ((struct elf64_mb_dyn_relocs *)
219 bfd_alloc (htab->elf.dynobj, amt));
220 if (p == NULL)
221 return false;
222@@ -2799,6 +2861,34 @@ microblaze_elf_check_relocs (bfd * abfd,
223 return true;
224 }
225
226+static bool
227+microblaze_elf_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info)
228+{
229+ struct elf64_mb_link_hash_table *htab;
230+
231+ htab = elf64_mb_hash_table (info);
232+ if (htab == NULL)
233+ return false;
234+
235+ if (!htab->sgot && !_bfd_elf_create_got_section (dynobj, info))
236+ return false;
237+
238+ if (!_bfd_elf_create_dynamic_sections (dynobj, info))
239+ return false;
240+
241+ htab->splt = bfd_get_linker_section (dynobj, ".plt");
242+ htab->srelplt = bfd_get_linker_section (dynobj, ".rela.plt");
243+ htab->sdynbss = bfd_get_linker_section (dynobj, ".dynbss");
244+ if (!bfd_link_pic (info))
245+ htab->srelbss = bfd_get_linker_section (dynobj, ".rela.bss");
246+
247+ if (!htab->splt || !htab->srelplt || !htab->sdynbss
248+ || (!bfd_link_pic (info) && !htab->srelbss))
249+ abort ();
250+
251+ return true;
252+}
253+
254 /* Copy the extra info we tack onto an elf_link_hash_entry. */
255
256 static void
257@@ -2811,6 +2901,40 @@ microblaze_elf_copy_indirect_symbol (struct bfd_link_info *info,
258 edir = (struct elf64_mb_link_hash_entry *) dir;
259 eind = (struct elf64_mb_link_hash_entry *) ind;
260
261+ if (eind->dyn_relocs != NULL)
262+ {
263+ if (edir->dyn_relocs != NULL)
264+ {
265+ struct elf64_mb_dyn_relocs **pp;
266+ struct elf64_mb_dyn_relocs *p;
267+
268+ if (ind->root.type == bfd_link_hash_indirect)
269+ abort ();
270+
271+ /* Add reloc counts against the weak sym to the strong sym
272+ list. Merge any entries against the same section. */
273+ for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
274+ {
275+ struct elf64_mb_dyn_relocs *q;
276+
277+ for (q = edir->dyn_relocs; q != NULL; q = q->next)
278+ if (q->sec == p->sec)
279+ {
280+ q->pc_count += p->pc_count;
281+ q->count += p->count;
282+ *pp = p->next;
283+ break;
284+ }
285+ if (q == NULL)
286+ pp = &p->next;
287+ }
288+ *pp = edir->dyn_relocs;
289+ }
290+
291+ edir->dyn_relocs = eind->dyn_relocs;
292+ eind->dyn_relocs = NULL;
293+ }
294+
295 edir->tls_mask |= eind->tls_mask;
296
297 _bfd_elf_link_hash_copy_indirect (info, dir, ind);
298@@ -2821,8 +2945,12 @@ microblaze_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
299 struct elf_link_hash_entry *h)
300 {
301 struct elf64_mb_link_hash_table *htab;
302+ struct elf64_mb_link_hash_entry * eh;
303+ struct elf64_mb_dyn_relocs *p;
304+ asection *sdynbss;
305 asection *s, *srel;
306 unsigned int power_of_two;
307+ bfd *dynobj;
308
309 htab = elf64_mb_hash_table (info);
310 if (htab == NULL)
311@@ -2892,9 +3020,17 @@ microblaze_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
312 return true;
313 }
314
315- /* If we don't find any dynamic relocs in read-only sections, then
316+ eh = (struct elf64_mb_link_hash_entry *) h;
317+ for (p = eh->dyn_relocs; p != NULL; p = p->next)
318+ {
319+ s = p->sec->output_section;
320+ if (s != NULL && (s->flags & SEC_READONLY) != 0)
321+ break;
322+ }
323+
324+ /* If we didn't find any dynamic relocs in read-only sections, then
325 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
326- if (!_bfd_elf_readonly_dynrelocs (h))
327+ if (p == NULL)
328 {
329 h->non_got_ref = 0;
330 return true;
331@@ -2913,19 +3049,11 @@ microblaze_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
332 /* We must generate a R_MICROBLAZE_COPY reloc to tell the dynamic linker
333 to copy the initial value out of the dynamic object and into the
334 runtime process image. */
335- if ((h->root.u.def.section->flags & SEC_READONLY) != 0)
336- {
337- s = htab->elf.sdynrelro;
338- srel = htab->elf.sreldynrelro;
339- }
340- else
341- {
342- s = htab->elf.sdynbss;
343- srel = htab->elf.srelbss;
344- }
345+ dynobj = elf_hash_table (info)->dynobj;
346+ BFD_ASSERT (dynobj != NULL);
347 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
348 {
349- srel->size += sizeof (Elf64_External_Rela);
350+ htab->srelbss->size += sizeof (Elf64_External_Rela);
351 h->needs_copy = 1;
352 }
353
354@@ -2935,11 +3063,12 @@ microblaze_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
355 if (power_of_two > 3)
356 power_of_two = 3;
357
358+ sdynbss = htab->sdynbss;
359 /* Apply the required alignment. */
360- s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two));
361- if (power_of_two > s->alignment_power)
362+ sdynbss->size = BFD_ALIGN (sdynbss->size, (bfd_size_type) (1 << power_of_two));
363+ if (power_of_two > sdynbss->alignment_power)
364 {
365- if (!bfd_set_section_alignment (s, power_of_two))
366+ if (! bfd_set_section_alignment (sdynbss, power_of_two))
367 return false;
368 }
369
370@@ -2961,7 +3090,7 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void * dat)
371 struct bfd_link_info *info;
372 struct elf64_mb_link_hash_table *htab;
373 struct elf64_mb_link_hash_entry *eh;
374- struct elf_dyn_relocs *p;
375+ struct elf64_mb_dyn_relocs *p;
376
377 if (h->root.type == bfd_link_hash_indirect)
378 return true;
379@@ -3013,7 +3142,7 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void * dat)
380 htab->elf.sgotplt->size += 4;
381
382 /* We also need to make an entry in the .rel.plt section. */
383- htab->elf.srelplt->size += sizeof (Elf32_External_Rela);
384+ htab->elf.srelplt->size += sizeof (Elf64_External_Rela);
385 }
386 else
387 {
388@@ -3079,7 +3208,7 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void * dat)
389 else
390 h->got.offset = (bfd_vma) -1;
391
392- if (h->dyn_relocs == NULL)
393+ if (eh->dyn_relocs == NULL)
394 return true;
395
396 /* In the shared -Bsymbolic case, discard space allocated for
397@@ -3094,9 +3223,9 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void * dat)
398 && (h->forced_local
399 || info->symbolic))
400 {
401- struct elf_dyn_relocs **pp;
402+ struct elf64_mb_dyn_relocs **pp;
403
404- for (pp = &h->dyn_relocs; (p = *pp) != NULL; )
405+ for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
406 {
407 p->count -= p->pc_count;
408 p->pc_count = 0;
409@@ -3188,7 +3317,7 @@ microblaze_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
410 {
411 struct elf_dyn_relocs *p;
412
413- for (p = ((struct elf_dyn_relocs *)
414+ for (p = ((struct elf64_mb_dyn_relocs *)
415 elf_section_data (s)->local_dynrel);
416 p != NULL;
417 p = p->next)
418@@ -3666,13 +3795,14 @@ microblaze_elf_add_symbol_hook (bfd *abfd,
419 #define bfd_elf64_new_section_hook microblaze_elf_new_section_hook
420 #define elf_backend_relocate_section microblaze_elf_relocate_section
421 #define bfd_elf64_bfd_relax_section microblaze_elf_relax_section
422-#define bfd_elf64_bfd_merge_private_bfd_data _bfd_generic_verify_endian_match
423+#define bfd_elf64_bfd_merge_private_bfd_data microblaze_elf_merge_private_bfd_data
424 #define bfd_elf64_bfd_reloc_name_lookup microblaze_elf_reloc_name_lookup
425
426 #define elf_backend_gc_mark_hook microblaze_elf_gc_mark_hook
427-#define elf_backend_check_relocs microblaze_elf_check_relocs
428-#define elf_backend_copy_indirect_symbol microblaze_elf_copy_indirect_symbol
429-#define bfd_elf64_bfd_link_hash_table_create microblaze_elf_link_hash_table_create
430+#define elf_backend_gc_sweep_hook microblaze_elf_gc_sweep_hook
431+#define elf_backend_check_relocs microblaze_elf_check_relocs
432+#define elf_backend_copy_indirect_symbol microblaze_elf_copy_indirect_symbol
433+#define bfd_elf64_bfd_link_hash_table_create microblaze_elf_link_hash_table_create
434 #define elf_backend_can_gc_sections 1
435 #define elf_backend_can_refcount 1
436 #define elf_backend_want_got_plt 1
437@@ -3682,11 +3812,11 @@ microblaze_elf_add_symbol_hook (bfd *abfd,
438 #define elf_backend_rela_normal 1
439 #define elf_backend_dtrel_excludes_plt 1
440
441-#define elf_backend_adjust_dynamic_symbol microblaze_elf_adjust_dynamic_symbol
442-#define elf_backend_create_dynamic_sections _bfd_elf_create_dynamic_sections
443-#define elf_backend_finish_dynamic_sections microblaze_elf_finish_dynamic_sections
444-#define elf_backend_finish_dynamic_symbol microblaze_elf_finish_dynamic_symbol
445-#define elf_backend_size_dynamic_sections microblaze_elf_size_dynamic_sections
446+#define elf_backend_adjust_dynamic_symbol microblaze_elf_adjust_dynamic_symbol
447+#define elf_backend_create_dynamic_sections microblaze_elf_create_dynamic_sections
448+#define elf_backend_finish_dynamic_sections microblaze_elf_finish_dynamic_sections
449+#define elf_backend_finish_dynamic_symbol microblaze_elf_finish_dynamic_symbol
450+#define elf_backend_size_dynamic_sections microblaze_elf_size_dynamic_sections
451 #define elf_backend_add_symbol_hook microblaze_elf_add_symbol_hook
452
453 #include "elf64-target.h"
454diff --git a/gas/config/tc-microblaze.c b/gas/config/tc-microblaze.c
455index 6b398ab5605..c4a3817bf19 100644
456--- a/gas/config/tc-microblaze.c
457+++ b/gas/config/tc-microblaze.c
458@@ -433,7 +433,7 @@ const pseudo_typeS md_pseudo_table[] =
459 void
460 md_begin (void)
461 {
462- const struct op_code_struct * opcode;
463+ struct op_code_struct * opcode;
464 const char *prev_name = "";
465
466 opcode_hash_control = str_htab_create ();
467diff --git a/opcodes/microblaze-dis.c b/opcodes/microblaze-dis.c
468index b5a78dcfe09..b76a5935a34 100644
469--- a/opcodes/microblaze-dis.c
470+++ b/opcodes/microblaze-dis.c
471@@ -140,7 +140,7 @@ get_field_imm16 (struct string_buf *buf, long instr)
472
473 static char *
474 get_field_special (struct string_buf *buf, long instr,
475- const struct op_code_struct *op)
476+ struct op_code_struct *op)
477 {
478 char *p = strbuf (buf);
479 char *spr;
480@@ -213,11 +213,11 @@ get_field_special (struct string_buf *buf, long instr,
481 static unsigned long
482 read_insn_microblaze (bfd_vma memaddr,
483 struct disassemble_info *info,
484- const struct op_code_struct **opr)
485+ struct op_code_struct **opr)
486 {
487 unsigned char ibytes[4];
488 int status;
489- const struct op_code_struct *op;
490+ struct op_code_struct *op;
491 unsigned long inst;
492
493 status = info->read_memory_func (memaddr, ibytes, 4, info);
494@@ -253,7 +253,7 @@ print_insn_microblaze (bfd_vma memaddr, struct disassemble_info * info)
495 fprintf_ftype print_func = info->fprintf_func;
496 void *stream = info->stream;
497 unsigned long inst, prev_inst;
498- const struct op_code_struct *op, *pop;
499+ struct op_code_struct *op, *pop;
500 int immval = 0;
501 bool immfound = false;
502 static bfd_vma prev_insn_addr = -1; /* Init the prev insn addr. */
503@@ -497,7 +497,7 @@ get_insn_microblaze (long inst,
504 enum microblaze_instr_type *insn_type,
505 short *delay_slots)
506 {
507- const struct op_code_struct *op;
508+ struct op_code_struct *op;
509 *isunsignedimm = false;
510
511 /* Just a linear search of the table. */
512@@ -539,7 +539,7 @@ microblaze_get_target_address (long inst, bool immfound, int immval,
513 bool *targetvalid,
514 bool *unconditionalbranch)
515 {
516- const struct op_code_struct *op;
517+ struct op_code_struct *op;
518 long targetaddr = 0;
519
520 *unconditionalbranch = false;
521diff --git a/opcodes/microblaze-opc.h b/opcodes/microblaze-opc.h
522index e65f4b58233..4a415495113 100644
523--- a/opcodes/microblaze-opc.h
524+++ b/opcodes/microblaze-opc.h
525@@ -145,7 +145,7 @@
526
527 #define MAX_OPCODES 424
528
529-const struct op_code_struct
530+struct op_code_struct
531 {
532 const char * name;
533 short inst_type; /* Registers and immediate values involved. */
534--
5352.37.1 (Apple Git-137.1)
536