Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 1 | From 68a91eb7ac94f0e0c6e9ebd7ad148c80cbc227df Mon Sep 17 00:00:00 2001 |
| 2 | From: Nagaraju Mekala <nmekala@xilix.com> |
| 3 | Date: Mon, 6 Feb 2017 15:53:08 +0530 |
| 4 | Subject: [PATCH] Fixup debug_loc sections after linker relaxation Adds a new |
| 5 | reloctype R_MICROBLAZE_32_NONE, used for passing reloc info from the |
| 6 | assembler to the linker when the linker manages to fully resolve a local |
| 7 | symbol reference. |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 8 | |
| 9 | This is a workaround for design flaws in the assembler to |
| 10 | linker interface with regards to linker relaxation. |
| 11 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 12 | Signed-off-by: Edgar E. Iglesias <edgar.iglesias@gmail.com> |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 13 | Signed-off-by: Nagaraju Mekala <nagaraju.mekala@xilinx.com> |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 14 | |
| 15 | --- |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 16 | bfd/bfd-in2.h | 9 ++++++-- |
| 17 | bfd/elf32-microblaze.c | 53 ++++++++++++++++++++++++++++++++++------------ |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 18 | bfd/libbfd.h | 1 + |
| 19 | bfd/reloc.c | 6 ++++++ |
| 20 | binutils/readelf.c | 4 ++++ |
| 21 | gas/config/tc-microblaze.c | 5 ++++- |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 22 | include/elf/microblaze.h | 2 ++ |
| 23 | 7 files changed, 64 insertions(+), 16 deletions(-) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 24 | |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 25 | diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h |
| 26 | index e251d7e..fe6933a 100644 |
| 27 | --- a/bfd/bfd-in2.h |
| 28 | +++ b/bfd/bfd-in2.h |
| 29 | @@ -5867,10 +5867,15 @@ value relative to the read-write small data area anchor */ |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 30 | expressions of the form "Symbol Op Symbol" */ |
| 31 | BFD_RELOC_MICROBLAZE_32_SYM_OP_SYM, |
| 32 | |
| 33 | -/* This is a 64 bit reloc that stores the 32 bit pc relative |
| 34 | +/* This is a 32 bit reloc that stores the 32 bit pc relative |
| 35 | value in two words (with an imm instruction). No relocation is |
| 36 | done here - only used for relaxing */ |
| 37 | - BFD_RELOC_MICROBLAZE_64_NONE, |
| 38 | + BFD_RELOC_MICROBLAZE_32_NONE, |
| 39 | + |
| 40 | +/* This is a 64 bit reloc that stores the 32 bit pc relative |
| 41 | + * +value in two words (with an imm instruction). No relocation is |
| 42 | + * +done here - only used for relaxing */ |
| 43 | + BFD_RELOC_MICROBLAZE_64_NONE, |
| 44 | |
| 45 | /* This is a 64 bit reloc that stores the 32 bit pc relative |
| 46 | value in two words (with an imm instruction). The relocation is |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 47 | diff --git a/bfd/elf32-microblaze.c b/bfd/elf32-microblaze.c |
| 48 | index 359484d..1c69c26 100644 |
| 49 | --- a/bfd/elf32-microblaze.c |
| 50 | +++ b/bfd/elf32-microblaze.c |
| 51 | @@ -176,7 +176,21 @@ static reloc_howto_type microblaze_elf_howto_raw[] = |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 52 | 0x0000ffff, /* Dest Mask. */ |
| 53 | FALSE), /* PC relative offset? */ |
| 54 | |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 55 | - /* This reloc does nothing. Used for relaxation. */ |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 56 | + HOWTO (R_MICROBLAZE_32_NONE, /* Type. */ |
| 57 | + 0, /* Rightshift. */ |
| 58 | + 2, /* Size (0 = byte, 1 = short, 2 = long). */ |
| 59 | + 32, /* Bitsize. */ |
| 60 | + TRUE, /* PC_relative. */ |
| 61 | + 0, /* Bitpos. */ |
| 62 | + complain_overflow_bitfield, /* Complain on overflow. */ |
| 63 | + NULL, /* Special Function. */ |
| 64 | + "R_MICROBLAZE_32_NONE",/* Name. */ |
| 65 | + FALSE, /* Partial Inplace. */ |
| 66 | + 0, /* Source Mask. */ |
| 67 | + 0, /* Dest Mask. */ |
| 68 | + FALSE), /* PC relative offset? */ |
| 69 | + |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 70 | + /* This reloc does nothing. Used for relaxation. */ |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 71 | HOWTO (R_MICROBLAZE_64_NONE, /* Type. */ |
| 72 | 0, /* Rightshift. */ |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 73 | 3, /* Size (0 = byte, 1 = short, 2 = long). */ |
| 74 | @@ -562,6 +576,9 @@ microblaze_elf_reloc_type_lookup (bfd * abfd ATTRIBUTE_UNUSED, |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 75 | case BFD_RELOC_NONE: |
| 76 | microblaze_reloc = R_MICROBLAZE_NONE; |
| 77 | break; |
| 78 | + case BFD_RELOC_MICROBLAZE_32_NONE: |
| 79 | + microblaze_reloc = R_MICROBLAZE_32_NONE; |
| 80 | + break; |
| 81 | case BFD_RELOC_MICROBLAZE_64_NONE: |
| 82 | microblaze_reloc = R_MICROBLAZE_64_NONE; |
| 83 | break; |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 84 | @@ -1918,6 +1935,7 @@ microblaze_elf_relax_section (bfd *abfd, |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 85 | } |
| 86 | break; |
| 87 | case R_MICROBLAZE_NONE: |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 88 | + case R_MICROBLAZE_32_NONE: |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 89 | { |
| 90 | /* This was a PC-relative instruction that was |
| 91 | completely resolved. */ |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 92 | @@ -1926,12 +1944,18 @@ microblaze_elf_relax_section (bfd *abfd, |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 93 | target_address = irel->r_addend + irel->r_offset; |
| 94 | sfix = calc_fixup (irel->r_offset, 0, sec); |
| 95 | efix = calc_fixup (target_address, 0, sec); |
| 96 | + |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 97 | + /* Validate the in-band val. */ |
| 98 | + val = bfd_get_32 (abfd, contents + irel->r_offset); |
| 99 | + if (val != irel->r_addend && ELF32_R_TYPE (irel->r_info) == R_MICROBLAZE_32_NONE) { |
| 100 | + fprintf(stderr, "%d: CORRUPT relax reloc %x %lx\n", __LINE__, val, irel->r_addend); |
| 101 | + } |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 102 | irel->r_addend -= (efix - sfix); |
| 103 | /* Should use HOWTO. */ |
| 104 | microblaze_bfd_write_imm_value_32 (abfd, contents + irel->r_offset, |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 105 | irel->r_addend); |
| 106 | - } |
| 107 | - break; |
| 108 | + } |
| 109 | + break; |
| 110 | case R_MICROBLAZE_64_NONE: |
| 111 | { |
| 112 | /* This was a PC-relative 64-bit instruction that was |
| 113 | @@ -1973,12 +1997,16 @@ microblaze_elf_relax_section (bfd *abfd, |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 114 | irelscanend = irelocs + o->reloc_count; |
| 115 | for (irelscan = irelocs; irelscan < irelscanend; irelscan++) |
| 116 | { |
| 117 | - if (ELF32_R_TYPE (irelscan->r_info) == (int) R_MICROBLAZE_NONE) |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 118 | + if (1 && ELF32_R_TYPE (irelscan->r_info) == (int) R_MICROBLAZE_32_NONE) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 119 | { |
| 120 | unsigned int val; |
| 121 | |
| 122 | isym = isymbuf + ELF32_R_SYM (irelscan->r_info); |
| 123 | |
| 124 | + /* hax: We only do the following fixup for debug location lists. */ |
| 125 | + if (strcmp(".debug_loc", o->name)) |
| 126 | + continue; |
| 127 | + |
| 128 | /* This was a PC-relative instruction that was completely resolved. */ |
| 129 | if (ocontents == NULL) |
| 130 | { |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 131 | @@ -1999,18 +2027,17 @@ microblaze_elf_relax_section (bfd *abfd, |
| 132 | (file_ptr) 0, |
| 133 | o->rawsize)) |
| 134 | goto error_return; |
| 135 | - elf_section_data (o)->this_hdr.contents = ocontents; |
| 136 | - } |
| 137 | - } |
| 138 | - irelscan->r_addend -= calc_fixup (irelscan->r_addend |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 139 | - + isym->st_value, sec); |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 140 | + elf_section_data (o)->this_hdr.contents = ocontents; |
| 141 | + } |
| 142 | + } |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 143 | val = bfd_get_32 (abfd, ocontents + irelscan->r_offset); |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 144 | + if (val != irelscan->r_addend) { |
| 145 | + fprintf(stderr, "%d: CORRUPT relax reloc! %x %lx\n", __LINE__, val, irelscan->r_addend); |
| 146 | + } |
| 147 | + irelscan->r_addend -= calc_fixup (irelscan->r_addend, 0, sec); |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 148 | microblaze_bfd_write_imm_value_32 (abfd, ocontents + irelscan->r_offset, |
| 149 | irelscan->r_addend); |
| 150 | } |
| 151 | - if (ELF32_R_TYPE (irelscan->r_info) == (int) R_MICROBLAZE_64_NONE) { |
| 152 | - fprintf(stderr, "Unhandled NONE 64\n"); |
| 153 | - } |
| 154 | if (ELF32_R_TYPE (irelscan->r_info) == (int) R_MICROBLAZE_32) |
| 155 | { |
| 156 | isym = isymbuf + ELF32_R_SYM (irelscan->r_info); |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 157 | @@ -2070,7 +2097,7 @@ microblaze_elf_relax_section (bfd *abfd, |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 158 | elf_section_data (o)->this_hdr.contents = ocontents; |
| 159 | } |
| 160 | } |
| 161 | - irelscan->r_addend -= calc_fixup (irel->r_addend |
| 162 | + irelscan->r_addend -= calc_fixup (irelscan->r_addend |
| 163 | + isym->st_value, |
| 164 | 0, |
| 165 | sec); |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 166 | diff --git a/bfd/libbfd.h b/bfd/libbfd.h |
| 167 | index 36284d7..feb9fad 100644 |
| 168 | --- a/bfd/libbfd.h |
| 169 | +++ b/bfd/libbfd.h |
| 170 | @@ -2901,6 +2901,7 @@ static const char *const bfd_reloc_code_real_names[] = { "@@uninitialized@@", |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 171 | "BFD_RELOC_MICROBLAZE_32_ROSDA", |
| 172 | "BFD_RELOC_MICROBLAZE_32_RWSDA", |
| 173 | "BFD_RELOC_MICROBLAZE_32_SYM_OP_SYM", |
| 174 | + "BFD_RELOC_MICROBLAZE_32_NONE", |
| 175 | "BFD_RELOC_MICROBLAZE_64_NONE", |
| 176 | "BFD_RELOC_MICROBLAZE_64_GOTPC", |
| 177 | "BFD_RELOC_MICROBLAZE_64_GOT", |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 178 | diff --git a/bfd/reloc.c b/bfd/reloc.c |
| 179 | index e6446a7..87753ae 100644 |
| 180 | --- a/bfd/reloc.c |
| 181 | +++ b/bfd/reloc.c |
| 182 | @@ -6796,6 +6796,12 @@ ENUMDOC |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 183 | This is a 32 bit reloc for the microblaze to handle |
| 184 | expressions of the form "Symbol Op Symbol" |
| 185 | ENUM |
| 186 | + BFD_RELOC_MICROBLAZE_32_NONE |
| 187 | +ENUMDOC |
| 188 | + This is a 32 bit reloc that stores the 32 bit pc relative |
| 189 | + value in two words (with an imm instruction). No relocation is |
| 190 | + done here - only used for relaxing |
| 191 | +ENUM |
| 192 | BFD_RELOC_MICROBLAZE_64_NONE |
| 193 | ENUMDOC |
| 194 | This is a 64 bit reloc that stores the 32 bit pc relative |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 195 | diff --git a/binutils/readelf.c b/binutils/readelf.c |
| 196 | index 9df3742..1bbc2d1 100644 |
| 197 | --- a/binutils/readelf.c |
| 198 | +++ b/binutils/readelf.c |
| 199 | @@ -13020,6 +13020,10 @@ is_none_reloc (Filedata * filedata, unsigned int reloc_type) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 200 | || reloc_type == 32 /* R_AVR_DIFF32. */); |
| 201 | case EM_METAG: |
| 202 | return reloc_type == 3; /* R_METAG_NONE. */ |
| 203 | + case EM_MICROBLAZE: |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 204 | + return reloc_type == 30 /* R_MICROBLAZE_32_NONE. */ |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 205 | + || reloc_type == 0 /* R_MICROBLAZE_NONE. */ |
| 206 | + || reloc_type == 9; /* R_MICROBLAZE_64_NONE. */ |
| 207 | case EM_NDS32: |
| 208 | return (reloc_type == 0 /* R_XTENSA_NONE. */ |
| 209 | || reloc_type == 204 /* R_NDS32_DIFF8. */ |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 210 | diff --git a/gas/config/tc-microblaze.c b/gas/config/tc-microblaze.c |
| 211 | index 3e72840..fa665b4 100644 |
| 212 | --- a/gas/config/tc-microblaze.c |
| 213 | +++ b/gas/config/tc-microblaze.c |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 214 | @@ -2201,7 +2201,9 @@ md_apply_fix (fixS * fixP, |
| 215 | /* This fixup has been resolved. Create a reloc in case the linker |
| 216 | moves code around due to relaxing. */ |
| 217 | if (fixP->fx_r_type == BFD_RELOC_64_PCREL) |
| 218 | - fixP->fx_r_type = BFD_RELOC_MICROBLAZE_64_NONE; |
| 219 | + fixP->fx_r_type = BFD_RELOC_MICROBLAZE_64_NONE; |
| 220 | + else if (fixP->fx_r_type == BFD_RELOC_32) |
| 221 | + fixP->fx_r_type = BFD_RELOC_MICROBLAZE_32_NONE; |
| 222 | else |
| 223 | fixP->fx_r_type = BFD_RELOC_NONE; |
| 224 | fixP->fx_addsy = section_symbol (absolute_section); |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 225 | @@ -2426,6 +2428,7 @@ tc_gen_reloc (asection * section ATTRIBUTE_UNUSED, fixS * fixp) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 226 | switch (fixp->fx_r_type) |
| 227 | { |
| 228 | case BFD_RELOC_NONE: |
| 229 | + case BFD_RELOC_MICROBLAZE_32_NONE: |
| 230 | case BFD_RELOC_MICROBLAZE_64_NONE: |
| 231 | case BFD_RELOC_32: |
| 232 | case BFD_RELOC_MICROBLAZE_32_LO: |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 233 | diff --git a/include/elf/microblaze.h b/include/elf/microblaze.h |
| 234 | index 830b5ad..6ee0966 100644 |
| 235 | --- a/include/elf/microblaze.h |
| 236 | +++ b/include/elf/microblaze.h |
| 237 | @@ -61,6 +61,8 @@ START_RELOC_NUMBERS (elf_microblaze_reloc_type) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 238 | RELOC_NUMBER (R_MICROBLAZE_TEXTPCREL_64, 30) /* PC-relative TEXT offset. */ |
| 239 | RELOC_NUMBER (R_MICROBLAZE_TEXTREL_64, 31) /* TEXT Entry offset 64-bit. */ |
| 240 | RELOC_NUMBER (R_MICROBLAZE_TEXTREL_32_LO, 32) /* TEXT Entry offset 32-bit. */ |
| 241 | + RELOC_NUMBER (R_MICROBLAZE_32_NONE, 33) |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 242 | + |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 243 | END_RELOC_NUMBERS (R_MICROBLAZE_max) |
| 244 | |
| 245 | /* Global base address names. */ |