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
00043
00044
00045
00046
00047 #include "xlateincl.h"
00048
00049 #ifdef _LIBELF_XTND_EXPANDED_DATA
00050 #pragma weak xlate_init_elf_xtnd = _xlate_init_elf_xtnd
00051 #elif defined(BUILD_OS_DARWIN)
00052 #else
00053 #pragma weak xlate_init_elf = _xlate_init_elf
00054 #endif
00055
00056 int
00057 xlate_init_elf(Elf * elf, int open_debug_table,
00058 xlate_table_con * ret_tab_ptr)
00059 {
00060 int res;
00061 Elf32_Word wanttype;
00062 Elf_Scn *scn = 0;
00063 int is64bit = 0;
00064 char *ident;
00065 size_t identsize;
00066 Elf64_Shdr *shdr64 = 0;
00067 Elf32_Shdr *shdr32 = 0;
00068 Elf32_Ehdr *ehdr32 = 0;
00069 Elf64_Ehdr *ehdr64 = 0;
00070 int stringindex = 0;
00071 char * sec_name;
00072
00073 if(elf_kind(elf) != ELF_K_ELF) {
00074 return XLATE_TB_STATUS_NOT_ELF;
00075 }
00076 ident = elf_getident(elf,&identsize);
00077
00078 if(open_debug_table == XLATE_OPEN_STD_TABLE) {
00079
00080 wanttype = SHT_MIPS_XLATE;
00081 } else if(open_debug_table == XLATE_OPEN_DEBUG_TABLE) {
00082
00083 wanttype = SHT_MIPS_XLATE_DEBUG;
00084 } else {
00085 return XLATE_TB_STATUS_NO_XLATE;
00086 }
00087 res = XLATE_TB_STATUS_NO_XLATE;
00088 if(ident == 0 || identsize < EI_NIDENT) {
00089 return XLATE_TB_STATUS_ELF_IDENT_BAD;
00090 }
00091 if(ident[EI_CLASS] == ELFCLASS64) {
00092 is64bit = 1;
00093 }
00094 if(is64bit) {
00095 ehdr64 = elf64_getehdr(elf);
00096 if(ehdr64 == 0 ) {
00097 return XLATE_TB_STATUS_ELF_EHDR_BAD;
00098 }
00099 stringindex = ehdr64->e_shstrndx;
00100 } else {
00101 ehdr32 = elf32_getehdr(elf);
00102 if(ehdr32 == 0 ) {
00103 return XLATE_TB_STATUS_ELF_EHDR_BAD;
00104 }
00105 stringindex = ehdr32->e_shstrndx;
00106 }
00107
00108 for(scn = elf_nextscn(elf,scn);
00109 scn != 0
00110 ; scn = elf_nextscn(elf,scn)) {
00111 if(is64bit) {
00112 shdr64 = elf64_getshdr(scn);
00113 if(shdr64 == 0) {
00114 return XLATE_TB_STATUS_ELF_SHDR_BAD;
00115 }
00116 sec_name = elf_strptr(elf,stringindex,shdr64->sh_name);
00117 if(sec_name == 0) {
00118 return XLATE_TB_STATUS_ELF_STRPTR_BAD;
00119 }
00120 if(shdr64->sh_type != wanttype) {
00121 continue;
00122 }
00123 res = xlate_named_init_elf(elf,
00124 sec_name,ret_tab_ptr);
00125 return res;
00126 } else {
00127 shdr32 = elf32_getshdr(scn);
00128 if(shdr32 == 0) {
00129 return XLATE_TB_STATUS_ELF_SHDR_BAD;
00130 }
00131 sec_name = elf_strptr(elf,stringindex,shdr32->sh_name);
00132 if(sec_name == 0) {
00133 return XLATE_TB_STATUS_ELF_STRPTR_BAD;
00134 }
00135 if(shdr32->sh_type != wanttype) {
00136 continue;
00137 }
00138 res = xlate_named_init_elf(elf,
00139 sec_name,ret_tab_ptr);
00140 return res;
00141 }
00142 }
00143
00144 return res;
00145 }