- Timestamp:
- Apr 29, 2015 11:59:02 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kLdr/kLdrModMachO.c
r67 r68 3081 3081 break; 3082 3082 case X86_64_RELOC_SIGNED: 3083 case X86_64_RELOC_SIGNED_1: 3084 case X86_64_RELOC_SIGNED_2: 3085 case X86_64_RELOC_SIGNED_4: 3083 3086 SymAddr -= 4; 3084 break;3085 case X86_64_RELOC_SIGNED_1:3086 SymAddr -= 4 + 1;3087 if (Fixup.r.r_extern)3088 SymAddr += 1;3089 break;3090 case X86_64_RELOC_SIGNED_2:3091 SymAddr -= 4 + 2;3092 if (Fixup.r.r_extern)3093 SymAddr += 2;3094 break;3095 case X86_64_RELOC_SIGNED_4:3096 SymAddr -= 4 + 4;3097 if (Fixup.r.r_extern)3098 SymAddr += 4;3099 3087 break; 3100 3088 default: … … 3177 3165 && Fixup2.r_type == X86_64_RELOC_UNSIGNED 3178 3166 && !Fixup2.r_pcrel 3179 && Fixup2.r_extern /*??*/3180 3167 && Fixup2.r_symbolnum < cSyms, 3181 3168 KLDR_ERR_BAD_FIXUP); 3182 3169 3183 pSym = &paSyms[Fixup.r.r_symbolnum]; 3184 KLDRMODMACHO_CHECK_RETURN(!(pSym->n_type & MACHO_N_STAB), KLDR_ERR_BAD_FIXUP); 3185 3186 /* Add it's value to SymAddr. */ 3187 switch (pSym->n_type & MACHO_N_TYPE) 3170 if (Fixup2.r_extern) 3188 3171 { 3189 case MACHO_N_SECT: 3172 KLDRMODMACHO_CHECK_RETURN(Fixup2.r_symbolnum < cSyms, KLDR_ERR_BAD_FIXUP); 3173 pSym = &paSyms[Fixup2.r_symbolnum]; 3174 KLDRMODMACHO_CHECK_RETURN(!(pSym->n_type & MACHO_N_STAB), KLDR_ERR_BAD_FIXUP); 3175 3176 /* Add it's value to SymAddr. */ 3177 switch (pSym->n_type & MACHO_N_TYPE) 3190 3178 { 3191 PKLDRMODMACHOSECT pSymSect; 3192 KLDRMODMACHO_CHECK_RETURN((KU32)pSym->n_sect - 1 <= pModMachO->cSections, KLDR_ERR_MACHO_BAD_SYMBOL); 3193 pSymSect = &pModMachO->paSections[pSym->n_sect - 1]; 3194 SymAddr += pSym->n_value - pSymSect->LinkAddress + pSymSect->RVA + NewBaseAddress; 3195 break; 3179 case MACHO_N_SECT: 3180 { 3181 PKLDRMODMACHOSECT pSymSect; 3182 KLDRMODMACHO_CHECK_RETURN((KU32)pSym->n_sect - 1 <= pModMachO->cSections, KLDR_ERR_MACHO_BAD_SYMBOL); 3183 pSymSect = &pModMachO->paSections[pSym->n_sect - 1]; 3184 SymAddr += pSym->n_value - pSymSect->LinkAddress + pSymSect->RVA + NewBaseAddress; 3185 break; 3186 } 3187 3188 case MACHO_N_UNDF: 3189 case MACHO_N_ABS: 3190 SymAddr += pSym->n_value; 3191 break; 3192 3193 case MACHO_N_INDR: 3194 case MACHO_N_PBUD: 3195 KLDRMODMACHO_CHECK_RETURN(0, KLDR_ERR_TODO); 3196 default: 3197 KLDRMODMACHO_CHECK_RETURN(0, KLDR_ERR_MACHO_BAD_SYMBOL); 3196 3198 } 3197 3198 case MACHO_N_UNDF:3199 case MACHO_N_ABS:3200 SymAddr += pSym->n_value;3201 break;3202 3203 case MACHO_N_INDR:3204 case MACHO_N_PBUD:3205 KLDRMODMACHO_CHECK_RETURN(0, KLDR_ERR_TODO);3206 default:3207 KLDRMODMACHO_CHECK_RETURN(0, KLDR_ERR_MACHO_BAD_SYMBOL);3208 3199 } 3200 else if (Fixup2.r_symbolnum != R_ABS) 3201 { 3202 PKLDRMODMACHOSECT pSymSect; 3203 KLDRADDR TmpAddr; 3204 KLDRMODMACHO_CHECK_RETURN(Fixup2.r_symbolnum <= pModMachO->cSections, KLDR_ERR_BAD_FIXUP); 3205 pSymSect = &pModMachO->paSections[Fixup2.r_symbolnum - 1]; 3206 SymAddr += pSymSect->RVA + NewBaseAddress; 3207 } 3208 else 3209 KLDRMODMACHO_CHECK_RETURN(0, KLDR_ERR_BAD_FIXUP); 3209 3210 } 3210 3211 break; … … 3213 3214 else 3214 3215 { 3215 /* verify against fixup type */3216 /* verify against fixup type and make adjustments */ 3216 3217 switch (Fixup.r.r_type) 3217 3218 { 3218 3219 case X86_64_RELOC_UNSIGNED: 3220 KLDRMODMACHO_CHECK_RETURN(!Fixup.r.r_pcrel, KLDR_ERR_BAD_FIXUP); 3221 break; 3222 case X86_64_RELOC_BRANCH: 3223 KLDRMODMACHO_CHECK_RETURN(Fixup.r.r_pcrel, KLDR_ERR_BAD_FIXUP); 3224 SymAddr += 4; /* dunno what the assmbler/linker really is doing here... */ 3225 break; 3219 3226 case X86_64_RELOC_SIGNED: 3220 case X86_64_RELOC_BRANCH:3221 /*case X86_64_RELOC_GOT_LOAD:*/3222 /*case X86_64_RELOC_GOT: */3223 /*case X86_64_RELOC_SUBTRACTOR: - ???*/3224 3227 case X86_64_RELOC_SIGNED_1: 3225 3228 case X86_64_RELOC_SIGNED_2: 3226 3229 case X86_64_RELOC_SIGNED_4: 3230 KLDRMODMACHO_CHECK_RETURN(Fixup.r.r_pcrel, KLDR_ERR_BAD_FIXUP); 3227 3231 break; 3232 /*case X86_64_RELOC_GOT_LOAD:*/ 3233 /*case X86_64_RELOC_GOT: */ 3234 /*case X86_64_RELOC_SUBTRACTOR: - must be r_extern=1 says as. */ 3228 3235 default: 3229 3236 KLDRMODMACHO_CHECK_RETURN(0, KLDR_ERR_BAD_FIXUP); … … 3237 3244 SymAddr -= pSymSect->LinkAddress; 3238 3245 SymAddr += pSymSect->RVA + NewBaseAddress; 3246 if (Fixup.r.r_pcrel) 3247 SymAddr += Fixup.r.r_address; 3239 3248 } 3240 3249 }
Note:
See TracChangeset
for help on using the changeset viewer.