aboutsummaryrefslogtreecommitdiffstats
path: root/meta-xilinx-bsp/recipes-microblaze/binutils/binutils-2.30/0005-Fixup-MicroBlaze-debug_loc-sections-after-linker-rel.patch
blob: 3817234b9ebc02187fcac7a6c480c4e203d23fce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
From 5bf68bc39976903929f730b6eed18686c3563c05 Mon Sep 17 00:00:00 2001
From: Nagaraju Mekala <nagaraju.mekala@xilinx.com>
Date: Mon, 28 Aug 2017 19:53:56 -0700
Subject: [PATCH] Fixup MicroBlaze debug_loc sections after linker relaxation

Fixup debug_loc sections after linker relaxation Adds a new reloctype
R_MICROBLAZE_32_NONE, used for passing reloc info from the assembler to
the linker when the linker manages to fully resolve a local symbol
reference.

This is a workaround for design flaws in the assembler to
linker interface with regards to linker relaxation.

03/2018
Rebased for binutils 2.30

Signed-off-by: Edgar E. Iglesias <edgar.iglesias@gmail.com>
Signed-off-by: Nagaraju Mekala <nmekala@xilinx.com>
Signed-off-by: Manjukumar Matha <manjukumar.harthikote-matha@xilinx.com>
Signed-off-by: Alejandro Enedino Hernandez Samaniego <alejandr@xilinx.com>

Upstream-Status: Pending

---
 bfd/bfd-in2.h              |  9 +++++++--
 bfd/elf32-microblaze.c     | 45 ++++++++++++++++++++++++++++++++++++++-------
 bfd/libbfd.h               |  1 +
 bfd/reloc.c                |  6 ++++++
 binutils/readelf.c         |  4 ++++
 gas/config/tc-microblaze.c |  5 ++++-
 include/elf/microblaze.h   |  1 +
 7 files changed, 61 insertions(+), 10 deletions(-)

diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h
index 4228603..1906195 100644
--- a/bfd/bfd-in2.h
+++ b/bfd/bfd-in2.h
@@ -5826,10 +5826,15 @@ value relative to the read-write small data area anchor  */
 expressions of the form "Symbol Op Symbol"  */
   BFD_RELOC_MICROBLAZE_32_SYM_OP_SYM,
 
-/* This is a 64 bit reloc that stores the 32 bit pc relative
+/* This is a 32 bit reloc that stores the 32 bit pc relative
 value in two words (with an imm instruction).  No relocation is
 done here - only used for relaxing  */
-  BFD_RELOC_MICROBLAZE_64_NONE,
+  BFD_RELOC_MICROBLAZE_32_NONE,
+
+/* This is a 64 bit reloc that stores the 32 bit pc relative
+ *  +value in two words (with an imm instruction).  No relocation is
+ *   +done here - only used for relaxing  */
+    BFD_RELOC_MICROBLAZE_64_NONE,
 
 /* This is a 64 bit reloc that stores the 32 bit pc relative
 value in two words (with an imm instruction).  The relocation is
diff --git a/bfd/elf32-microblaze.c b/bfd/elf32-microblaze.c
index a1d810c..fc0d3e1 100644
--- a/bfd/elf32-microblaze.c
+++ b/bfd/elf32-microblaze.c
@@ -176,6 +176,20 @@ static reloc_howto_type microblaze_elf_howto_raw[] =
 	  0x0000ffff,		/* Dest Mask.  */
 	  FALSE),		/* PC relative offset?  */
 
