Rev 2999 | Rev 3681 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2999 | Rev 3562 | ||
---|---|---|---|
Line 67... | Line 67... | ||
67 | char *str_tab; |
67 | char *str_tab; |
68 | 68 | ||
69 | elf_symbol_t *sym_def; |
69 | elf_symbol_t *sym_def; |
70 | module_t *dest; |
70 | module_t *dest; |
71 | 71 | ||
72 | printf("parse relocation table\n"); |
72 | DPRINTF("parse relocation table\n"); |
73 | 73 | ||
74 | sym_table = m->dyn.sym_tab; |
74 | sym_table = m->dyn.sym_tab; |
75 | rt_entries = rt_size / sizeof(elf_rel_t); |
75 | rt_entries = rt_size / sizeof(elf_rel_t); |
76 | str_tab = m->dyn.str_tab; |
76 | str_tab = m->dyn.str_tab; |
77 | 77 | ||
78 | printf("address: 0x%x, entries: %d\n", (uintptr_t)rt, rt_entries); |
78 | DPRINTF("address: 0x%x, entries: %d\n", (uintptr_t)rt, rt_entries); |
79 | 79 | ||
80 | for (i = 0; i < rt_entries; ++i) { |
80 | for (i = 0; i < rt_entries; ++i) { |
81 | // printf("symbol %d: ", i); |
81 | // DPRINTF("symbol %d: ", i); |
82 | r_offset = rt[i].r_offset; |
82 | r_offset = rt[i].r_offset; |
83 | r_info = rt[i].r_info; |
83 | r_info = rt[i].r_info; |
84 | 84 | ||
85 | sym_idx = ELF32_R_SYM(r_info); |
85 | sym_idx = ELF32_R_SYM(r_info); |
86 | sym = &sym_table[sym_idx]; |
86 | sym = &sym_table[sym_idx]; |
87 | 87 | ||
88 | /* printf("name '%s', value 0x%x, size 0x%x\n", |
88 | /* DPRINTF("name '%s', value 0x%x, size 0x%x\n", |
89 | str_tab + sym->st_name, |
89 | str_tab + sym->st_name, |
90 | sym->st_value, |
90 | sym->st_value, |
91 | sym->st_size); |
91 | sym->st_size); |
92 | */ |
92 | */ |
93 | rel_type = ELF32_R_TYPE(r_info); |
93 | rel_type = ELF32_R_TYPE(r_info); |
94 | r_ptr = (uint32_t *)(r_offset + m->bias); |
94 | r_ptr = (uint32_t *)(r_offset + m->bias); |
95 | 95 | ||
96 | if (sym->st_name != 0) { |
96 | if (sym->st_name != 0) { |
97 | // printf("rel_type: %x, rel_offset: 0x%x\n", rel_type, r_offset); |
97 | // DPRINTF("rel_type: %x, rel_offset: 0x%x\n", rel_type, r_offset); |
98 | sym_def = symbol_def_find(str_tab + sym->st_name, |
98 | sym_def = symbol_def_find(str_tab + sym->st_name, |
99 | m, &dest); |
99 | m, &dest); |
100 | // printf("dest name: '%s'\n", dest->dyn.soname); |
100 | // DPRINTF("dest name: '%s'\n", dest->dyn.soname); |
101 | // printf("dest bias: 0x%x\n", dest->bias); |
101 | // DPRINTF("dest bias: 0x%x\n", dest->bias); |
102 | if (sym_def) { |
102 | if (sym_def) { |
103 | sym_addr = symbol_get_addr(sym_def, dest); |
103 | sym_addr = symbol_get_addr(sym_def, dest); |
104 | // printf("symbol definition found, addr=0x%x\n", sym_addr); |
104 | // DPRINTF("symbol definition found, addr=0x%x\n", sym_addr); |
105 | } else { |
105 | } else { |
106 | printf("symbol definition not found\n"); |
106 | DPRINTF("symbol definition not found\n"); |
107 | continue; |
107 | continue; |
108 | } |
108 | } |
109 | } |
109 | } |
110 | 110 | ||
111 | switch (rel_type) { |
111 | switch (rel_type) { |
112 | case R_386_GLOB_DAT: |
112 | case R_386_GLOB_DAT: |
113 | case R_386_JUMP_SLOT: |
113 | case R_386_JUMP_SLOT: |
114 | // printf("fixup R_386_GLOB_DAT/JUMP_SLOT (b+v)\n"); |
114 | // DPRINTF("fixup R_386_GLOB_DAT/JUMP_SLOT (b+v)\n"); |
115 | *r_ptr = sym_addr; |
115 | *r_ptr = sym_addr; |
116 | break; |
116 | break; |
117 | 117 | ||
118 | case R_386_32: |
118 | case R_386_32: |
119 | // printf("fixup R_386_32 (b+v+a)\n"); |
119 | // DPRINTF("fixup R_386_32 (b+v+a)\n"); |
120 | *r_ptr += sym_addr; |
120 | *r_ptr += sym_addr; |
121 | break; |
121 | break; |
122 | 122 | ||
123 | case R_386_RELATIVE: |
123 | case R_386_RELATIVE: |
124 | // printf("fixup R_386_RELATIVE (b+a)\n"); |
124 | // DPRINTF("fixup R_386_RELATIVE (b+a)\n"); |
125 | *r_ptr += m->bias; |
125 | *r_ptr += m->bias; |
126 | break; |
126 | break; |
127 | } |
127 | } |
128 | } |
128 | } |
129 | 129 |