summaryrefslogtreecommitdiffstats
path: root/meta-microblaze/recipes-devtools/gdb/gdb/0015-intial-commit-of-MB-64-bit.patch
diff options
context:
space:
mode:
Diffstat (limited to 'meta-microblaze/recipes-devtools/gdb/gdb/0015-intial-commit-of-MB-64-bit.patch')
-rw-r--r--meta-microblaze/recipes-devtools/gdb/gdb/0015-intial-commit-of-MB-64-bit.patch4186
1 files changed, 4186 insertions, 0 deletions
diff --git a/meta-microblaze/recipes-devtools/gdb/gdb/0015-intial-commit-of-MB-64-bit.patch b/meta-microblaze/recipes-devtools/gdb/gdb/0015-intial-commit-of-MB-64-bit.patch
new file mode 100644
index 00000000..96cab28a
--- /dev/null
+++ b/meta-microblaze/recipes-devtools/gdb/gdb/0015-intial-commit-of-MB-64-bit.patch
@@ -0,0 +1,4186 @@
1From b42fae987795bb210476dcaa5e086f42602208f8 Mon Sep 17 00:00:00 2001
2From: Nagaraju Mekala <nmekala@xilix.com>
3Date: Sun, 30 Sep 2018 16:28:28 +0530
4Subject: [PATCH 15/43] intial commit of MB 64-bit
5
6---
7 bfd/Makefile.am | 2 +
8 bfd/Makefile.in | 3 +
9 bfd/config.bfd | 4 +
10 bfd/configure | 2 +
11 bfd/configure.ac | 2 +
12 bfd/cpu-microblaze.c | 52 +-
13 bfd/elf64-microblaze.c | 3584 ++++++++++++++++++++++++++++
14 bfd/targets.c | 6 +
15 include/elf/common.h | 1 +
16 opcodes/microblaze-dis.c | 39 +-
17 opcodes/microblaze-opc.h | 162 +-
18 opcodes/microblaze-opcm.h | 20 +-
19 19 files changed, 4181 insertions(+), 41 deletions(-)
20 create mode 100644 bfd/elf64-microblaze.c
21
22diff --git a/bfd/Makefile.am b/bfd/Makefile.am
23index a9191555ad..c5fd250812 100644
24--- a/bfd/Makefile.am
25+++ b/bfd/Makefile.am
26@@ -570,6 +570,7 @@ BFD64_BACKENDS = \
27 elf64-riscv.lo \
28 elfxx-riscv.lo \
29 elf64-s390.lo \
30+ elf64-microblaze.lo \
31 elf64-sparc.lo \
32 elf64-tilegx.lo \
33 elf64-x86-64.lo \
34@@ -603,6 +604,7 @@ BFD64_BACKENDS_CFILES = \
35 elf64-nfp.c \
36 elf64-ppc.c \
37 elf64-s390.c \
38+ elf64-microblaze.c \
39 elf64-sparc.c \
40 elf64-tilegx.c \
41 elf64-x86-64.c \
42diff --git a/bfd/Makefile.in b/bfd/Makefile.in
43index 896df52042..fd457cba1e 100644
44--- a/bfd/Makefile.in
45+++ b/bfd/Makefile.in
46@@ -995,6 +995,7 @@ BFD64_BACKENDS = \
47 elf64-riscv.lo \
48 elfxx-riscv.lo \
49 elf64-s390.lo \
50+ elf64-microblaze.lo \
51 elf64-sparc.lo \
52 elf64-tilegx.lo \
53 elf64-x86-64.lo \
54@@ -1028,6 +1029,7 @@ BFD64_BACKENDS_CFILES = \
55 elf64-nfp.c \
56 elf64-ppc.c \
57 elf64-s390.c \
58+ elf64-microblaze.c \
59 elf64-sparc.c \
60 elf64-tilegx.c \
61 elf64-x86-64.c \
62@@ -1494,6 +1496,7 @@ distclean-compile:
63 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/elf64-ppc.Plo@am__quote@
64 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/elf64-riscv.Plo@am__quote@
65 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/elf64-s390.Plo@am__quote@
66+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/elf64-microblaze.Plo@am__quote@
67 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/elf64-sparc.Plo@am__quote@
68 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/elf64-tilegx.Plo@am__quote@
69 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/elf64-x86-64.Plo@am__quote@
70diff --git a/bfd/config.bfd b/bfd/config.bfd
71index f13812b7c7..a98c220db5 100644
72--- a/bfd/config.bfd
73+++ b/bfd/config.bfd
74@@ -850,11 +850,15 @@ case "${targ}" in
75 microblazeel*-*)
76 targ_defvec=microblaze_elf32_le_vec
77 targ_selvecs=microblaze_elf32_vec
78+ targ64_selvecs=microblaze_elf64_vec
79+ targ64_selvecs=microblaze_elf64_le_vec
80 ;;
81
82 microblaze*-*)
83 targ_defvec=microblaze_elf32_vec
84 targ_selvecs=microblaze_elf32_le_vec
85+ targ64_selvecs=microblaze_elf64_vec
86+ targ64_selvecs=microblaze_elf64_le_vec
87 ;;
88
89 #ifdef BFD64
90diff --git a/bfd/configure b/bfd/configure
91index 8d6c94aef2..3defb1f784 100755
92--- a/bfd/configure
93+++ b/bfd/configure
94@@ -14847,6 +14847,8 @@ do
95 rx_elf32_linux_le_vec) tb="$tb elf32-rx.lo elf32.lo $elf" ;;
96 s390_elf32_vec) tb="$tb elf32-s390.lo elf32.lo $elf" ;;
97 s390_elf64_vec) tb="$tb elf64-s390.lo elf64.lo $elf"; target_size=64 ;;
98+ microblaze_elf64_vec) tb="$tb elf64-microblaze.lo elf64.lo $elf"; target_size=64 ;;
99+ microblaze_elf64_le_vec) tb="$tb elf64-microblaze.lo elf64.lo $elf"; target_size=64 ;;
100 score_elf32_be_vec) tb="$tb elf32-score.lo elf32-score7.lo elf32.lo $elf"; want64=true; target_size=64 ;;
101 score_elf32_le_vec) tb="$tb elf32-score.lo elf32-score7.lo elf32.lo $elf"; want64=true; target_size=64 ;;
102 sh_coff_vec) tb="$tb coff-sh.lo $coff" ;;
103diff --git a/bfd/configure.ac b/bfd/configure.ac
104index 5f02c41520..d3010b47dc 100644
105--- a/bfd/configure.ac
106+++ b/bfd/configure.ac
107@@ -615,6 +615,8 @@ do
108 rx_elf32_linux_le_vec) tb="$tb elf32-rx.lo elf32.lo $elf" ;;
109 s390_elf32_vec) tb="$tb elf32-s390.lo elf32.lo $elf" ;;
110 s390_elf64_vec) tb="$tb elf64-s390.lo elf64.lo $elf"; target_size=64 ;;
111+ microblaze_elf64_vec) tb="$tb elf64-microblaze.lo elf64.lo $elf"; target_size=64 ;;
112+ microblaze_elf64_le_vec) tb="$tb elf64-microblaze.lo elf64.lo $elf"; target_size=64 ;;
113 score_elf32_be_vec) tb="$tb elf32-score.lo elf32-score7.lo elf32.lo $elf"; want64=true; target_size=64 ;;
114 score_elf32_le_vec) tb="$tb elf32-score.lo elf32-score7.lo elf32.lo $elf"; want64=true; target_size=64 ;;
115 sh_coff_vec) tb="$tb coff-sh.lo $coff" ;;
116diff --git a/bfd/cpu-microblaze.c b/bfd/cpu-microblaze.c
117index 9bc2eb3de9..c91ba46f75 100644
118--- a/bfd/cpu-microblaze.c
119+++ b/bfd/cpu-microblaze.c
120@@ -23,7 +23,24 @@
121 #include "bfd.h"
122 #include "libbfd.h"
123
124-const bfd_arch_info_type bfd_microblaze_arch =
125+const bfd_arch_info_type bfd_microblaze_arch[] =
126+{
127+#if BFD_DEFAULT_TARGET_SIZE == 64
128+{
129+ 64, /* 32 bits in a word. */
130+ 64, /* 32 bits in an address. */
131+ 8, /* 8 bits in a byte. */
132+ bfd_arch_microblaze, /* Architecture. */
133+ 0, /* Machine number - 0 for now. */
134+ "microblaze", /* Architecture name. */
135+ "MicroBlaze", /* Printable name. */
136+ 3, /* Section align power. */
137+ FALSE, /* Is this the default architecture ? */
138+ bfd_default_compatible, /* Architecture comparison function. */
139+ bfd_default_scan, /* String to architecture conversion. */
140+ bfd_arch_default_fill, /* Default fill. */
141+ &bfd_microblaze_arch[1] /* Next in list. */
142+},
143 {
144 32, /* 32 bits in a word. */
145 32, /* 32 bits in an address. */
146@@ -38,4 +55,37 @@ const bfd_arch_info_type bfd_microblaze_arch =
147 bfd_default_scan, /* String to architecture conversion. */
148 bfd_arch_default_fill, /* Default fill. */
149 NULL /* Next in list. */
150+}
151+#else
152+{
153+ 32, /* 32 bits in a word. */
154+ 32, /* 32 bits in an address. */
155+ 8, /* 8 bits in a byte. */
156+ bfd_arch_microblaze, /* Architecture. */
157+ 0, /* Machine number - 0 for now. */
158+ "microblaze", /* Architecture name. */
159+ "MicroBlaze", /* Printable name. */
160+ 3, /* Section align power. */
161+ TRUE, /* Is this the default architecture ? */
162+ bfd_default_compatible, /* Architecture comparison function. */
163+ bfd_default_scan, /* String to architecture conversion. */
164+ bfd_arch_default_fill, /* Default fill. */
165+ &bfd_microblaze_arch[1] /* Next in list. */
166+},
167+{
168+ 64, /* 32 bits in a word. */
169+ 64, /* 32 bits in an address. */
170+ 8, /* 8 bits in a byte. */
171+ bfd_arch_microblaze, /* Architecture. */
172+ 0, /* Machine number - 0 for now. */
173+ "microblaze", /* Architecture name. */
174+ "MicroBlaze", /* Printable name. */
175+ 3, /* Section align power. */
176+ FALSE, /* Is this the default architecture ? */
177+ bfd_default_compatible, /* Architecture comparison function. */
178+ bfd_default_scan, /* String to architecture conversion. */
179+ bfd_arch_default_fill, /* Default fill. */
180+ NULL /* Next in list. */
181+}
182+#endif
183 };
184diff --git a/bfd/elf64-microblaze.c b/bfd/elf64-microblaze.c
185new file mode 100644
186index 0000000000..0f43ae6ea8
187--- /dev/null
188+++ b/bfd/elf64-microblaze.c
189@@ -0,0 +1,3584 @@
190+/* Xilinx MicroBlaze-specific support for 32-bit ELF
191+
192+ Copyright (C) 2009-2016 Free Software Foundation, Inc.
193+
194+ This file is part of BFD, the Binary File Descriptor library.
195+
196+ This program is free software; you can redistribute it and/or modify
197+ it under the terms of the GNU General Public License as published by
198+ the Free Software Foundation; either version 3 of the License, or
199+ (at your option) any later version.
200+
201+ This program is distributed in the hope that it will be useful,
202+ but WITHOUT ANY WARRANTY; without even the implied warranty of
203+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
204+ GNU General Public License for more details.
205+
206+ You should have received a copy of the GNU General Public License
207+ along with this program; if not, write to the
208+ Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
209+ Boston, MA 02110-1301, USA. */
210+
211+
212+int dbg1 = 0;
213+
214+#include "sysdep.h"
215+#include "bfd.h"
216+#include "bfdlink.h"
217+#include "libbfd.h"
218+#include "elf-bfd.h"
219+#include "elf/microblaze.h"
220+#include <assert.h>
221+
222+#define USE_RELA /* Only USE_REL is actually significant, but this is
223+ here are a reminder... */
224+#define INST_WORD_SIZE 4
225+
226+static int ro_small_data_pointer = 0;
227+static int rw_small_data_pointer = 0;
228+
229+static reloc_howto_type * microblaze_elf_howto_table [(int) R_MICROBLAZE_max];
230+
231+static reloc_howto_type microblaze_elf_howto_raw[] =
232+{
233+ /* This reloc does nothing. */
234+ HOWTO (R_MICROBLAZE_NONE, /* Type. */
235+ 0, /* Rightshift. */
236+ 3, /* Size (0 = byte, 1 = short, 2 = long). */
237+ 0, /* Bitsize. */
238+ FALSE, /* PC_relative. */
239+ 0, /* Bitpos. */
240+ complain_overflow_dont, /* Complain on overflow. */
241+ NULL, /* Special Function. */
242+ "R_MICROBLAZE_NONE", /* Name. */
243+ FALSE, /* Partial Inplace. */
244+ 0, /* Source Mask. */
245+ 0, /* Dest Mask. */
246+ FALSE), /* PC relative offset? */
247+
248+ /* A standard 32 bit relocation. */
249+ HOWTO (R_MICROBLAZE_32, /* Type. */
250+ 0, /* Rightshift. */
251+ 2, /* Size (0 = byte, 1 = short, 2 = long). */
252+ 32, /* Bitsize. */
253+ FALSE, /* PC_relative. */
254+ 0, /* Bitpos. */
255+ complain_overflow_bitfield, /* Complain on overflow. */
256+ bfd_elf_generic_reloc,/* Special Function. */
257+ "R_MICROBLAZE_32", /* Name. */
258+ FALSE, /* Partial Inplace. */
259+ 0, /* Source Mask. */
260+ 0xffffffff, /* Dest Mask. */
261+ FALSE), /* PC relative offset? */
262+
263+ /* A standard PCREL 32 bit relocation. */
264+ HOWTO (R_MICROBLAZE_32_PCREL,/* Type. */
265+ 0, /* Rightshift. */
266+ 2, /* Size (0 = byte, 1 = short, 2 = long). */
267+ 32, /* Bitsize. */
268+ TRUE, /* PC_relative. */
269+ 0, /* Bitpos. */
270+ complain_overflow_bitfield, /* Complain on overflow. */
271+ bfd_elf_generic_reloc,/* Special Function. */
272+ "R_MICROBLAZE_32_PCREL", /* Name. */
273+ TRUE, /* Partial Inplace. */
274+ 0, /* Source Mask. */
275+ 0xffffffff, /* Dest Mask. */
276+ TRUE), /* PC relative offset? */
277+
278+ /* A 64 bit PCREL relocation. Table-entry not really used. */
279+ HOWTO (R_MICROBLAZE_64_PCREL,/* Type. */
280+ 0, /* Rightshift. */
281+ 4, /* Size (0 = byte, 1 = short, 2 = long). */
282+ 64, /* Bitsize. */
283+ TRUE, /* PC_relative. */
284+ 0, /* Bitpos. */
285+ complain_overflow_dont, /* Complain on overflow. */
286+ bfd_elf_generic_reloc,/* Special Function. */
287+ "R_MICROBLAZE_64_PCREL", /* Name. */
288+ FALSE, /* Partial Inplace. */
289+ 0, /* Source Mask. */
290+ 0x0000ffff, /* Dest Mask. */
291+ TRUE), /* PC relative offset? */
292+
293+ /* The low half of a PCREL 32 bit relocation. */
294+ HOWTO (R_MICROBLAZE_32_PCREL_LO, /* Type. */
295+ 0, /* Rightshift. */
296+ 2, /* Size (0 = byte, 1 = short, 2 = long). */
297+ 16, /* Bitsize. */
298+ TRUE, /* PC_relative. */
299+ 0, /* Bitpos. */
300+ complain_overflow_signed, /* Complain on overflow. */
301+ bfd_elf_generic_reloc, /* Special Function. */
302+ "R_MICROBLAZE_32_PCREL_LO", /* Name. */
303+ FALSE, /* Partial Inplace. */
304+ 0, /* Source Mask. */
305+ 0x0000ffff, /* Dest Mask. */
306+ TRUE), /* PC relative offset? */
307+
308+ /* A 64 bit relocation. Table entry not really used. */
309+ HOWTO (R_MICROBLAZE_64, /* Type. */
310+ 0, /* Rightshift. */
311+ 2, /* Size (0 = byte, 1 = short, 2 = long). */
312+ 16, /* Bitsize. */
313+ FALSE, /* PC_relative. */
314+ 0, /* Bitpos. */
315+ complain_overflow_dont, /* Complain on overflow. */
316+ bfd_elf_generic_reloc,/* Special Function. */
317+ "R_MICROBLAZE_64", /* Name. */
318+ FALSE, /* Partial Inplace. */
319+ 0, /* Source Mask. */
320+ 0x0000ffff, /* Dest Mask. */
321+ FALSE), /* PC relative offset? */
322+
323+ /* The low half of a 32 bit relocation. */
324+ HOWTO (R_MICROBLAZE_32_LO, /* Type. */
325+ 0, /* Rightshift. */
326+ 2, /* Size (0 = byte, 1 = short, 2 = long). */
327+ 16, /* Bitsize. */
328+ FALSE, /* PC_relative. */
329+ 0, /* Bitpos. */
330+ complain_overflow_signed, /* Complain on overflow. */
331+ bfd_elf_generic_reloc,/* Special Function. */
332+ "R_MICROBLAZE_32_LO", /* Name. */
333+ FALSE, /* Partial Inplace. */
334+ 0, /* Source Mask. */
335+ 0x0000ffff, /* Dest Mask. */
336+ FALSE), /* PC relative offset? */
337+
338+ /* Read-only small data section relocation. */
339+ HOWTO (R_MICROBLAZE_SRO32, /* Type. */
340+ 0, /* Rightshift. */
341+ 2, /* Size (0 = byte, 1 = short, 2 = long). */
342+ 16, /* Bitsize. */
343+ FALSE, /* PC_relative. */
344+ 0, /* Bitpos. */
345+ complain_overflow_bitfield, /* Complain on overflow. */
346+ bfd_elf_generic_reloc,/* Special Function. */
347+ "R_MICROBLAZE_SRO32", /* Name. */
348+ FALSE, /* Partial Inplace. */
349+ 0, /* Source Mask. */
350+ 0x0000ffff, /* Dest Mask. */
351+ FALSE), /* PC relative offset? */
352+
353+ /* Read-write small data area relocation. */
354+ HOWTO (R_MICROBLAZE_SRW32, /* Type. */
355+ 0, /* Rightshift. */
356+ 2, /* Size (0 = byte, 1 = short, 2 = long). */
357+ 16, /* Bitsize. */
358+ FALSE, /* PC_relative. */
359+ 0, /* Bitpos. */
360+ complain_overflow_bitfield, /* Complain on overflow. */
361+ bfd_elf_generic_reloc,/* Special Function. */
362+ "R_MICROBLAZE_SRW32", /* Name. */
363+ FALSE, /* Partial Inplace. */
364+ 0, /* Source Mask. */
365+ 0x0000ffff, /* Dest Mask. */
366+ FALSE), /* PC relative offset? */
367+
368+ HOWTO (R_MICROBLAZE_32_NONE, /* Type. */
369+ 0, /* Rightshift. */
370+ 2, /* Size (0 = byte, 1 = short, 2 = long). */
371+ 32, /* Bitsize. */
372+ TRUE, /* PC_relative. */
373+ 0, /* Bitpos. */
374+ complain_overflow_bitfield, /* Complain on overflow. */
375+ NULL, /* Special Function. */
376+ "R_MICROBLAZE_32_NONE",/* Name. */
377+ FALSE, /* Partial Inplace. */
378+ 0, /* Source Mask. */
379+ 0, /* Dest Mask. */
380+ FALSE), /* PC relative offset? */
381+
382+ /* This reloc does nothing. Used for relaxation. */
383+ HOWTO (R_MICROBLAZE_64_NONE, /* Type. */
384+ 0, /* Rightshift. */
385+ 3, /* Size (0 = byte, 1 = short, 2 = long). */
386+ 0, /* Bitsize. */
387+ TRUE, /* PC_relative. */
388+ 0, /* Bitpos. */
389+ complain_overflow_dont, /* Complain on overflow. */
390+ NULL, /* Special Function. */
391+ "R_MICROBLAZE_64_NONE",/* Name. */
392+ FALSE, /* Partial Inplace. */
393+ 0, /* Source Mask. */
394+ 0, /* Dest Mask. */
395+ FALSE), /* PC relative offset? */
396+
397+ /* Symbol Op Symbol relocation. */
398+ HOWTO (R_MICROBLAZE_32_SYM_OP_SYM, /* Type. */
399+ 0, /* Rightshift. */
400+ 2, /* Size (0 = byte, 1 = short, 2 = long). */
401+ 32, /* Bitsize. */
402+ FALSE, /* PC_relative. */
403+ 0, /* Bitpos. */
404+ complain_overflow_bitfield, /* Complain on overflow. */
405+ bfd_elf_generic_reloc,/* Special Function. */
406+ "R_MICROBLAZE_32_SYM_OP_SYM", /* Name. */
407+ FALSE, /* Partial Inplace. */
408+ 0, /* Source Mask. */
409+ 0xffffffff, /* Dest Mask. */
410+ FALSE), /* PC relative offset? */
411+
412+ /* GNU extension to record C++ vtable hierarchy. */
413+ HOWTO (R_MICROBLAZE_GNU_VTINHERIT, /* Type. */
414+ 0, /* Rightshift. */
415+ 2, /* Size (0 = byte, 1 = short, 2 = long). */
416+ 0, /* Bitsize. */
417+ FALSE, /* PC_relative. */
418+ 0, /* Bitpos. */
419+ complain_overflow_dont,/* Complain on overflow. */
420+ NULL, /* Special Function. */
421+ "R_MICROBLAZE_GNU_VTINHERIT", /* Name. */
422+ FALSE, /* Partial Inplace. */
423+ 0, /* Source Mask. */
424+ 0, /* Dest Mask. */
425+ FALSE), /* PC relative offset? */
426+
427+ /* GNU extension to record C++ vtable member usage. */
428+ HOWTO (R_MICROBLAZE_GNU_VTENTRY, /* Type. */
429+ 0, /* Rightshift. */
430+ 2, /* Size (0 = byte, 1 = short, 2 = long). */
431+ 0, /* Bitsize. */
432+ FALSE, /* PC_relative. */
433+ 0, /* Bitpos. */
434+ complain_overflow_dont,/* Complain on overflow. */
435+ _bfd_elf_rel_vtable_reloc_fn, /* Special Function. */
436+ "R_MICROBLAZE_GNU_VTENTRY", /* Name. */
437+ FALSE, /* Partial Inplace. */
438+ 0, /* Source Mask. */
439+ 0, /* Dest Mask. */
440+ FALSE), /* PC relative offset? */
441+
442+ /* A 64 bit GOTPC relocation. Table-entry not really used. */
443+ HOWTO (R_MICROBLAZE_GOTPC_64, /* Type. */
444+ 0, /* Rightshift. */
445+ 2, /* Size (0 = byte, 1 = short, 2 = long). */
446+ 16, /* Bitsize. */
447+ TRUE, /* PC_relative. */
448+ 0, /* Bitpos. */
449+ complain_overflow_dont, /* Complain on overflow. */
450+ bfd_elf_generic_reloc, /* Special Function. */
451+ "R_MICROBLAZE_GOTPC_64", /* Name. */
452+ FALSE, /* Partial Inplace. */
453+ 0, /* Source Mask. */
454+ 0x0000ffff, /* Dest Mask. */
455+ TRUE), /* PC relative offset? */
456+
457+ /* A 64 bit GOT relocation. Table-entry not really used. */
458+ HOWTO (R_MICROBLAZE_GOT_64, /* Type. */
459+ 0, /* Rightshift. */
460+ 2, /* Size (0 = byte, 1 = short, 2 = long). */
461+ 16, /* Bitsize. */
462+ FALSE, /* PC_relative. */
463+ 0, /* Bitpos. */
464+ complain_overflow_dont, /* Complain on overflow. */
465+ bfd_elf_generic_reloc,/* Special Function. */
466+ "R_MICROBLAZE_GOT_64",/* Name. */
467+ FALSE, /* Partial Inplace. */
468+ 0, /* Source Mask. */
469+ 0x0000ffff, /* Dest Mask. */
470+ FALSE), /* PC relative offset? */
471+
472+ /* A 64 bit PLT relocation. Table-entry not really used. */
473+ HOWTO (R_MICROBLAZE_PLT_64, /* Type. */
474+ 0, /* Rightshift. */
475+ 2, /* Size (0 = byte, 1 = short, 2 = long). */
476+ 16, /* Bitsize. */
477+ TRUE, /* PC_relative. */
478+ 0, /* Bitpos. */
479+ complain_overflow_dont, /* Complain on overflow. */
480+ bfd_elf_generic_reloc,/* Special Function. */
481+ "R_MICROBLAZE_PLT_64",/* Name. */
482+ FALSE, /* Partial Inplace. */
483+ 0, /* Source Mask. */
484+ 0x0000ffff, /* Dest Mask. */
485+ TRUE), /* PC relative offset? */
486+
487+ /* Table-entry not really used. */
488+ HOWTO (R_MICROBLAZE_REL, /* Type. */
489+ 0, /* Rightshift. */
490+ 2, /* Size (0 = byte, 1 = short, 2 = long). */
491+ 16, /* Bitsize. */
492+ TRUE, /* PC_relative. */
493+ 0, /* Bitpos. */
494+ complain_overflow_dont, /* Complain on overflow. */
495+ bfd_elf_generic_reloc,/* Special Function. */
496+ "R_MICROBLAZE_REL", /* Name. */
497+ FALSE, /* Partial Inplace. */
498+ 0, /* Source Mask. */
499+ 0x0000ffff, /* Dest Mask. */
500+ TRUE), /* PC relative offset? */
501+
502+ /* Table-entry not really used. */
503+ HOWTO (R_MICROBLAZE_JUMP_SLOT,/* Type. */
504+ 0, /* Rightshift. */
505+ 2, /* Size (0 = byte, 1 = short, 2 = long). */
506+ 16, /* Bitsize. */
507+ TRUE, /* PC_relative. */
508+ 0, /* Bitpos. */
509+ complain_overflow_dont, /* Complain on overflow. */
510+ bfd_elf_generic_reloc,/* Special Function. */
511+ "R_MICROBLAZE_JUMP_SLOT", /* Name. */
512+ FALSE, /* Partial Inplace. */
513+ 0, /* Source Mask. */
514+ 0x0000ffff, /* Dest Mask. */
515+ TRUE), /* PC relative offset? */
516+
517+ /* Table-entry not really used. */
518+ HOWTO (R_MICROBLAZE_GLOB_DAT,/* Type. */
519+ 0, /* Rightshift. */
520+ 2, /* Size (0 = byte, 1 = short, 2 = long). */
521+ 16, /* Bitsize. */
522+ TRUE, /* PC_relative. */
523+ 0, /* Bitpos. */
524+ complain_overflow_dont, /* Complain on overflow. */
525+ bfd_elf_generic_reloc,/* Special Function. */
526+ "R_MICROBLAZE_GLOB_DAT", /* Name. */
527+ FALSE, /* Partial Inplace. */
528+ 0, /* Source Mask. */
529+ 0x0000ffff, /* Dest Mask. */
530+ TRUE), /* PC relative offset? */
531+
532+ /* A 64 bit GOT relative relocation. Table-entry not really used. */
533+ HOWTO (R_MICROBLAZE_GOTOFF_64, /* Type. */
534+ 0, /* Rightshift. */
535+ 2, /* Size (0 = byte, 1 = short, 2 = long). */
536+ 16, /* Bitsize. */
537+ FALSE, /* PC_relative. */
538+ 0, /* Bitpos. */
539+ complain_overflow_dont, /* Complain on overflow. */
540+ bfd_elf_generic_reloc,/* Special Function. */
541+ "R_MICROBLAZE_GOTOFF_64", /* Name. */
542+ FALSE, /* Partial Inplace. */
543+ 0, /* Source Mask. */
544+ 0x0000ffff, /* Dest Mask. */
545+ FALSE), /* PC relative offset? */
546+
547+ /* A 32 bit GOT relative relocation. Table-entry not really used. */
548+ HOWTO (R_MICROBLAZE_GOTOFF_32, /* Type. */
549+ 0, /* Rightshift. */
550+ 2, /* Size (0 = byte, 1 = short, 2 = long). */
551+ 16, /* Bitsize. */
552+ FALSE, /* PC_relative. */
553+ 0, /* Bitpos. */
554+ complain_overflow_dont, /* Complain on overflow. */
555+ bfd_elf_generic_reloc, /* Special Function. */
556+ "R_MICROBLAZE_GOTOFF_32", /* Name. */
557+ FALSE, /* Partial Inplace. */
558+ 0, /* Source Mask. */
559+ 0x0000ffff, /* Dest Mask. */
560+ FALSE), /* PC relative offset? */
561+
562+ /* COPY relocation. Table-entry not really used. */
563+ HOWTO (R_MICROBLAZE_COPY, /* Type. */
564+ 0, /* Rightshift. */
565+ 2, /* Size (0 = byte, 1 = short, 2 = long). */
566+ 16, /* Bitsize. */
567+ FALSE, /* PC_relative. */
568+ 0, /* Bitpos. */
569+ complain_overflow_dont, /* Complain on overflow. */
570+ bfd_elf_generic_reloc,/* Special Function. */
571+ "R_MICROBLAZE_COPY", /* Name. */
572+ FALSE, /* Partial Inplace. */
573+ 0, /* Source Mask. */
574+ 0x0000ffff, /* Dest Mask. */
575+ FALSE), /* PC relative offset? */
576+
577+ /* Marker relocs for TLS. */
578+ HOWTO (R_MICROBLAZE_TLS,
579+ 0, /* rightshift */
580+ 2, /* size (0 = byte, 1 = short, 2 = long) */
581+ 32, /* bitsize */
582+ FALSE, /* pc_relative */
583+ 0, /* bitpos */
584+ complain_overflow_dont, /* complain_on_overflow */
585+ bfd_elf_generic_reloc, /* special_function */
586+ "R_MICROBLAZE_TLS", /* name */
587+ FALSE, /* partial_inplace */
588+ 0, /* src_mask */
589+ 0x0000ffff, /* dst_mask */
590+ FALSE), /* pcrel_offset */
591+
592+ HOWTO (R_MICROBLAZE_TLSGD,
593+ 0, /* rightshift */
594+ 2, /* size (0 = byte, 1 = short, 2 = long) */
595+ 32, /* bitsize */
596+ FALSE, /* pc_relative */
597+ 0, /* bitpos */
598+ complain_overflow_dont, /* complain_on_overflow */
599+ bfd_elf_generic_reloc, /* special_function */
600+ "R_MICROBLAZE_TLSGD", /* name */
601+ FALSE, /* partial_inplace */
602+ 0, /* src_mask */
603+ 0x0000ffff, /* dst_mask */
604+ FALSE), /* pcrel_offset */
605+
606+ HOWTO (R_MICROBLAZE_TLSLD,
607+ 0, /* rightshift */
608+ 2, /* size (0 = byte, 1 = short, 2 = long) */
609+ 32, /* bitsize */
610+ FALSE, /* pc_relative */
611+ 0, /* bitpos */
612+ complain_overflow_dont, /* complain_on_overflow */
613+ bfd_elf_generic_reloc, /* special_function */
614+ "R_MICROBLAZE_TLSLD", /* name */
615+ FALSE, /* partial_inplace */
616+ 0, /* src_mask */
617+ 0x0000ffff, /* dst_mask */
618+ FALSE), /* pcrel_offset */
619+
620+ /* Computes the load module index of the load module that contains the
621+ definition of its TLS sym. */
622+ HOWTO (R_MICROBLAZE_TLSDTPMOD32,
623+ 0, /* rightshift */
624+ 2, /* size (0 = byte, 1 = short, 2 = long) */
625+ 32, /* bitsize */
626+ FALSE, /* pc_relative */
627+ 0, /* bitpos */
628+ complain_overflow_dont, /* complain_on_overflow */
629+ bfd_elf_generic_reloc, /* special_function */
630+ "R_MICROBLAZE_TLSDTPMOD32", /* name */
631+ FALSE, /* partial_inplace */
632+ 0, /* src_mask */
633+ 0x0000ffff, /* dst_mask */
634+ FALSE), /* pcrel_offset */
635+
636+ /* Computes a dtv-relative displacement, the difference between the value
637+ of sym+add and the base address of the thread-local storage block that
638+ contains the definition of sym, minus 0x8000. Used for initializing GOT */
639+ HOWTO (R_MICROBLAZE_TLSDTPREL32,
640+ 0, /* rightshift */
641+ 2, /* size (0 = byte, 1 = short, 2 = long) */
642+ 32, /* bitsize */
643+ FALSE, /* pc_relative */
644+ 0, /* bitpos */
645+ complain_overflow_dont, /* complain_on_overflow */
646+ bfd_elf_generic_reloc, /* special_function */
647+ "R_MICROBLAZE_TLSDTPREL32", /* name */
648+ FALSE, /* partial_inplace */
649+ 0, /* src_mask */
650+ 0x0000ffff, /* dst_mask */
651+ FALSE), /* pcrel_offset */
652+
653+ /* Computes a dtv-relative displacement, the difference between the value
654+ of sym+add and the base address of the thread-local storage block that
655+ contains the definition of sym, minus 0x8000. */
656+ HOWTO (R_MICROBLAZE_TLSDTPREL64,
657+ 0, /* rightshift */
658+ 2, /* size (0 = byte, 1 = short, 2 = long) */
659+ 32, /* bitsize */
660+ FALSE, /* pc_relative */
661+ 0, /* bitpos */
662+ complain_overflow_dont, /* complain_on_overflow */
663+ bfd_elf_generic_reloc, /* special_function */
664+ "R_MICROBLAZE_TLSDTPREL64", /* name */
665+ FALSE, /* partial_inplace */
666+ 0, /* src_mask */
667+ 0x0000ffff, /* dst_mask */
668+ FALSE), /* pcrel_offset */
669+
670+ /* Computes a tp-relative displacement, the difference between the value of
671+ sym+add and the value of the thread pointer (r13). */
672+ HOWTO (R_MICROBLAZE_TLSGOTTPREL32,
673+ 0, /* rightshift */
674+ 2, /* size (0 = byte, 1 = short, 2 = long) */
675+ 32, /* bitsize */
676+ FALSE, /* pc_relative */
677+ 0, /* bitpos */
678+ complain_overflow_dont, /* complain_on_overflow */
679+ bfd_elf_generic_reloc, /* special_function */
680+ "R_MICROBLAZE_TLSGOTTPREL32", /* name */
681+ FALSE, /* partial_inplace */
682+ 0, /* src_mask */
683+ 0x0000ffff, /* dst_mask */
684+ FALSE), /* pcrel_offset */
685+
686+ /* Computes a tp-relative displacement, the difference between the value of
687+ sym+add and the value of the thread pointer (r13). */
688+ HOWTO (R_MICROBLAZE_TLSTPREL32,
689+ 0, /* rightshift */
690+ 2, /* size (0 = byte, 1 = short, 2 = long) */
691+ 32, /* bitsize */
692+ FALSE, /* pc_relative */
693+ 0, /* bitpos */
694+ complain_overflow_dont, /* complain_on_overflow */
695+ bfd_elf_generic_reloc, /* special_function */
696+ "R_MICROBLAZE_TLSTPREL32", /* name */
697+ FALSE, /* partial_inplace */
698+ 0, /* src_mask */
699+ 0x0000ffff, /* dst_mask */
700+ FALSE), /* pcrel_offset */
701+
702+};
703+
704+#ifndef NUM_ELEM
705+#define NUM_ELEM(a) (sizeof (a) / sizeof (a)[0])
706+#endif
707+
708+/* Initialize the microblaze_elf_howto_table, so that linear accesses can be done. */
709+
710+static void
711+microblaze_elf_howto_init (void)
712+{
713+ unsigned int i;
714+
715+ for (i = NUM_ELEM (microblaze_elf_howto_raw); i--;)
716+ {
717+ unsigned int type;
718+
719+ type = microblaze_elf_howto_raw[i].type;
720+
721+ BFD_ASSERT (type < NUM_ELEM (microblaze_elf_howto_table));
722+
723+ microblaze_elf_howto_table [type] = & microblaze_elf_howto_raw [i];
724+ }
725+}
726+
727+static reloc_howto_type *
728+microblaze_elf_reloc_type_lookup (bfd * abfd ATTRIBUTE_UNUSED,
729+ bfd_reloc_code_real_type code)
730+{
731+ enum elf_microblaze_reloc_type microblaze_reloc = R_MICROBLAZE_NONE;
732+
733+ switch (code)
734+ {
735+ case BFD_RELOC_NONE:
736+ microblaze_reloc = R_MICROBLAZE_NONE;
737+ break;
738+ case BFD_RELOC_MICROBLAZE_32_NONE:
739+ microblaze_reloc = R_MICROBLAZE_32_NONE;
740+ break;
741+ case BFD_RELOC_MICROBLAZE_64_NONE:
742+ microblaze_reloc = R_MICROBLAZE_64_NONE;
743+ break;
744+ case BFD_RELOC_32:
745+ microblaze_reloc = R_MICROBLAZE_32;
746+ break;
747+ /* RVA is treated the same as 32 */
748+ case BFD_RELOC_RVA:
749+ microblaze_reloc = R_MICROBLAZE_32;
750+ break;
751+ case BFD_RELOC_32_PCREL:
752+ microblaze_reloc = R_MICROBLAZE_32_PCREL;
753+ break;
754+ case BFD_RELOC_64_PCREL:
755+ microblaze_reloc = R_MICROBLAZE_64_PCREL;
756+ break;
757+ case BFD_RELOC_MICROBLAZE_32_LO_PCREL:
758+ microblaze_reloc = R_MICROBLAZE_32_PCREL_LO;
759+ break;
760+ case BFD_RELOC_64:
761+ microblaze_reloc = R_MICROBLAZE_64;
762+ break;
763+ case BFD_RELOC_MICROBLAZE_32_LO:
764+ microblaze_reloc = R_MICROBLAZE_32_LO;
765+ break;
766+ case BFD_RELOC_MICROBLAZE_32_ROSDA:
767+ microblaze_reloc = R_MICROBLAZE_SRO32;
768+ break;
769+ case BFD_RELOC_MICROBLAZE_32_RWSDA:
770+ microblaze_reloc = R_MICROBLAZE_SRW32;
771+ break;
772+ case BFD_RELOC_MICROBLAZE_32_SYM_OP_SYM:
773+ microblaze_reloc = R_MICROBLAZE_32_SYM_OP_SYM;
774+ break;
775+ case BFD_RELOC_VTABLE_INHERIT:
776+ microblaze_reloc = R_MICROBLAZE_GNU_VTINHERIT;
777+ break;
778+ case BFD_RELOC_VTABLE_ENTRY:
779+ microblaze_reloc = R_MICROBLAZE_GNU_VTENTRY;
780+ break;
781+ case BFD_RELOC_MICROBLAZE_64_GOTPC:
782+ microblaze_reloc = R_MICROBLAZE_GOTPC_64;
783+ break;
784+ case BFD_RELOC_MICROBLAZE_64_GOT:
785+ microblaze_reloc = R_MICROBLAZE_GOT_64;
786+ break;
787+ case BFD_RELOC_MICROBLAZE_64_PLT:
788+ microblaze_reloc = R_MICROBLAZE_PLT_64;
789+ break;
790+ case BFD_RELOC_MICROBLAZE_64_GOTOFF:
791+ microblaze_reloc = R_MICROBLAZE_GOTOFF_64;
792+ break;
793+ case BFD_RELOC_MICROBLAZE_32_GOTOFF:
794+ microblaze_reloc = R_MICROBLAZE_GOTOFF_32;
795+ break;
796+ case BFD_RELOC_MICROBLAZE_64_TLSGD:
797+ microblaze_reloc = R_MICROBLAZE_TLSGD;
798+ break;
799+ case BFD_RELOC_MICROBLAZE_64_TLSLD:
800+ microblaze_reloc = R_MICROBLAZE_TLSLD;
801+ break;
802+ case BFD_RELOC_MICROBLAZE_32_TLSDTPREL:
803+ microblaze_reloc = R_MICROBLAZE_TLSDTPREL32;
804+ break;
805+ case BFD_RELOC_MICROBLAZE_64_TLSDTPREL:
806+ microblaze_reloc = R_MICROBLAZE_TLSDTPREL64;
807+ break;
808+ case BFD_RELOC_MICROBLAZE_32_TLSDTPMOD:
809+ microblaze_reloc = R_MICROBLAZE_TLSDTPMOD32;
810+ break;
811+ case BFD_RELOC_MICROBLAZE_64_TLSGOTTPREL:
812+ microblaze_reloc = R_MICROBLAZE_TLSGOTTPREL32;
813+ break;
814+ case BFD_RELOC_MICROBLAZE_64_TLSTPREL:
815+ microblaze_reloc = R_MICROBLAZE_TLSTPREL32;
816+ break;
817+ case BFD_RELOC_MICROBLAZE_COPY:
818+ microblaze_reloc = R_MICROBLAZE_COPY;
819+ break;
820+ default:
821+ return (reloc_howto_type *) NULL;
822+ }
823+
824+ if (!microblaze_elf_howto_table [R_MICROBLAZE_32])
825+ /* Initialize howto table if needed. */
826+ microblaze_elf_howto_init ();
827+
828+ return microblaze_elf_howto_table [(int) microblaze_reloc];
829+};
830+
831+static reloc_howto_type *
832+microblaze_elf_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
833+ const char *r_name)
834+{
835+ unsigned int i;
836+
837+ for (i = 0; i < NUM_ELEM (microblaze_elf_howto_raw); i++)
838+ if (microblaze_elf_howto_raw[i].name != NULL
839+ && strcasecmp (microblaze_elf_howto_raw[i].name, r_name) == 0)
840+ return &microblaze_elf_howto_raw[i];
841+
842+ return NULL;
843+}
844+
845+/* Set the howto pointer for a RCE ELF reloc. */
846+
847+static void
848+microblaze_elf_info_to_howto (bfd * abfd ATTRIBUTE_UNUSED,
849+ arelent * cache_ptr,
850+ Elf_Internal_Rela * dst)
851+{
852+ unsigned int r_type;
853+
854+ if (!microblaze_elf_howto_table [R_MICROBLAZE_32])
855+ /* Initialize howto table if needed. */
856+ microblaze_elf_howto_init ();
857+
858+ r_type = ELF64_R_TYPE (dst->r_info);
859+ if (r_type >= R_MICROBLAZE_max)
860+ {
861+ (*_bfd_error_handler) (_("%B: unrecognised MicroBlaze reloc number: %d"),
862+ abfd, r_type);
863+ bfd_set_error (bfd_error_bad_value);
864+ r_type = R_MICROBLAZE_NONE;
865+ }
866+
867+ cache_ptr->howto = microblaze_elf_howto_table [r_type];
868+}
869+
870+/* Microblaze ELF local labels start with 'L.' or '$L', not '.L'. */
871+
872+static bfd_boolean
873+microblaze_elf_is_local_label_name (bfd *abfd, const char *name)
874+{
875+ if (name[0] == 'L' && name[1] == '.')
876+ return TRUE;
877+
878+ if (name[0] == '$' && name[1] == 'L')
879+ return TRUE;
880+
881+ /* With gcc, the labels go back to starting with '.', so we accept
882+ the generic ELF local label syntax as well. */
883+ return _bfd_elf_is_local_label_name (abfd, name);
884+}
885+
886+/* The microblaze linker (like many others) needs to keep track of
887+ the number of relocs that it decides to copy as dynamic relocs in
888+ check_relocs for each symbol. This is so that it can later discard
889+ them if they are found to be unnecessary. We store the information
890+ in a field extending the regular ELF linker hash table. */
891+
892+struct elf64_mb_dyn_relocs
893+{
894+ struct elf64_mb_dyn_relocs *next;
895+
896+ /* The input section of the reloc. */
897+ asection *sec;
898+
899+ /* Total number of relocs copied for the input section. */
900+ bfd_size_type count;
901+
902+ /* Number of pc-relative relocs copied for the input section. */
903+ bfd_size_type pc_count;
904+};
905+
906+/* ELF linker hash entry. */
907+
908+struct elf64_mb_link_hash_entry
909+{
910+ struct elf_link_hash_entry elf;
911+
912+ /* Track dynamic relocs copied for this symbol. */
913+ struct elf64_mb_dyn_relocs *dyn_relocs;
914+
915+ /* TLS Reference Types for the symbol; Updated by check_relocs */
916+#define TLS_GD 1 /* GD reloc. */
917+#define TLS_LD 2 /* LD reloc. */
918+#define TLS_TPREL 4 /* TPREL reloc, => IE. */
919+#define TLS_DTPREL 8 /* DTPREL reloc, => LD. */
920+#define TLS_TLS 16 /* Any TLS reloc. */
921+ unsigned char tls_mask;
922+
923+};
924+
925+#define IS_TLS_GD(x) (x == (TLS_TLS | TLS_GD))
926+#define IS_TLS_LD(x) (x == (TLS_TLS | TLS_LD))
927+#define IS_TLS_DTPREL(x) (x == (TLS_TLS | TLS_DTPREL))
928+#define IS_TLS_NONE(x) (x == 0)
929+
930+#define elf64_mb_hash_entry(ent) ((struct elf64_mb_link_hash_entry *)(ent))
931+
932+/* ELF linker hash table. */
933+
934+struct elf64_mb_link_hash_table
935+{
936+ struct elf_link_hash_table elf;
937+
938+ /* Short-cuts to get to dynamic linker sections. */
939+ asection *sgot;
940+ asection *sgotplt;
941+ asection *srelgot;
942+ asection *splt;
943+ asection *srelplt;
944+ asection *sdynbss;
945+ asection *srelbss;
946+
947+ /* Small local sym to section mapping cache. */
948+ struct sym_cache sym_sec;
949+
950+ /* TLS Local Dynamic GOT Entry */
951+ union {
952+ bfd_signed_vma refcount;
953+ bfd_vma offset;
954+ } tlsld_got;
955+};
956+
957+/* Nonzero if this section has TLS related relocations. */
958+#define has_tls_reloc sec_flg0
959+
960+/* Get the ELF linker hash table from a link_info structure. */
961+
962+#define elf64_mb_hash_table(p) \
963+ (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
964+ == MICROBLAZE_ELF_DATA ? ((struct elf64_mb_link_hash_table *) ((p)->hash)) : NULL)
965+
966+/* Create an entry in a microblaze ELF linker hash table. */
967+
968+static struct bfd_hash_entry *
969+link_hash_newfunc (struct bfd_hash_entry *entry,
970+ struct bfd_hash_table *table,
971+ const char *string)
972+{
973+ /* Allocate the structure if it has not already been allocated by a
974+ subclass. */
975+ if (entry == NULL)
976+ {
977+ entry = bfd_hash_allocate (table,
978+ sizeof (struct elf64_mb_link_hash_entry));
979+ if (entry == NULL)
980+ return entry;
981+ }
982+
983+ /* Call the allocation method of the superclass. */
984+ entry = _bfd_elf_link_hash_newfunc (entry, table, string);
985+ if (entry != NULL)
986+ {
987+ struct elf64_mb_link_hash_entry *eh;
988+
989+ eh = (struct elf64_mb_link_hash_entry *) entry;
990+ eh->dyn_relocs = NULL;
991+ eh->tls_mask = 0;
992+ }
993+
994+ return entry;
995+}
996+
997+/* Create a mb ELF linker hash table. */
998+
999+static struct bfd_link_hash_table *
1000+microblaze_elf_link_hash_table_create (bfd *abfd)
1001+{
1002+ struct elf64_mb_link_hash_table *ret;
1003+ bfd_size_type amt = sizeof (struct elf64_mb_link_hash_table);
1004+
1005+ ret = (struct elf64_mb_link_hash_table *) bfd_zmalloc (amt);
1006+ if (ret == NULL)
1007+ return NULL;
1008+
1009+ if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd, link_hash_newfunc,
1010+ sizeof (struct elf64_mb_link_hash_entry),
1011+ MICROBLAZE_ELF_DATA))
1012+ {
1013+ free (ret);
1014+ return NULL;
1015+ }
1016+
1017+ return &ret->elf.root;
1018+}
1019+
1020+/* Set the values of the small data pointers. */
1021+
1022+static void
1023+microblaze_elf_final_sdp (struct bfd_link_info *info)
1024+{
1025+ struct bfd_link_hash_entry *h;
1026+
1027+ h = bfd_link_hash_lookup (info->hash, RO_SDA_ANCHOR_NAME, FALSE, FALSE, TRUE);
1028+ if (h != (struct bfd_link_hash_entry *) NULL
1029+ && h->type == bfd_link_hash_defined)
1030+ ro_small_data_pointer = (h->u.def.value
1031+ + h->u.def.section->output_section->vma
1032+ + h->u.def.section->output_offset);
1033+
1034+ h = bfd_link_hash_lookup (info->hash, RW_SDA_ANCHOR_NAME, FALSE, FALSE, TRUE);
1035+ if (h != (struct bfd_link_hash_entry *) NULL
1036+ && h->type == bfd_link_hash_defined)
1037+ rw_small_data_pointer = (h->u.def.value
1038+ + h->u.def.section->output_section->vma
1039+ + h->u.def.section->output_offset);
1040+}
1041+
1042+static bfd_vma
1043+dtprel_base (struct bfd_link_info *info)
1044+{
1045+ /* If tls_sec is NULL, we should have signalled an error already. */
1046+ if (elf_hash_table (info)->tls_sec == NULL)
1047+ return 0;
1048+ return elf_hash_table (info)->tls_sec->vma;
1049+}
1050+
1051+/* The size of the thread control block. */
1052+#define TCB_SIZE 8
1053+
1054+/* Output a simple dynamic relocation into SRELOC. */
1055+
1056+static void
1057+microblaze_elf_output_dynamic_relocation (bfd *output_bfd,
1058+ asection *sreloc,
1059+ unsigned long reloc_index,
1060+ unsigned long indx,
1061+ int r_type,
1062+ bfd_vma offset,
1063+ bfd_vma addend)
1064+{
1065+
1066+ Elf_Internal_Rela rel;
1067+
1068+ rel.r_info = ELF64_R_INFO (indx, r_type);
1069+ rel.r_offset = offset;
1070+ rel.r_addend = addend;
1071+
1072+ bfd_elf64_swap_reloca_out (output_bfd, &rel,
1073+ (sreloc->contents + reloc_index * sizeof (Elf64_External_Rela)));
1074+}
1075+
1076+/* This code is taken from elf64-m32r.c
1077+ There is some attempt to make this function usable for many architectures,
1078+ both USE_REL and USE_RELA ['twould be nice if such a critter existed],
1079+ if only to serve as a learning tool.
1080+
1081+ The RELOCATE_SECTION function is called by the new ELF backend linker
1082+ to handle the relocations for a section.
1083+
1084+ The relocs are always passed as Rela structures; if the section
1085+ actually uses Rel structures, the r_addend field will always be
1086+ zero.
1087+
1088+ This function is responsible for adjust the section contents as
1089+ necessary, and (if using Rela relocs and generating a
1090+ relocatable output file) adjusting the reloc addend as
1091+ necessary.
1092+
1093+ This function does not have to worry about setting the reloc
1094+ address or the reloc symbol index.
1095+
1096+ LOCAL_SYMS is a pointer to the swapped in local symbols.
1097+
1098+ LOCAL_SECTIONS is an array giving the section in the input file
1099+ corresponding to the st_shndx field of each local symbol.
1100+
1101+ The global hash table entry for the global symbols can be found
1102+ via elf_sym_hashes (input_bfd).
1103+
1104+ When generating relocatable output, this function must handle
1105+ STB_LOCAL/STT_SECTION symbols specially. The output symbol is
1106+ going to be the section symbol corresponding to the output
1107+ section, which means that the addend must be adjusted
1108+ accordingly. */
1109+
1110+static bfd_boolean
1111+microblaze_elf_relocate_section (bfd *output_bfd,
1112+ struct bfd_link_info *info,
1113+ bfd *input_bfd,
1114+ asection *input_section,
1115+ bfd_byte *contents,
1116+ Elf_Internal_Rela *relocs,
1117+ Elf_Internal_Sym *local_syms,
1118+ asection **local_sections)
1119+{
1120+ struct elf64_mb_link_hash_table *htab;
1121+ Elf_Internal_Shdr *symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
1122+ struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (input_bfd);
1123+ Elf_Internal_Rela *rel, *relend;
1124+ int endian = (bfd_little_endian (output_bfd)) ? 0 : 2;
1125+ /* Assume success. */
1126+ bfd_boolean ret = TRUE;
1127+ asection *sreloc;
1128+ bfd_vma *local_got_offsets;
1129+ unsigned int tls_type;
1130+
1131+ if (!microblaze_elf_howto_table[R_MICROBLAZE_max-1])
1132+ microblaze_elf_howto_init ();
1133+
1134+ htab = elf64_mb_hash_table (info);
1135+ if (htab == NULL)
1136+ return FALSE;
1137+
1138+ local_got_offsets = elf_local_got_offsets (input_bfd);
1139+
1140+ sreloc = elf_section_data (input_section)->sreloc;
1141+
1142+ rel = relocs;
1143+ relend = relocs + input_section->reloc_count;
1144+ for (; rel < relend; rel++)
1145+ {
1146+ int r_type;
1147+ reloc_howto_type *howto;
1148+ unsigned long r_symndx;
1149+ bfd_vma addend = rel->r_addend;
1150+ bfd_vma offset = rel->r_offset;
1151+ struct elf_link_hash_entry *h;
1152+ Elf_Internal_Sym *sym;
1153+ asection *sec;
1154+ const char *sym_name;
1155+ bfd_reloc_status_type r = bfd_reloc_ok;
1156+ const char *errmsg = NULL;
1157+ bfd_boolean unresolved_reloc = FALSE;
1158+
1159+ h = NULL;
1160+ r_type = ELF64_R_TYPE (rel->r_info);
1161+ tls_type = 0;
1162+
1163+ if (r_type < 0 || r_type >= (int) R_MICROBLAZE_max)
1164+ {
1165+ (*_bfd_error_handler) (_("%s: unknown relocation type %d"),
1166+ bfd_get_filename (input_bfd), (int) r_type);
1167+ bfd_set_error (bfd_error_bad_value);
1168+ ret = FALSE;
1169+ continue;
1170+ }
1171+
1172+ howto = microblaze_elf_howto_table[r_type];
1173+ r_symndx = ELF64_R_SYM (rel->r_info);
1174+
1175+ if (bfd_link_relocatable (info))
1176+ {
1177+ /* This is a relocatable link. We don't have to change
1178+ anything, unless the reloc is against a section symbol,
1179+ in which case we have to adjust according to where the
1180+ section symbol winds up in the output section. */
1181+ sec = NULL;
1182+ if (r_symndx >= symtab_hdr->sh_info)
1183+ /* External symbol. */
1184+ continue;
1185+
1186+ /* Local symbol. */
1187+ sym = local_syms + r_symndx;
1188+ sym_name = "<local symbol>";
1189+ /* STT_SECTION: symbol is associated with a section. */
1190+ if (ELF_ST_TYPE (sym->st_info) != STT_SECTION)
1191+ /* Symbol isn't associated with a section. Nothing to do. */
1192+ continue;
1193+
1194+ sec = local_sections[r_symndx];
1195+ addend += sec->output_offset + sym->st_value;
1196+#ifndef USE_REL
1197+ /* This can't be done for USE_REL because it doesn't mean anything
1198+ and elf_link_input_bfd asserts this stays zero. */
1199+ /* rel->r_addend = addend; */
1200+#endif
1201+
1202+#ifndef USE_REL
1203+ /* Addends are stored with relocs. We're done. */
1204+ continue;
1205+#else /* USE_REL */
1206+ /* If partial_inplace, we need to store any additional addend
1207+ back in the section. */
1208+ if (!howto->partial_inplace)
1209+ continue;
1210+ /* ??? Here is a nice place to call a special_function like handler. */
1211+ r = _bfd_relocate_contents (howto, input_bfd, addend,
1212+ contents + offset);
1213+#endif /* USE_REL */
1214+ }
1215+ else
1216+ {
1217+ bfd_vma relocation;
1218+
1219+ /* This is a final link. */
1220+ sym = NULL;
1221+ sec = NULL;
1222+ unresolved_reloc = FALSE;
1223+
1224+ if (r_symndx < symtab_hdr->sh_info)
1225+ {
1226+ /* Local symbol. */
1227+ sym = local_syms + r_symndx;
1228+ sec = local_sections[r_symndx];
1229+ if (sec == 0)
1230+ continue;
1231+ sym_name = "<local symbol>";
1232+ relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
1233+ /* r_addend may have changed if the reference section was
1234+ a merge section. */
1235+ addend = rel->r_addend;
1236+ }
1237+ else
1238+ {
1239+ /* External symbol. */
1240+ bfd_boolean warned ATTRIBUTE_UNUSED;
1241+ bfd_boolean ignored ATTRIBUTE_UNUSED;
1242+
1243+ RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
1244+ r_symndx, symtab_hdr, sym_hashes,
1245+ h, sec, relocation,
1246+ unresolved_reloc, warned, ignored);
1247+ sym_name = h->root.root.string;
1248+ }
1249+
1250+ /* Sanity check the address. */
1251+ if (offset > bfd_get_section_limit (input_bfd, input_section))
1252+ {
1253+ r = bfd_reloc_outofrange;
1254+ goto check_reloc;
1255+ }
1256+
1257+ switch ((int) r_type)
1258+ {
1259+ case (int) R_MICROBLAZE_SRO32 :
1260+ {
1261+ const char *name;
1262+
1263+ /* Only relocate if the symbol is defined. */
1264+ if (sec)
1265+ {
1266+ name = bfd_get_section_name (sec->owner, sec);
1267+
1268+ if (strcmp (name, ".sdata2") == 0
1269+ || strcmp (name, ".sbss2") == 0)
1270+ {
1271+ if (ro_small_data_pointer == 0)
1272+ microblaze_elf_final_sdp (info);
1273+ if (ro_small_data_pointer == 0)
1274+ {
1275+ ret = FALSE;
1276+ r = bfd_reloc_undefined;
1277+ goto check_reloc;
1278+ }
1279+
1280+ /* At this point `relocation' contains the object's
1281+ address. */
1282+ relocation -= ro_small_data_pointer;
1283+ /* Now it contains the offset from _SDA2_BASE_. */
1284+ r = _bfd_final_link_relocate (howto, input_bfd,
1285+ input_section,
1286+ contents, offset,
1287+ relocation, addend);
1288+ }
1289+ else
1290+ {
1291+ (*_bfd_error_handler) (_("%s: The target (%s) of an %s relocation is in the wrong section (%s)"),
1292+ bfd_get_filename (input_bfd),
1293+ sym_name,
1294+ microblaze_elf_howto_table[(int) r_type]->name,
1295+ bfd_get_section_name (sec->owner, sec));
1296+ /*bfd_set_error (bfd_error_bad_value); ??? why? */
1297+ ret = FALSE;
1298+ continue;
1299+ }
1300+ }
1301+ }
1302+ break;
1303+
1304+ case (int) R_MICROBLAZE_SRW32 :
1305+ {
1306+ const char *name;
1307+
1308+ /* Only relocate if the symbol is defined. */
1309+ if (sec)
1310+ {
1311+ name = bfd_get_section_name (sec->owner, sec);
1312+
1313+ if (strcmp (name, ".sdata") == 0
1314+ || strcmp (name, ".sbss") == 0)
1315+ {
1316+ if (rw_small_data_pointer == 0)
1317+ microblaze_elf_final_sdp (info);
1318+ if (rw_small_data_pointer == 0)
1319+ {
1320+ ret = FALSE;
1321+ r = bfd_reloc_undefined;
1322+ goto check_reloc;
1323+ }
1324+
1325+ /* At this point `relocation' contains the object's
1326+ address. */
1327+ relocation -= rw_small_data_pointer;
1328+ /* Now it contains the offset from _SDA_BASE_. */
1329+ r = _bfd_final_link_relocate (howto, input_bfd,
1330+ input_section,
1331+ contents, offset,
1332+ relocation, addend);
1333+ }
1334+ else
1335+ {
1336+ (*_bfd_error_handler) (_("%s: The target (%s) of an %s relocation is in the wrong section (%s)"),
1337+ bfd_get_filename (input_bfd),
1338+ sym_name,
1339+ microblaze_elf_howto_table[(int) r_type]->name,
1340+ bfd_get_section_name (sec->owner, sec));
1341+ /*bfd_set_error (bfd_error_bad_value); ??? why? */
1342+ ret = FALSE;
1343+ continue;
1344+ }
1345+ }
1346+ }
1347+ break;
1348+
1349+ case (int) R_MICROBLAZE_32_SYM_OP_SYM:
1350+ break; /* Do nothing. */
1351+
1352+ case (int) R_MICROBLAZE_GOTPC_64:
1353+ relocation = htab->sgotplt->output_section->vma
1354+ + htab->sgotplt->output_offset;
1355+ relocation -= (input_section->output_section->vma
1356+ + input_section->output_offset
1357+ + offset + INST_WORD_SIZE);
1358+ relocation += addend;
1359+ bfd_put_16 (input_bfd, (relocation >> 16) & 0xffff,
1360+ contents + offset + endian);
1361+ bfd_put_16 (input_bfd, relocation & 0xffff,
1362+ contents + offset + endian + INST_WORD_SIZE);
1363+ break;
1364+
1365+ case (int) R_MICROBLAZE_PLT_64:
1366+ {
1367+ bfd_vma immediate;
1368+ if (htab->splt != NULL && h != NULL
1369+ && h->plt.offset != (bfd_vma) -1)
1370+ {
1371+ relocation = (htab->splt->output_section->vma
1372+ + htab->splt->output_offset
1373+ + h->plt.offset);
1374+ unresolved_reloc = FALSE;
1375+ immediate = relocation - (input_section->output_section->vma
1376+ + input_section->output_offset
1377+ + offset + INST_WORD_SIZE);
1378+ bfd_put_16 (input_bfd, (immediate >> 16) & 0xffff,
1379+ contents + offset + endian);
1380+ bfd_put_16 (input_bfd, immediate & 0xffff,
1381+ contents + offset + endian + INST_WORD_SIZE);
1382+ }
1383+ else
1384+ {
1385+ relocation -= (input_section->output_section->vma
1386+ + input_section->output_offset
1387+ + offset + INST_WORD_SIZE);
1388+ immediate = relocation;
1389+ bfd_put_16 (input_bfd, (immediate >> 16) & 0xffff,
1390+ contents + offset + endian);
1391+ bfd_put_16 (input_bfd, immediate & 0xffff,
1392+ contents + offset + endian + INST_WORD_SIZE);
1393+ }
1394+ break;
1395+ }
1396+
1397+ case (int) R_MICROBLAZE_TLSGD:
1398+ tls_type = (TLS_TLS | TLS_GD);
1399+ goto dogot;
1400+ case (int) R_MICROBLAZE_TLSLD:
1401+ tls_type = (TLS_TLS | TLS_LD);
1402+ dogot:
1403+ case (int) R_MICROBLAZE_GOT_64:
1404+ {
1405+ bfd_vma *offp;
1406+ bfd_vma off, off2;
1407+ unsigned long indx;
1408+ bfd_vma static_value;
1409+
1410+ bfd_boolean need_relocs = FALSE;
1411+ if (htab->sgot == NULL)
1412+ abort ();
1413+
1414+ indx = 0;
1415+ offp = NULL;
1416+
1417+ /* 1. Identify GOT Offset;
1418+ 2. Compute Static Values
1419+ 3. Process Module Id, Process Offset
1420+ 4. Fixup Relocation with GOT offset value. */
1421+
1422+ /* 1. Determine GOT Offset to use : TLS_LD, global, local */
1423+ if (IS_TLS_LD (tls_type))
1424+ offp = &htab->tlsld_got.offset;
1425+ else if (h != NULL)
1426+ {
1427+ if (htab->sgotplt != NULL && h->got.offset != (bfd_vma) -1)
1428+ offp = &h->got.offset;
1429+ else
1430+ abort ();
1431+ }
1432+ else
1433+ {
1434+ if (local_got_offsets == NULL)
1435+ abort ();
1436+ offp = &local_got_offsets[r_symndx];
1437+ }
1438+
1439+ if (!offp)
1440+ abort ();
1441+
1442+ off = (*offp) & ~1;
1443+ off2 = off;
1444+
1445+ if (IS_TLS_LD(tls_type) || IS_TLS_GD(tls_type))
1446+ off2 = off + 4;
1447+
1448+ /* Symbol index to use for relocs */
1449+ if (h != NULL)
1450+ {
1451+ bfd_boolean dyn =
1452+ elf_hash_table (info)->dynamic_sections_created;
1453+
1454+ if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn,
1455+ bfd_link_pic (info),
1456+ h)
1457+ && (!bfd_link_pic (info)
1458+ || !SYMBOL_REFERENCES_LOCAL (info, h)))
1459+ indx = h->dynindx;
1460+ }
1461+
1462+ /* Need to generate relocs ? */
1463+ if ((bfd_link_pic (info) || indx != 0)
1464+ && (h == NULL
1465+ || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
1466+ || h->root.type != bfd_link_hash_undefweak))
1467+ need_relocs = TRUE;
1468+
1469+ /* 2. Compute/Emit Static value of r-expression */
1470+ static_value = relocation + addend;
1471+
1472+ /* 3. Process module-id and offset */
1473+ if (! ((*offp) & 1) )
1474+ {
1475+ bfd_vma got_offset;
1476+
1477+ got_offset = (htab->sgot->output_section->vma
1478+ + htab->sgot->output_offset
1479+ + off);
1480+
1481+ /* Process module-id */
1482+ if (IS_TLS_LD(tls_type))
1483+ {
1484+ if (! bfd_link_pic (info))
1485+ {
1486+ bfd_put_32 (output_bfd, 1, htab->sgot->contents + off);
1487+ }
1488+ else
1489+ {
1490+ microblaze_elf_output_dynamic_relocation (output_bfd,
1491+ htab->srelgot, htab->srelgot->reloc_count++,
1492+ /* symindex= */ 0, R_MICROBLAZE_TLSDTPMOD32,
1493+ got_offset, 0);
1494+ }
1495+ }
1496+ else if (IS_TLS_GD(tls_type))
1497+ {
1498+ if (! need_relocs)
1499+ {
1500+ bfd_put_32 (output_bfd, 1, htab->sgot->contents + off);
1501+ }
1502+ else
1503+ {
1504+ microblaze_elf_output_dynamic_relocation (output_bfd,
1505+ htab->srelgot,
1506+ htab->srelgot->reloc_count++,
1507+ /* symindex= */ indx, R_MICROBLAZE_TLSDTPMOD32,
1508+ got_offset, indx ? 0 : static_value);
1509+ }
1510+ }
1511+
1512+ /* Process Offset */
1513+ if (htab->srelgot == NULL)
1514+ abort ();
1515+
1516+ got_offset = (htab->sgot->output_section->vma
1517+ + htab->sgot->output_offset
1518+ + off2);
1519+ if (IS_TLS_LD(tls_type))
1520+ {
1521+ /* For LD, offset should be 0 */
1522+ *offp |= 1;
1523+ bfd_put_32 (output_bfd, 0, htab->sgot->contents + off2);
1524+ }
1525+ else if (IS_TLS_GD(tls_type))
1526+ {
1527+ *offp |= 1;
1528+ static_value -= dtprel_base(info);
1529+ if (need_relocs)
1530+ {
1531+ microblaze_elf_output_dynamic_relocation (output_bfd,
1532+ htab->srelgot, htab->srelgot->reloc_count++,
1533+ /* symindex= */ indx, R_MICROBLAZE_TLSDTPREL32,
1534+ got_offset, indx ? 0 : static_value);
1535+ }
1536+ else
1537+ {
1538+ bfd_put_32 (output_bfd, static_value,
1539+ htab->sgot->contents + off2);
1540+ }
1541+ }
1542+ else
1543+ {
1544+ bfd_put_32 (output_bfd, static_value,
1545+ htab->sgot->contents + off2);
1546+
1547+ /* Relocs for dyn symbols generated by
1548+ finish_dynamic_symbols */
1549+ if (bfd_link_pic (info) && h == NULL)
1550+ {
1551+ *offp |= 1;
1552+ microblaze_elf_output_dynamic_relocation (output_bfd,
1553+ htab->srelgot, htab->srelgot->reloc_count++,
1554+ /* symindex= */ indx, R_MICROBLAZE_REL,
1555+ got_offset, static_value);
1556+ }
1557+ }
1558+ }
1559+
1560+ /* 4. Fixup Relocation with GOT offset value
1561+ Compute relative address of GOT entry for applying
1562+ the current relocation */
1563+ relocation = htab->sgot->output_section->vma
1564+ + htab->sgot->output_offset
1565+ + off
1566+ - htab->sgotplt->output_section->vma
1567+ - htab->sgotplt->output_offset;
1568+
1569+ /* Apply Current Relocation */
1570+ bfd_put_16 (input_bfd, (relocation >> 16) & 0xffff,
1571+ contents + offset + endian);
1572+ bfd_put_16 (input_bfd, relocation & 0xffff,
1573+ contents + offset + endian + INST_WORD_SIZE);
1574+
1575+ unresolved_reloc = FALSE;
1576+ break;
1577+ }
1578+
1579+ case (int) R_MICROBLAZE_GOTOFF_64:
1580+ {
1581+ bfd_vma immediate;
1582+ unsigned short lo, high;
1583+ relocation += addend;
1584+ relocation -= htab->sgotplt->output_section->vma
1585+ + htab->sgotplt->output_offset;
1586+ /* Write this value into correct location. */
1587+ immediate = relocation;
1588+ lo = immediate & 0x0000ffff;
1589+ high = (immediate >> 16) & 0x0000ffff;
1590+ bfd_put_16 (input_bfd, high, contents + offset + endian);
1591+ bfd_put_16 (input_bfd, lo, contents + offset + INST_WORD_SIZE + endian);
1592+ break;
1593+ }
1594+
1595+ case (int) R_MICROBLAZE_GOTOFF_32:
1596+ {
1597+ relocation += addend;
1598+ relocation -= htab->sgotplt->output_section->vma
1599+ + htab->sgotplt->output_offset;
1600+ /* Write this value into correct location. */
1601+ bfd_put_32 (input_bfd, relocation, contents + offset);
1602+ break;
1603+ }
1604+
1605+ case (int) R_MICROBLAZE_TLSDTPREL64:
1606+ relocation += addend;
1607+ relocation -= dtprel_base(info);
1608+ bfd_put_16 (input_bfd, (relocation >> 16) & 0xffff,
1609+ contents + offset + endian);
1610+ bfd_put_16 (input_bfd, relocation & 0xffff,
1611+ contents + offset + endian + INST_WORD_SIZE);
1612+ break;
1613+ case (int) R_MICROBLAZE_64_PCREL :
1614+ case (int) R_MICROBLAZE_64:
1615+ case (int) R_MICROBLAZE_32:
1616+ {
1617+ /* r_symndx will be STN_UNDEF (zero) only for relocs against symbols
1618+ from removed linkonce sections, or sections discarded by
1619+ a linker script. */
1620+ if (r_symndx == STN_UNDEF || (input_section->flags & SEC_ALLOC) == 0)
1621+ {
1622+ relocation += addend;
1623+ if (r_type == R_MICROBLAZE_32)
1624+ bfd_put_32 (input_bfd, relocation, contents + offset);
1625+ else
1626+ {
1627+ if (r_type == R_MICROBLAZE_64_PCREL)
1628+ relocation -= (input_section->output_section->vma
1629+ + input_section->output_offset
1630+ + offset + INST_WORD_SIZE);
1631+ bfd_put_16 (input_bfd, (relocation >> 16) & 0xffff,
1632+ contents + offset + endian);
1633+ bfd_put_16 (input_bfd, relocation & 0xffff,
1634+ contents + offset + endian + INST_WORD_SIZE);
1635+ }
1636+ break;
1637+ }
1638+
1639+ if ((bfd_link_pic (info)
1640+ && (h == NULL
1641+ || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
1642+ || h->root.type != bfd_link_hash_undefweak)
1643+ && (!howto->pc_relative
1644+ || (h != NULL
1645+ && h->dynindx != -1
1646+ && (!info->symbolic
1647+ || !h->def_regular))))
1648+ || (!bfd_link_pic (info)
1649+ && h != NULL
1650+ && h->dynindx != -1
1651+ && !h->non_got_ref
1652+ && ((h->def_dynamic
1653+ && !h->def_regular)
1654+ || h->root.type == bfd_link_hash_undefweak
1655+ || h->root.type == bfd_link_hash_undefined)))
1656+ {
1657+ Elf_Internal_Rela outrel;
1658+ bfd_byte *loc;
1659+ bfd_boolean skip;
1660+
1661+ /* When generating a shared object, these relocations
1662+ are copied into the output file to be resolved at run
1663+ time. */
1664+
1665+ BFD_ASSERT (sreloc != NULL);
1666+
1667+ skip = FALSE;
1668+
1669+ outrel.r_offset =
1670+ _bfd_elf_section_offset (output_bfd, info, input_section,
1671+ rel->r_offset);
1672+ if (outrel.r_offset == (bfd_vma) -1)
1673+ skip = TRUE;
1674+ else if (outrel.r_offset == (bfd_vma) -2)
1675+ skip = TRUE;
1676+ outrel.r_offset += (input_section->output_section->vma
1677+ + input_section->output_offset);
1678+
1679+ if (skip)
1680+ memset (&outrel, 0, sizeof outrel);
1681+ /* h->dynindx may be -1 if the symbol was marked to
1682+ become local. */
1683+ else if (h != NULL
1684+ && ((! info->symbolic && h->dynindx != -1)
1685+ || !h->def_regular))
1686+ {
1687+ BFD_ASSERT (h->dynindx != -1);
1688+ outrel.r_info = ELF64_R_INFO (h->dynindx, r_type);
1689+ outrel.r_addend = addend;
1690+ }
1691+ else
1692+ {
1693+ if (r_type == R_MICROBLAZE_32)
1694+ {
1695+ outrel.r_info = ELF64_R_INFO (0, R_MICROBLAZE_REL);
1696+ outrel.r_addend = relocation + addend;
1697+ }
1698+ else
1699+ {
1700+ BFD_FAIL ();
1701+ (*_bfd_error_handler)
1702+ (_("%B: probably compiled without -fPIC?"),
1703+ input_bfd);
1704+ bfd_set_error (bfd_error_bad_value);
1705+ return FALSE;
1706+ }
1707+ }
1708+
1709+ loc = sreloc->contents;
1710+ loc += sreloc->reloc_count++ * sizeof (Elf64_External_Rela);
1711+ bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
1712+ break;
1713+ }
1714+ else
1715+ {
1716+ relocation += addend;
1717+ if (r_type == R_MICROBLAZE_32)
1718+ bfd_put_32 (input_bfd, relocation, contents + offset);
1719+ else
1720+ {
1721+ if (r_type == R_MICROBLAZE_64_PCREL)
1722+ relocation -= (input_section->output_section->vma
1723+ + input_section->output_offset
1724+ + offset + INST_WORD_SIZE);
1725+ bfd_put_16 (input_bfd, (relocation >> 16) & 0xffff,
1726+ contents + offset + endian);
1727+ bfd_put_16 (input_bfd, relocation & 0xffff,
1728+ contents + offset + endian + INST_WORD_SIZE);
1729+ }
1730+ break;
1731+ }
1732+ }
1733+
1734+ default :
1735+ r = _bfd_final_link_relocate (howto, input_bfd, input_section,
1736+ contents, offset,
1737+ relocation, addend);
1738+ break;
1739+ }
1740+ }
1741+
1742+ check_reloc:
1743+
1744+ if (r != bfd_reloc_ok)
1745+ {
1746+ /* FIXME: This should be generic enough to go in a utility. */
1747+ const char *name;
1748+
1749+ if (h != NULL)
1750+ name = h->root.root.string;
1751+ else
1752+ {
1753+ name = (bfd_elf_string_from_elf_section
1754+ (input_bfd, symtab_hdr->sh_link, sym->st_name));
1755+ if (name == NULL || *name == '\0')
1756+ name = bfd_section_name (input_bfd, sec);
1757+ }
1758+
1759+ if (errmsg != NULL)
1760+ goto common_error;
1761+
1762+ switch (r)
1763+ {
1764+ case bfd_reloc_overflow:
1765+ (*info->callbacks->reloc_overflow)
1766+ (info, (h ? &h->root : NULL), name, howto->name,
1767+ (bfd_vma) 0, input_bfd, input_section, offset);
1768+ break;
1769+
1770+ case bfd_reloc_undefined:
1771+ (*info->callbacks->undefined_symbol)
1772+ (info, name, input_bfd, input_section, offset, TRUE);
1773+ break;
1774+
1775+ case bfd_reloc_outofrange:
1776+ errmsg = _("internal error: out of range error");
1777+ goto common_error;
1778+
1779+ case bfd_reloc_notsupported:
1780+ errmsg = _("internal error: unsupported relocation error");
1781+ goto common_error;
1782+
1783+ case bfd_reloc_dangerous:
1784+ errmsg = _("internal error: dangerous error");
1785+ goto common_error;
1786+
1787+ default:
1788+ errmsg = _("internal error: unknown error");
1789+ /* Fall through. */
1790+ common_error:
1791+ (*info->callbacks->warning) (info, errmsg, name, input_bfd,
1792+ input_section, offset);
1793+ break;
1794+ }
1795+ }
1796+ }
1797+
1798+ return ret;
1799+}
1800+
1801+/* Merge backend specific data from an object file to the output
1802+ object file when linking.
1803+
1804+ Note: We only use this hook to catch endian mismatches. */
1805+static bfd_boolean
1806+microblaze_elf_merge_private_bfd_data (bfd * ibfd, bfd * obfd)
1807+{
1808+ /* Check if we have the same endianess. */
1809+ if (! _bfd_generic_verify_endian_match (ibfd, obfd))
1810+ return FALSE;
1811+
1812+ return TRUE;
1813+}
1814+
1815+
1816+/* Calculate fixup value for reference. */
1817+
1818+static int
1819+calc_fixup (bfd_vma start, bfd_vma size, asection *sec)
1820+{
1821+ bfd_vma end = start + size;
1822+ int i, fixup = 0;
1823+
1824+ if (sec == NULL || sec->relax == NULL)
1825+ return 0;
1826+
1827+ /* Look for addr in relax table, total fixup value. */
1828+ for (i = 0; i < sec->relax_count; i++)
1829+ {
1830+ if (end <= sec->relax[i].addr)
1831+ break;
1832+ if ((end != start) && (start > sec->relax[i].addr))
1833+ continue;
1834+ fixup += sec->relax[i].size;
1835+ }
1836+ return fixup;
1837+}
1838+
1839+/* Read-modify-write into the bfd, an immediate value into appropriate fields of
1840+ a 32-bit instruction. */
1841+static void
1842+microblaze_bfd_write_imm_value_32 (bfd *abfd, bfd_byte *bfd_addr, bfd_vma val)
1843+{
1844+ unsigned long instr = bfd_get_32 (abfd, bfd_addr);
1845+ instr &= ~0x0000ffff;
1846+ instr |= (val & 0x0000ffff);
1847+ bfd_put_32 (abfd, instr, bfd_addr);
1848+}
1849+
1850+/* Read-modify-write into the bfd, an immediate value into appropriate fields of
1851+ two consecutive 32-bit instructions. */
1852+static void
1853+microblaze_bfd_write_imm_value_64 (bfd *abfd, bfd_byte *bfd_addr, bfd_vma val)
1854+{
1855+ unsigned long instr_hi;
1856+ unsigned long instr_lo;
1857+
1858+ instr_hi = bfd_get_32 (abfd, bfd_addr);
1859+ instr_hi &= ~0x0000ffff;
1860+ instr_hi |= ((val >> 16) & 0x0000ffff);
1861+ bfd_put_32 (abfd, instr_hi, bfd_addr);
1862+
1863+ instr_lo = bfd_get_32 (abfd, bfd_addr + INST_WORD_SIZE);
1864+ instr_lo &= ~0x0000ffff;
1865+ instr_lo |= (val & 0x0000ffff);
1866+ bfd_put_32 (abfd, instr_lo, bfd_addr + INST_WORD_SIZE);
1867+}
1868+
1869+static bfd_boolean
1870+microblaze_elf_relax_section (bfd *abfd,
1871+ asection *sec,
1872+ struct bfd_link_info *link_info,
1873+ bfd_boolean *again)
1874+{
1875+ Elf_Internal_Shdr *symtab_hdr;
1876+ Elf_Internal_Rela *internal_relocs;
1877+ Elf_Internal_Rela *free_relocs = NULL;
1878+ Elf_Internal_Rela *irel, *irelend;
1879+ bfd_byte *contents = NULL;
1880+ bfd_byte *free_contents = NULL;
1881+ int rel_count;
1882+ unsigned int shndx;
1883+ int i, sym_index;
1884+ asection *o;
1885+ struct elf_link_hash_entry *sym_hash;
1886+ Elf_Internal_Sym *isymbuf, *isymend;
1887+ Elf_Internal_Sym *isym;
1888+ int symcount;
1889+ int offset;
1890+ bfd_vma src, dest;
1891+
1892+ /* We only do this once per section. We may be able to delete some code
1893+ by running multiple passes, but it is not worth it. */
1894+ *again = FALSE;
1895+
1896+ /* Only do this for a text section. */
1897+ if (bfd_link_relocatable (link_info)
1898+ || (sec->flags & SEC_RELOC) == 0
1899+ || (sec->reloc_count == 0)
1900+ || (sec->flags & SEC_CODE) == 0)
1901+ return TRUE;
1902+
1903+ BFD_ASSERT ((sec->size > 0) || (sec->rawsize > 0));
1904+
1905+ /* If this is the first time we have been called for this section,
1906+ initialize the cooked size. */
1907+ if (sec->size == 0)
1908+ sec->size = sec->rawsize;
1909+
1910+ /* Get symbols for this section. */
1911+ symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
1912+ isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
1913+ symcount = symtab_hdr->sh_size / sizeof (Elf64_External_Sym);
1914+ if (isymbuf == NULL)
1915+ isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr, symcount,
1916+ 0, NULL, NULL, NULL);
1917+ BFD_ASSERT (isymbuf != NULL);
1918+
1919+ internal_relocs = _bfd_elf_link_read_relocs (abfd, sec, NULL, NULL, link_info->keep_memory);
1920+ if (internal_relocs == NULL)
1921+ goto error_return;
1922+ if (! link_info->keep_memory)
1923+ free_relocs = internal_relocs;
1924+
1925+ sec->relax = (struct relax_table *) bfd_malloc ((sec->reloc_count + 1)
1926+ * sizeof (struct relax_table));
1927+ if (sec->relax == NULL)
1928+ goto error_return;
1929+ sec->relax_count = 0;
1930+
1931+ irelend = internal_relocs + sec->reloc_count;
1932+ rel_count = 0;
1933+ for (irel = internal_relocs; irel < irelend; irel++, rel_count++)
1934+ {
1935+ bfd_vma symval;
1936+ if ((ELF64_R_TYPE (irel->r_info) != (int) R_MICROBLAZE_64_PCREL)
1937+ && (ELF64_R_TYPE (irel->r_info) != (int) R_MICROBLAZE_64 ))
1938+ continue; /* Can't delete this reloc. */
1939+
1940+ /* Get the section contents. */
1941+ if (contents == NULL)
1942+ {
1943+ if (elf_section_data (sec)->this_hdr.contents != NULL)
1944+ contents = elf_section_data (sec)->this_hdr.contents;
1945+ else
1946+ {
1947+ contents = (bfd_byte *) bfd_malloc (sec->size);
1948+ if (contents == NULL)
1949+ goto error_return;
1950+ free_contents = contents;
1951+
1952+ if (!bfd_get_section_contents (abfd, sec, contents,
1953+ (file_ptr) 0, sec->size))
1954+ goto error_return;
1955+ elf_section_data (sec)->this_hdr.contents = contents;
1956+ }
1957+ }
1958+
1959+ /* Get the value of the symbol referred to by the reloc. */
1960+ if (ELF64_R_SYM (irel->r_info) < symtab_hdr->sh_info)
1961+ {
1962+ /* A local symbol. */
1963+ asection *sym_sec;
1964+
1965+ isym = isymbuf + ELF64_R_SYM (irel->r_info);
1966+ if (isym->st_shndx == SHN_UNDEF)
1967+ sym_sec = bfd_und_section_ptr;
1968+ else if (isym->st_shndx == SHN_ABS)
1969+ sym_sec = bfd_abs_section_ptr;
1970+ else if (isym->st_shndx == SHN_COMMON)
1971+ sym_sec = bfd_com_section_ptr;
1972+ else
1973+ sym_sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
1974+
1975+ symval = _bfd_elf_rela_local_sym (abfd, isym, &sym_sec, irel);
1976+ }
1977+ else
1978+ {
1979+ unsigned long indx;
1980+ struct elf_link_hash_entry *h;
1981+
1982+ indx = ELF64_R_SYM (irel->r_info) - symtab_hdr->sh_info;
1983+ h = elf_sym_hashes (abfd)[indx];
1984+ BFD_ASSERT (h != NULL);
1985+
1986+ if (h->root.type != bfd_link_hash_defined
1987+ && h->root.type != bfd_link_hash_defweak)
1988+ /* This appears to be a reference to an undefined
1989+ symbol. Just ignore it--it will be caught by the
1990+ regular reloc processing. */
1991+ continue;
1992+
1993+ symval = (h->root.u.def.value
1994+ + h->root.u.def.section->output_section->vma
1995+ + h->root.u.def.section->output_offset);
1996+ }
1997+
1998+ /* If this is a PC-relative reloc, subtract the instr offset from
1999+ the symbol value. */
2000+ if (ELF64_R_TYPE (irel->r_info) == (int) R_MICROBLAZE_64_PCREL)
2001+ {
2002+ symval = symval + irel->r_addend
2003+ - (irel->r_offset
2004+ + sec->output_section->vma
2005+ + sec->output_offset);
2006+ }
2007+ else
2008+ symval += irel->r_addend;
2009+
2010+ if ((symval & 0xffff8000) == 0)
2011+ {
2012+ /* We can delete this instruction. */
2013+ sec->relax[sec->relax_count].addr = irel->r_offset;
2014+ sec->relax[sec->relax_count].size = INST_WORD_SIZE;
2015+ sec->relax_count++;
2016+
2017+ /* Rewrite relocation type. */
2018+ switch ((enum elf_microblaze_reloc_type) ELF64_R_TYPE (irel->r_info))
2019+ {
2020+ case R_MICROBLAZE_64_PCREL:
2021+ irel->r_info = ELF64_R_INFO (ELF64_R_SYM (irel->r_info),
2022+ (int) R_MICROBLAZE_32_PCREL_LO);
2023+ break;
2024+ case R_MICROBLAZE_64:
2025+ irel->r_info = ELF64_R_INFO (ELF64_R_SYM (irel->r_info),
2026+ (int) R_MICROBLAZE_32_LO);
2027+ break;
2028+ default:
2029+ /* Cannot happen. */
2030+ BFD_ASSERT (FALSE);
2031+ }
2032+ }
2033+ } /* Loop through all relocations. */
2034+
2035+ /* Loop through the relocs again, and see if anything needs to change. */
2036+ if (sec->relax_count > 0)
2037+ {
2038+ shndx = _bfd_elf_section_from_bfd_section (abfd, sec);
2039+ rel_count = 0;
2040+ sec->relax[sec->relax_count].addr = sec->size;
2041+
2042+ for (irel = internal_relocs; irel < irelend; irel++, rel_count++)
2043+ {
2044+ bfd_vma nraddr;
2045+
2046+ /* Get the new reloc address. */
2047+ nraddr = irel->r_offset - calc_fixup (irel->r_offset, 0, sec);
2048+ switch ((enum elf_microblaze_reloc_type) ELF64_R_TYPE (irel->r_info))
2049+ {
2050+ default:
2051+ break;
2052+ case R_MICROBLAZE_64_PCREL:
2053+ break;
2054+ case R_MICROBLAZE_64:
2055+ case R_MICROBLAZE_32_LO:
2056+ /* If this reloc is against a symbol defined in this
2057+ section, we must check the addend to see it will put the value in
2058+ range to be adjusted, and hence must be changed. */
2059+ if (ELF64_R_SYM (irel->r_info) < symtab_hdr->sh_info)
2060+ {
2061+ isym = isymbuf + ELF64_R_SYM (irel->r_info);
2062+ /* Only handle relocs against .text. */
2063+ if (isym->st_shndx == shndx
2064+ && ELF64_ST_TYPE (isym->st_info) == STT_SECTION)
2065+ irel->r_addend -= calc_fixup (irel->r_addend, 0, sec);
2066+ }
2067+ break;
2068+ case R_MICROBLAZE_NONE:
2069+ case R_MICROBLAZE_32_NONE:
2070+ {
2071+ /* This was a PC-relative instruction that was
2072+ completely resolved. */
2073+ int sfix, efix;
2074+ unsigned int val;
2075+ bfd_vma target_address;
2076+ target_address = irel->r_addend + irel->r_offset;
2077+ sfix = calc_fixup (irel->r_offset, 0, sec);
2078+ efix = calc_fixup (target_address, 0, sec);
2079+
2080+ /* Validate the in-band val. */
2081+ val = bfd_get_32 (abfd, contents + irel->r_offset);
2082+ if (val != irel->r_addend && ELF64_R_TYPE (irel->r_info) == R_MICROBLAZE_32_NONE) {
2083+ fprintf(stderr, "%d: CORRUPT relax reloc %x %lx\n", __LINE__, val, irel->r_addend);
2084+ }
2085+ irel->r_addend -= (efix - sfix);
2086+ /* Should use HOWTO. */
2087+ microblaze_bfd_write_imm_value_32 (abfd, contents + irel->r_offset,
2088+ irel->r_addend);
2089+ }
2090+ break;
2091+ case R_MICROBLAZE_64_NONE:
2092+ {
2093+ /* This was a PC-relative 64-bit instruction that was
2094+ completely resolved. */
2095+ int sfix, efix;
2096+ bfd_vma target_address;
2097+ target_address = irel->r_addend + irel->r_offset + INST_WORD_SIZE;
2098+ sfix = calc_fixup (irel->r_offset + INST_WORD_SIZE, 0, sec);
2099+ efix = calc_fixup (target_address, 0, sec);
2100+ irel->r_addend -= (efix - sfix);
2101+ microblaze_bfd_write_imm_value_32 (abfd, contents + irel->r_offset
2102+ + INST_WORD_SIZE, irel->r_addend);
2103+ }
2104+ break;
2105+ }
2106+ irel->r_offset = nraddr;
2107+ } /* Change all relocs in this section. */
2108+
2109+ /* Look through all other sections. */
2110+ for (o = abfd->sections; o != NULL; o = o->next)
2111+ {
2112+ Elf_Internal_Rela *irelocs;
2113+ Elf_Internal_Rela *irelscan, *irelscanend;
2114+ bfd_byte *ocontents;
2115+
2116+ if (o == sec
2117+ || (o->flags & SEC_RELOC) == 0
2118+ || o->reloc_count == 0)
2119+ continue;
2120+
2121+ /* We always cache the relocs. Perhaps, if info->keep_memory is
2122+ FALSE, we should free them, if we are permitted to. */
2123+
2124+ irelocs = _bfd_elf_link_read_relocs (abfd, o, NULL, NULL, TRUE);
2125+ if (irelocs == NULL)
2126+ goto error_return;
2127+
2128+ ocontents = NULL;
2129+ irelscanend = irelocs + o->reloc_count;
2130+ for (irelscan = irelocs; irelscan < irelscanend; irelscan++)
2131+ {
2132+ if (1 && ELF64_R_TYPE (irelscan->r_info) == (int) R_MICROBLAZE_32_NONE)
2133+ {
2134+ unsigned int val;
2135+
2136+ isym = isymbuf + ELF64_R_SYM (irelscan->r_info);
2137+
2138+ /* hax: We only do the following fixup for debug location lists. */
2139+ if (strcmp(".debug_loc", o->name))
2140+ continue;
2141+
2142+ /* This was a PC-relative instruction that was completely resolved. */
2143+ if (ocontents == NULL)
2144+ {
2145+ if (elf_section_data (o)->this_hdr.contents != NULL)
2146+ ocontents = elf_section_data (o)->this_hdr.contents;
2147+ else
2148+ {
2149+ /* We always cache the section contents.
2150+ Perhaps, if info->keep_memory is FALSE, we
2151+ should free them, if we are permitted to. */
2152+
2153+ if (o->rawsize == 0)
2154+ o->rawsize = o->size;
2155+ ocontents = (bfd_byte *) bfd_malloc (o->rawsize);
2156+ if (ocontents == NULL)
2157+ goto error_return;
2158+ if (!bfd_get_section_contents (abfd, o, ocontents,
2159+ (file_ptr) 0,
2160+ o->rawsize))
2161+ goto error_return;
2162+ elf_section_data (o)->this_hdr.contents = ocontents;
2163+ }
2164+ }
2165+
2166+ val = bfd_get_32 (abfd, ocontents + irelscan->r_offset);
2167+ if (val != irelscan->r_addend) {
2168+ fprintf(stderr, "%d: CORRUPT relax reloc! %x %lx\n", __LINE__, val, irelscan->r_addend);
2169+ }
2170+ irelscan->r_addend -= calc_fixup (irelscan->r_addend, 0, sec);
2171+ microblaze_bfd_write_imm_value_32 (abfd, ocontents + irelscan->r_offset,
2172+ irelscan->r_addend);
2173+ }
2174+ if (ELF64_R_TYPE (irelscan->r_info) == (int) R_MICROBLAZE_32)
2175+ {
2176+ isym = isymbuf + ELF64_R_SYM (irelscan->r_info);
2177+
2178+ /* Look at the reloc only if the value has been resolved. */
2179+ if (isym->st_shndx == shndx
2180+ && (ELF64_ST_TYPE (isym->st_info) == STT_SECTION))
2181+ {
2182+ if (ocontents == NULL)
2183+ {
2184+ if (elf_section_data (o)->this_hdr.contents != NULL)
2185+ ocontents = elf_section_data (o)->this_hdr.contents;
2186+ else
2187+ {
2188+ /* We always cache the section contents.
2189+ Perhaps, if info->keep_memory is FALSE, we
2190+ should free them, if we are permitted to. */
2191+ if (o->rawsize == 0)
2192+ o->rawsize = o->size;
2193+ ocontents = (bfd_byte *) bfd_malloc (o->rawsize);
2194+ if (ocontents == NULL)
2195+ goto error_return;
2196+ if (!bfd_get_section_contents (abfd, o, ocontents,
2197+ (file_ptr) 0,
2198+ o->rawsize))
2199+ goto error_return;
2200+ elf_section_data (o)->this_hdr.contents = ocontents;
2201+ }
2202+
2203+ }
2204+ irelscan->r_addend -= calc_fixup (irelscan->r_addend, 0, sec);
2205+ }
2206+ else if (ELF64_R_TYPE (irelscan->r_info) == (int) R_MICROBLAZE_32_SYM_OP_SYM)
2207+ {
2208+ isym = isymbuf + ELF64_R_SYM (irelscan->r_info);
2209+
2210+ /* Look at the reloc only if the value has been resolved. */
2211+ if (ocontents == NULL)
2212+ {
2213+ if (elf_section_data (o)->this_hdr.contents != NULL)
2214+ ocontents = elf_section_data (o)->this_hdr.contents;
2215+ else
2216+ {
2217+ /* We always cache the section contents.
2218+ Perhaps, if info->keep_memory is FALSE, we
2219+ should free them, if we are permitted to. */
2220+
2221+ if (o->rawsize == 0)
2222+ o->rawsize = o->size;
2223+ ocontents = (bfd_byte *) bfd_malloc (o->rawsize);
2224+ if (ocontents == NULL)
2225+ goto error_return;
2226+ if (!bfd_get_section_contents (abfd, o, ocontents,
2227+ (file_ptr) 0,
2228+ o->rawsize))
2229+ goto error_return;
2230+ elf_section_data (o)->this_hdr.contents = ocontents;
2231+ }
2232+ }
2233+ irelscan->r_addend -= calc_fixup (irelscan->r_addend
2234+ + isym->st_value,
2235+ 0,
2236+ sec);
2237+ }
2238+ }
2239+ else if ((ELF64_R_TYPE (irelscan->r_info) == (int) R_MICROBLAZE_32_PCREL_LO)
2240+ || (ELF64_R_TYPE (irelscan->r_info) == (int) R_MICROBLAZE_32_LO))
2241+ {
2242+ isym = isymbuf + ELF64_R_SYM (irelscan->r_info);
2243+
2244+ /* Look at the reloc only if the value has been resolved. */
2245+ if (isym->st_shndx == shndx
2246+ && (ELF64_ST_TYPE (isym->st_info) == STT_SECTION))
2247+ {
2248+ bfd_vma immediate;
2249+ bfd_vma target_address;
2250+
2251+ if (ocontents == NULL)
2252+ {
2253+ if (elf_section_data (o)->this_hdr.contents != NULL)
2254+ ocontents = elf_section_data (o)->this_hdr.contents;
2255+ else
2256+ {
2257+ /* We always cache the section contents.
2258+ Perhaps, if info->keep_memory is FALSE, we
2259+ should free them, if we are permitted to. */
2260+ if (o->rawsize == 0)
2261+ o->rawsize = o->size;
2262+ ocontents = (bfd_byte *) bfd_malloc (o->rawsize);
2263+ if (ocontents == NULL)
2264+ goto error_return;
2265+ if (!bfd_get_section_contents (abfd, o, ocontents,
2266+ (file_ptr) 0,
2267+ o->rawsize))
2268+ goto error_return;
2269+ elf_section_data (o)->this_hdr.contents = ocontents;
2270+ }
2271+ }
2272+
2273+ unsigned long instr = bfd_get_32 (abfd, ocontents + irelscan->r_offset);
2274+ immediate = instr & 0x0000ffff;
2275+ target_address = immediate;
2276+ offset = calc_fixup (target_address, 0, sec);
2277+ immediate -= offset;
2278+ irelscan->r_addend -= offset;
2279+ microblaze_bfd_write_imm_value_32 (abfd, ocontents + irelscan->r_offset,
2280+ irelscan->r_addend);
2281+ }
2282+ }
2283+
2284+ if (ELF64_R_TYPE (irelscan->r_info) == (int) R_MICROBLAZE_64)
2285+ {
2286+ isym = isymbuf + ELF64_R_SYM (irelscan->r_info);
2287+
2288+ /* Look at the reloc only if the value has been resolved. */
2289+ if (isym->st_shndx == shndx
2290+ && (ELF64_ST_TYPE (isym->st_info) == STT_SECTION))
2291+ {
2292+ bfd_vma immediate;
2293+
2294+ if (ocontents == NULL)
2295+ {
2296+ if (elf_section_data (o)->this_hdr.contents != NULL)
2297+ ocontents = elf_section_data (o)->this_hdr.contents;
2298+ else
2299+ {
2300+ /* We always cache the section contents.
2301+ Perhaps, if info->keep_memory is FALSE, we
2302+ should free them, if we are permitted to. */
2303+
2304+ if (o->rawsize == 0)
2305+ o->rawsize = o->size;
2306+ ocontents = (bfd_byte *) bfd_malloc (o->rawsize);
2307+ if (ocontents == NULL)
2308+ goto error_return;
2309+ if (!bfd_get_section_contents (abfd, o, ocontents,
2310+ (file_ptr) 0,
2311+ o->rawsize))
2312+ goto error_return;
2313+ elf_section_data (o)->this_hdr.contents = ocontents;
2314+ }
2315+ }
2316+ unsigned long instr_hi = bfd_get_32 (abfd, ocontents
2317+ + irelscan->r_offset);
2318+ unsigned long instr_lo = bfd_get_32 (abfd, ocontents
2319+ + irelscan->r_offset
2320+ + INST_WORD_SIZE);
2321+ immediate = (instr_hi & 0x0000ffff) << 16;
2322+ immediate |= (instr_lo & 0x0000ffff);
2323+ offset = calc_fixup (irelscan->r_addend, 0, sec);
2324+ immediate -= offset;
2325+ irelscan->r_addend -= offset;
2326+ }
2327+ }
2328+ else if (ELF64_R_TYPE (irelscan->r_info) == (int) R_MICROBLAZE_64_PCREL)
2329+ {
2330+ isym = isymbuf + ELF64_R_SYM (irelscan->r_info);
2331+
2332+ /* Look at the reloc only if the value has been resolved. */
2333+ if (isym->st_shndx == shndx
2334+ && (ELF64_ST_TYPE (isym->st_info) == STT_SECTION))
2335+ {
2336+ bfd_vma immediate;
2337+ bfd_vma target_address;
2338+
2339+ if (ocontents == NULL)
2340+ {
2341+ if (elf_section_data (o)->this_hdr.contents != NULL)
2342+ ocontents = elf_section_data (o)->this_hdr.contents;
2343+ else
2344+ {
2345+ /* We always cache the section contents.
2346+ Perhaps, if info->keep_memory is FALSE, we
2347+ should free them, if we are permitted to. */
2348+ if (o->rawsize == 0)
2349+ o->rawsize = o->size;
2350+ ocontents = (bfd_byte *) bfd_malloc (o->rawsize);
2351+ if (ocontents == NULL)
2352+ goto error_return;
2353+ if (!bfd_get_section_contents (abfd, o, ocontents,
2354+ (file_ptr) 0,
2355+ o->rawsize))
2356+ goto error_return;
2357+ elf_section_data (o)->this_hdr.contents = ocontents;
2358+ }
2359+ }
2360+ unsigned long instr_hi = bfd_get_32 (abfd, ocontents
2361+ + irelscan->r_offset);
2362+ unsigned long instr_lo = bfd_get_32 (abfd, ocontents
2363+ + irelscan->r_offset
2364+ + INST_WORD_SIZE);
2365+ immediate = (instr_hi & 0x0000ffff) << 16;
2366+ immediate |= (instr_lo & 0x0000ffff);
2367+ target_address = immediate;
2368+ offset = calc_fixup (target_address, 0, sec);
2369+ immediate -= offset;
2370+ irelscan->r_addend -= offset;
2371+ microblaze_bfd_write_imm_value_64 (abfd, ocontents
2372+ + irelscan->r_offset, immediate);
2373+ }
2374+ }
2375+ }
2376+ }
2377+
2378+ /* Adjust the local symbols defined in this section. */
2379+ isymend = isymbuf + symtab_hdr->sh_info;
2380+ for (isym = isymbuf; isym < isymend; isym++)
2381+ {
2382+ if (isym->st_shndx == shndx)
2383+ {
2384+ isym->st_value -= calc_fixup (isym->st_value, 0, sec);
2385+ if (isym->st_size)
2386+ isym->st_size -= calc_fixup (isym->st_value, isym->st_size, sec);
2387+ }
2388+ }
2389+
2390+ /* Now adjust the global symbols defined in this section. */
2391+ isym = isymbuf + symtab_hdr->sh_info;
2392+ symcount = (symtab_hdr->sh_size / sizeof (Elf64_External_Sym)) - symtab_hdr->sh_info;
2393+ for (sym_index = 0; sym_index < symcount; sym_index++)
2394+ {
2395+ sym_hash = elf_sym_hashes (abfd)[sym_index];
2396+ if ((sym_hash->root.type == bfd_link_hash_defined
2397+ || sym_hash->root.type == bfd_link_hash_defweak)
2398+ && sym_hash->root.u.def.section == sec)
2399+ {
2400+ sym_hash->root.u.def.value -= calc_fixup (sym_hash->root.u.def.value,
2401+ 0, sec);
2402+ if (sym_hash->size)
2403+ sym_hash->size -= calc_fixup (sym_hash->root.u.def.value,
2404+ sym_hash->size, sec);
2405+ }
2406+ }
2407+
2408+ /* Physically move the code and change the cooked size. */
2409+ dest = sec->relax[0].addr;
2410+ for (i = 0; i < sec->relax_count; i++)
2411+ {
2412+ int len;
2413+ src = sec->relax[i].addr + sec->relax[i].size;
2414+ len = sec->relax[i+1].addr - sec->relax[i].addr - sec->relax[i].size;
2415+
2416+ memmove (contents + dest, contents + src, len);
2417+ sec->size -= sec->relax[i].size;
2418+ dest += len;
2419+ }
2420+
2421+ elf_section_data (sec)->relocs = internal_relocs;
2422+ free_relocs = NULL;
2423+
2424+ elf_section_data (sec)->this_hdr.contents = contents;
2425+ free_contents = NULL;
2426+
2427+ symtab_hdr->contents = (bfd_byte *) isymbuf;
2428+ }
2429+
2430+ if (free_relocs != NULL)
2431+ {
2432+ free (free_relocs);
2433+ free_relocs = NULL;
2434+ }
2435+
2436+ if (free_contents != NULL)
2437+ {
2438+ if (!link_info->keep_memory)
2439+ free (free_contents);
2440+ else
2441+ /* Cache the section contents for elf_link_input_bfd. */
2442+ elf_section_data (sec)->this_hdr.contents = contents;
2443+ free_contents = NULL;
2444+ }
2445+
2446+ if (sec->relax_count == 0)
2447+ {
2448+ *again = FALSE;
2449+ free (sec->relax);
2450+ sec->relax = NULL;
2451+ }
2452+ else
2453+ *again = TRUE;
2454+ return TRUE;
2455+
2456+ error_return:
2457+ if (free_relocs != NULL)
2458+ free (free_relocs);
2459+ if (free_contents != NULL)
2460+ free (free_contents);
2461+ if (sec->relax != NULL)
2462+ {
2463+ free (sec->relax);
2464+ sec->relax = NULL;
2465+ sec->relax_count = 0;
2466+ }
2467+ return FALSE;
2468+}
2469+
2470+/* Return the section that should be marked against GC for a given
2471+ relocation. */
2472+
2473+static asection *
2474+microblaze_elf_gc_mark_hook (asection *sec,
2475+ struct bfd_link_info * info,
2476+ Elf_Internal_Rela * rel,
2477+ struct elf_link_hash_entry * h,
2478+ Elf_Internal_Sym * sym)
2479+{
2480+ if (h != NULL)
2481+ switch (ELF64_R_TYPE (rel->r_info))
2482+ {
2483+ case R_MICROBLAZE_GNU_VTINHERIT:
2484+ case R_MICROBLAZE_GNU_VTENTRY:
2485+ return NULL;
2486+ }
2487+
2488+ return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
2489+}
2490+
2491+/* Update the got entry reference counts for the section being removed. */
2492+
2493+static bfd_boolean
2494+microblaze_elf_gc_sweep_hook (bfd * abfd ATTRIBUTE_UNUSED,
2495+ struct bfd_link_info * info ATTRIBUTE_UNUSED,
2496+ asection * sec ATTRIBUTE_UNUSED,
2497+ const Elf_Internal_Rela * relocs ATTRIBUTE_UNUSED)
2498+{
2499+ return TRUE;
2500+}
2501+
2502+/* PIC support. */
2503+
2504+#define PLT_ENTRY_SIZE 16
2505+
2506+#define PLT_ENTRY_WORD_0 0xb0000000 /* "imm 0". */
2507+#define PLT_ENTRY_WORD_1 0xe9940000 /* "lwi r12,r20,0" - relocated to lwi r12,r20,func@GOT. */
2508+#define PLT_ENTRY_WORD_1_NOPIC 0xe9800000 /* "lwi r12,r0,0" - non-PIC object. */
2509+#define PLT_ENTRY_WORD_2 0x98186000 /* "brad r12". */
2510+#define PLT_ENTRY_WORD_3 0x80000000 /* "nop". */
2511+
2512+/* Create .got, .gotplt, and .rela.got sections in DYNOBJ, and set up
2513+ shortcuts to them in our hash table. */
2514+
2515+static bfd_boolean
2516+create_got_section (bfd *dynobj, struct bfd_link_info *info)
2517+{
2518+ struct elf64_mb_link_hash_table *htab;
2519+
2520+ if (! _bfd_elf_create_got_section (dynobj, info))
2521+ return FALSE;
2522+ htab = elf64_mb_hash_table (info);
2523+ if (htab == NULL)
2524+ return FALSE;
2525+
2526+ htab->sgot = bfd_get_linker_section (dynobj, ".got");
2527+ htab->sgotplt = bfd_get_linker_section (dynobj, ".got.plt");
2528+ if (!htab->sgot || !htab->sgotplt)
2529+ return FALSE;
2530+
2531+ if ((htab->srelgot = bfd_get_linker_section (dynobj, ".rela.got")) == NULL)
2532+ htab->srelgot = bfd_make_section_anyway (dynobj, ".rela.got");
2533+ if (htab->srelgot == NULL
2534+ || ! bfd_set_section_flags (dynobj, htab->srelgot, SEC_ALLOC
2535+ | SEC_LOAD
2536+ | SEC_HAS_CONTENTS
2537+ | SEC_IN_MEMORY
2538+ | SEC_LINKER_CREATED
2539+ | SEC_READONLY)
2540+ || ! bfd_set_section_alignment (dynobj, htab->srelgot, 2))
2541+ return FALSE;
2542+ return TRUE;
2543+}
2544+
2545+static bfd_boolean
2546+update_local_sym_info (bfd *abfd,
2547+ Elf_Internal_Shdr *symtab_hdr,
2548+ unsigned long r_symndx,
2549+ unsigned int tls_type)
2550+{
2551+ bfd_signed_vma *local_got_refcounts = elf_local_got_refcounts (abfd);
2552+ unsigned char *local_got_tls_masks;
2553+
2554+ if (local_got_refcounts == NULL)
2555+ {
2556+ bfd_size_type size = symtab_hdr->sh_info;
2557+
2558+ size *= (sizeof (*local_got_refcounts) + sizeof (*local_got_tls_masks));
2559+ local_got_refcounts = bfd_zalloc (abfd, size);
2560+ if (local_got_refcounts == NULL)
2561+ return FALSE;
2562+ elf_local_got_refcounts (abfd) = local_got_refcounts;
2563+ }
2564+
2565+ local_got_tls_masks =
2566+ (unsigned char *) (local_got_refcounts + symtab_hdr->sh_info);
2567+ local_got_tls_masks[r_symndx] |= tls_type;
2568+ local_got_refcounts[r_symndx] += 1;
2569+
2570+ return TRUE;
2571+}
2572+/* Look through the relocs for a section during the first phase. */
2573+
2574+static bfd_boolean
2575+microblaze_elf_check_relocs (bfd * abfd,
2576+ struct bfd_link_info * info,
2577+ asection * sec,
2578+ const Elf_Internal_Rela * relocs)
2579+{
2580+ Elf_Internal_Shdr * symtab_hdr;
2581+ struct elf_link_hash_entry ** sym_hashes;
2582+ struct elf_link_hash_entry ** sym_hashes_end;
2583+ const Elf_Internal_Rela * rel;
2584+ const Elf_Internal_Rela * rel_end;
2585+ struct elf64_mb_link_hash_table *htab;
2586+ asection *sreloc = NULL;
2587+
2588+ if (bfd_link_relocatable (info))
2589+ return TRUE;
2590+
2591+ htab = elf64_mb_hash_table (info);
2592+ if (htab == NULL)
2593+ return FALSE;
2594+
2595+ symtab_hdr = & elf_tdata (abfd)->symtab_hdr;
2596+ sym_hashes = elf_sym_hashes (abfd);
2597+ sym_hashes_end = sym_hashes + symtab_hdr->sh_size / sizeof (Elf64_External_Sym);
2598+ if (!elf_bad_symtab (abfd))
2599+ sym_hashes_end -= symtab_hdr->sh_info;
2600+
2601+ rel_end = relocs + sec->reloc_count;
2602+
2603+ for (rel = relocs; rel < rel_end; rel++)
2604+ {
2605+ unsigned int r_type;
2606+ struct elf_link_hash_entry * h;
2607+ unsigned long r_symndx;
2608+ unsigned char tls_type = 0;
2609+
2610+ r_symndx = ELF64_R_SYM (rel->r_info);
2611+ r_type = ELF64_R_TYPE (rel->r_info);
2612+
2613+ if (r_symndx < symtab_hdr->sh_info)
2614+ h = NULL;
2615+ else
2616+ {
2617+ h = sym_hashes [r_symndx - symtab_hdr->sh_info];
2618+
2619+ /* PR15323, ref flags aren't set for references in the same
2620+ object. */
2621+ h->root.non_ir_ref = 1;
2622+ }
2623+
2624+ switch (r_type)
2625+ {
2626+ /* This relocation describes the C++ object vtable hierarchy.
2627+ Reconstruct it for later use during GC. */
2628+ case R_MICROBLAZE_GNU_VTINHERIT:
2629+ if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
2630+ return FALSE;
2631+ break;
2632+
2633+ /* This relocation describes which C++ vtable entries are actually
2634+ used. Record for later use during GC. */
2635+ case R_MICROBLAZE_GNU_VTENTRY:
2636+ if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
2637+ return FALSE;
2638+ break;
2639+
2640+ /* This relocation requires .plt entry. */
2641+ case R_MICROBLAZE_PLT_64:
2642+ if (h != NULL)
2643+ {
2644+ h->needs_plt = 1;
2645+ h->plt.refcount += 1;
2646+ }
2647+ break;
2648+
2649+ /* This relocation requires .got entry. */
2650+ case R_MICROBLAZE_TLSGD:
2651+ tls_type |= (TLS_TLS | TLS_GD);
2652+ goto dogottls;
2653+ case R_MICROBLAZE_TLSLD:
2654+ tls_type |= (TLS_TLS | TLS_LD);
2655+ dogottls:
2656+ sec->has_tls_reloc = 1;
2657+ case R_MICROBLAZE_GOT_64:
2658+ if (htab->sgot == NULL)
2659+ {
2660+ if (htab->elf.dynobj == NULL)
2661+ htab->elf.dynobj = abfd;
2662+ if (!create_got_section (htab->elf.dynobj, info))
2663+ return FALSE;
2664+ }
2665+ if (h != NULL)
2666+ {
2667+ h->got.refcount += 1;
2668+ elf64_mb_hash_entry (h)->tls_mask |= tls_type;
2669+ }
2670+ else
2671+ {
2672+ if (! update_local_sym_info(abfd, symtab_hdr, r_symndx, tls_type) )
2673+ return FALSE;
2674+ }
2675+ break;
2676+
2677+ case R_MICROBLAZE_64:
2678+ case R_MICROBLAZE_64_PCREL:
2679+ case R_MICROBLAZE_32:
2680+ {
2681+ if (h != NULL && !bfd_link_pic (info))
2682+ {
2683+ /* we may need a copy reloc. */
2684+ h->non_got_ref = 1;
2685+
2686+ /* we may also need a .plt entry. */
2687+ h->plt.refcount += 1;
2688+ if (ELF64_R_TYPE (rel->r_info) != R_MICROBLAZE_64_PCREL)
2689+ h->pointer_equality_needed = 1;
2690+ }
2691+
2692+
2693+ /* If we are creating a shared library, and this is a reloc
2694+ against a global symbol, or a non PC relative reloc
2695+ against a local symbol, then we need to copy the reloc
2696+ into the shared library. However, if we are linking with
2697+ -Bsymbolic, we do not need to copy a reloc against a
2698+ global symbol which is defined in an object we are
2699+ including in the link (i.e., DEF_REGULAR is set). At
2700+ this point we have not seen all the input files, so it is
2701+ possible that DEF_REGULAR is not set now but will be set
2702+ later (it is never cleared). In case of a weak definition,
2703+ DEF_REGULAR may be cleared later by a strong definition in
2704+ a shared library. We account for that possibility below by
2705+ storing information in the relocs_copied field of the hash
2706+ table entry. A similar situation occurs when creating
2707+ shared libraries and symbol visibility changes render the
2708+ symbol local.
2709+
2710+ If on the other hand, we are creating an executable, we
2711+ may need to keep relocations for symbols satisfied by a
2712+ dynamic library if we manage to avoid copy relocs for the
2713+ symbol. */
2714+
2715+ if ((bfd_link_pic (info)
2716+ && (sec->flags & SEC_ALLOC) != 0
2717+ && (r_type != R_MICROBLAZE_64_PCREL
2718+ || (h != NULL
2719+ && (! info->symbolic
2720+ || h->root.type == bfd_link_hash_defweak
2721+ || !h->def_regular))))
2722+ || (!bfd_link_pic (info)
2723+ && (sec->flags & SEC_ALLOC) != 0
2724+ && h != NULL
2725+ && (h->root.type == bfd_link_hash_defweak
2726+ || !h->def_regular)))
2727+ {
2728+ struct elf64_mb_dyn_relocs *p;
2729+ struct elf64_mb_dyn_relocs **head;
2730+
2731+ /* When creating a shared object, we must copy these
2732+ relocs into the output file. We create a reloc
2733+ section in dynobj and make room for the reloc. */
2734+
2735+ if (sreloc == NULL)
2736+ {
2737+ bfd *dynobj;
2738+
2739+ if (htab->elf.dynobj == NULL)
2740+ htab->elf.dynobj = abfd;
2741+ dynobj = htab->elf.dynobj;
2742+
2743+ sreloc = _bfd_elf_make_dynamic_reloc_section (sec, dynobj,
2744+ 2, abfd, 1);
2745+ if (sreloc == NULL)
2746+ return FALSE;
2747+ }
2748+
2749+ /* If this is a global symbol, we count the number of
2750+ relocations we need for this symbol. */
2751+ if (h != NULL)
2752+ head = &((struct elf64_mb_link_hash_entry *) h)->dyn_relocs;
2753+ else
2754+ {
2755+ /* Track dynamic relocs needed for local syms too.
2756+ We really need local syms available to do this
2757+ easily. Oh well. */
2758+
2759+ asection *s;
2760+ Elf_Internal_Sym *isym;
2761+ void *vpp;
2762+
2763+ isym = bfd_sym_from_r_symndx (&htab->sym_sec,
2764+ abfd, r_symndx);
2765+ if (isym == NULL)
2766+ return FALSE;
2767+
2768+ s = bfd_section_from_elf_index (abfd, isym->st_shndx);
2769+ if (s == NULL)
2770+ return FALSE;
2771+
2772+ vpp = &elf_section_data (s)->local_dynrel;
2773+ head = (struct elf64_mb_dyn_relocs **) vpp;
2774+ }
2775+
2776+ p = *head;
2777+ if (p == NULL || p->sec != sec)
2778+ {
2779+ bfd_size_type amt = sizeof *p;
2780+ p = ((struct elf64_mb_dyn_relocs *)
2781+ bfd_alloc (htab->elf.dynobj, amt));
2782+ if (p == NULL)
2783+ return FALSE;
2784+ p->next = *head;
2785+ *head = p;
2786+ p->sec = sec;
2787+ p->count = 0;
2788+ p->pc_count = 0;
2789+ }
2790+
2791+ p->count += 1;
2792+ if (r_type == R_MICROBLAZE_64_PCREL)
2793+ p->pc_count += 1;
2794+ }
2795+ }
2796+ break;
2797+ }
2798+ }
2799+
2800+ return TRUE;
2801+}
2802+
2803+static bfd_boolean
2804+microblaze_elf_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info)
2805+{
2806+ struct elf64_mb_link_hash_table *htab;
2807+
2808+ htab = elf64_mb_hash_table (info);
2809+ if (htab == NULL)
2810+ return FALSE;
2811+
2812+ if (!htab->sgot && !create_got_section (dynobj, info))
2813+ return FALSE;
2814+
2815+ if (!_bfd_elf_create_dynamic_sections (dynobj, info))
2816+ return FALSE;
2817+
2818+ htab->splt = bfd_get_linker_section (dynobj, ".plt");
2819+ htab->srelplt = bfd_get_linker_section (dynobj, ".rela.plt");
2820+ htab->sdynbss = bfd_get_linker_section (dynobj, ".dynbss");
2821+ if (!bfd_link_pic (info))
2822+ htab->srelbss = bfd_get_linker_section (dynobj, ".rela.bss");
2823+
2824+ if (!htab->splt || !htab->srelplt || !htab->sdynbss
2825+ || (!bfd_link_pic (info) && !htab->srelbss))
2826+ abort ();
2827+
2828+ return TRUE;
2829+}
2830+
2831+/* Copy the extra info we tack onto an elf_link_hash_entry. */
2832+
2833+static void
2834+microblaze_elf_copy_indirect_symbol (struct bfd_link_info *info,
2835+ struct elf_link_hash_entry *dir,
2836+ struct elf_link_hash_entry *ind)
2837+{
2838+ struct elf64_mb_link_hash_entry *edir, *eind;
2839+
2840+ edir = (struct elf64_mb_link_hash_entry *) dir;
2841+ eind = (struct elf64_mb_link_hash_entry *) ind;
2842+
2843+ if (eind->dyn_relocs != NULL)
2844+ {
2845+ if (edir->dyn_relocs != NULL)
2846+ {
2847+ struct elf64_mb_dyn_relocs **pp;
2848+ struct elf64_mb_dyn_relocs *p;
2849+
2850+ if (ind->root.type == bfd_link_hash_indirect)
2851+ abort ();
2852+
2853+ /* Add reloc counts against the weak sym to the strong sym
2854+ list. Merge any entries against the same section. */
2855+ for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
2856+ {
2857+ struct elf64_mb_dyn_relocs *q;
2858+
2859+ for (q = edir->dyn_relocs; q != NULL; q = q->next)
2860+ if (q->sec == p->sec)
2861+ {
2862+ q->pc_count += p->pc_count;
2863+ q->count += p->count;
2864+ *pp = p->next;
2865+ break;
2866+ }
2867+ if (q == NULL)
2868+ pp = &p->next;
2869+ }
2870+ *pp = edir->dyn_relocs;
2871+ }
2872+
2873+ edir->dyn_relocs = eind->dyn_relocs;
2874+ eind->dyn_relocs = NULL;
2875+ }
2876+
2877+ edir->tls_mask |= eind->tls_mask;
2878+
2879+ _bfd_elf_link_hash_copy_indirect (info, dir, ind);
2880+}
2881+
2882+static bfd_boolean
2883+microblaze_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
2884+ struct elf_link_hash_entry *h)
2885+{
2886+ struct elf64_mb_link_hash_table *htab;
2887+ struct elf64_mb_link_hash_entry * eh;
2888+ struct elf64_mb_dyn_relocs *p;
2889+ asection *sdynbss, *s;
2890+ unsigned int power_of_two;
2891+ bfd *dynobj;
2892+
2893+ htab = elf64_mb_hash_table (info);
2894+ if (htab == NULL)
2895+ return FALSE;
2896+
2897+ /* If this is a function, put it in the procedure linkage table. We
2898+ will fill in the contents of the procedure linkage table later,
2899+ when we know the address of the .got section. */
2900+ if (h->type == STT_FUNC
2901+ || h->needs_plt)
2902+ {
2903+ if (h->plt.refcount <= 0
2904+ || SYMBOL_CALLS_LOCAL (info, h)
2905+ || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
2906+ && h->root.type == bfd_link_hash_undefweak))
2907+ {
2908+ /* This case can occur if we saw a PLT reloc in an input
2909+ file, but the symbol was never referred to by a dynamic
2910+ object, or if all references were garbage collected. In
2911+ such a case, we don't actually need to build a procedure
2912+ linkage table, and we can just do a PC32 reloc instead. */
2913+ h->plt.offset = (bfd_vma) -1;
2914+ h->needs_plt = 0;
2915+ }
2916+
2917+ return TRUE;
2918+ }
2919+ else
2920+ /* It's possible that we incorrectly decided a .plt reloc was
2921+ needed for an R_MICROBLAZE_64_PCREL reloc to a non-function sym in
2922+ check_relocs. We can't decide accurately between function and
2923+ non-function syms in check-relocs; Objects loaded later in
2924+ the link may change h->type. So fix it now. */
2925+ h->plt.offset = (bfd_vma) -1;
2926+
2927+ /* If this is a weak symbol, and there is a real definition, the
2928+ processor independent code will have arranged for us to see the
2929+ real definition first, and we can just use the same value. */
2930+ if (h->u.weakdef != NULL)
2931+ {
2932+ BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
2933+ || h->u.weakdef->root.type == bfd_link_hash_defweak);
2934+ h->root.u.def.section = h->u.weakdef->root.u.def.section;
2935+ h->root.u.def.value = h->u.weakdef->root.u.def.value;
2936+ return TRUE;
2937+ }
2938+
2939+ /* This is a reference to a symbol defined by a dynamic object which
2940+ is not a function. */
2941+
2942+ /* If we are creating a shared library, we must presume that the
2943+ only references to the symbol are via the global offset table.
2944+ For such cases we need not do anything here; the relocations will
2945+ be handled correctly by relocate_section. */
2946+ if (bfd_link_pic (info))
2947+ return TRUE;
2948+
2949+ /* If there are no references to this symbol that do not use the
2950+ GOT, we don't need to generate a copy reloc. */
2951+ if (!h->non_got_ref)
2952+ return TRUE;
2953+
2954+ /* If -z nocopyreloc was given, we won't generate them either. */
2955+ if (info->nocopyreloc)
2956+ {
2957+ h->non_got_ref = 0;
2958+ return TRUE;
2959+ }
2960+
2961+ eh = (struct elf64_mb_link_hash_entry *) h;
2962+ for (p = eh->dyn_relocs; p != NULL; p = p->next)
2963+ {
2964+ s = p->sec->output_section;
2965+ if (s != NULL && (s->flags & SEC_READONLY) != 0)
2966+ break;
2967+ }
2968+
2969+ /* If we didn't find any dynamic relocs in read-only sections, then
2970+ we'll be keeping the dynamic relocs and avoiding the copy reloc. */
2971+ if (p == NULL)
2972+ {
2973+ h->non_got_ref = 0;
2974+ return TRUE;
2975+ }
2976+
2977+ /* We must allocate the symbol in our .dynbss section, which will
2978+ become part of the .bss section of the executable. There will be
2979+ an entry for this symbol in the .dynsym section. The dynamic
2980+ object will contain position independent code, so all references
2981+ from the dynamic object to this symbol will go through the global
2982+ offset table. The dynamic linker will use the .dynsym entry to
2983+ determine the address it must put in the global offset table, so
2984+ both the dynamic object and the regular object will refer to the
2985+ same memory location for the variable. */
2986+
2987+ /* We must generate a R_MICROBLAZE_COPY reloc to tell the dynamic linker
2988+ to copy the initial value out of the dynamic object and into the
2989+ runtime process image. */
2990+ dynobj = elf_hash_table (info)->dynobj;
2991+ BFD_ASSERT (dynobj != NULL);
2992+ if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
2993+ {
2994+ htab->srelbss->size += sizeof (Elf64_External_Rela);
2995+ h->needs_copy = 1;
2996+ }
2997+
2998+ /* We need to figure out the alignment required for this symbol. I
2999+ have no idea how ELF linkers handle this. */
3000+ power_of_two = bfd_log2 (h->size);
3001+ if (power_of_two > 3)
3002+ power_of_two = 3;
3003+
3004+ sdynbss = htab->sdynbss;
3005+ /* Apply the required alignment. */
3006+ sdynbss->size = BFD_ALIGN (sdynbss->size, (bfd_size_type) (1 << power_of_two));
3007+ if (power_of_two > bfd_get_section_alignment (dynobj, sdynbss))
3008+ {
3009+ if (! bfd_set_section_alignment (dynobj, sdynbss, power_of_two))
3010+ return FALSE;
3011+ }
3012+
3013+ /* Define the symbol as being at this point in the section. */
3014+ h->root.u.def.section = sdynbss;
3015+ h->root.u.def.value = sdynbss->size;
3016+
3017+ /* Increment the section size to make room for the symbol. */
3018+ sdynbss->size += h->size;
3019+ return TRUE;
3020+}
3021+
3022+/* Allocate space in .plt, .got and associated reloc sections for
3023+ dynamic relocs. */
3024+
3025+static bfd_boolean
3026+allocate_dynrelocs (struct elf_link_hash_entry *h, void * dat)
3027+{
3028+ struct bfd_link_info *info;
3029+ struct elf64_mb_link_hash_table *htab;
3030+ struct elf64_mb_link_hash_entry *eh;
3031+ struct elf64_mb_dyn_relocs *p;
3032+
3033+ if (h->root.type == bfd_link_hash_indirect)
3034+ return TRUE;
3035+
3036+ info = (struct bfd_link_info *) dat;
3037+ htab = elf64_mb_hash_table (info);
3038+ if (htab == NULL)
3039+ return FALSE;
3040+
3041+ if (htab->elf.dynamic_sections_created
3042+ && h->plt.refcount > 0)
3043+ {
3044+ /* Make sure this symbol is output as a dynamic symbol.
3045+ Undefined weak syms won't yet be marked as dynamic. */
3046+ if (h->dynindx == -1
3047+ && !h->forced_local)
3048+ {
3049+ if (! bfd_elf_link_record_dynamic_symbol (info, h))
3050+ return FALSE;
3051+ }
3052+
3053+ if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, bfd_link_pic (info), h))
3054+ {
3055+ asection *s = htab->splt;
3056+
3057+ /* The first entry in .plt is reserved. */
3058+ if (s->size == 0)
3059+ s->size = PLT_ENTRY_SIZE;
3060+
3061+ h->plt.offset = s->size;
3062+
3063+ /* If this symbol is not defined in a regular file, and we are
3064+ not generating a shared library, then set the symbol to this
3065+ location in the .plt. This is required to make function
3066+ pointers compare as equal between the normal executable and
3067+ the shared library. */
3068+ if (! bfd_link_pic (info)
3069+ && !h->def_regular)
3070+ {
3071+ h->root.u.def.section = s;
3072+ h->root.u.def.value = h->plt.offset;
3073+ }
3074+
3075+ /* Make room for this entry. */
3076+ s->size += PLT_ENTRY_SIZE;
3077+
3078+ /* We also need to make an entry in the .got.plt section, which
3079+ will be placed in the .got section by the linker script. */
3080+ htab->sgotplt->size += 4;
3081+
3082+ /* We also need to make an entry in the .rel.plt section. */
3083+ htab->srelplt->size += sizeof (Elf64_External_Rela);
3084+ }
3085+ else
3086+ {
3087+ h->plt.offset = (bfd_vma) -1;
3088+ h->needs_plt = 0;
3089+ }
3090+ }
3091+ else
3092+ {
3093+ h->plt.offset = (bfd_vma) -1;
3094+ h->needs_plt = 0;
3095+ }
3096+
3097+ eh = (struct elf64_mb_link_hash_entry *) h;
3098+ if (h->got.refcount > 0)
3099+ {
3100+ unsigned int need;
3101+ asection *s;
3102+
3103+ /* Make sure this symbol is output as a dynamic symbol.
3104+ Undefined weak syms won't yet be marked as dynamic. */
3105+ if (h->dynindx == -1
3106+ && !h->forced_local)
3107+ {
3108+ if (! bfd_elf_link_record_dynamic_symbol (info, h))
3109+ return FALSE;
3110+ }
3111+
3112+ need = 0;
3113+ if ((eh->tls_mask & TLS_TLS) != 0)
3114+ {
3115+ /* Handle TLS Symbol */
3116+ if ((eh->tls_mask & TLS_LD) != 0)
3117+ {
3118+ if (!eh->elf.def_dynamic)
3119+ /* We'll just use htab->tlsld_got.offset. This should
3120+ always be the case. It's a little odd if we have
3121+ a local dynamic reloc against a non-local symbol. */
3122+ htab->tlsld_got.refcount += 1;
3123+ else
3124+ need += 8;
3125+ }
3126+ if ((eh->tls_mask & TLS_GD) != 0)
3127+ need += 8;
3128+ }
3129+ else
3130+ {
3131+ /* Regular (non-TLS) symbol */
3132+ need += 4;
3133+ }
3134+ if (need == 0)
3135+ {
3136+ h->got.offset = (bfd_vma) -1;
3137+ }
3138+ else
3139+ {
3140+ s = htab->sgot;
3141+ h->got.offset = s->size;
3142+ s->size += need;
3143+ htab->srelgot->size += need * (sizeof (Elf64_External_Rela) / 4);
3144+ }
3145+ }
3146+ else
3147+ h->got.offset = (bfd_vma) -1;
3148+
3149+ if (eh->dyn_relocs == NULL)
3150+ return TRUE;
3151+
3152+ /* In the shared -Bsymbolic case, discard space allocated for
3153+ dynamic pc-relative relocs against symbols which turn out to be
3154+ defined in regular objects. For the normal shared case, discard
3155+ space for pc-relative relocs that have become local due to symbol
3156+ visibility changes. */
3157+
3158+ if (bfd_link_pic (info))
3159+ {
3160+ if (h->def_regular
3161+ && (h->forced_local
3162+ || info->symbolic))
3163+ {
3164+ struct elf64_mb_dyn_relocs **pp;
3165+
3166+ for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
3167+ {
3168+ p->count -= p->pc_count;
3169+ p->pc_count = 0;
3170+ if (p->count == 0)
3171+ *pp = p->next;
3172+ else
3173+ pp = &p->next;
3174+ }
3175+ }
3176+ }
3177+ else
3178+ {
3179+ /* For the non-shared case, discard space for relocs against
3180+ symbols which turn out to need copy relocs or are not
3181+ dynamic. */
3182+
3183+ if (!h->non_got_ref
3184+ && ((h->def_dynamic
3185+ && !h->def_regular)
3186+ || (htab->elf.dynamic_sections_created
3187+ && (h->root.type == bfd_link_hash_undefweak
3188+ || h->root.type == bfd_link_hash_undefined))))
3189+ {
3190+ /* Make sure this symbol is output as a dynamic symbol.
3191+ Undefined weak syms won't yet be marked as dynamic. */
3192+ if (h->dynindx == -1
3193+ && !h->forced_local)
3194+ {
3195+ if (! bfd_elf_link_record_dynamic_symbol (info, h))
3196+ return FALSE;
3197+ }
3198+
3199+ /* If that succeeded, we know we'll be keeping all the
3200+ relocs. */
3201+ if (h->dynindx != -1)
3202+ goto keep;
3203+ }
3204+
3205+ eh->dyn_relocs = NULL;
3206+
3207+ keep: ;
3208+ }
3209+
3210+ /* Finally, allocate space. */
3211+ for (p = eh->dyn_relocs; p != NULL; p = p->next)
3212+ {
3213+ asection *sreloc = elf_section_data (p->sec)->sreloc;
3214+ sreloc->size += p->count * sizeof (Elf64_External_Rela);
3215+ }
3216+
3217+ return TRUE;
3218+}
3219+
3220+/* Set the sizes of the dynamic sections. */
3221+
3222+static bfd_boolean
3223+microblaze_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
3224+ struct bfd_link_info *info)
3225+{
3226+ struct elf64_mb_link_hash_table *htab;
3227+ bfd *dynobj;
3228+ asection *s;
3229+ bfd *ibfd;
3230+
3231+ htab = elf64_mb_hash_table (info);
3232+ if (htab == NULL)
3233+ return FALSE;
3234+
3235+ dynobj = htab->elf.dynobj;
3236+ BFD_ASSERT (dynobj != NULL);
3237+
3238+ /* Set up .got offsets for local syms, and space for local dynamic
3239+ relocs. */
3240+ for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
3241+ {
3242+ bfd_signed_vma *local_got;
3243+ bfd_signed_vma *end_local_got;
3244+ bfd_size_type locsymcount;
3245+ Elf_Internal_Shdr *symtab_hdr;
3246+ unsigned char *lgot_masks;
3247+ asection *srel;
3248+
3249+ if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
3250+ continue;
3251+
3252+ for (s = ibfd->sections; s != NULL; s = s->next)
3253+ {
3254+ struct elf64_mb_dyn_relocs *p;
3255+
3256+ for (p = ((struct elf64_mb_dyn_relocs *)
3257+ elf_section_data (s)->local_dynrel);
3258+ p != NULL;
3259+ p = p->next)
3260+ {
3261+ if (!bfd_is_abs_section (p->sec)
3262+ && bfd_is_abs_section (p->sec->output_section))
3263+ {
3264+ /* Input section has been discarded, either because
3265+ it is a copy of a linkonce section or due to
3266+ linker script /DISCARD/, so we'll be discarding
3267+ the relocs too. */
3268+ }
3269+ else if (p->count != 0)
3270+ {
3271+ srel = elf_section_data (p->sec)->sreloc;
3272+ srel->size += p->count * sizeof (Elf64_External_Rela);
3273+ if ((p->sec->output_section->flags & SEC_READONLY) != 0)
3274+ info->flags |= DF_TEXTREL;
3275+ }
3276+ }
3277+ }
3278+
3279+ local_got = elf_local_got_refcounts (ibfd);
3280+ if (!local_got)
3281+ continue;
3282+
3283+ symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
3284+ locsymcount = symtab_hdr->sh_info;
3285+ end_local_got = local_got + locsymcount;
3286+ lgot_masks = (unsigned char *) end_local_got;
3287+ s = htab->sgot;
3288+ srel = htab->srelgot;
3289+
3290+ for (; local_got < end_local_got; ++local_got, ++lgot_masks)
3291+ {
3292+ if (*local_got > 0)
3293+ {
3294+ unsigned int need = 0;
3295+ if ((*lgot_masks & TLS_TLS) != 0)
3296+ {
3297+ if ((*lgot_masks & TLS_GD) != 0)
3298+ need += 8;
3299+ if ((*lgot_masks & TLS_LD) != 0)
3300+ htab->tlsld_got.refcount += 1;
3301+ }
3302+ else
3303+ need += 4;
3304+
3305+ if (need == 0)
3306+ {
3307+ *local_got = (bfd_vma) -1;
3308+ }
3309+ else
3310+ {
3311+ *local_got = s->size;
3312+ s->size += need;
3313+ if (bfd_link_pic (info))
3314+ srel->size += need * (sizeof (Elf64_External_Rela) / 4);
3315+ }
3316+ }
3317+ else
3318+ *local_got = (bfd_vma) -1;
3319+ }
3320+ }
3321+
3322+ /* Allocate global sym .plt and .got entries, and space for global
3323+ sym dynamic relocs. */
3324+ elf_link_hash_traverse (elf_hash_table (info), allocate_dynrelocs, info);
3325+
3326+ if (htab->tlsld_got.refcount > 0)
3327+ {
3328+ htab->tlsld_got.offset = htab->sgot->size;
3329+ htab->sgot->size += 8;
3330+ if (bfd_link_pic (info))
3331+ htab->srelgot->size += sizeof (Elf64_External_Rela);
3332+ }
3333+ else
3334+ htab->tlsld_got.offset = (bfd_vma) -1;
3335+
3336+ if (elf_hash_table (info)->dynamic_sections_created)
3337+ {
3338+ /* Make space for the trailing nop in .plt. */
3339+ if (htab->splt->size > 0)
3340+ htab->splt->size += 4;
3341+ }
3342+
3343+ /* The check_relocs and adjust_dynamic_symbol entry points have
3344+ determined the sizes of the various dynamic sections. Allocate
3345+ memory for them. */
3346+ for (s = dynobj->sections; s != NULL; s = s->next)
3347+ {
3348+ const char *name;
3349+ bfd_boolean strip = FALSE;
3350+
3351+ if ((s->flags & SEC_LINKER_CREATED) == 0)
3352+ continue;
3353+
3354+ /* It's OK to base decisions on the section name, because none
3355+ of the dynobj section names depend upon the input files. */
3356+ name = bfd_get_section_name (dynobj, s);
3357+
3358+ if (strncmp (name, ".rela", 5) == 0)
3359+ {
3360+ if (s->size == 0)
3361+ {
3362+ /* If we don't need this section, strip it from the
3363+ output file. This is to handle .rela.bss and
3364+ .rela.plt. We must create it in
3365+ create_dynamic_sections, because it must be created
3366+ before the linker maps input sections to output
3367+ sections. The linker does that before
3368+ adjust_dynamic_symbol is called, and it is that
3369+ function which decides whether anything needs to go
3370+ into these sections. */
3371+ strip = TRUE;
3372+ }
3373+ else
3374+ {
3375+ /* We use the reloc_count field as a counter if we need
3376+ to copy relocs into the output file. */
3377+ s->reloc_count = 0;
3378+ }
3379+ }
3380+ else if (s != htab->splt && s != htab->sgot && s != htab->sgotplt)
3381+ {
3382+ /* It's not one of our sections, so don't allocate space. */
3383+ continue;
3384+ }
3385+
3386+ if (strip)
3387+ {
3388+ s->flags |= SEC_EXCLUDE;
3389+ continue;
3390+ }
3391+
3392+ /* Allocate memory for the section contents. */
3393+ /* FIXME: This should be a call to bfd_alloc not bfd_zalloc.
3394+ Unused entries should be reclaimed before the section's contents
3395+ are written out, but at the moment this does not happen. Thus in
3396+ order to prevent writing out garbage, we initialise the section's
3397+ contents to zero. */
3398+ s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
3399+ if (s->contents == NULL && s->size != 0)
3400+ return FALSE;
3401+ }
3402+
3403+ if (elf_hash_table (info)->dynamic_sections_created)
3404+ {
3405+ /* Add some entries to the .dynamic section. We fill in the
3406+ values later, in microblaze_elf_finish_dynamic_sections, but we
3407+ must add the entries now so that we get the correct size for
3408+ the .dynamic section. The DT_DEBUG entry is filled in by the
3409+ dynamic linker and used by the debugger. */
3410+#define add_dynamic_entry(TAG, VAL) \
3411+ _bfd_elf_add_dynamic_entry (info, TAG, VAL)
3412+
3413+ if (bfd_link_executable (info))
3414+ {
3415+ if (!add_dynamic_entry (DT_DEBUG, 0))
3416+ return FALSE;
3417+ }
3418+
3419+ if (!add_dynamic_entry (DT_RELA, 0)
3420+ || !add_dynamic_entry (DT_RELASZ, 0)
3421+ || !add_dynamic_entry (DT_RELAENT, sizeof (Elf64_External_Rela)))
3422+ return FALSE;
3423+
3424+ if (htab->splt->size != 0)
3425+ {
3426+ if (!add_dynamic_entry (DT_PLTGOT, 0)
3427+ || !add_dynamic_entry (DT_PLTRELSZ, 0)
3428+ || !add_dynamic_entry (DT_PLTREL, DT_RELA)
3429+ || !add_dynamic_entry (DT_JMPREL, 0)
3430+ || !add_dynamic_entry (DT_BIND_NOW, 1))
3431+ return FALSE;
3432+ }
3433+
3434+ if (info->flags & DF_TEXTREL)
3435+ {
3436+ if (!add_dynamic_entry (DT_TEXTREL, 0))
3437+ return FALSE;
3438+ }
3439+ }
3440+#undef add_dynamic_entry
3441+ return TRUE;
3442+}
3443+
3444+/* Finish up dynamic symbol handling. We set the contents of various
3445+ dynamic sections here. */
3446+
3447+static bfd_boolean
3448+microblaze_elf_finish_dynamic_symbol (bfd *output_bfd,
3449+ struct bfd_link_info *info,
3450+ struct elf_link_hash_entry *h,
3451+ Elf_Internal_Sym *sym)
3452+{
3453+ struct elf64_mb_link_hash_table *htab;
3454+ struct elf64_mb_link_hash_entry *eh = elf64_mb_hash_entry(h);
3455+
3456+ htab = elf64_mb_hash_table (info);
3457+ if (htab == NULL)
3458+ return FALSE;
3459+
3460+ if (h->plt.offset != (bfd_vma) -1)
3461+ {
3462+ asection *splt;
3463+ asection *srela;
3464+ asection *sgotplt;
3465+ Elf_Internal_Rela rela;
3466+ bfd_byte *loc;
3467+ bfd_vma plt_index;
3468+ bfd_vma got_offset;
3469+ bfd_vma got_addr;
3470+
3471+ /* This symbol has an entry in the procedure linkage table. Set
3472+ it up. */
3473+ BFD_ASSERT (h->dynindx != -1);
3474+
3475+ splt = htab->splt;
3476+ srela = htab->srelplt;
3477+ sgotplt = htab->sgotplt;
3478+ BFD_ASSERT (splt != NULL && srela != NULL && sgotplt != NULL);
3479+
3480+ plt_index = h->plt.offset / PLT_ENTRY_SIZE - 1; /* first entry reserved. */
3481+ got_offset = (plt_index + 3) * 4; /* 3 reserved ??? */
3482+ got_addr = got_offset;
3483+
3484+ /* For non-PIC objects we need absolute address of the GOT entry. */
3485+ if (!bfd_link_pic (info))
3486+ got_addr += htab->sgotplt->output_section->vma + sgotplt->output_offset;
3487+
3488+ /* Fill in the entry in the procedure linkage table. */
3489+ bfd_put_32 (output_bfd, PLT_ENTRY_WORD_0 + ((got_addr >> 16) & 0xffff),
3490+ splt->contents + h->plt.offset);
3491+ if (bfd_link_pic (info))
3492+ bfd_put_32 (output_bfd, PLT_ENTRY_WORD_1 + (got_addr & 0xffff),
3493+ splt->contents + h->plt.offset + 4);
3494+ else
3495+ bfd_put_32 (output_bfd, PLT_ENTRY_WORD_1_NOPIC + (got_addr & 0xffff),
3496+ splt->contents + h->plt.offset + 4);
3497+ bfd_put_32 (output_bfd, (bfd_vma) PLT_ENTRY_WORD_2,
3498+ splt->contents + h->plt.offset + 8);
3499+ bfd_put_32 (output_bfd, (bfd_vma) PLT_ENTRY_WORD_3,
3500+ splt->contents + h->plt.offset + 12);
3501+
3502+ /* Any additions to the .got section??? */
3503+ /* bfd_put_32 (output_bfd,
3504+ splt->output_section->vma + splt->output_offset + h->plt.offset + 4,
3505+ sgotplt->contents + got_offset); */
3506+
3507+ /* Fill in the entry in the .rela.plt section. */
3508+ rela.r_offset = (sgotplt->output_section->vma
3509+ + sgotplt->output_offset
3510+ + got_offset);
3511+ rela.r_info = ELF64_R_INFO (h->dynindx, R_MICROBLAZE_JUMP_SLOT);
3512+ rela.r_addend = 0;
3513+ loc = srela->contents;
3514+ loc += plt_index * sizeof (Elf64_External_Rela);
3515+ bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
3516+
3517+ if (!h->def_regular)
3518+ {
3519+ /* Mark the symbol as undefined, rather than as defined in
3520+ the .plt section. Zero the value. */
3521+ sym->st_shndx = SHN_UNDEF;
3522+ sym->st_value = 0;
3523+ }
3524+ }
3525+
3526+ /* h->got.refcount to be checked ? */
3527+ if (h->got.offset != (bfd_vma) -1 &&
3528+ ! ((h->got.offset & 1) ||
3529+ IS_TLS_LD(eh->tls_mask) || IS_TLS_GD(eh->tls_mask)))
3530+ {
3531+ asection *sgot;
3532+ asection *srela;
3533+ bfd_vma offset;
3534+
3535+ /* This symbol has an entry in the global offset table. Set it
3536+ up. */
3537+
3538+ sgot = htab->sgot;
3539+ srela = htab->srelgot;
3540+ BFD_ASSERT (sgot != NULL && srela != NULL);
3541+
3542+ offset = (sgot->output_section->vma + sgot->output_offset
3543+ + (h->got.offset &~ (bfd_vma) 1));
3544+
3545+ /* If this is a -Bsymbolic link, and the symbol is defined
3546+ locally, we just want to emit a RELATIVE reloc. Likewise if
3547+ the symbol was forced to be local because of a version file.
3548+ The entry in the global offset table will already have been
3549+ initialized in the relocate_section function. */
3550+ if (bfd_link_pic (info)
3551+ && ((info->symbolic && h->def_regular)
3552+ || h->dynindx == -1))
3553+ {
3554+ asection *sec = h->root.u.def.section;
3555+ microblaze_elf_output_dynamic_relocation (output_bfd,
3556+ srela, srela->reloc_count++,
3557+ /* symindex= */ 0,
3558+ R_MICROBLAZE_REL, offset,
3559+ h->root.u.def.value
3560+ + sec->output_section->vma
3561+ + sec->output_offset);
3562+ }
3563+ else
3564+ {
3565+ microblaze_elf_output_dynamic_relocation (output_bfd,
3566+ srela, srela->reloc_count++,
3567+ h->dynindx,
3568+ R_MICROBLAZE_GLOB_DAT,
3569+ offset, 0);
3570+ }
3571+
3572+ bfd_put_32 (output_bfd, (bfd_vma) 0,
3573+ sgot->contents + (h->got.offset &~ (bfd_vma) 1));
3574+ }
3575+
3576+ if (h->needs_copy)
3577+ {
3578+ asection *s;
3579+ Elf_Internal_Rela rela;
3580+ bfd_byte *loc;
3581+
3582+ /* This symbols needs a copy reloc. Set it up. */
3583+
3584+ BFD_ASSERT (h->dynindx != -1);
3585+
3586+ s = bfd_get_linker_section (htab->elf.dynobj, ".rela.bss");
3587+ BFD_ASSERT (s != NULL);
3588+
3589+ rela.r_offset = (h->root.u.def.value
3590+ + h->root.u.def.section->output_section->vma
3591+ + h->root.u.def.section->output_offset);
3592+ rela.r_info = ELF64_R_INFO (h->dynindx, R_MICROBLAZE_COPY);
3593+ rela.r_addend = 0;
3594+ loc = s->contents + s->reloc_count++ * sizeof (Elf64_External_Rela);
3595+ bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
3596+ }
3597+
3598+ /* Mark some specially defined symbols as absolute. */
3599+ if (h == htab->elf.hdynamic
3600+ || h == htab->elf.hgot
3601+ || h == htab->elf.hplt)
3602+ sym->st_shndx = SHN_ABS;
3603+
3604+ return TRUE;
3605+}
3606+
3607+
3608+/* Finish up the dynamic sections. */
3609+
3610+static bfd_boolean
3611+microblaze_elf_finish_dynamic_sections (bfd *output_bfd,
3612+ struct bfd_link_info *info)
3613+{
3614+ bfd *dynobj;
3615+ asection *sdyn, *sgot;
3616+ struct elf64_mb_link_hash_table *htab;
3617+
3618+ htab = elf64_mb_hash_table (info);
3619+ if (htab == NULL)
3620+ return FALSE;
3621+
3622+ dynobj = htab->elf.dynobj;
3623+
3624+ sdyn = bfd_get_linker_section (dynobj, ".dynamic");
3625+
3626+ if (htab->elf.dynamic_sections_created)
3627+ {
3628+ asection *splt;
3629+ Elf64_External_Dyn *dyncon, *dynconend;
3630+
3631+ splt = bfd_get_linker_section (dynobj, ".plt");
3632+ BFD_ASSERT (splt != NULL && sdyn != NULL);
3633+
3634+ dyncon = (Elf64_External_Dyn *) sdyn->contents;
3635+ dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->size);
3636+ for (; dyncon < dynconend; dyncon++)
3637+ {
3638+ Elf_Internal_Dyn dyn;
3639+ const char *name;
3640+ bfd_boolean size;
3641+
3642+ bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn);
3643+
3644+ switch (dyn.d_tag)
3645+ {
3646+ case DT_PLTGOT: name = ".got.plt"; size = FALSE; break;
3647+ case DT_PLTRELSZ: name = ".rela.plt"; size = TRUE; break;
3648+ case DT_JMPREL: name = ".rela.plt"; size = FALSE; break;
3649+ case DT_RELA: name = ".rela.dyn"; size = FALSE; break;
3650+ case DT_RELASZ: name = ".rela.dyn"; size = TRUE; break;
3651+ default: name = NULL; size = FALSE; break;
3652+ }
3653+
3654+ if (name != NULL)
3655+ {
3656+ asection *s;
3657+
3658+ s = bfd_get_section_by_name (output_bfd, name);
3659+ if (s == NULL)
3660+ dyn.d_un.d_val = 0;
3661+ else
3662+ {
3663+ if (! size)
3664+ dyn.d_un.d_ptr = s->vma;
3665+ else
3666+ dyn.d_un.d_val = s->size;
3667+ }
3668+ bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
3669+ }
3670+ }
3671+
3672+ /* Clear the first entry in the procedure linkage table,
3673+ and put a nop in the last four bytes. */
3674+ if (splt->size > 0)
3675+ {
3676+ memset (splt->contents, 0, PLT_ENTRY_SIZE);
3677+ bfd_put_32 (output_bfd, (bfd_vma) 0x80000000 /* nop. */,
3678+ splt->contents + splt->size - 4);
3679+ }
3680+
3681+ elf_section_data (splt->output_section)->this_hdr.sh_entsize = 4;
3682+ }
3683+
3684+ /* Set the first entry in the global offset table to the address of
3685+ the dynamic section. */
3686+ sgot = bfd_get_linker_section (dynobj, ".got.plt");
3687+ if (sgot && sgot->size > 0)
3688+ {
3689+ if (sdyn == NULL)
3690+ bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
3691+ else
3692+ bfd_put_32 (output_bfd,
3693+ sdyn->output_section->vma + sdyn->output_offset,
3694+ sgot->contents);
3695+ elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
3696+ }
3697+
3698+ if (htab->sgot && htab->sgot->size > 0)
3699+ elf_section_data (htab->sgot->output_section)->this_hdr.sh_entsize = 4;
3700+
3701+ return TRUE;
3702+}
3703+
3704+/* Hook called by the linker routine which adds symbols from an object
3705+ file. We use it to put .comm items in .sbss, and not .bss. */
3706+
3707+static bfd_boolean
3708+microblaze_elf_add_symbol_hook (bfd *abfd,
3709+ struct bfd_link_info *info,
3710+ Elf_Internal_Sym *sym,
3711+ const char **namep ATTRIBUTE_UNUSED,
3712+ flagword *flagsp ATTRIBUTE_UNUSED,
3713+ asection **secp,
3714+ bfd_vma *valp)
3715+{
3716+ if (sym->st_shndx == SHN_COMMON
3717+ && !bfd_link_relocatable (info)
3718+ && sym->st_size <= elf_gp_size (abfd))
3719+ {
3720+ /* Common symbols less than or equal to -G nn bytes are automatically
3721+ put into .sbss. */
3722+ *secp = bfd_make_section_old_way (abfd, ".sbss");
3723+ if (*secp == NULL
3724+ || ! bfd_set_section_flags (abfd, *secp, SEC_IS_COMMON))
3725+ return FALSE;
3726+
3727+ *valp = sym->st_size;
3728+ }
3729+
3730+ return TRUE;
3731+}
3732+
3733+#define TARGET_LITTLE_SYM microblaze_elf64_le_vec
3734+#define TARGET_LITTLE_NAME "elf64-microblazeel"
3735+
3736+#define TARGET_BIG_SYM microblaze_elf64_vec
3737+#define TARGET_BIG_NAME "elf64-microblaze"
3738+
3739+#define ELF_ARCH bfd_arch_microblaze
3740+#define ELF_TARGET_ID MICROBLAZE_ELF_DATA
3741+#define ELF_MACHINE_CODE EM_MICROBLAZE
3742+#define ELF_MACHINE_ALT1 EM_MICROBLAZE_OLD
3743+#define ELF_MAXPAGESIZE 0x1000
3744+#define elf_info_to_howto microblaze_elf_info_to_howto
3745+#define elf_info_to_howto_rel NULL
3746+
3747+#define bfd_elf64_bfd_reloc_type_lookup microblaze_elf_reloc_type_lookup
3748+#define bfd_elf64_bfd_is_local_label_name microblaze_elf_is_local_label_name
3749+#define elf_backend_relocate_section microblaze_elf_relocate_section
3750+#define bfd_elf64_bfd_relax_section microblaze_elf_relax_section
3751+#define bfd_elf64_bfd_merge_private_bfd_data microblaze_elf_merge_private_bfd_data
3752+#define bfd_elf64_bfd_reloc_name_lookup microblaze_elf_reloc_name_lookup
3753+
3754+#define elf_backend_gc_mark_hook microblaze_elf_gc_mark_hook
3755+#define elf_backend_gc_sweep_hook microblaze_elf_gc_sweep_hook
3756+#define elf_backend_check_relocs microblaze_elf_check_relocs
3757+#define elf_backend_copy_indirect_symbol microblaze_elf_copy_indirect_symbol
3758+#define bfd_elf64_bfd_link_hash_table_create microblaze_elf_link_hash_table_create
3759+#define elf_backend_can_gc_sections 1
3760+#define elf_backend_can_refcount 1
3761+#define elf_backend_want_got_plt 1
3762+#define elf_backend_plt_readonly 1
3763+#define elf_backend_got_header_size 12
3764+#define elf_backend_rela_normal 1
3765+
3766+#define elf_backend_adjust_dynamic_symbol microblaze_elf_adjust_dynamic_symbol
3767+#define elf_backend_create_dynamic_sections microblaze_elf_create_dynamic_sections
3768+#define elf_backend_finish_dynamic_sections microblaze_elf_finish_dynamic_sections
3769+#define elf_backend_finish_dynamic_symbol microblaze_elf_finish_dynamic_symbol
3770+#define elf_backend_size_dynamic_sections microblaze_elf_size_dynamic_sections
3771+#define elf_backend_add_symbol_hook microblaze_elf_add_symbol_hook
3772+
3773+#include "elf64-target.h"
3774diff --git a/bfd/targets.c b/bfd/targets.c
3775index 158168cb3b..ef567a30c8 100644
3776--- a/bfd/targets.c
3777+++ b/bfd/targets.c
3778@@ -706,6 +706,8 @@ extern const bfd_target mep_elf32_le_vec;
3779 extern const bfd_target metag_elf32_vec;
3780 extern const bfd_target microblaze_elf32_vec;
3781 extern const bfd_target microblaze_elf32_le_vec;
3782+extern const bfd_target microblaze_elf64_vec;
3783+extern const bfd_target microblaze_elf64_le_vec;
3784 extern const bfd_target mips_ecoff_be_vec;
3785 extern const bfd_target mips_ecoff_le_vec;
3786 extern const bfd_target mips_ecoff_bele_vec;
3787@@ -1073,6 +1075,10 @@ static const bfd_target * const _bfd_target_vector[] =
3788
3789 &metag_elf32_vec,
3790
3791+#ifdef BFD64
3792+ &microblaze_elf64_vec,
3793+ &microblaze_elf64_le_vec,
3794+#endif
3795 &microblaze_elf32_vec,
3796
3797 &mips_ecoff_be_vec,
3798diff --git a/include/elf/common.h b/include/elf/common.h
3799index e8faf67be3..ca89da1631 100644
3800--- a/include/elf/common.h
3801+++ b/include/elf/common.h
3802@@ -339,6 +339,7 @@
3803 #define EM_RISCV 243 /* RISC-V */
3804 #define EM_LANAI 244 /* Lanai 32-bit processor. */
3805 #define EM_BPF 247 /* Linux BPF – in-kernel virtual machine. */
3806+#define EM_MB_64 248 /* Xilinx MicroBlaze 32-bit RISC soft processor core */
3807 #define EM_NFP 250 /* Netronome Flow Processor. */
3808 #define EM_CSKY 252 /* C-SKY processor family. */
3809
3810diff --git a/opcodes/microblaze-dis.c b/opcodes/microblaze-dis.c
3811index f8aaf27873..20ea6a885a 100644
3812--- a/opcodes/microblaze-dis.c
3813+++ b/opcodes/microblaze-dis.c
3814@@ -33,6 +33,7 @@
3815 #define get_field_r1(instr) get_field (instr, RA_MASK, RA_LOW)
3816 #define get_field_r2(instr) get_field (instr, RB_MASK, RB_LOW)
3817 #define get_int_field_imm(instr) ((instr & IMM_MASK) >> IMM_LOW)
3818+#define get_int_field_imml(instr) ((instr & IMML_MASK) >> IMM_LOW)
3819 #define get_int_field_r1(instr) ((instr & RA_MASK) >> RA_LOW)
3820
3821
3822@@ -56,11 +57,20 @@ get_field_imm (long instr)
3823 }
3824
3825 static char *
3826-get_field_imm5 (long instr)
3827+get_field_imml (long instr)
3828 {
3829 char tmpstr[25];
3830
3831- sprintf (tmpstr, "%d", (short)((instr & IMM5_MASK) >> IMM_LOW));
3832+ sprintf (tmpstr, "%d", (short)((instr & IMML_MASK) >> IMM_LOW));
3833+ return (strdup (tmpstr));
3834+}
3835+
3836+static char *
3837+get_field_imms (long instr)
3838+{
3839+ char tmpstr[25];
3840+
3841+ sprintf (tmpstr, "%d", (short)((instr & IMM6_MASK) >> IMM_LOW));
3842 return (strdup (tmpstr));
3843 }
3844
3845@@ -74,14 +84,14 @@ get_field_imm5_mbar (long instr)
3846 }
3847
3848 static char *
3849-get_field_imm5width (long instr)
3850+get_field_immw (long instr)
3851 {
3852 char tmpstr[25];
3853
3854 if (instr & 0x00004000)
3855- sprintf (tmpstr, "%d", (short)(((instr & IMM5_WIDTH_MASK) >> IMM_WIDTH_LOW))); /* bsefi */
3856+ sprintf (tmpstr, "%d", (short)(((instr & IMM6_WIDTH_MASK) >> IMM_WIDTH_LOW))); /* bsefi */
3857 else
3858- sprintf (tmpstr, "%d", (short)(((instr & IMM5_WIDTH_MASK) >> IMM_WIDTH_LOW) - ((instr & IMM5_MASK) >> IMM_LOW) + 1)); /* bsifi */
3859+ sprintf (tmpstr, "%d", (short)(((instr & IMM6_WIDTH_MASK) >> IMM_WIDTH_LOW) - ((instr & IMM6_MASK) >> IMM_LOW) + 1)); /* bsifi */
3860 return (strdup (tmpstr));
3861 }
3862
3863@@ -286,9 +296,13 @@ print_insn_microblaze (bfd_vma memaddr, struct disassemble_info * info)
3864 }
3865 }
3866 break;
3867- case INST_TYPE_RD_R1_IMM5:
3868+ case INST_TYPE_RD_R1_IMML:
3869+ print_func (stream, "\t%s, %s, %s", get_field_rd (inst),
3870+ get_field_r1(inst), get_field_imm (inst));
3871+ /* TODO: Also print symbol */
3872+ case INST_TYPE_RD_R1_IMMS:
3873 print_func (stream, "\t%s, %s, %s", get_field_rd (inst),
3874- get_field_r1(inst), get_field_imm5 (inst));
3875+ get_field_r1(inst), get_field_imms (inst));
3876 break;
3877 case INST_TYPE_RD_RFSL:
3878 print_func (stream, "\t%s, %s", get_field_rd (inst), get_field_rfsl (inst));
3879@@ -386,6 +400,10 @@ print_insn_microblaze (bfd_vma memaddr, struct disassemble_info * info)
3880 }
3881 }
3882 break;
3883+ case INST_TYPE_IMML:
3884+ print_func (stream, "\t%s", get_field_imml (inst));
3885+ /* TODO: Also print symbol */
3886+ break;
3887 case INST_TYPE_RD_R2:
3888 print_func (stream, "\t%s, %s", get_field_rd (inst), get_field_r2 (inst));
3889 break;
3890@@ -409,9 +427,10 @@ print_insn_microblaze (bfd_vma memaddr, struct disassemble_info * info)
3891 case INST_TYPE_NONE:
3892 break;
3893 /* For bit field insns. */
3894- case INST_TYPE_RD_R1_IMM5_IMM5:
3895- print_func (stream, "\t%s, %s, %s, %s", get_field_rd (inst),get_field_r1(inst),get_field_imm5width (inst), get_field_imm5 (inst));
3896- break;
3897+ case INST_TYPE_RD_R1_IMMW_IMMS:
3898+ print_func (stream, "\t%s, %s, %s, %s", get_field_rd (inst), get_field_r1(inst),
3899+ get_field_immw (inst), get_field_imms (inst));
3900+ break;
3901 /* For tuqula instruction */
3902 case INST_TYPE_RD:
3903 print_func (stream, "\t%s", get_field_rd (inst));
3904diff --git a/opcodes/microblaze-opc.h b/opcodes/microblaze-opc.h
3905index ce8ac351b5..985834b8df 100644
3906--- a/opcodes/microblaze-opc.h
3907+++ b/opcodes/microblaze-opc.h
3908@@ -40,7 +40,7 @@
3909 #define INST_TYPE_RD_SPECIAL 11
3910 #define INST_TYPE_R1 12
3911 /* New instn type for barrel shift imms. */
3912-#define INST_TYPE_RD_R1_IMM5 13
3913+#define INST_TYPE_RD_R1_IMMS 13
3914 #define INST_TYPE_RD_RFSL 14
3915 #define INST_TYPE_R1_RFSL 15
3916
3917@@ -60,7 +60,13 @@
3918 #define INST_TYPE_IMM5 20
3919
3920 /* For bsefi and bsifi */
3921-#define INST_TYPE_RD_R1_IMM5_IMM5 21
3922+#define INST_TYPE_RD_R1_IMMW_IMMS 21
3923+
3924+/* For 64-bit instructions */
3925+#define INST_TYPE_IMML 22
3926+#define INST_TYPE_RD_R1_IMML 23
3927+#define INST_TYPE_R1_IMML 24
3928+#define INST_TYPE_RD_R1_IMMW_IMMS 21
3929
3930 #define INST_TYPE_NONE 25
3931
3932@@ -91,13 +97,14 @@
3933 #define OPCODE_MASK_H24 0xFC1F07FF /* High 6, bits 20-16 and low 11 bits. */
3934 #define OPCODE_MASK_H124 0xFFFF07FF /* High 16, and low 11 bits. */
3935 #define OPCODE_MASK_H1234 0xFFFFFFFF /* All 32 bits. */
3936-#define OPCODE_MASK_H3 0xFC000600 /* High 6 bits and bits 21, 22. */
3937-#define OPCODE_MASK_H3B 0xFC00C600 /* High 6 bits and bits 16, 17, 21, 22. */
3938+#define OPCODE_MASK_H3 0xFC000700 /* High 6 bits and bits 21, 22, 23. */
3939+#define OPCODE_MASK_H3B 0xFC00E600 /* High 6 bits and bits 16, 17, 18, 21, 22. */
3940 #define OPCODE_MASK_H32 0xFC00FC00 /* High 6 bits and bit 16-21. */
3941-#define OPCODE_MASK_H32B 0xFC00C000 /* High 6 bits and bit 16, 17. */
3942+#define OPCODE_MASK_H32B 0xFC00E000 /* High 6 bits and bit 16, 17, 18. */
3943 #define OPCODE_MASK_H34B 0xFC0000FF /* High 6 bits and low 8 bits. */
3944 #define OPCODE_MASK_H35B 0xFC0004FF /* High 6 bits and low 9 bits. */
3945 #define OPCODE_MASK_H34C 0xFC0007E0 /* High 6 bits and bits 21-26. */
3946+#define OPCODE_MASK_H8 0xFF000000 /* High 8 bits only. */
3947
3948 /* New Mask for msrset, msrclr insns. */
3949 #define OPCODE_MASK_H23N 0xFC1F8000 /* High 6 and bits 11 - 16. */
3950@@ -107,7 +114,7 @@
3951 #define DELAY_SLOT 1
3952 #define NO_DELAY_SLOT 0
3953
3954-#define MAX_OPCODES 301
3955+#define MAX_OPCODES 412
3956
3957 struct op_code_struct
3958 {
3959@@ -125,6 +132,7 @@ struct op_code_struct
3960 /* More info about output format here. */
3961 } opcodes[MAX_OPCODES] =
3962 {
3963+ /* 32-bit instructions */
3964 {"add", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x00000000, OPCODE_MASK_H4, add, arithmetic_inst },
3965 {"rsub", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x04000000, OPCODE_MASK_H4, rsub, arithmetic_inst },
3966 {"addc", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x08000000, OPCODE_MASK_H4, addc, arithmetic_inst },
3967@@ -161,11 +169,11 @@ struct op_code_struct
3968 {"ncget", INST_TYPE_RD_RFSL, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x6C006000, OPCODE_MASK_H32, ncget, anyware_inst },
3969 {"ncput", INST_TYPE_R1_RFSL, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x6C00E000, OPCODE_MASK_H32, ncput, anyware_inst },
3970 {"muli", INST_TYPE_RD_R1_IMM, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x60000000, OPCODE_MASK_H, muli, mult_inst },
3971- {"bslli", INST_TYPE_RD_R1_IMM5, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x64000400, OPCODE_MASK_H3, bslli, barrel_shift_inst },
3972- {"bsrai", INST_TYPE_RD_R1_IMM5, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x64000200, OPCODE_MASK_H3, bsrai, barrel_shift_inst },
3973- {"bsrli", INST_TYPE_RD_R1_IMM5, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x64000000, OPCODE_MASK_H3, bsrli, barrel_shift_inst },
3974- {"bsefi", INST_TYPE_RD_R1_IMM5_IMM5, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x64004000, OPCODE_MASK_H32B, bsefi, barrel_shift_inst },
3975- {"bsifi", INST_TYPE_RD_R1_IMM5_IMM5, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x64008000, OPCODE_MASK_H32B, bsifi, barrel_shift_inst },
3976+ {"bslli", INST_TYPE_RD_R1_IMMS, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x64000400, OPCODE_MASK_H3B, bslli, barrel_shift_inst },
3977+ {"bsrai", INST_TYPE_RD_R1_IMMS, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x64000200, OPCODE_MASK_H3B, bsrai, barrel_shift_inst },
3978+ {"bsrli", INST_TYPE_RD_R1_IMMS, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x64000000, OPCODE_MASK_H3B, bsrli, barrel_shift_inst },
3979+ {"bsefi", INST_TYPE_RD_R1_IMMW_IMMS, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x64004000, OPCODE_MASK_H32B, bsefi, barrel_shift_inst },
3980+ {"bsifi", INST_TYPE_RD_R1_IMMW_IMMS, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x64008000, OPCODE_MASK_H32B, bsifi, barrel_shift_inst },
3981 {"or", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x80000000, OPCODE_MASK_H4, microblaze_or, logical_inst },
3982 {"and", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x84000000, OPCODE_MASK_H4, microblaze_and, logical_inst },
3983 {"xor", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x88000000, OPCODE_MASK_H4, microblaze_xor, logical_inst },
3984@@ -425,6 +433,129 @@ struct op_code_struct
3985 {"suspend", INST_TYPE_NONE, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBB020004, OPCODE_MASK_HN, invalid_inst, special_inst }, /* translates to mbar 24. */
3986 {"swapb", INST_TYPE_RD_R1, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x900001E0, OPCODE_MASK_H4, swapb, arithmetic_inst },
3987 {"swaph", INST_TYPE_RD_R1, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x900001E2, OPCODE_MASK_H4, swaph, arithmetic_inst },
3988+
3989+ /* 64-bit instructions */
3990+ {"addl", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x00000100, OPCODE_MASK_H4, addl, arithmetic_inst },
3991+ {"rsubl", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x04000100, OPCODE_MASK_H4, rsubl, arithmetic_inst },
3992+ {"addlc", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x08000100, OPCODE_MASK_H4, addlc, arithmetic_inst },
3993+ {"rsublc", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x0C000100, OPCODE_MASK_H4, rsublc, arithmetic_inst },
3994+ {"addlk", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x10000100, OPCODE_MASK_H4, addlk, arithmetic_inst },
3995+ {"rsublk", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x14000100, OPCODE_MASK_H4, rsublk, arithmetic_inst },
3996+ {"addlkc", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x18000100, OPCODE_MASK_H4, addlkc, arithmetic_inst },
3997+ {"rsublkc", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x1C000100, OPCODE_MASK_H4, rsublkc, arithmetic_inst },
3998+ {"cmpl", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x14000101, OPCODE_MASK_H4, cmpl, arithmetic_inst },
3999+ {"cmplu", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x14000103, OPCODE_MASK_H4, cmplu, arithmetic_inst },
4000+ {"addli", INST_TYPE_RD_R1_IMML, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x20000000, OPCODE_MASK_H, invalid_inst, arithmetic_inst }, /* Identical to 32-bit */
4001+ {"rsubli", INST_TYPE_RD_R1_IMML, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x24000000, OPCODE_MASK_H, invalid_inst, arithmetic_inst }, /* Identical to 32-bit */
4002+ {"addlic", INST_TYPE_RD_R1_IMML, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x28000000, OPCODE_MASK_H, invalid_inst, arithmetic_inst }, /* Identical to 32-bit */
4003+ {"rsublic", INST_TYPE_RD_R1_IMML, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x2C000000, OPCODE_MASK_H, invalid_inst, arithmetic_inst }, /* Identical to 32-bit */
4004+ {"addlik", INST_TYPE_RD_R1_IMML, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x30000000, OPCODE_MASK_H, invalid_inst, arithmetic_inst }, /* Identical to 32-bit */
4005+ {"rsublik", INST_TYPE_RD_R1_IMML, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x34000000, OPCODE_MASK_H, invalid_inst, arithmetic_inst }, /* Identical to 32-bit */
4006+ {"addlikc", INST_TYPE_RD_R1_IMML, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x38000000, OPCODE_MASK_H, invalid_inst, arithmetic_inst }, /* Identical to 32-bit */
4007+ {"rsublikc",INST_TYPE_RD_R1_IMML, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x3C000000, OPCODE_MASK_H, invalid_inst, arithmetic_inst }, /* Identical to 32-bit */
4008+ {"mull", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x40000100, OPCODE_MASK_H4, mull, mult_inst },
4009+ {"bslll", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x44000500, OPCODE_MASK_H3, bslll, barrel_shift_inst },
4010+ {"bslra", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x44000300, OPCODE_MASK_H3, bslra, barrel_shift_inst },
4011+ {"bslrl", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x44000100, OPCODE_MASK_H3, bslrl, barrel_shift_inst },
4012+ {"bsllli", INST_TYPE_RD_R1_IMMS, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x64002400, OPCODE_MASK_H3B, bsllli, barrel_shift_inst },
4013+ {"bslrai", INST_TYPE_RD_R1_IMMS, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x64002200, OPCODE_MASK_H3B, bslrai, barrel_shift_inst },
4014+ {"bslrli", INST_TYPE_RD_R1_IMMS, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x64002000, OPCODE_MASK_H3B, bslrli, barrel_shift_inst },
4015+ {"bslefi", INST_TYPE_RD_R1_IMMW_IMMS, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x64006000, OPCODE_MASK_H32B, bslefi, barrel_shift_inst },
4016+ {"bslifi", INST_TYPE_RD_R1_IMMW_IMMS, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x6400a000, OPCODE_MASK_H32B, bslifi, barrel_shift_inst },
4017+ {"orl", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x80000100, OPCODE_MASK_H4, orl, logical_inst },
4018+ {"andl", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x84000100, OPCODE_MASK_H4, andl, logical_inst },
4019+ {"xorl", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x88000100, OPCODE_MASK_H4, xorl, logical_inst },
4020+ {"andnl", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x8C000100, OPCODE_MASK_H4, andnl, logical_inst },
4021+ {"pcmplbf", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x80000500, OPCODE_MASK_H4, pcmplbf, logical_inst },
4022+ {"pcmpleq", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x88000500, OPCODE_MASK_H4, pcmpleq, logical_inst },
4023+ {"pcmplne", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x8C000500, OPCODE_MASK_H4, pcmplne, logical_inst },
4024+ {"srla", INST_TYPE_RD_R1, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x90000101, OPCODE_MASK_H34, srla, logical_inst },
4025+ {"srlc", INST_TYPE_RD_R1, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x90000121, OPCODE_MASK_H34, srlc, logical_inst },
4026+ {"srll", INST_TYPE_RD_R1, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x90000141, OPCODE_MASK_H34, srll, logical_inst },
4027+ {"sextl8", INST_TYPE_RD_R1, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x90000160, OPCODE_MASK_H34, sextl8, logical_inst },
4028+ {"sextl16", INST_TYPE_RD_R1, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x90000161, OPCODE_MASK_H34, sextl16, logical_inst },
4029+ {"sextl32", INST_TYPE_RD_R1, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x90000162, OPCODE_MASK_H34, sextl32, logical_inst },
4030+ {"brea", INST_TYPE_R2, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x98010000, OPCODE_MASK_H124, brea, branch_inst },
4031+ {"bread", INST_TYPE_R2, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x98110000, OPCODE_MASK_H124, bread, branch_inst },
4032+ {"breald", INST_TYPE_RD_R2, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x98150000, OPCODE_MASK_H24, breald, branch_inst },
4033+ {"beaeq", INST_TYPE_R1_R2, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x9D000000, OPCODE_MASK_H14, beaeq, branch_inst },
4034+ {"bealeq", INST_TYPE_R1_R2, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x9D000100, OPCODE_MASK_H14, bealeq, branch_inst },
4035+ {"beaeqd", INST_TYPE_R1_R2, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x9F000000, OPCODE_MASK_H14, beaeqd, branch_inst },
4036+ {"bealeqd", INST_TYPE_R1_R2, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x9F000100, OPCODE_MASK_H14, bealeqd, branch_inst },
4037+ {"beane", INST_TYPE_R1_R2, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x9D200000, OPCODE_MASK_H14, beane, branch_inst },
4038+ {"bealne", INST_TYPE_R1_R2, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x9D200100, OPCODE_MASK_H14, bealne, branch_inst },
4039+ {"beaned", INST_TYPE_R1_R2, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x9F200000, OPCODE_MASK_H14, beaned, branch_inst },
4040+ {"bealned", INST_TYPE_R1_R2, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x9F200100, OPCODE_MASK_H14, bealned, branch_inst },
4041+ {"bealt", INST_TYPE_R1_R2, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x9D400000, OPCODE_MASK_H14, bealt, branch_inst },
4042+ {"beallt", INST_TYPE_R1_R2, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x9D400100, OPCODE_MASK_H14, beallt, branch_inst },
4043+ {"bealtd", INST_TYPE_R1_R2, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x9F400000, OPCODE_MASK_H14, bealtd, branch_inst },
4044+ {"bealltd", INST_TYPE_R1_R2, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x9F400100, OPCODE_MASK_H14, bealltd, branch_inst },
4045+ {"beale", INST_TYPE_R1_R2, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x9D600000, OPCODE_MASK_H14, beale, branch_inst },
4046+ {"bealle", INST_TYPE_R1_R2, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x9D600100, OPCODE_MASK_H14, bealle, branch_inst },
4047+ {"bealed", INST_TYPE_R1_R2, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x9F600000, OPCODE_MASK_H14, bealed, branch_inst },
4048+ {"bealled", INST_TYPE_R1_R2, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x9F600100, OPCODE_MASK_H14, bealled, branch_inst },
4049+ {"beagt", INST_TYPE_R1_R2, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x9D800000, OPCODE_MASK_H14, beagt, branch_inst },
4050+ {"bealgt", INST_TYPE_R1_R2, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x9D800100, OPCODE_MASK_H14, bealgt, branch_inst },
4051+ {"beagtd", INST_TYPE_R1_R2, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x9F800000, OPCODE_MASK_H14, beagtd, branch_inst },
4052+ {"bealgtd", INST_TYPE_R1_R2, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x9F800100, OPCODE_MASK_H14, bealgtd, branch_inst },
4053+ {"beage", INST_TYPE_R1_R2, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x9DA00000, OPCODE_MASK_H14, beage, branch_inst },
4054+ {"bealge", INST_TYPE_R1_R2, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x9DA00100, OPCODE_MASK_H14, bealge, branch_inst },
4055+ {"beaged", INST_TYPE_R1_R2, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x9FA00000, OPCODE_MASK_H14, beaged, branch_inst },
4056+ {"bealged", INST_TYPE_R1_R2, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x9FA00100, OPCODE_MASK_H14, bealged, branch_inst },
4057+ {"orli", INST_TYPE_RD_R1_IMML, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xA0000000, OPCODE_MASK_H, invalid_inst, logical_inst }, /* Identical to 32-bit */
4058+ {"andli", INST_TYPE_RD_R1_IMML, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xA4000000, OPCODE_MASK_H, invalid_inst, logical_inst }, /* Identical to 32-bit */
4059+ {"xorli", INST_TYPE_RD_R1_IMML, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xA8000000, OPCODE_MASK_H, invalid_inst, logical_inst }, /* Identical to 32-bit */
4060+ {"andnli", INST_TYPE_RD_R1_IMML, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xAC000000, OPCODE_MASK_H, invalid_inst, logical_inst }, /* Identical to 32-bit */
4061+ {"imml", INST_TYPE_IMML, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xB2000000, OPCODE_MASK_H8, imml, immediate_inst },
4062+ {"breai", INST_TYPE_IMM, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xB8010000, OPCODE_MASK_H12, breai, branch_inst },
4063+ {"breaid", INST_TYPE_IMM, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xB8110000, OPCODE_MASK_H12, breaid, branch_inst },
4064+ {"brealid", INST_TYPE_RD_IMM, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xB8150000, OPCODE_MASK_H2, brealid, branch_inst },
4065+ {"beaeqi", INST_TYPE_R1_IMM, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBD000000, OPCODE_MASK_H1, beaeqi, branch_inst },
4066+ {"bealeqi", INST_TYPE_R1_IMML, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBD000000, OPCODE_MASK_H1, invalid_inst, branch_inst }, /* Identical to beaeqi */
4067+ {"beaeqid", INST_TYPE_R1_IMM, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBF000000, OPCODE_MASK_H1, beaeqid, branch_inst },
4068+ {"bealeqid",INST_TYPE_R1_IMML, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBF000000, OPCODE_MASK_H1, invalid_inst, branch_inst }, /* Identical to beaeqid */
4069+ {"beanei", INST_TYPE_R1_IMM, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBD200000, OPCODE_MASK_H1, beanei, branch_inst },
4070+ {"bealnei", INST_TYPE_R1_IMML, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBD200000, OPCODE_MASK_H1, invalid_inst, branch_inst }, /* Identical to beanei */
4071+ {"beaneid", INST_TYPE_R1_IMM, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBF200000, OPCODE_MASK_H1, beaneid, branch_inst },
4072+ {"bealneid",INST_TYPE_R1_IMML, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBF200000, OPCODE_MASK_H1, invalid_inst, branch_inst }, /* Identical to beaneid */
4073+ {"bealti", INST_TYPE_R1_IMM, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBD400000, OPCODE_MASK_H1, bealti, branch_inst },
4074+ {"beallti", INST_TYPE_R1_IMML, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBD400000, OPCODE_MASK_H1, invalid_inst, branch_inst }, /* Identical to bealti */
4075+ {"bealtid", INST_TYPE_R1_IMM, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBF400000, OPCODE_MASK_H1, bealtid, branch_inst },
4076+ {"bealltid",INST_TYPE_R1_IMML, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBF400000, OPCODE_MASK_H1, invalid_inst, branch_inst }, /* Identical to bealtid */
4077+ {"bealei", INST_TYPE_R1_IMM, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBD600000, OPCODE_MASK_H1, bealei, branch_inst },
4078+ {"beallei", INST_TYPE_R1_IMML, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBD600000, OPCODE_MASK_H1, invalid_inst, branch_inst }, /* Identical to bealei */
4079+ {"bealeid", INST_TYPE_R1_IMM, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBF600000, OPCODE_MASK_H1, bealeid, branch_inst },
4080+ {"bealleid",INST_TYPE_R1_IMML, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBF600000, OPCODE_MASK_H1, invalid_inst, branch_inst }, /* Identical to bealeid */
4081+ {"beagti", INST_TYPE_R1_IMM, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBD800000, OPCODE_MASK_H1, beagti, branch_inst },
4082+ {"bealgti", INST_TYPE_R1_IMML, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBD800000, OPCODE_MASK_H1, invalid_inst, branch_inst }, /* Identical to beagti */
4083+ {"beagtid", INST_TYPE_R1_IMM, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBF800000, OPCODE_MASK_H1, beagtid, branch_inst },
4084+ {"bealgtid",INST_TYPE_R1_IMML, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBF800000, OPCODE_MASK_H1, invalid_inst, branch_inst }, /* Identical to beagtid */
4085+ {"beagei", INST_TYPE_R1_IMM, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBDA00000, OPCODE_MASK_H1, beagei, branch_inst },
4086+ {"bealgei", INST_TYPE_R1_IMML, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBDA00000, OPCODE_MASK_H1, invalid_inst, branch_inst }, /* Identical to beagei */
4087+ {"beageid", INST_TYPE_R1_IMM, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBFA00000, OPCODE_MASK_H1, beageid, branch_inst },
4088+ {"bealgeid",INST_TYPE_R1_IMML, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBFA00000, OPCODE_MASK_H1, invalid_inst, branch_inst }, /* Identical to beageid */
4089+ {"ll", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xC8000100, OPCODE_MASK_H4, ll, memory_load_inst },
4090+ {"llr", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xC8000300, OPCODE_MASK_H4, llr, memory_load_inst },
4091+ {"sl", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xD8000100, OPCODE_MASK_H4, sl, memory_store_inst },
4092+ {"slr", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xD8000300, OPCODE_MASK_H4, slr, memory_store_inst },
4093+ {"lli", INST_TYPE_RD_R1_IMML, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xE8000000, OPCODE_MASK_H, invalid_inst, memory_load_inst }, /* Identical to 32-bit */
4094+ {"sli", INST_TYPE_RD_R1_IMML, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xF8000000, OPCODE_MASK_H, invalid_inst, memory_store_inst }, /* Identical to 32-bit */
4095+ {"lla", INST_TYPE_RD_R1_IMML, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x30000000, OPCODE_MASK_H, invalid_inst, arithmetic_inst }, /* lla translates to addlik */
4096+ {"dadd", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x58000400, OPCODE_MASK_H4, dadd, arithmetic_inst },
4097+ {"drsub", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x58000480, OPCODE_MASK_H4, drsub, arithmetic_inst },
4098+ {"dmul", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x58000500, OPCODE_MASK_H4, dmul, arithmetic_inst },
4099+ {"ddiv", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x58000580, OPCODE_MASK_H4, ddiv, arithmetic_inst },
4100+ {"dcmp.lt", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x58000610, OPCODE_MASK_H4, dcmp_lt, arithmetic_inst },
4101+ {"dcmp.eq", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x58000620, OPCODE_MASK_H4, dcmp_eq, arithmetic_inst },
4102+ {"dcmp.le", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x58000630, OPCODE_MASK_H4, dcmp_le, arithmetic_inst },
4103+ {"dcmp.gt", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x58000640, OPCODE_MASK_H4, dcmp_gt, arithmetic_inst },
4104+ {"dcmp.ne", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x58000650, OPCODE_MASK_H4, dcmp_ne, arithmetic_inst },
4105+ {"dcmp.ge", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x58000660, OPCODE_MASK_H4, dcmp_ge, arithmetic_inst },
4106+ {"dcmp.un", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x58000600, OPCODE_MASK_H4, dcmp_un, arithmetic_inst },
4107+ {"dbl", INST_TYPE_RD_R1, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x58000680, OPCODE_MASK_H4, dbl, arithmetic_inst },
4108+ {"dlong", INST_TYPE_RD_R1, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x58000700, OPCODE_MASK_H4, dlong, arithmetic_inst },
4109+ {"dsqrt", INST_TYPE_RD_R1, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x58000780, OPCODE_MASK_H4, dsqrt, arithmetic_inst },
4110+
4111 {"", 0, 0, 0, 0, 0, 0, 0, 0},
4112 };
4113
4114@@ -445,8 +576,17 @@ char pvr_register_prefix[] = "rpvr";
4115 #define MIN_IMM5 ((int) 0x00000000)
4116 #define MAX_IMM5 ((int) 0x0000001f)
4117
4118+#define MIN_IMM6 ((int) 0x00000000)
4119+#define MAX_IMM6 ((int) 0x0000003f)
4120+
4121 #define MIN_IMM_WIDTH ((int) 0x00000001)
4122 #define MAX_IMM_WIDTH ((int) 0x00000020)
4123
4124+#define MIN_IMM6_WIDTH ((int) 0x00000001)
4125+#define MAX_IMM6_WIDTH ((int) 0x00000040)
4126+
4127+#define MIN_IMML ((long) 0xffffff8000000000L)
4128+#define MAX_IMML ((long) 0x0000007fffffffffL)
4129+
4130 #endif /* MICROBLAZE_OPC */
4131
4132diff --git a/opcodes/microblaze-opcm.h b/opcodes/microblaze-opcm.h
4133index 28662694cd..076dbcd0b3 100644
4134--- a/opcodes/microblaze-opcm.h
4135+++ b/opcodes/microblaze-opcm.h
4136@@ -25,6 +25,7 @@
4137
4138 enum microblaze_instr
4139 {
4140+ /* 32-bit instructions */
4141 add, rsub, addc, rsubc, addk, rsubk, addkc, rsubkc, clz, cmp, cmpu,
4142 addi, rsubi, addic, rsubic, addik, rsubik, addikc, rsubikc, mul,
4143 mulh, mulhu, mulhsu,swapb,swaph,
4144@@ -58,6 +59,18 @@ enum microblaze_instr
4145 aputd, taputd, caputd, tcaputd, naputd, tnaputd, ncaputd, tncaputd,
4146 eagetd, teagetd, ecagetd, tecagetd, neagetd, tneagetd, necagetd, tnecagetd,
4147 eaputd, teaputd, ecaputd, tecaputd, neaputd, tneaputd, necaputd, tnecaputd,
4148+
4149+ /* 64-bit instructions */
4150+ addl, rsubl, addlc, rsublc, addlk, rsublk, addlkc, rsublkc, cmpl, cmplu, mull,
4151+ bslll, bslra, bslrl, bsllli, bslrai, bslrli, bslefi, bslifi, orl, andl, xorl,
4152+ andnl, pcmplbf, pcmpleq, pcmplne, srla, srlc, srll, sextl8, sextl16, sextl32,
4153+ brea, bread, breald, beaeq, bealeq, beaeqd, bealeqd, beane, bealne, beaned,
4154+ bealned, bealt, beallt, bealtd, bealltd, beale, bealle, bealed, bealled, beagt,
4155+ bealgt, beagtd, bealgtd, beage, bealge, beaged, bealged, breai, breaid, brealid,
4156+ beaeqi, beaeqid, beanei, beaneid, bealti, bealtid, bealei, bealeid, beagti,
4157+ beagtid, beagei, beageid, imml, ll, llr, sl, slr,
4158+ dadd, drsub, dmul, ddiv, dcmp_lt, dcmp_eq, dcmp_le, dcmp_gt, dcmp_ne, dcmp_ge,
4159+ dcmp_un, dbl, dlong, dsqrt,
4160 invalid_inst
4161 };
4162
4163@@ -135,15 +148,18 @@ enum microblaze_instr_type
4164 #define RA_MASK 0x001F0000
4165 #define RB_MASK 0x0000F800
4166 #define IMM_MASK 0x0000FFFF
4167+#define IMML_MASK 0x00FFFFFF
4168
4169-/* Imm mask for barrel shifts. */
4170+/* Imm masks for barrel shifts. */
4171 #define IMM5_MASK 0x0000001F
4172+#define IMM6_MASK 0x0000003F
4173
4174 /* Imm mask for mbar. */
4175 #define IMM5_MBAR_MASK 0x03E00000
4176
4177-/* Imm mask for extract/insert width. */
4178+/* Imm masks for extract/insert width. */
4179 #define IMM5_WIDTH_MASK 0x000007C0
4180+#define IMM6_WIDTH_MASK 0x00000FC0
4181
4182 /* FSL imm mask for get, put instructions. */
4183 #define RFSL_MASK 0x000000F
4184--
41852.17.1
4186