Andrew Geissler | 84ad7c5 | 2020-06-27 00:00:16 -0500 | [diff] [blame^] | 1 | From 62859c17077c559ad5e5db1cfbb496d5e8c3da68 Mon Sep 17 00:00:00 2001 |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 2 | From: Nagaraju Mekala <nmekala@xilix.com> |
| 3 | Date: Mon, 6 Feb 2017 15:53:08 +0530 |
Andrew Geissler | 84ad7c5 | 2020-06-27 00:00:16 -0500 | [diff] [blame^] | 4 | Subject: [PATCH 05/43] [LOCAL]: Fixup debug_loc sections after linker |
| 5 | relaxation Adds a new reloctype R_MICROBLAZE_32_NONE, used for passing reloc |
| 6 | info from the assembler to the linker when the linker manages to fully |
| 7 | resolve a local 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> |
Andrew Geissler | 84ad7c5 | 2020-06-27 00:00:16 -0500 | [diff] [blame^] | 13 | Signed-off-by: Nagaraju Mekala <nmekala@xilinx.com> |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 14 | --- |
Andrew Geissler | 84ad7c5 | 2020-06-27 00:00:16 -0500 | [diff] [blame^] | 15 | bfd/bfd-in2.h | 9 +++++-- |
| 16 | bfd/elf32-microblaze.c | 53 ++++++++++++++++++++++++++++---------- |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 17 | bfd/libbfd.h | 1 + |
Andrew Geissler | 84ad7c5 | 2020-06-27 00:00:16 -0500 | [diff] [blame^] | 18 | bfd/reloc.c | 6 +++++ |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 19 | include/elf/microblaze.h | 2 ++ |
| 20 | 7 files changed, 64 insertions(+), 16 deletions(-) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 21 | |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 22 | diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h |
Andrew Geissler | 84ad7c5 | 2020-06-27 00:00:16 -0500 | [diff] [blame^] | 23 | index e25da50aaf..721531886a 100644 |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 24 | --- a/bfd/bfd-in2.h |
| 25 | +++ b/bfd/bfd-in2.h |
Andrew Geissler | 84ad7c5 | 2020-06-27 00:00:16 -0500 | [diff] [blame^] | 26 | @@ -5866,10 +5866,15 @@ value relative to the read-write small data area anchor */ |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 27 | expressions of the form "Symbol Op Symbol" */ |
| 28 | BFD_RELOC_MICROBLAZE_32_SYM_OP_SYM, |
| 29 | |
| 30 | -/* This is a 64 bit reloc that stores the 32 bit pc relative |
| 31 | +/* This is a 32 bit reloc that stores the 32 bit pc relative |
| 32 | value in two words (with an imm instruction). No relocation is |
| 33 | done here - only used for relaxing */ |
| 34 | - BFD_RELOC_MICROBLAZE_64_NONE, |
| 35 | + BFD_RELOC_MICROBLAZE_32_NONE, |
| 36 | + |
| 37 | +/* This is a 64 bit reloc that stores the 32 bit pc relative |
| 38 | + * +value in two words (with an imm instruction). No relocation is |
| 39 | + * +done here - only used for relaxing */ |
| 40 | + BFD_RELOC_MICROBLAZE_64_NONE, |
| 41 | |
| 42 | /* This is a 64 bit reloc that stores the 32 bit pc relative |
| 43 | value in two words (with an imm instruction). The relocation is |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 44 | diff --git a/bfd/elf32-microblaze.c b/bfd/elf32-microblaze.c |
Andrew Geissler | 84ad7c5 | 2020-06-27 00:00:16 -0500 | [diff] [blame^] | 45 | index 359484dd5e..1c69c269c7 100644 |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 46 | --- a/bfd/elf32-microblaze.c |
| 47 | +++ b/bfd/elf32-microblaze.c |
| 48 | @@ -176,7 +176,21 @@ static reloc_howto_type microblaze_elf_howto_raw[] = |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 49 | 0x0000ffff, /* Dest Mask. */ |
| 50 | FALSE), /* PC relative offset? */ |
| 51 | |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 52 | - /* This reloc does nothing. Used for relaxation. */ |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 53 | + HOWTO (R_MICROBLAZE_32_NONE, /* Type. */ |
| 54 | + 0, /* Rightshift. */ |
| 55 | + 2, /* Size (0 = byte, 1 = short, 2 = long). */ |
| 56 | + 32, /* Bitsize. */ |
| 57 | + TRUE, /* PC_relative. */ |
| 58 | + 0, /* Bitpos. */ |
| 59 | + complain_overflow_bitfield, /* Complain on overflow. */ |
| 60 | + NULL, /* Special Function. */ |
| 61 | + "R_MICROBLAZE_32_NONE",/* Name. */ |
| 62 | + FALSE, /* Partial Inplace. */ |
| 63 | + 0, /* Source Mask. */ |
| 64 | + 0, /* Dest Mask. */ |
| 65 | + FALSE), /* PC relative offset? */ |
| 66 | + |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 67 | + /* This reloc does nothing. Used for relaxation. */ |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 68 | HOWTO (R_MICROBLAZE_64_NONE, /* Type. */ |
| 69 | 0, /* Rightshift. */ |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 70 | 3, /* Size (0 = byte, 1 = short, 2 = long). */ |
| 71 | @@ -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] | 72 | case BFD_RELOC_NONE: |
| 73 | microblaze_reloc = R_MICROBLAZE_NONE; |
| 74 | break; |
| 75 | + case BFD_RELOC_MICROBLAZE_32_NONE: |
| 76 | + microblaze_reloc = R_MICROBLAZE_32_NONE; |
| 77 | + break; |
| 78 | case BFD_RELOC_MICROBLAZE_64_NONE: |
| 79 | microblaze_reloc = R_MICROBLAZE_64_NONE; |
| 80 | break; |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 81 | @@ -1918,6 +1935,7 @@ microblaze_elf_relax_section (bfd *abfd, |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 82 | } |
| 83 | break; |
| 84 | case R_MICROBLAZE_NONE: |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 85 | + case R_MICROBLAZE_32_NONE: |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 86 | { |
| 87 | /* This was a PC-relative instruction that was |
| 88 | completely resolved. */ |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 89 | @@ -1926,12 +1944,18 @@ microblaze_elf_relax_section (bfd *abfd, |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 90 | target_address = irel->r_addend + irel->r_offset; |
| 91 | sfix = calc_fixup (irel->r_offset, 0, sec); |
| 92 | efix = calc_fixup (target_address, 0, sec); |
| 93 | + |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 94 | + /* Validate the in-band val. */ |
| 95 | + val = bfd_get_32 (abfd, contents + irel->r_offset); |
| 96 | + if (val != irel->r_addend && ELF32_R_TYPE (irel->r_info) == R_MICROBLAZE_32_NONE) { |
| 97 | + fprintf(stderr, "%d: CORRUPT relax reloc %x %lx\n", __LINE__, val, irel->r_addend); |
| 98 | + } |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 99 | irel->r_addend -= (efix - sfix); |
| 100 | /* Should use HOWTO. */ |
| 101 | microblaze_bfd_write_imm_value_32 (abfd, contents + irel->r_offset, |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 102 | irel->r_addend); |
| 103 | - } |
| 104 | - break; |
| 105 | + } |
| 106 | + break; |
| 107 | case R_MICROBLAZE_64_NONE: |
| 108 | { |
| 109 | /* This was a PC-relative 64-bit instruction that was |
| 110 | @@ -1973,12 +1997,16 @@ microblaze_elf_relax_section (bfd *abfd, |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 111 | irelscanend = irelocs + o->reloc_count; |
| 112 | for (irelscan = irelocs; irelscan < irelscanend; irelscan++) |
| 113 | { |
| 114 | - if (ELF32_R_TYPE (irelscan->r_info) == (int) R_MICROBLAZE_NONE) |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 115 | + 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] | 116 | { |
| 117 | unsigned int val; |
| 118 | |
| 119 | isym = isymbuf + ELF32_R_SYM (irelscan->r_info); |
| 120 | |
| 121 | + /* hax: We only do the following fixup for debug location lists. */ |
| 122 | + if (strcmp(".debug_loc", o->name)) |
| 123 | + continue; |
| 124 | + |
| 125 | /* This was a PC-relative instruction that was completely resolved. */ |
| 126 | if (ocontents == NULL) |
| 127 | { |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 128 | @@ -1999,18 +2027,17 @@ microblaze_elf_relax_section (bfd *abfd, |
| 129 | (file_ptr) 0, |
| 130 | o->rawsize)) |
| 131 | goto error_return; |
| 132 | - elf_section_data (o)->this_hdr.contents = ocontents; |
| 133 | - } |
| 134 | - } |
| 135 | - irelscan->r_addend -= calc_fixup (irelscan->r_addend |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 136 | - + isym->st_value, sec); |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 137 | + elf_section_data (o)->this_hdr.contents = ocontents; |
| 138 | + } |
| 139 | + } |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 140 | val = bfd_get_32 (abfd, ocontents + irelscan->r_offset); |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 141 | + if (val != irelscan->r_addend) { |
| 142 | + fprintf(stderr, "%d: CORRUPT relax reloc! %x %lx\n", __LINE__, val, irelscan->r_addend); |
| 143 | + } |
| 144 | + irelscan->r_addend -= calc_fixup (irelscan->r_addend, 0, sec); |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 145 | microblaze_bfd_write_imm_value_32 (abfd, ocontents + irelscan->r_offset, |
| 146 | irelscan->r_addend); |
| 147 | } |
| 148 | - if (ELF32_R_TYPE (irelscan->r_info) == (int) R_MICROBLAZE_64_NONE) { |
| 149 | - fprintf(stderr, "Unhandled NONE 64\n"); |
| 150 | - } |
| 151 | if (ELF32_R_TYPE (irelscan->r_info) == (int) R_MICROBLAZE_32) |
| 152 | { |
| 153 | isym = isymbuf + ELF32_R_SYM (irelscan->r_info); |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 154 | @@ -2070,7 +2097,7 @@ microblaze_elf_relax_section (bfd *abfd, |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 155 | elf_section_data (o)->this_hdr.contents = ocontents; |
| 156 | } |
| 157 | } |
| 158 | - irelscan->r_addend -= calc_fixup (irel->r_addend |
| 159 | + irelscan->r_addend -= calc_fixup (irelscan->r_addend |
| 160 | + isym->st_value, |
| 161 | 0, |
| 162 | sec); |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 163 | diff --git a/bfd/libbfd.h b/bfd/libbfd.h |
Andrew Geissler | 84ad7c5 | 2020-06-27 00:00:16 -0500 | [diff] [blame^] | 164 | index 36284d71a9..feb9fada1e 100644 |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 165 | --- a/bfd/libbfd.h |
| 166 | +++ b/bfd/libbfd.h |
| 167 | @@ -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] | 168 | "BFD_RELOC_MICROBLAZE_32_ROSDA", |
| 169 | "BFD_RELOC_MICROBLAZE_32_RWSDA", |
| 170 | "BFD_RELOC_MICROBLAZE_32_SYM_OP_SYM", |
| 171 | + "BFD_RELOC_MICROBLAZE_32_NONE", |
| 172 | "BFD_RELOC_MICROBLAZE_64_NONE", |
| 173 | "BFD_RELOC_MICROBLAZE_64_GOTPC", |
| 174 | "BFD_RELOC_MICROBLAZE_64_GOT", |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 175 | diff --git a/bfd/reloc.c b/bfd/reloc.c |
Andrew Geissler | 84ad7c5 | 2020-06-27 00:00:16 -0500 | [diff] [blame^] | 176 | index e6446a7809..87753ae4f0 100644 |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 177 | --- a/bfd/reloc.c |
| 178 | +++ b/bfd/reloc.c |
Andrew Geissler | 84ad7c5 | 2020-06-27 00:00:16 -0500 | [diff] [blame^] | 179 | @@ -6795,6 +6795,12 @@ ENUM |
| 180 | ENUMDOC |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 181 | This is a 32 bit reloc for the microblaze to handle |
| 182 | expressions of the form "Symbol Op Symbol" |
Andrew Geissler | 84ad7c5 | 2020-06-27 00:00:16 -0500 | [diff] [blame^] | 183 | +ENUM |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 184 | + BFD_RELOC_MICROBLAZE_32_NONE |
| 185 | +ENUMDOC |
| 186 | + This is a 32 bit reloc that stores the 32 bit pc relative |
| 187 | + value in two words (with an imm instruction). No relocation is |
| 188 | + done here - only used for relaxing |
Andrew Geissler | 84ad7c5 | 2020-06-27 00:00:16 -0500 | [diff] [blame^] | 189 | ENUM |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 190 | BFD_RELOC_MICROBLAZE_64_NONE |
| 191 | ENUMDOC |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 192 | diff --git a/include/elf/microblaze.h b/include/elf/microblaze.h |
Andrew Geissler | 84ad7c5 | 2020-06-27 00:00:16 -0500 | [diff] [blame^] | 193 | index 830b5ad446..6ee0966444 100644 |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 194 | --- a/include/elf/microblaze.h |
| 195 | +++ b/include/elf/microblaze.h |
| 196 | @@ -61,6 +61,8 @@ START_RELOC_NUMBERS (elf_microblaze_reloc_type) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 197 | RELOC_NUMBER (R_MICROBLAZE_TEXTPCREL_64, 30) /* PC-relative TEXT offset. */ |
| 198 | RELOC_NUMBER (R_MICROBLAZE_TEXTREL_64, 31) /* TEXT Entry offset 64-bit. */ |
| 199 | RELOC_NUMBER (R_MICROBLAZE_TEXTREL_32_LO, 32) /* TEXT Entry offset 32-bit. */ |
| 200 | + RELOC_NUMBER (R_MICROBLAZE_32_NONE, 33) |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 201 | + |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 202 | END_RELOC_NUMBERS (R_MICROBLAZE_max) |
| 203 | |
| 204 | /* Global base address names. */ |
Andrew Geissler | 84ad7c5 | 2020-06-27 00:00:16 -0500 | [diff] [blame^] | 205 | -- |
| 206 | 2.17.1 |
| 207 | |