Brad Bishop | 286d45c | 2018-10-02 15:21:57 -0400 | [diff] [blame] | 1 | From aca2758cff1f8fdc5ad7b6076ef985ba9ec5f857 Mon Sep 17 00:00:00 2001 |
| 2 | From: David Holsgrove <david.holsgrove@xilinx.com> |
| 3 | Date: Mon, 4 Feb 2013 12:15:22 +1000 |
| 4 | Subject: [PATCH 14/16] [LOCAL]: Fixup debug_loc sections after linker |
| 5 | relaxation |
| 6 | |
| 7 | Adds a new reloctype R_MICROBLAZE_32_NONE, used for passing |
| 8 | reloc info from the assembler to the linker when the linker |
| 9 | manages to fully resolve a local symbol reference. |
| 10 | |
| 11 | This is a workaround for design flaws in the assembler to |
| 12 | linker interface with regards to linker relaxation. |
| 13 | |
| 14 | Signed-off-by: Edgar E. Iglesias <edgar.iglesias@gmail.com> |
| 15 | Signed-off-by: David Holsgrove <david.holsgrove@xilinx.com> |
| 16 | Upstream-Status: Pending |
| 17 | --- |
| 18 | bfd/bfd-in2.h | 5 +++++ |
| 19 | bfd/elf32-microblaze.c | 45 +++++++++++++++++++++++++++++++++++++-------- |
| 20 | bfd/libbfd.h | 1 + |
| 21 | bfd/reloc.c | 6 ++++++ |
| 22 | include/elf/microblaze.h | 1 + |
| 23 | 5 files changed, 50 insertions(+), 8 deletions(-) |
| 24 | |
| 25 | diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h |
| 26 | index 8b7f2ee..de38907 100644 |
| 27 | --- a/bfd/bfd-in2.h |
| 28 | +++ b/bfd/bfd-in2.h |
| 29 | @@ -5449,6 +5449,11 @@ value relative to the read-write small data area anchor */ |
| 30 | expressions of the form "Symbol Op Symbol" */ |
| 31 | BFD_RELOC_MICROBLAZE_32_SYM_OP_SYM, |
| 32 | |
| 33 | +/* This is a 32 bit reloc that stores the 32 bit pc relative |
| 34 | +value in two words (with an imm instruction). No relocation is |
| 35 | +done here - only used for relaxing */ |
| 36 | + BFD_RELOC_MICROBLAZE_32_NONE, |
| 37 | + |
| 38 | /* This is a 64 bit reloc that stores the 32 bit pc relative |
| 39 | value in two words (with an imm instruction). No relocation is |
| 40 | done here - only used for relaxing */ |
| 41 | diff --git a/bfd/elf32-microblaze.c b/bfd/elf32-microblaze.c |
| 42 | index f90df47..a3f89b9 100644 |
| 43 | --- a/bfd/elf32-microblaze.c |
| 44 | +++ b/bfd/elf32-microblaze.c |
| 45 | @@ -177,6 +177,20 @@ static reloc_howto_type microblaze_elf_howto_raw[] = |
| 46 | FALSE), /* PC relative offset? */ |
| 47 | |
| 48 | /* This reloc does nothing. Used for relaxation. */ |
| 49 | + HOWTO (R_MICROBLAZE_32_NONE, /* Type. */ |
| 50 | + 0, /* Rightshift. */ |
| 51 | + 2, /* Size (0 = byte, 1 = short, 2 = long). */ |
| 52 | + 32, /* Bitsize. */ |
| 53 | + TRUE, /* PC_relative. */ |
| 54 | + 0, /* Bitpos. */ |
| 55 | + complain_overflow_bitfield, /* Complain on overflow. */ |
| 56 | + NULL, /* Special Function. */ |
| 57 | + "R_MICROBLAZE_32_NONE",/* Name. */ |
| 58 | + FALSE, /* Partial Inplace. */ |
| 59 | + 0, /* Source Mask. */ |
| 60 | + 0, /* Dest Mask. */ |
| 61 | + FALSE), /* PC relative offset? */ |
| 62 | + |
| 63 | HOWTO (R_MICROBLAZE_64_NONE, /* Type. */ |
| 64 | 0, /* Rightshift. */ |
| 65 | 2, /* Size (0 = byte, 1 = short, 2 = long). */ |
| 66 | @@ -532,7 +546,10 @@ microblaze_elf_reloc_type_lookup (bfd * abfd ATTRIBUTE_UNUSED, |
| 67 | case BFD_RELOC_NONE: |
| 68 | microblaze_reloc = R_MICROBLAZE_NONE; |
| 69 | break; |
| 70 | - case BFD_RELOC_MICROBLAZE_64_NONE: |
| 71 | + case BFD_RELOC_MICROBLAZE_32_NONE: |
| 72 | + microblaze_reloc = R_MICROBLAZE_32_NONE; |
| 73 | + break; |
| 74 | + case BFD_RELOC_MICROBLAZE_64_NONE: |
| 75 | microblaze_reloc = R_MICROBLAZE_64_NONE; |
| 76 | break; |
| 77 | case BFD_RELOC_32: |
| 78 | @@ -1913,14 +1930,22 @@ microblaze_elf_relax_section (bfd *abfd, |
| 79 | } |
| 80 | break; |
| 81 | case R_MICROBLAZE_NONE: |
| 82 | + case R_MICROBLAZE_32_NONE: |
| 83 | { |
| 84 | /* This was a PC-relative instruction that was |
| 85 | completely resolved. */ |
| 86 | int sfix, efix; |
| 87 | + unsigned int val; |
| 88 | bfd_vma target_address; |
| 89 | target_address = irel->r_addend + irel->r_offset; |
| 90 | sfix = calc_fixup (irel->r_offset, 0, sec); |
| 91 | efix = calc_fixup (target_address, 0, sec); |
| 92 | + |
| 93 | + /* Validate the in-band val. */ |
| 94 | + val = bfd_get_32 (abfd, contents + irel->r_offset); |
| 95 | + if (val != irel->r_addend && ELF32_R_TYPE (irel->r_info) == R_MICROBLAZE_32_NONE) { |
| 96 | + fprintf(stderr, "%d: CORRUPT relax reloc %x %lx\n", __LINE__, val, irel->r_addend); |
| 97 | + } |
| 98 | irel->r_addend -= (efix - sfix); |
| 99 | /* Should use HOWTO. */ |
| 100 | microblaze_bfd_write_imm_value_32 (abfd, contents + irel->r_offset, |
| 101 | @@ -1968,12 +1993,16 @@ microblaze_elf_relax_section (bfd *abfd, |
| 102 | irelscanend = irelocs + o->reloc_count; |
| 103 | for (irelscan = irelocs; irelscan < irelscanend; irelscan++) |
| 104 | { |
| 105 | - if (ELF32_R_TYPE (irelscan->r_info) == (int) R_MICROBLAZE_NONE) |
| 106 | + if (1 && ELF32_R_TYPE (irelscan->r_info) == (int) R_MICROBLAZE_32_NONE) |
| 107 | { |
| 108 | unsigned int val; |
| 109 | |
| 110 | isym = isymbuf + ELF32_R_SYM (irelscan->r_info); |
| 111 | |
| 112 | + /* hax: We only do the following fixup for debug location lists. */ |
| 113 | + if (strcmp(".debug_loc", o->name)) |
| 114 | + continue; |
| 115 | + |
| 116 | /* This was a PC-relative instruction that was completely resolved. */ |
| 117 | if (ocontents == NULL) |
| 118 | { |
| 119 | @@ -1998,15 +2027,15 @@ microblaze_elf_relax_section (bfd *abfd, |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | - irelscan->r_addend -= calc_fixup (irelscan->r_addend |
| 124 | - + isym->st_value, sec); |
| 125 | val = bfd_get_32 (abfd, ocontents + irelscan->r_offset); |
| 126 | + if (val != irelscan->r_addend) { |
| 127 | + fprintf(stderr, "%d: CORRUPT relax reloc! %x %lx\n", __LINE__, val, irelscan->r_addend); |
| 128 | + } |
| 129 | + |
| 130 | + irelscan->r_addend -= calc_fixup (irelscan->r_addend, 0, sec); |
| 131 | microblaze_bfd_write_imm_value_32 (abfd, ocontents + irelscan->r_offset, |
| 132 | irelscan->r_addend); |
| 133 | } |
| 134 | - if (ELF32_R_TYPE (irelscan->r_info) == (int) R_MICROBLAZE_64_NONE) { |
| 135 | - fprintf(stderr, "Unhandled NONE 64\n"); |
| 136 | - } |
| 137 | if (ELF32_R_TYPE (irelscan->r_info) == (int) R_MICROBLAZE_32) |
| 138 | { |
| 139 | isym = isymbuf + ELF32_R_SYM (irelscan->r_info); |
| 140 | @@ -2066,7 +2095,7 @@ microblaze_elf_relax_section (bfd *abfd, |
| 141 | elf_section_data (o)->this_hdr.contents = ocontents; |
| 142 | } |
| 143 | } |
| 144 | - irelscan->r_addend -= calc_fixup (irel->r_addend |
| 145 | + irelscan->r_addend -= calc_fixup (irelscan->r_addend |
| 146 | + isym->st_value, |
| 147 | 0, |
| 148 | sec); |
| 149 | diff --git a/bfd/libbfd.h b/bfd/libbfd.h |
| 150 | index 09f307f..840c662 100644 |
| 151 | --- a/bfd/libbfd.h |
| 152 | +++ b/bfd/libbfd.h |
| 153 | @@ -2644,6 +2644,7 @@ static const char *const bfd_reloc_code_real_names[] = { "@@uninitialized@@", |
| 154 | "BFD_RELOC_MICROBLAZE_32_ROSDA", |
| 155 | "BFD_RELOC_MICROBLAZE_32_RWSDA", |
| 156 | "BFD_RELOC_MICROBLAZE_32_SYM_OP_SYM", |
| 157 | + "BFD_RELOC_MICROBLAZE_32_NONE", |
| 158 | "BFD_RELOC_MICROBLAZE_64_NONE", |
| 159 | "BFD_RELOC_MICROBLAZE_64_GOTPC", |
| 160 | "BFD_RELOC_MICROBLAZE_64_GOT", |
| 161 | diff --git a/bfd/reloc.c b/bfd/reloc.c |
| 162 | index 7f46c58..5bcd52d 100644 |
| 163 | --- a/bfd/reloc.c |
| 164 | +++ b/bfd/reloc.c |
| 165 | @@ -6396,6 +6396,12 @@ ENUMDOC |
| 166 | This is a 32 bit reloc for the microblaze to handle |
| 167 | expressions of the form "Symbol Op Symbol" |
| 168 | ENUM |
| 169 | + BFD_RELOC_MICROBLAZE_32_NONE |
| 170 | +ENUMDOC |
| 171 | + This is a 32 bit reloc that stores the 32 bit pc relative |
| 172 | + value in two words (with an imm instruction). No relocation is |
| 173 | + done here - only used for relaxing |
| 174 | +ENUM |
| 175 | BFD_RELOC_MICROBLAZE_64_NONE |
| 176 | ENUMDOC |
| 177 | This is a 64 bit reloc that stores the 32 bit pc relative |
| 178 | diff --git a/include/elf/microblaze.h b/include/elf/microblaze.h |
| 179 | index effca20..f8420dc 100644 |
| 180 | --- a/include/elf/microblaze.h |
| 181 | +++ b/include/elf/microblaze.h |
| 182 | @@ -58,6 +58,7 @@ START_RELOC_NUMBERS (elf_microblaze_reloc_type) |
| 183 | RELOC_NUMBER (R_MICROBLAZE_TLSDTPREL64, 27) /* TLS Offset Within TLS Block */ |
| 184 | RELOC_NUMBER (R_MICROBLAZE_TLSGOTTPREL32, 28) /* TLS Offset From Thread Pointer */ |
| 185 | RELOC_NUMBER (R_MICROBLAZE_TLSTPREL32, 29) /* TLS Offset From Thread Pointer */ |
| 186 | + RELOC_NUMBER (R_MICROBLAZE_32_NONE, 30) |
| 187 | |
| 188 | END_RELOC_NUMBERS (R_MICROBLAZE_max) |
| 189 | |
| 190 | -- |
| 191 | 1.9.0 |
| 192 | |