Rev 2999 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2999 | Rev 3589 | ||
---|---|---|---|
Line 157... | Line 157... | ||
157 | plt = m->dyn.plt_got; |
157 | plt = m->dyn.plt_got; |
158 | plt_n = m->dyn.plt_rel_sz / sizeof(elf_rela_t); |
158 | plt_n = m->dyn.plt_rel_sz / sizeof(elf_rela_t); |
159 | _plt_ent = plt+ 18; |
159 | _plt_ent = plt+ 18; |
160 | _plt_table = plt + 18 + plt_n; |
160 | _plt_table = plt + 18 + plt_n; |
161 | 161 | ||
162 | printf("parse relocation table\n"); |
162 | DPRINTF("parse relocation table\n"); |
163 | 163 | ||
164 | sym_table = m->dyn.sym_tab; |
164 | sym_table = m->dyn.sym_tab; |
165 | rt_entries = rt_size / sizeof(elf_rela_t); |
165 | rt_entries = rt_size / sizeof(elf_rela_t); |
166 | str_tab = m->dyn.str_tab; |
166 | str_tab = m->dyn.str_tab; |
167 | 167 | ||
168 | printf("address: 0x%x, entries: %d\n", (uintptr_t)rt, rt_entries); |
168 | DPRINTF("address: 0x%x, entries: %d\n", (uintptr_t)rt, rt_entries); |
169 | 169 | ||
170 | for (i = 0; i < rt_entries; ++i) { |
170 | for (i = 0; i < rt_entries; ++i) { |
171 | printf("symbol %d: ", i); |
171 | DPRINTF("symbol %d: ", i); |
172 | r_offset = rt[i].r_offset; |
172 | r_offset = rt[i].r_offset; |
173 | r_info = rt[i].r_info; |
173 | r_info = rt[i].r_info; |
174 | r_addend = rt[i].r_addend; |
174 | r_addend = rt[i].r_addend; |
175 | 175 | ||
176 | sym_idx = ELF32_R_SYM(r_info); |
176 | sym_idx = ELF32_R_SYM(r_info); |
177 | sym = &sym_table[sym_idx]; |
177 | sym = &sym_table[sym_idx]; |
178 | 178 | ||
179 | printf("name '%s', value 0x%x, size 0x%x\n", |
179 | DPRINTF("name '%s', value 0x%x, size 0x%x\n", |
180 | str_tab + sym->st_name, |
180 | str_tab + sym->st_name, |
181 | sym->st_value, |
181 | sym->st_value, |
182 | sym->st_size); |
182 | sym->st_size); |
183 | 183 | ||
184 | rel_type = ELF32_R_TYPE(r_info); |
184 | rel_type = ELF32_R_TYPE(r_info); |
185 | r_ptr = (uint32_t *)(r_offset + m->bias); |
185 | r_ptr = (uint32_t *)(r_offset + m->bias); |
186 | 186 | ||
187 | if (sym->st_name != 0) { |
187 | if (sym->st_name != 0) { |
188 | printf("rel_type: %x, rel_offset: 0x%x\n", rel_type, r_offset); |
188 | DPRINTF("rel_type: %x, rel_offset: 0x%x\n", rel_type, r_offset); |
189 | sym_def = symbol_def_find(str_tab + sym->st_name, |
189 | sym_def = symbol_def_find(str_tab + sym->st_name, |
190 | m, &dest); |
190 | m, &dest); |
191 | printf("dest name: '%s'\n", dest->dyn.soname); |
191 | DPRINTF("dest name: '%s'\n", dest->dyn.soname); |
192 | printf("dest bias: 0x%x\n", dest->bias); |
192 | DPRINTF("dest bias: 0x%x\n", dest->bias); |
193 | if (sym_def) { |
193 | if (sym_def) { |
194 | sym_addr = symbol_get_addr(sym_def, dest); |
194 | sym_addr = symbol_get_addr(sym_def, dest); |
195 | printf("symbol definition found, addr=0x%x\n", sym_addr); |
195 | DPRINTF("symbol definition found, addr=0x%x\n", sym_addr); |
196 | } else { |
196 | } else { |
197 | printf("symbol definition not found\n"); |
197 | DPRINTF("symbol definition not found\n"); |
198 | continue; |
198 | continue; |
199 | } |
199 | } |
200 | } |
200 | } |
201 | 201 | ||
202 | switch (rel_type) { |
202 | switch (rel_type) { |
203 | case R_PPC_JMP_SLOT: |
203 | case R_PPC_JMP_SLOT: |
204 | printf("fixup R_PPC_JMP_SLOT (b+v)\n"); |
204 | DPRINTF("fixup R_PPC_JMP_SLOT (b+v)\n"); |
205 | pidx = (r_ptr - _plt_ent) / 2; |
205 | pidx = (r_ptr - _plt_ent) / 2; |
206 | if (pidx >= plt_n) { |
206 | if (pidx >= plt_n) { |
207 | printf("error: proc index out of range\n"); |
207 | DPRINTF("error: proc index out of range\n"); |
208 | //kputint(0xee00ee0ee00); |
208 | //kputint(0xee00ee0ee00); |
209 | while(1); |
209 | while(1); |
210 | } |
210 | } |
211 | //_plt_table[pidx] = sym_addr; |
211 | //_plt_table[pidx] = sym_addr; |
212 | plt[18+2*pidx] = _b((void *)sym_addr, &plt[18+2*pidx]); |
212 | plt[18+2*pidx] = _b((void *)sym_addr, &plt[18+2*pidx]); |
213 | break; |
213 | break; |
214 | 214 | ||
215 | case R_PPC_ADDR32: |
215 | case R_PPC_ADDR32: |
216 | printf("fixup R_PPC_ADDR32 (b+v+a)\n"); |
216 | DPRINTF("fixup R_PPC_ADDR32 (b+v+a)\n"); |
217 | *r_ptr = r_addend + sym_addr; |
217 | *r_ptr = r_addend + sym_addr; |
218 | break; |
218 | break; |
219 | 219 | ||
220 | case R_PPC_RELATIVE: |
220 | case R_PPC_RELATIVE: |
221 | printf("fixup R_PPC_RELATIVE (b+a)\n"); |
221 | DPRINTF("fixup R_PPC_RELATIVE (b+a)\n"); |
222 | *r_ptr = r_addend + m->bias; |
222 | *r_ptr = r_addend + m->bias; |
223 | break; |
223 | break; |
224 | case R_PPC_REL24: |
224 | case R_PPC_REL24: |
- | 225 | // printf("ignore R_PPC_REL24 at 0x%04x\n", (uintptr_t) r_ptr); |
|
- | 226 | *r_ptr = (sym_addr + r_addend - (uint32_t)r_ptr) >> 2; |
|
225 | printf("ignore R_PPC_REL24\n"); |
227 | DPRINTF("fixup R_PPC_REL24 (s+a-p)>>2\n"); |
226 | /*TODO*/ |
228 | /*TODO*/ |
227 | break; |
229 | break; |
- | 230 | default: |
|
- | 231 | printf("unknown relocation type\n"); |
|
- | 232 | break; |
|
228 | } |
233 | } |
229 | } |
234 | } |
230 | 235 | ||
231 | } |
236 | } |
232 | 237 |