libunwind: update to 1.8.1
[openadk.git] / package / gdb-microblaze / patches / patch-bfd_elf32-microblaze_c
blob9c3cd884cc028c1fb44ce565a6aa50943beb60af
1 --- gdb-7.8.2.orig/bfd/elf32-microblaze.c       2015-01-15 11:58:11.000000000 +0100
2 +++ gdb-7.8.2/bfd/elf32-microblaze.c    2016-09-21 10:34:30.025222164 +0200
3 @@ -177,6 +177,20 @@ static reloc_howto_type microblaze_elf_h
4            FALSE),              /* PC relative offset?  */
5  
6     /* This reloc does nothing.  Used for relaxation.  */
7 +   HOWTO (R_MICROBLAZE_32_NONE,        /* Type.  */
8 +          0,                   /* Rightshift.  */
9 +          2,                   /* Size (0 = byte, 1 = short, 2 = long).  */
10 +          32,                  /* Bitsize.  */
11 +          TRUE,                        /* PC_relative.  */
12 +          0,                   /* Bitpos.  */
13 +          complain_overflow_bitfield,  /* Complain on overflow.  */
14 +          NULL,                  /* Special Function.  */
15 +          "R_MICROBLAZE_32_NONE",/* Name.  */
16 +          FALSE,               /* Partial Inplace.  */
17 +          0,                   /* Source Mask.  */
18 +          0,                   /* Dest Mask.  */
19 +          FALSE),              /* PC relative offset?  */
21     HOWTO (R_MICROBLAZE_64_NONE,        /* Type.  */
22            0,                   /* Rightshift.  */
23            2,                   /* Size (0 = byte, 1 = short, 2 = long).  */
24 @@ -532,7 +546,10 @@ microblaze_elf_reloc_type_lookup (bfd *
25      case BFD_RELOC_NONE:
26        microblaze_reloc = R_MICROBLAZE_NONE;
27        break;
28 -    case BFD_RELOC_MICROBLAZE_64_NONE:
29 +    case BFD_RELOC_MICROBLAZE_32_NONE:
30 +      microblaze_reloc = R_MICROBLAZE_32_NONE;
31 +      break;
32 +     case BFD_RELOC_MICROBLAZE_64_NONE:
33        microblaze_reloc = R_MICROBLAZE_64_NONE;
34        break;
35      case BFD_RELOC_32:
36 @@ -668,6 +685,67 @@ microblaze_elf_is_local_label_name (bfd
37    return _bfd_elf_is_local_label_name (abfd, name);
38  }
40 +/* Support for core dump NOTE sections.  */
41 +static bfd_boolean
42 +microblaze_elf_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
44 +  int offset;
45 +  unsigned int size;
47 +  switch (note->descsz)
48 +    {
49 +      default:
50 +        return FALSE;
52 +      case 228:         /* Linux/MicroBlaze */
53 +        /* pr_cursig */
54 +        elf_tdata (abfd)->core->signal = bfd_get_16 (abfd, note->descdata + 12);
56 +        /* pr_pid */
57 +        elf_tdata (abfd)->core->pid = bfd_get_32 (abfd, note->descdata + 24);
59 +        /* pr_reg */
60 +        offset = 72;
61 +        size = 50 * 4;
63 +        break;
64 +    }
66 +  /* Make a ".reg/999" section.  */
67 +  return _bfd_elfcore_make_pseudosection (abfd, ".reg",
68 +                                          size, note->descpos + offset);
71 +static bfd_boolean
72 +microblaze_elf_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
74 +  switch (note->descsz)
75 +    {
76 +      default:
77 +        return FALSE;
79 +      case 128:         /* Linux/MicroBlaze elf_prpsinfo */
80 +        elf_tdata (abfd)->core->program
81 +         = _bfd_elfcore_strndup (abfd, note->descdata + 32, 16);
82 +        elf_tdata (abfd)->core->command
83 +         = _bfd_elfcore_strndup (abfd, note->descdata + 48, 80);
84 +    }
86 +  /* Note that for some reason, a spurious space is tacked
87 +     onto the end of the args in some (at least one anyway)
88 +     implementations, so strip it off if it exists.  */
90 +  {
91 +    char *command = elf_tdata (abfd)->core->command;
92 +    int n = strlen (command);
94 +    if (0 < n && command[n - 1] == ' ')
95 +      command[n - 1] = '\0';
96 +  }
98 +  return TRUE;
101  /* The microblaze linker (like many others) needs to keep track of
102     the number of relocs that it decides to copy as dynamic relocs in
103     check_relocs for each symbol. This is so that it can later discard
104 @@ -1023,7 +1101,7 @@ microblaze_elf_relocate_section (bfd *ou
105             {
106               /* External symbol.  */
107               bfd_boolean warned ATTRIBUTE_UNUSED;
108 -             bfd_boolean ignored ATTRIBUTE_UNUSED;
109 +             bfd_boolean ignored;
111               RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
112                                        r_symndx, symtab_hdr, sym_hashes,
113 @@ -1852,14 +1930,22 @@ microblaze_elf_relax_section (bfd *abfd,
114                 }
115               break;
116             case R_MICROBLAZE_NONE:
117 +           case R_MICROBLAZE_32_NONE:
118               {
119                 /* This was a PC-relative instruction that was
120                    completely resolved.  */
121                 int sfix, efix;
122 +               unsigned int val;
123                 bfd_vma target_address;
124                 target_address = irel->r_addend + irel->r_offset;
125                 sfix = calc_fixup (irel->r_offset, 0, sec);
126                 efix = calc_fixup (target_address, 0, sec);
128 +                /* Validate the in-band val.  */
129 +                val = bfd_get_32 (abfd, contents + irel->r_offset);
130 +                if (val != irel->r_addend && ELF32_R_TYPE (irel->r_info) == R_MICROBLAZE_32_NONE) {
131 +                    fprintf(stderr, "%d: CORRUPT relax reloc %x %lx\n", __LINE__, val, irel->r_addend);
132 +                }
133                 irel->r_addend -= (efix - sfix);
134                 /* Should use HOWTO.  */
135                 microblaze_bfd_write_imm_value_32 (abfd, contents + irel->r_offset,
136 @@ -1907,6 +1993,49 @@ microblaze_elf_relax_section (bfd *abfd,
137            irelscanend = irelocs + o->reloc_count;
138            for (irelscan = irelocs; irelscan < irelscanend; irelscan++)
139              {
140 +              if (1 && ELF32_R_TYPE (irelscan->r_info) == (int) R_MICROBLAZE_32_NONE)
141 +                {
142 +                  unsigned int val;
144 +                  isym = isymbuf + ELF32_R_SYM (irelscan->r_info);
146 +                  /* hax: We only do the following fixup for debug location lists.  */
147 +                  if (strcmp(".debug_loc", o->name))
148 +                    continue;
150 +                  /* This was a PC-relative instruction that was completely resolved.  */
151 +                  if (ocontents == NULL)
152 +                    {
153 +                     if (elf_section_data (o)->this_hdr.contents != NULL)
154 +                         ocontents = elf_section_data (o)->this_hdr.contents;
155 +                     else
156 +                       {
157 +                         /* We always cache the section contents.
158 +                            Perhaps, if info->keep_memory is FALSE, we
159 +                            should free them, if we are permitted to.  */
161 +                         if (o->rawsize == 0)
162 +                             o->rawsize = o->size;
163 +                         ocontents = (bfd_byte *) bfd_malloc (o->rawsize);
164 +                         if (ocontents == NULL)
165 +                             goto error_return;
166 +                         if (!bfd_get_section_contents (abfd, o, ocontents,
167 +                                                         (file_ptr) 0,
168 +                                                         o->rawsize))
169 +                              goto error_return;
170 +                         elf_section_data (o)->this_hdr.contents = ocontents;
171 +                       }
172 +                   }
174 +                  val = bfd_get_32 (abfd, ocontents + irelscan->r_offset);
175 +                  if (val != irelscan->r_addend) {
176 +                       fprintf(stderr, "%d: CORRUPT relax reloc! %x %lx\n", __LINE__, val, irelscan->r_addend);
177 +                  }
179 +                  irelscan->r_addend -= calc_fixup (irelscan->r_addend, 0, sec);
180 +                  microblaze_bfd_write_imm_value_32 (abfd, ocontents + irelscan->r_offset,
181 +                                                     irelscan->r_addend);
182 +              }
183                if (ELF32_R_TYPE (irelscan->r_info) == (int) R_MICROBLAZE_32)
184                  {
185                   isym = isymbuf + ELF32_R_SYM (irelscan->r_info);
186 @@ -1966,7 +2095,7 @@ microblaze_elf_relax_section (bfd *abfd,
187                               elf_section_data (o)->this_hdr.contents = ocontents;
188                             }
189                         }
190 -                     irelscan->r_addend -= calc_fixup (irel->r_addend
191 +                     irelscan->r_addend -= calc_fixup (irelscan->r_addend
192                                                         + isym->st_value,
193                                                         0,
194                                                         sec);
195 @@ -3506,4 +3635,7 @@ microblaze_elf_add_symbol_hook (bfd *abf
196  #define elf_backend_size_dynamic_sections       microblaze_elf_size_dynamic_sections
197  #define elf_backend_add_symbol_hook            microblaze_elf_add_symbol_hook
199 +#define elf_backend_grok_prstatus               microblaze_elf_grok_prstatus
200 +#define elf_backend_grok_psinfo                 microblaze_elf_grok_psinfo
202  #include "elf32-target.h"