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 #include "bfd.h"
00027 #include "sysdep.h"
00028 #include "libbfd.h"
00029 #include "bfdlink.h"
00030
00031 static bfd_boolean
00032 simple_dummy_warning (struct bfd_link_info *link_info ATTRIBUTE_UNUSED,
00033 const char *warning ATTRIBUTE_UNUSED,
00034 const char *symbol ATTRIBUTE_UNUSED,
00035 bfd *abfd ATTRIBUTE_UNUSED,
00036 asection *section ATTRIBUTE_UNUSED,
00037 bfd_vma address ATTRIBUTE_UNUSED)
00038 {
00039 return TRUE;
00040 }
00041
00042 static bfd_boolean
00043 simple_dummy_undefined_symbol (struct bfd_link_info *link_info ATTRIBUTE_UNUSED,
00044 const char *name ATTRIBUTE_UNUSED,
00045 bfd *abfd ATTRIBUTE_UNUSED,
00046 asection *section ATTRIBUTE_UNUSED,
00047 bfd_vma address ATTRIBUTE_UNUSED,
00048 bfd_boolean fatal ATTRIBUTE_UNUSED)
00049 {
00050 return TRUE;
00051 }
00052
00053 static bfd_boolean
00054 simple_dummy_reloc_overflow (struct bfd_link_info *link_info ATTRIBUTE_UNUSED,
00055 struct bfd_link_hash_entry *entry ATTRIBUTE_UNUSED,
00056 const char *name ATTRIBUTE_UNUSED,
00057 const char *reloc_name ATTRIBUTE_UNUSED,
00058 bfd_vma addend ATTRIBUTE_UNUSED,
00059 bfd *abfd ATTRIBUTE_UNUSED,
00060 asection *section ATTRIBUTE_UNUSED,
00061 bfd_vma address ATTRIBUTE_UNUSED)
00062 {
00063 return TRUE;
00064 }
00065
00066 static bfd_boolean
00067 simple_dummy_reloc_dangerous (struct bfd_link_info *link_info ATTRIBUTE_UNUSED,
00068 const char *message ATTRIBUTE_UNUSED,
00069 bfd *abfd ATTRIBUTE_UNUSED,
00070 asection *section ATTRIBUTE_UNUSED,
00071 bfd_vma address ATTRIBUTE_UNUSED)
00072 {
00073 return TRUE;
00074 }
00075
00076 static bfd_boolean
00077 simple_dummy_unattached_reloc (struct bfd_link_info *link_info ATTRIBUTE_UNUSED,
00078 const char *name ATTRIBUTE_UNUSED,
00079 bfd *abfd ATTRIBUTE_UNUSED,
00080 asection *section ATTRIBUTE_UNUSED,
00081 bfd_vma address ATTRIBUTE_UNUSED)
00082 {
00083 return TRUE;
00084 }
00085
00086 static bfd_boolean
00087 simple_dummy_multiple_definition (struct bfd_link_info *link_info ATTRIBUTE_UNUSED,
00088 const char *name ATTRIBUTE_UNUSED,
00089 bfd *obfd ATTRIBUTE_UNUSED,
00090 asection *osec ATTRIBUTE_UNUSED,
00091 bfd_vma oval ATTRIBUTE_UNUSED,
00092 bfd *nbfd ATTRIBUTE_UNUSED,
00093 asection *nsec ATTRIBUTE_UNUSED,
00094 bfd_vma nval ATTRIBUTE_UNUSED)
00095 {
00096 return TRUE;
00097 }
00098
00099 struct saved_output_info
00100 {
00101 bfd_vma offset;
00102 asection *section;
00103 };
00104
00105 static void
00106 simple_save_output_info (bfd *abfd ATTRIBUTE_UNUSED,
00107 asection *section,
00108 void *ptr)
00109 {
00110 struct saved_output_info *output_info = ptr;
00111 output_info[section->index].offset = section->output_offset;
00112 output_info[section->index].section = section->output_section;
00113 if ((section->flags & SEC_DEBUGGING) != 0
00114 || section->output_section == NULL)
00115 {
00116 section->output_offset = 0;
00117 section->output_section = section;
00118 }
00119 }
00120
00121 static void
00122 simple_restore_output_info (bfd *abfd ATTRIBUTE_UNUSED,
00123 asection *section,
00124 void *ptr)
00125 {
00126 struct saved_output_info *output_info = ptr;
00127 section->output_offset = output_info[section->index].offset;
00128 section->output_section = output_info[section->index].section;
00129 }
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150 bfd_byte *
00151 bfd_simple_get_relocated_section_contents (bfd *abfd,
00152 asection *sec,
00153 bfd_byte *outbuf,
00154 asymbol **symbol_table)
00155 {
00156 struct bfd_link_info link_info;
00157 struct bfd_link_order link_order;
00158 struct bfd_link_callbacks callbacks;
00159 bfd_byte *contents, *data;
00160 int storage_needed;
00161 void *saved_offsets;
00162
00163 if (! (sec->flags & SEC_RELOC))
00164 {
00165 bfd_size_type amt = sec->rawsize > sec->size ? sec->rawsize : sec->size;
00166 bfd_size_type size = sec->rawsize ? sec->rawsize : sec->size;
00167
00168 if (outbuf == NULL)
00169 contents = bfd_malloc (amt);
00170 else
00171 contents = outbuf;
00172
00173 if (contents)
00174 bfd_get_section_contents (abfd, sec, contents, 0, size);
00175
00176 return contents;
00177 }
00178
00179
00180
00181
00182
00183 memset (&link_info, 0, sizeof (link_info));
00184 link_info.input_bfds = abfd;
00185
00186 link_info.hash = _bfd_generic_link_hash_table_create (abfd);
00187 link_info.callbacks = &callbacks;
00188 callbacks.warning = simple_dummy_warning;
00189 callbacks.undefined_symbol = simple_dummy_undefined_symbol;
00190 callbacks.reloc_overflow = simple_dummy_reloc_overflow;
00191 callbacks.reloc_dangerous = simple_dummy_reloc_dangerous;
00192 callbacks.unattached_reloc = simple_dummy_unattached_reloc;
00193 callbacks.multiple_definition = simple_dummy_multiple_definition;
00194
00195 memset (&link_order, 0, sizeof (link_order));
00196 link_order.next = NULL;
00197 link_order.type = bfd_indirect_link_order;
00198 link_order.offset = 0;
00199 link_order.size = sec->size;
00200 link_order.u.indirect.section = sec;
00201
00202 data = NULL;
00203 if (outbuf == NULL)
00204 {
00205 data = bfd_malloc (sec->size);
00206 if (data == NULL)
00207 return NULL;
00208 outbuf = data;
00209 }
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220 saved_offsets = malloc (sizeof (struct saved_output_info)
00221 * abfd->section_count);
00222 if (saved_offsets == NULL)
00223 {
00224 if (data)
00225 free (data);
00226 return NULL;
00227 }
00228 bfd_map_over_sections (abfd, simple_save_output_info, saved_offsets);
00229
00230 if (symbol_table == NULL)
00231 {
00232 _bfd_generic_link_add_symbols (abfd, &link_info);
00233
00234 storage_needed = bfd_get_symtab_upper_bound (abfd);
00235 symbol_table = bfd_malloc (storage_needed);
00236 bfd_canonicalize_symtab (abfd, symbol_table);
00237 }
00238 else
00239 storage_needed = 0;
00240
00241 contents = bfd_get_relocated_section_contents (abfd,
00242 &link_info,
00243 &link_order,
00244 outbuf,
00245 0,
00246 symbol_table);
00247 if (contents == NULL && data != NULL)
00248 free (data);
00249
00250 bfd_map_over_sections (abfd, simple_restore_output_info, saved_offsets);
00251 free (saved_offsets);
00252
00253 _bfd_generic_link_hash_table_free (link_info.hash);
00254 return contents;
00255 }