+   HOWTO (R_MICROBLAZE_32_NONE,   /* Type.  */
+          0,         /* Rightshift.  */
+          2,            /* Size (0 = byte, 1 = short, 2 = long).  */
+          32,           /* Bitsize.  */
+          TRUE,         /* PC_relative.  */
+          0,           /* Bitpos.  */
+          complain_overflow_bitfield,  /* Complain on overflow.  */
+          NULL,                  /* Special Function.  */
+          "R_MICROBLAZE_32_NONE",/* Name.  */
+          FALSE,       /* Partial Inplace.  */
+          0,          /* Source Mask.  */
+          0,         /* Dest Mask.  */
+          FALSE),       /* PC relative offset?  */
+
    /* This reloc does nothing.	Used for relaxation.  */
    HOWTO (R_MICROBLAZE_64_NONE,	/* Type.  */
 	  0,			/* Rightshift.  */
@@ -532,6 +546,9 @@ microblaze_elf_reloc_type_lookup (bfd * abfd ATTRIBUTE_UNUSED,
     case BFD_RELOC_NONE:
       microblaze_reloc = R_MICROBLAZE_NONE;
       break;
+    case BFD_RELOC_MICROBLAZE_32_NONE:
+      microblaze_reloc = R_MICROBLAZE_32_NONE;
+      break;
     case BFD_RELOC_MICROBLAZE_64_NONE:
       microblaze_reloc = R_MICROBLAZE_64_NONE;
       break;
@@ -1832,14 +1849,23 @@ microblaze_elf_relax_section (bfd *abfd,
 		}
 	      break;
 	    case R_MICROBLAZE_NONE:
+            case R_MICROBLAZE_32_NONE:
 	      {
 		/* This was a PC-relative instruction that was
 		   completely resolved.  */
 		int sfix, efix;
+            unsigned int val;
 		bfd_vma target_address;
 		target_address = irel->r_addend + irel->r_offset;
 		sfix = calc_fixup (irel->r_offset, 0, sec);
 		efix = calc_fixup (target_address, 0, sec);
+
+            /* Validate the in-band val.  */
+            val = bfd_get_32 (abfd, contents + irel->r_offset);
+            if (val != irel->r_addend && ELF32_R_TYPE (irel->r_info) == R_MICROBLAZE_32_NONE) {
+               fprintf(stderr, "%d: CORRUPT relax reloc %x %lx\n", __LINE__, val, irel->r_addend);
+            }
+
 		irel->r_addend -= (efix - sfix);
 		/* Should use HOWTO.  */
 		microblaze_bfd_write_imm_value_32 (abfd, contents + irel->r_offset,
@@ -1887,12 +1913,16 @@ microblaze_elf_relax_section (bfd *abfd,
 	  irelscanend = irelocs + o->reloc_count;
 	  for (irelscan = irelocs; irelscan < irelscanend; irelscan++)
 	    {
-              if (ELF32_R_TYPE (irelscan->r_info) == (int) R_MICROBLAZE_NONE)
+              if (1 && ELF32_R_TYPE (irelscan->r_info) == (int) R_MICROBLAZE_32_NONE)
                 {
                   unsigned int val;
 
                   isym = isymbuf + ELF32_R_SYM (irelscan->r_info);
 
+                  /* hax: We only do the following fixup for debug location lists.  */
+                  if (strcmp(".debug_loc", o->name))
+                    continue;
+
                   /* This was a PC-relative instruction that was completely resolved.  */
                   if (ocontents == NULL)
                     {
@@ -1917,15 +1947,16 @@ microblaze_elf_relax_section (bfd *abfd,
                         }
                     }
 
-                  irelscan->r_addend -= calc_fixup (irelscan->r_addend
-                                                    + isym->st_value, sec);
                   val = bfd_get_32 (abfd, ocontents + irelscan->r_offset);
+
+                  if (val != irelscan->r_addend) {
+                    fprintf(stderr, "%d: CORRUPT relax reloc! %x %lx\n", __LINE__, val, irelscan->r_addend);
+                  }
+                  irelscan->r_addend -= calc_fixup (irelscan->r_addend, 0, sec);
+
                   microblaze_bfd_write_imm_value_32 (abfd, ocontents + irelscan->r_offset,
                                                      irelscan->r_addend);
               }
-              if (ELF32_R_TYPE (irelscan->r_info) == (int) R_MICROBLAZE_64_NONE) {
-                  fprintf(stderr, "Unhandled NONE 64\n");
-              }
 	      if (ELF32_R_TYPE (irelscan->r_info) == (int) R_MICROBLAZE_32)
 		{
 		  isym = isymbuf + ELF32_R_SYM (irelscan->r_info);
@@ -1985,7 +2016,7 @@ microblaze_elf_relax_section (bfd *abfd,
 			      elf_section_data (o)->this_hdr.contents = ocontents;
 			    }
 			}
-		      irelscan->r_addend -= calc_fixup (irel->r_addend
+              irelscan->r_addend -= calc_fixup (irelscan->r_addend
 							+ isym->st_value,
 							0,
 							sec);
diff --git a/bfd/libbfd.h b/bfd/libbfd.h
index 2f5f16e..854bb0c 100644
--- a/bfd/libbfd.h
+++ b/bfd/libbfd.h
@@ -2853,6 +2853,7 @@ static const char *const bfd_reloc_code_real_names[] = { "@@uninitialized@@",
   "BFD_RELOC_MICROBLAZE_32_ROSDA",
   "BFD_RELOC_MICROBLAZE_32_RWSDA",
   "BFD_RELOC_MICROBLAZE_32_SYM_OP_SYM",
+  "BFD_RELOC_MICROBLAZE_32_NONE",
   "BFD_RELOC_MICROBLAZE_64_NONE",
   "BFD_RELOC_MICROBLAZE_64_GOTPC",
   "BFD_RELOC_MICROBLAZE_64_GOT",
diff --git a/bfd/reloc.c b/bfd/reloc.c
index a1353a2..4b57de7 100644
--- a/bfd/reloc.c
+++ b/bfd/reloc.c
@@ -6903,6 +6903,12 @@ ENUMDOC
   This is a 32 bit reloc for the microblaze to handle
   expressions of the form "Symbol Op Symbol"
 ENUM
+  BFD_RELOC_MICROBLAZE_32_NONE
+ENUMDOC
+  This is a 32 bit reloc that stores the 32 bit pc relative
+  value in two words (with an imm instruction).  No relocation is
+  done here - only used for relaxing
+ENUM
   BFD_RELOC_MICROBLAZE_64_NONE
 ENUMDOC
   This is a 64 bit reloc that stores the 32 bit pc relative
diff --git a/binutils/readelf.c b/binutils/readelf.c
index fed0387..92f655d 100644
--- a/binutils/readelf.c
+++ b/binutils/readelf.c
@@ -12774,6 +12774,10 @@ is_none_reloc (Filedata * filedata, unsigned int reloc_type)
 	      || reloc_type == 32 /* R_AVR_DIFF32.  */);
     case EM_METAG:
       return reloc_type == 3; /* R_METAG_NONE.  */
+    case EM_MICROBLAZE:
+      return reloc_type == 30 /* R_MICROBLAZE_32_NONE.  */
+             || reloc_type == 0 /* R_MICROBLAZE_NONE.  */
+             || reloc_type == 9; /* R_MICROBLAZE_64_NONE.  */
     case EM_NDS32:
       return (reloc_type == 0       /* R_XTENSA_NONE.  */
 	      || reloc_type == 204  /* R_NDS32_DIFF8.  */
diff --git a/gas/config/tc-microblaze.c b/gas/config/tc-microblaze.c
index 50dbfc7..d66e949 100644
--- a/gas/config/tc-microblaze.c
+++ b/gas/config/tc-microblaze.c
@@ -2179,7 +2179,9 @@ md_apply_fix (fixS *   fixP,
       /* This fixup has been resolved.  Create a reloc in case the linker
 	 moves code around due to relaxing.  */
       if (fixP->fx_r_type == BFD_RELOC_64_PCREL)
-	fixP->fx_r_type = BFD_RELOC_MICROBLAZE_64_NONE;
+	    fixP->fx_r_type = BFD_RELOC_MICROBLAZE_64_NONE;
+      else if (fixP->fx_r_type == BFD_RELOC_32)
+        fixP->fx_r_type = BFD_RELOC_MICROBLAZE_32_NONE;
       else
 	fixP->fx_r_type = BFD_RELOC_NONE;
       fixP->fx_addsy = section_symbol (absolute_section);
@@ -2401,6 +2403,7 @@ tc_gen_reloc (asection * section ATTRIBUTE_UNUSED, fixS * fixp)
   switch (fixp->fx_r_type)
     {
     case BFD_RELOC_NONE:
+    case BFD_RELOC_MICROBLAZE_32_NONE: 
     case BFD_RELOC_MICROBLAZE_64_NONE:
     case BFD_RELOC_32:
     case BFD_RELOC_MICROBLAZE_32_LO:
diff --git a/include/elf/microblaze.h b/include/elf/microblaze.h
index ae98099..c8cc57b 100644
--- a/include/elf/microblaze.h
+++ b/include/elf/microblaze.h
@@ -58,6 +58,7 @@ START_RELOC_NUMBERS (elf_microblaze_reloc_type)
   RELOC_NUMBER (R_MICROBLAZE_TLSDTPREL64, 27)   /* TLS Offset Within TLS Block */
   RELOC_NUMBER (R_MICROBLAZE_TLSGOTTPREL32, 28) /* TLS Offset From Thread Pointer */
   RELOC_NUMBER (R_MICROBLAZE_TLSTPREL32, 29)    /* TLS Offset From Thread Pointer */
+  RELOC_NUMBER (R_MICROBLAZE_32_NONE, 30)
    
 END_RELOC_NUMBERS (R_MICROBLAZE_max)