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 char*
00026 elf_core_file_failing_command (bfd *abfd)
00027 {
00028 return elf_tdata (abfd)->core_command;
00029 }
00030
00031 int
00032 elf_core_file_failing_signal (bfd *abfd)
00033 {
00034 return elf_tdata (abfd)->core_signal;
00035 }
00036
00037 bfd_boolean
00038 elf_core_file_matches_executable_p (bfd *core_bfd, bfd *exec_bfd)
00039 {
00040 char* corename;
00041
00042
00043
00044 if (core_bfd->xvec != exec_bfd->xvec)
00045 {
00046 bfd_set_error (bfd_error_system_call);
00047 return FALSE;
00048 }
00049
00050
00051 corename = elf_tdata (core_bfd)->core_program;
00052 if (corename != NULL)
00053 {
00054 const char* execname = strrchr (exec_bfd->filename, '/');
00055
00056 execname = execname ? execname + 1 : exec_bfd->filename;
00057
00058 if (strcmp (execname, corename) != 0)
00059 return FALSE;
00060 }
00061
00062 return TRUE;
00063 }
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076 const bfd_target *
00077 elf_core_file_p (bfd *abfd)
00078 {
00079 Elf_External_Ehdr x_ehdr;
00080 Elf_Internal_Ehdr *i_ehdrp;
00081 Elf_Internal_Phdr *i_phdrp;
00082 unsigned int phindex;
00083 const struct elf_backend_data *ebd;
00084 struct bfd_preserve preserve;
00085 bfd_size_type amt;
00086
00087 preserve.marker = NULL;
00088
00089
00090 if (bfd_bread (&x_ehdr, sizeof (x_ehdr), abfd) != sizeof (x_ehdr))
00091 {
00092 if (bfd_get_error () != bfd_error_system_call)
00093 goto wrong;
00094 else
00095 goto fail;
00096 }
00097
00098
00099 if (! elf_file_p (&x_ehdr))
00100 goto wrong;
00101
00102
00103
00104
00105 if (x_ehdr.e_ident[EI_CLASS] != ELFCLASS)
00106 goto wrong;
00107
00108
00109 switch (x_ehdr.e_ident[EI_DATA])
00110 {
00111 case ELFDATA2MSB:
00112 if (! bfd_big_endian (abfd))
00113 goto wrong;
00114 break;
00115 case ELFDATA2LSB:
00116 if (! bfd_little_endian (abfd))
00117 goto wrong;
00118 break;
00119 default:
00120 goto wrong;
00121 }
00122
00123 if (!bfd_preserve_save (abfd, &preserve))
00124 goto fail;
00125
00126
00127 if (! (*abfd->xvec->_bfd_set_format[bfd_core]) (abfd))
00128 goto fail;
00129 preserve.marker = elf_tdata (abfd);
00130
00131
00132 i_ehdrp = elf_elfheader (abfd);
00133 elf_swap_ehdr_in (abfd, &x_ehdr, i_ehdrp);
00134
00135 #if DEBUG & 1
00136 elf_debug_file (i_ehdrp);
00137 #endif
00138
00139 ebd = get_elf_backend_data (abfd);
00140
00141
00142
00143
00144 if (ebd->elf_machine_code != i_ehdrp->e_machine
00145 && (ebd->elf_machine_alt1 == 0
00146 || i_ehdrp->e_machine != ebd->elf_machine_alt1)
00147 && (ebd->elf_machine_alt2 == 0
00148 || i_ehdrp->e_machine != ebd->elf_machine_alt2))
00149 {
00150 const bfd_target * const *target_ptr;
00151
00152 if (ebd->elf_machine_code != EM_NONE)
00153 goto wrong;
00154
00155
00156
00157
00158 for (target_ptr = bfd_target_vector; *target_ptr != NULL; target_ptr++)
00159 {
00160 const struct elf_backend_data *back;
00161
00162 if ((*target_ptr)->flavour != bfd_target_elf_flavour)
00163 continue;
00164 back = (const struct elf_backend_data *) (*target_ptr)->backend_data;
00165 if (back->elf_machine_code == i_ehdrp->e_machine
00166 || (back->elf_machine_alt1 != 0
00167 && i_ehdrp->e_machine == back->elf_machine_alt1)
00168 || (back->elf_machine_alt2 != 0
00169 && i_ehdrp->e_machine == back->elf_machine_alt2))
00170 {
00171
00172
00173 goto wrong;
00174 }
00175 }
00176 }
00177
00178
00179
00180 if (i_ehdrp->e_phoff == 0 || i_ehdrp->e_type != ET_CORE)
00181 goto wrong;
00182
00183
00184
00185 if (i_ehdrp->e_phentsize != sizeof (Elf_External_Phdr))
00186 goto wrong;
00187
00188
00189 if (bfd_seek (abfd, (file_ptr) i_ehdrp->e_phoff, SEEK_SET) != 0)
00190 goto wrong;
00191
00192
00193 amt = sizeof (*i_phdrp) * i_ehdrp->e_phnum;
00194 i_phdrp = bfd_alloc (abfd, amt);
00195 if (!i_phdrp)
00196 goto fail;
00197
00198 elf_tdata (abfd)->phdr = i_phdrp;
00199
00200
00201 for (phindex = 0; phindex < i_ehdrp->e_phnum; ++phindex)
00202 {
00203 Elf_External_Phdr x_phdr;
00204
00205 if (bfd_bread (&x_phdr, sizeof (x_phdr), abfd) != sizeof (x_phdr))
00206 goto fail;
00207
00208 elf_swap_phdr_in (abfd, &x_phdr, i_phdrp + phindex);
00209 }
00210
00211
00212
00213
00214 if (! bfd_default_set_arch_mach (abfd, ebd->arch, 0)
00215
00216 && ebd->elf_machine_code != EM_NONE)
00217 goto fail;
00218
00219
00220
00221
00222
00223
00224 if (ebd->elf_backend_object_p != NULL
00225 && ! ebd->elf_backend_object_p (abfd))
00226 goto wrong;
00227
00228
00229 for (phindex = 0; phindex < i_ehdrp->e_phnum; ++phindex)
00230 if (! bfd_section_from_phdr (abfd, i_phdrp + phindex, (int) phindex))
00231 goto fail;
00232
00233
00234 bfd_get_start_address (abfd) = i_ehdrp->e_entry;
00235
00236 bfd_preserve_finish (abfd, &preserve);
00237 return abfd->xvec;
00238
00239 wrong:
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249 bfd_set_error (bfd_error_wrong_format);
00250
00251 fail:
00252 if (preserve.marker != NULL)
00253 bfd_preserve_restore (abfd, &preserve);
00254 return NULL;
00255 }