00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #include "config.h"
00043 #include "libdwarfdefs.h"
00044 #include <stdio.h>
00045 #include <string.h>
00046
00047 #include "pro_incl.h"
00048 #include "pro_section.h"
00049 #include "pro_reloc.h"
00050 #include "pro_reloc_symbolic.h"
00051
00052
00053
00054
00055
00056
00057 int
00058 _dwarf_pro_reloc_name_symbolic(Dwarf_P_Debug dbg, int base_sec_index, Dwarf_Unsigned offset,
00059
00060
00061
00062 Dwarf_Unsigned symidx,
00063 enum Dwarf_Rel_Type type,
00064 int reltarget_length)
00065 {
00066
00067 void *relrec_to_fill;
00068 int res;
00069 struct Dwarf_Relocation_Data_s *slotp;
00070
00071 res = _dwarf_pro_reloc_get_a_slot(dbg, base_sec_index,
00072 &relrec_to_fill);
00073 if (res != DW_DLV_OK)
00074 return res;
00075
00076 slotp = (struct Dwarf_Relocation_Data_s *) relrec_to_fill;
00077 slotp->drd_type = type;
00078 slotp->drd_length = reltarget_length;
00079 slotp->drd_offset = offset;
00080 slotp->drd_symbol_index = symidx;
00081 return DW_DLV_OK;
00082
00083 }
00084
00085
00086
00087
00088
00089
00090
00091 int
00092 _dwarf_pro_reloc_length_symbolic(Dwarf_P_Debug dbg, int base_sec_index, Dwarf_Unsigned offset,
00093
00094
00095
00096 Dwarf_Unsigned start_symidx,
00097 Dwarf_Unsigned end_symidx,
00098 enum Dwarf_Rel_Type type,
00099 int reltarget_length)
00100 {
00101
00102 void *relrec_to_fill;
00103 int res;
00104 struct Dwarf_Relocation_Data_s *slotp1;
00105 struct Dwarf_Relocation_Data_s *slotp2;
00106
00107
00108
00109 res = _dwarf_pro_reloc_get_a_slot(dbg, base_sec_index,
00110 &relrec_to_fill);
00111 if (res != DW_DLV_OK)
00112 return res;
00113 slotp1 = (struct Dwarf_Relocation_Data_s *) relrec_to_fill;
00114 res = _dwarf_pro_reloc_get_a_slot(dbg, base_sec_index,
00115 &relrec_to_fill);
00116 if (res != DW_DLV_OK)
00117 return res;
00118 slotp2 = (struct Dwarf_Relocation_Data_s *) relrec_to_fill;
00119
00120
00121 slotp1->drd_type = type;
00122 slotp1->drd_length = reltarget_length;
00123 slotp1->drd_offset = offset;
00124 slotp1->drd_symbol_index = start_symidx;
00125
00126 slotp2->drd_type = dwarf_drt_second_of_length_pair;
00127 slotp2->drd_length = reltarget_length;
00128 slotp2->drd_offset = offset;
00129 slotp2->drd_symbol_index = end_symidx;
00130
00131 return DW_DLV_OK;
00132 }
00133
00134
00135
00136
00137
00138
00139
00140 static void
00141 _dwarf_reset_reloc_sect_info(struct Dwarf_P_Per_Reloc_Sect_s *pblk,
00142 unsigned long ct)
00143 {
00144
00145
00146
00147
00148 pblk->pr_reloc_total_count = 0;
00149 pblk->pr_first_block = 0;
00150 pblk->pr_last_block = 0;
00151 pblk->pr_block_count = 0;
00152 pblk->pr_slots_per_block_to_alloc = ct;
00153 }
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174 int
00175 _dwarf_symbolic_relocs_to_disk(Dwarf_P_Debug dbg,
00176 Dwarf_Signed * new_sec_count)
00177 {
00178
00179 Dwarf_Small *data;
00180 int sec_index;
00181 int res;
00182 unsigned long i;
00183 Dwarf_Error error;
00184
00185 Dwarf_Signed sec_count = 0;
00186
00187 Dwarf_P_Per_Reloc_Sect p_reloc = &dbg->de_reloc_sect[0];
00188
00189 for (i = 0; i < NUM_DEBUG_SECTIONS; ++i, ++p_reloc) {
00190
00191 unsigned long ct = p_reloc->pr_reloc_total_count;
00192 struct Dwarf_P_Relocation_Block_s *p_blk;
00193 struct Dwarf_P_Relocation_Block_s *p_blk_last;
00194
00195
00196 int err;
00197
00198
00199 if (ct == 0) {
00200 continue;
00201 }
00202
00203
00204 ++sec_count;
00205
00206
00207 sec_index = p_reloc->pr_sect_num_of_reloc_sect;
00208 if (sec_index == 0) {
00209
00210
00211 int rel_section_index;
00212 int int_name;
00213 Dwarf_Unsigned name_idx;
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223 if (dbg->de_func_b) {
00224 rel_section_index =
00225 dbg->de_func_b(_dwarf_rel_section_names[i],
00226 dbg->de_relocation_record_size,
00227 SHT_REL,
00228 0,
00229
00230 SHN_UNDEF,
00231
00232 dbg->de_elf_sects[i],
00233 &name_idx, &err);
00234 } else {
00235 rel_section_index =
00236 dbg->de_func(_dwarf_rel_section_names[i],
00237 dbg->de_relocation_record_size,
00238 SHT_REL,
00239 0,
00240
00241 SHN_UNDEF,
00242
00243 dbg->de_elf_sects[i], &int_name, &err);
00244 name_idx = int_name;
00245 }
00246 if (rel_section_index == -1) {
00247 {
00248 _dwarf_p_error(dbg, &error, DW_DLE_ELF_SECT_ERR);
00249 return (DW_DLV_ERROR);
00250 }
00251 }
00252 p_reloc->pr_sect_num_of_reloc_sect = rel_section_index;
00253 sec_index = rel_section_index;
00254 }
00255
00256 p_blk = p_reloc->pr_first_block;
00257
00258 if (p_reloc->pr_block_count > 1) {
00259 struct Dwarf_P_Relocation_Block_s *new_blk;
00260
00261
00262
00263 _dwarf_reset_reloc_sect_info(p_reloc, ct);
00264
00265
00266 res = _dwarf_pro_pre_alloc_n_reloc_slots(dbg, (int) i, ct);
00267
00268
00269 if (res != DW_DLV_OK) {
00270 return res;
00271 }
00272 new_blk = p_reloc->pr_first_block;
00273
00274 data = (Dwarf_Small *) new_blk->rb_data;
00275
00276
00277
00278 do {
00279
00280 unsigned long len =
00281 p_blk->rb_where_to_add_next - p_blk->rb_data;
00282
00283 memcpy(data, p_blk->rb_data, len);
00284 data += len;
00285
00286 p_blk_last = p_blk;
00287 p_blk = p_blk->rb_next;
00288
00289 _dwarf_p_dealloc(dbg, (Dwarf_Small *) p_blk_last);
00290 } while (p_blk) ;
00291
00292 new_blk->rb_next_slot_to_use = ct;
00293 new_blk->rb_where_to_add_next = (char *) data;
00294 p_reloc->pr_reloc_total_count = ct;
00295
00296
00297
00298 }
00299 }
00300
00301 *new_sec_count = 0;
00302 return DW_DLV_OK;
00303 }