| Juan Cespedes | d914a20 | 2004-11-10 00:15:33 +0100 | [diff] [blame] | 1 | #include <gelf.h> |
| Juan Cespedes | a7af00d | 2009-07-26 13:23:18 +0200 | [diff] [blame] | 2 | #include <sys/ptrace.h> |
| Petr Machata | e67635d | 2012-03-21 03:37:39 +0100 | [diff] [blame] | 3 | #include <errno.h> |
| 4 | #include <error.h> |
| 5 | #include <inttypes.h> |
| 6 | #include <assert.h> |
| Petr Machata | 37d368e | 2012-03-24 04:58:08 +0100 | [diff] [blame] | 7 | #include <string.h> |
| Petr Machata | e67635d | 2012-03-21 03:37:39 +0100 | [diff] [blame] | 8 | |
| Petr Machata | 366c2f4 | 2012-02-09 19:34:36 +0100 | [diff] [blame] | 9 | #include "proc.h" |
| Juan Cespedes | f728123 | 2009-06-25 16:11:21 +0200 | [diff] [blame] | 10 | #include "common.h" |
| Petr Machata | e67635d | 2012-03-21 03:37:39 +0100 | [diff] [blame] | 11 | #include "library.h" |
| Petr Machata | b64b5c7 | 2012-03-27 03:19:42 +0200 | [diff] [blame] | 12 | #include "breakpoint.h" |
| Petr Machata | 58b2d0f | 2012-03-28 02:19:20 +0200 | [diff] [blame] | 13 | #include "linux-gnu/trace.h" |
| Petr Machata | e67635d | 2012-03-21 03:37:39 +0100 | [diff] [blame] | 14 | |
| Petr Machata | 37d368e | 2012-03-24 04:58:08 +0100 | [diff] [blame] | 15 | /* There are two PLT types on 32-bit PPC: old-style, BSS PLT, and |
| 16 | * new-style "secure" PLT. We can tell one from the other by the |
| 17 | * flags on the .plt section. If it's +X (executable), it's BSS PLT, |
| 18 | * otherwise it's secure. |
| 19 | * |
| 20 | * BSS PLT works the same way as most architectures: the .plt section |
| 21 | * contains trampolines and we put breakpoints to those. With secure |
| 22 | * PLT, the .plt section doesn't contain instructions but addresses. |
| 23 | * The real PLT table is stored in .text. Addresses of those PLT |
| 24 | * entries can be computed, and it fact that's what the glink deal |
| 25 | * below does. |
| 26 | * |
| 27 | * If not prelinked, BSS PLT entries in the .plt section contain |
| 28 | * zeroes that are overwritten by the dynamic linker during start-up. |
| 29 | * For that reason, ltrace realizes those breakpoints only after |
| Petr Machata | d957332 | 2012-04-17 05:21:02 +0200 | [diff] [blame] | 30 | * _start is hit. |
| Petr Machata | 37d368e | 2012-03-24 04:58:08 +0100 | [diff] [blame] | 31 | * |
| 32 | * 64-bit PPC is more involved. Program linker creates for each |
| 33 | * library call a _stub_ symbol named xxxxxxxx.plt_call.<callee> |
| 34 | * (where xxxxxxxx is a hexadecimal number). That stub does the call |
| 35 | * dispatch: it loads an address of a function to call from the |
| 36 | * section .plt, and branches. PLT entries themselves are essentially |
| 37 | * a curried call to the resolver. When the symbol is resolved, the |
| 38 | * resolver updates the value stored in .plt, and the next time |
| 39 | * around, the stub calls the library function directly. So we make |
| 40 | * at most one trip (none if the binary is prelinked) through each PLT |
| 41 | * entry, and correspondingly that is useless as a breakpoint site. |
| 42 | * |
| 43 | * Note the three confusing terms: stubs (that play the role of PLT |
| 44 | * entries), PLT entries, .plt section. |
| 45 | * |
| 46 | * We first check symbol tables and see if we happen to have stub |
| 47 | * symbols available. If yes we just put breakpoints to those, and |
| 48 | * treat them as usual breakpoints. The only tricky part is realizing |
| 49 | * that there can be more than one breakpoint per symbol. |
| 50 | * |
| 51 | * The case that we don't have the stub symbols available is harder. |
| 52 | * The following scheme uses two kinds of PLT breakpoints: unresolved |
| 53 | * and resolved (to some address). When the process starts (or when |
| 54 | * we attach), we distribute unresolved PLT breakpoints to the PLT |
| 55 | * entries (not stubs). Then we look in .plt, and for each entry |
| 56 | * whose value is different than the corresponding PLT entry address, |
| 57 | * we assume it was already resolved, and convert the breakpoint to |
| 58 | * resolved. We also rewrite the resolved value in .plt back to the |
| 59 | * PLT address. |
| 60 | * |
| 61 | * When a PLT entry hits a resolved breakpoint (which happens because |
| Petr Machata | 19c0f29 | 2012-04-15 19:09:02 +0200 | [diff] [blame] | 62 | * we rewrite .plt with the original unresolved addresses), we move |
| 63 | * the instruction pointer to the corresponding address and continue |
| 64 | * the process as if nothing happened. |
| Petr Machata | 37d368e | 2012-03-24 04:58:08 +0100 | [diff] [blame] | 65 | * |
| 66 | * When unresolved PLT entry is called for the first time, we need to |
| 67 | * catch the new value that the resolver will write to a .plt slot. |
| 68 | * We also need to prevent another thread from racing through and |
| 69 | * taking the branch without ltrace noticing. So when unresolved PLT |
| 70 | * entry hits, we have to stop all threads. We then single-step |
| 71 | * through the resolver, until the .plt slot changes. When it does, |
| 72 | * we treat it the same way as above: convert the PLT breakpoint to |
| 73 | * resolved, and rewrite the .plt value back to PLT address. We then |
| 74 | * start all threads again. |
| 75 | * |
| Petr Machata | 19c0f29 | 2012-04-15 19:09:02 +0200 | [diff] [blame] | 76 | * As an optimization, we remember the address where the address was |
| 77 | * resolved, and put a breakpoint there. The next time around (when |
| 78 | * the next PLT entry is to be resolved), instead of single-stepping |
| 79 | * through half the dynamic linker, we just let the thread run and hit |
| 80 | * this breakpoint. When it hits, we know the PLT entry was resolved. |
| Petr Machata | 58b2d0f | 2012-03-28 02:19:20 +0200 | [diff] [blame] | 81 | * |
| Petr Machata | 19c0f29 | 2012-04-15 19:09:02 +0200 | [diff] [blame] | 82 | * XXX TODO As an additional optimization, after the above is done, we |
| 83 | * might emulate the instruction that updates .plt. We would compute |
| 84 | * the resolved address, and instead of letting the dynamic linker put |
| 85 | * it in .plt, we would resolve the breakpoint to that address. This |
| 86 | * way we wouldn't need to stop other threads. Otherwise there's no |
| Petr Machata | 58b2d0f | 2012-03-28 02:19:20 +0200 | [diff] [blame] | 87 | * way around that. Unless we know where the stubs are, we don't have |
| 88 | * a way to catch a thread that would use the window of opportunity |
| Petr Machata | 19c0f29 | 2012-04-15 19:09:02 +0200 | [diff] [blame] | 89 | * between updating .plt and notifying ltrace that it happened. |
| 90 | * |
| 91 | * XXX TODO If we have hardware watch point, we might put a read watch |
| 92 | * on .plt slot, and discover the offenders this way. I don't know |
| 93 | * the details, but I assume at most a handful (like, one or two, if |
| 94 | * available at all) addresses may be watched at a time, and thus this |
| 95 | * would be used as an amendment of the above rather than full-on |
| 96 | * solution to PLT tracing on PPC. |
| Petr Machata | 37d368e | 2012-03-24 04:58:08 +0100 | [diff] [blame] | 97 | */ |
| 98 | |
| Petr Machata | e67635d | 2012-03-21 03:37:39 +0100 | [diff] [blame] | 99 | #define PPC_PLT_STUB_SIZE 16 |
| Petr Machata | b64b5c7 | 2012-03-27 03:19:42 +0200 | [diff] [blame] | 100 | #define PPC64_PLT_STUB_SIZE 8 //xxx |
| Petr Machata | e67635d | 2012-03-21 03:37:39 +0100 | [diff] [blame] | 101 | |
| 102 | static inline int |
| Petr Machata | 4e2073f | 2012-03-21 05:15:44 +0100 | [diff] [blame] | 103 | host_powerpc64() |
| Petr Machata | e67635d | 2012-03-21 03:37:39 +0100 | [diff] [blame] | 104 | { |
| 105 | #ifdef __powerpc64__ |
| 106 | return 1; |
| 107 | #else |
| 108 | return 0; |
| 109 | #endif |
| 110 | } |
| 111 | |
| Petr Machata | d957332 | 2012-04-17 05:21:02 +0200 | [diff] [blame] | 112 | static enum callback_status |
| 113 | reenable_breakpoint(struct Process *proc, struct breakpoint *bp, void *data) |
| 114 | { |
| 115 | /* We don't need to re-enable non-PLT breakpoints and |
| 116 | * breakpoints that are not PPC32 BSS unprelinked. */ |
| 117 | if (bp->libsym == NULL |
| 118 | || bp->libsym->plt_type == LS_TOPLT_NONE |
| 119 | || bp->libsym->lib->arch.bss_plt_prelinked != 0) |
| 120 | return CBS_CONT; |
| 121 | |
| 122 | debug(DEBUG_PROCESS, "pid=%d reenable_breakpoint %s", |
| 123 | proc->pid, breakpoint_name(bp)); |
| 124 | |
| 125 | /* Re-enable the breakpoint that was overwritten by the |
| 126 | * dynamic linker. XXX unfortunately it's overwritten |
| 127 | * again after the first call :-/ */ |
| 128 | enable_breakpoint(proc, bp); |
| 129 | |
| 130 | return CBS_CONT; |
| 131 | } |
| 132 | |
| 133 | void |
| 134 | arch_dynlink_done(struct Process *proc) |
| 135 | { |
| 136 | /* On PPC32, .plt of objects that use BSS PLT are overwritten |
| 137 | * by the dynamic linker (unless that object was prelinked). |
| 138 | * We need to re-enable breakpoints in those objects. */ |
| 139 | proc_each_breakpoint(proc, NULL, reenable_breakpoint, NULL); |
| 140 | } |
| 141 | |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 142 | GElf_Addr |
| Petr Machata | 4e2073f | 2012-03-21 05:15:44 +0100 | [diff] [blame] | 143 | arch_plt_sym_val(struct ltelf *lte, size_t ndx, GElf_Rela *rela) |
| 144 | { |
| 145 | if (lte->ehdr.e_machine == EM_PPC && lte->arch.secure_plt) { |
| 146 | assert(lte->arch.plt_stub_vma != 0); |
| Petr Machata | e67635d | 2012-03-21 03:37:39 +0100 | [diff] [blame] | 147 | return lte->arch.plt_stub_vma + PPC_PLT_STUB_SIZE * ndx; |
| Petr Machata | 4e2073f | 2012-03-21 05:15:44 +0100 | [diff] [blame] | 148 | |
| 149 | } else if (lte->ehdr.e_machine == EM_PPC) { |
| Petr Machata | e67635d | 2012-03-21 03:37:39 +0100 | [diff] [blame] | 150 | return rela->r_offset; |
| Petr Machata | 4e2073f | 2012-03-21 05:15:44 +0100 | [diff] [blame] | 151 | |
| 152 | } else { |
| Petr Machata | b64b5c7 | 2012-03-27 03:19:42 +0200 | [diff] [blame] | 153 | /* If we get here, we don't have stub symbols. In |
| 154 | * that case we put brakpoints to PLT entries the same |
| 155 | * as the PPC32 secure PLT case does. */ |
| 156 | assert(lte->arch.plt_stub_vma != 0); |
| 157 | return lte->arch.plt_stub_vma + PPC64_PLT_STUB_SIZE * ndx; |
| Petr Machata | 4e2073f | 2012-03-21 05:15:44 +0100 | [diff] [blame] | 158 | } |
| Petr Machata | e67635d | 2012-03-21 03:37:39 +0100 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | int |
| 162 | arch_translate_address(struct Process *proc, |
| 163 | target_address_t addr, target_address_t *ret) |
| 164 | { |
| Petr Machata | b64b5c7 | 2012-03-27 03:19:42 +0200 | [diff] [blame] | 165 | if (proc->e_machine == EM_PPC64) { |
| 166 | assert(host_powerpc64()); |
| Petr Machata | e67635d | 2012-03-21 03:37:39 +0100 | [diff] [blame] | 167 | long l = ptrace(PTRACE_PEEKTEXT, proc->pid, addr, 0); |
| Petr Machata | e67635d | 2012-03-21 03:37:39 +0100 | [diff] [blame] | 168 | if (l == -1 && errno) { |
| 169 | error(0, errno, ".opd translation of %p", addr); |
| 170 | return -1; |
| 171 | } |
| 172 | *ret = (target_address_t)l; |
| 173 | return 0; |
| 174 | } |
| 175 | |
| 176 | *ret = addr; |
| 177 | return 0; |
| Juan Cespedes | d914a20 | 2004-11-10 00:15:33 +0100 | [diff] [blame] | 178 | } |
| Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame] | 179 | |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 180 | void * |
| Petr Machata | 18c801c | 2012-04-07 01:24:08 +0200 | [diff] [blame] | 181 | sym2addr(struct Process *proc, struct library_symbol *sym) |
| 182 | { |
| 183 | return sym->enter_addr; |
| Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame] | 184 | } |
| Petr Machata | e67635d | 2012-03-21 03:37:39 +0100 | [diff] [blame] | 185 | |
| 186 | static GElf_Addr |
| 187 | get_glink_vma(struct ltelf *lte, GElf_Addr ppcgot, Elf_Data *plt_data) |
| 188 | { |
| 189 | Elf_Scn *ppcgot_sec = NULL; |
| 190 | GElf_Shdr ppcgot_shdr; |
| 191 | if (ppcgot != 0 |
| 192 | && elf_get_section_covering(lte, ppcgot, |
| 193 | &ppcgot_sec, &ppcgot_shdr) < 0) |
| Petr Machata | 8b00d5b | 2012-04-06 16:05:10 +0200 | [diff] [blame] | 194 | error(0, 0, "DT_PPC_GOT=%#"PRIx64", but no such section found", |
| 195 | ppcgot); |
| Petr Machata | e67635d | 2012-03-21 03:37:39 +0100 | [diff] [blame] | 196 | |
| 197 | if (ppcgot_sec != NULL) { |
| 198 | Elf_Data *data = elf_loaddata(ppcgot_sec, &ppcgot_shdr); |
| 199 | if (data == NULL || data->d_size < 8 ) { |
| Petr Machata | 8b00d5b | 2012-04-06 16:05:10 +0200 | [diff] [blame] | 200 | error(0, 0, "couldn't read GOT data"); |
| Petr Machata | e67635d | 2012-03-21 03:37:39 +0100 | [diff] [blame] | 201 | } else { |
| 202 | // where PPCGOT begins in .got |
| 203 | size_t offset = ppcgot - ppcgot_shdr.sh_addr; |
| 204 | assert(offset % 4 == 0); |
| 205 | uint32_t glink_vma; |
| 206 | if (elf_read_u32(data, offset + 4, &glink_vma) < 0) { |
| Petr Machata | 8b00d5b | 2012-04-06 16:05:10 +0200 | [diff] [blame] | 207 | error(0, 0, "couldn't read glink VMA address" |
| 208 | " at %zd@GOT", offset); |
| Petr Machata | e67635d | 2012-03-21 03:37:39 +0100 | [diff] [blame] | 209 | return 0; |
| 210 | } |
| 211 | if (glink_vma != 0) { |
| 212 | debug(1, "PPC GOT glink_vma address: %#" PRIx32, |
| 213 | glink_vma); |
| Petr Machata | e67635d | 2012-03-21 03:37:39 +0100 | [diff] [blame] | 214 | return (GElf_Addr)glink_vma; |
| 215 | } |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | if (plt_data != NULL) { |
| 220 | uint32_t glink_vma; |
| 221 | if (elf_read_u32(plt_data, 0, &glink_vma) < 0) { |
| Petr Machata | 8b00d5b | 2012-04-06 16:05:10 +0200 | [diff] [blame] | 222 | error(0, 0, "couldn't read glink VMA address"); |
| Petr Machata | e67635d | 2012-03-21 03:37:39 +0100 | [diff] [blame] | 223 | return 0; |
| 224 | } |
| 225 | debug(1, ".plt glink_vma address: %#" PRIx32, glink_vma); |
| Petr Machata | e67635d | 2012-03-21 03:37:39 +0100 | [diff] [blame] | 226 | return (GElf_Addr)glink_vma; |
| 227 | } |
| 228 | |
| 229 | return 0; |
| 230 | } |
| 231 | |
| Petr Machata | 644d669 | 2012-03-24 02:06:48 +0100 | [diff] [blame] | 232 | static int |
| Petr Machata | d1746d1 | 2012-03-27 03:14:14 +0200 | [diff] [blame] | 233 | load_dynamic_entry(struct ltelf *lte, int tag, GElf_Addr *valuep) |
| Petr Machata | e67635d | 2012-03-21 03:37:39 +0100 | [diff] [blame] | 234 | { |
| Petr Machata | 644d669 | 2012-03-24 02:06:48 +0100 | [diff] [blame] | 235 | Elf_Scn *scn; |
| 236 | GElf_Shdr shdr; |
| 237 | if (elf_get_section_type(lte, SHT_DYNAMIC, &scn, &shdr) < 0 |
| 238 | || scn == NULL) { |
| 239 | fail: |
| 240 | error(0, 0, "Couldn't get SHT_DYNAMIC: %s", |
| 241 | elf_errmsg(-1)); |
| 242 | return -1; |
| Petr Machata | e67635d | 2012-03-21 03:37:39 +0100 | [diff] [blame] | 243 | } |
| Petr Machata | 644d669 | 2012-03-24 02:06:48 +0100 | [diff] [blame] | 244 | |
| 245 | Elf_Data *data = elf_loaddata(scn, &shdr); |
| 246 | if (data == NULL) |
| 247 | goto fail; |
| 248 | |
| 249 | size_t j; |
| 250 | for (j = 0; j < shdr.sh_size / shdr.sh_entsize; ++j) { |
| 251 | GElf_Dyn dyn; |
| 252 | if (gelf_getdyn(data, j, &dyn) == NULL) |
| 253 | goto fail; |
| 254 | |
| Petr Machata | d1746d1 | 2012-03-27 03:14:14 +0200 | [diff] [blame] | 255 | if(dyn.d_tag == tag) { |
| 256 | *valuep = dyn.d_un.d_ptr; |
| Petr Machata | 644d669 | 2012-03-24 02:06:48 +0100 | [diff] [blame] | 257 | return 0; |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | return -1; |
| Petr Machata | e67635d | 2012-03-21 03:37:39 +0100 | [diff] [blame] | 262 | } |
| 263 | |
| Petr Machata | d1746d1 | 2012-03-27 03:14:14 +0200 | [diff] [blame] | 264 | static int |
| 265 | load_ppcgot(struct ltelf *lte, GElf_Addr *ppcgotp) |
| 266 | { |
| 267 | return load_dynamic_entry(lte, DT_PPC_GOT, ppcgotp); |
| 268 | } |
| 269 | |
| Petr Machata | b64b5c7 | 2012-03-27 03:19:42 +0200 | [diff] [blame] | 270 | static int |
| 271 | load_ppc64_glink(struct ltelf *lte, GElf_Addr *glinkp) |
| 272 | { |
| 273 | return load_dynamic_entry(lte, DT_PPC64_GLINK, glinkp); |
| 274 | } |
| 275 | |
| Petr Machata | d957332 | 2012-04-17 05:21:02 +0200 | [diff] [blame] | 276 | static int |
| 277 | nonzero_data(Elf_Data *data) |
| 278 | { |
| 279 | /* We are not supposed to get here if there are no PLT data in |
| 280 | * the binary. */ |
| 281 | assert(data != NULL); |
| 282 | |
| 283 | unsigned char *buf = data->d_buf; |
| 284 | if (buf == NULL) |
| 285 | return 0; |
| 286 | |
| 287 | size_t i; |
| 288 | for (i = 0; i < data->d_size; ++i) |
| 289 | if (buf[i] != 0) |
| 290 | return 1; |
| 291 | return 0; |
| 292 | } |
| 293 | |
| Petr Machata | e67635d | 2012-03-21 03:37:39 +0100 | [diff] [blame] | 294 | int |
| Petr Machata | d957332 | 2012-04-17 05:21:02 +0200 | [diff] [blame] | 295 | arch_elf_init(struct ltelf *lte, struct library *lib) |
| Petr Machata | e67635d | 2012-03-21 03:37:39 +0100 | [diff] [blame] | 296 | { |
| Petr Machata | 18c801c | 2012-04-07 01:24:08 +0200 | [diff] [blame] | 297 | lte->arch.secure_plt = !(lte->plt_flags & SHF_EXECINSTR); |
| Petr Machata | d957332 | 2012-04-17 05:21:02 +0200 | [diff] [blame] | 298 | |
| 299 | /* For PPC32 BSS, it is important whether the binary was |
| 300 | * prelinked. If .plt section is NODATA, or if it contains |
| 301 | * zeroes, then this library is not prelinked, and we need to |
| 302 | * delay breakpoints. */ |
| 303 | if (lte->ehdr.e_machine == EM_PPC && !lte->arch.secure_plt) |
| 304 | lib->arch.bss_plt_prelinked = nonzero_data(lte->plt_data); |
| 305 | else |
| 306 | /* For cases where it's irrelevant, initialize the |
| 307 | * value to something conspicuous. */ |
| 308 | lib->arch.bss_plt_prelinked = -1; |
| 309 | |
| Petr Machata | 4e2073f | 2012-03-21 05:15:44 +0100 | [diff] [blame] | 310 | if (lte->ehdr.e_machine == EM_PPC && lte->arch.secure_plt) { |
| Petr Machata | 644d669 | 2012-03-24 02:06:48 +0100 | [diff] [blame] | 311 | GElf_Addr ppcgot; |
| 312 | if (load_ppcgot(lte, &ppcgot) < 0) { |
| Petr Machata | 8b00d5b | 2012-04-06 16:05:10 +0200 | [diff] [blame] | 313 | error(0, 0, "couldn't find DT_PPC_GOT"); |
| Petr Machata | 644d669 | 2012-03-24 02:06:48 +0100 | [diff] [blame] | 314 | return -1; |
| 315 | } |
| 316 | GElf_Addr glink_vma = get_glink_vma(lte, ppcgot, lte->plt_data); |
| Petr Machata | e67635d | 2012-03-21 03:37:39 +0100 | [diff] [blame] | 317 | |
| 318 | assert (lte->relplt_size % 12 == 0); |
| 319 | size_t count = lte->relplt_size / 12; // size of RELA entry |
| 320 | lte->arch.plt_stub_vma = glink_vma |
| 321 | - (GElf_Addr)count * PPC_PLT_STUB_SIZE; |
| 322 | debug(1, "stub_vma is %#" PRIx64, lte->arch.plt_stub_vma); |
| Petr Machata | b64b5c7 | 2012-03-27 03:19:42 +0200 | [diff] [blame] | 323 | |
| 324 | } else if (lte->ehdr.e_machine == EM_PPC64) { |
| 325 | GElf_Addr glink_vma; |
| 326 | if (load_ppc64_glink(lte, &glink_vma) < 0) { |
| Petr Machata | 8b00d5b | 2012-04-06 16:05:10 +0200 | [diff] [blame] | 327 | error(0, 0, "couldn't find DT_PPC64_GLINK"); |
| Petr Machata | b64b5c7 | 2012-03-27 03:19:42 +0200 | [diff] [blame] | 328 | return -1; |
| 329 | } |
| 330 | |
| 331 | /* The first glink stub starts at offset 32. */ |
| 332 | lte->arch.plt_stub_vma = glink_vma + 32; |
| Petr Machata | e67635d | 2012-03-21 03:37:39 +0100 | [diff] [blame] | 333 | } |
| 334 | |
| Petr Machata | 37d368e | 2012-03-24 04:58:08 +0100 | [diff] [blame] | 335 | /* On PPC64, look for stub symbols in symbol table. These are |
| 336 | * called: xxxxxxxx.plt_call.callee_name@version+addend. */ |
| 337 | if (lte->ehdr.e_machine == EM_PPC64 |
| 338 | && lte->symtab != NULL && lte->strtab != NULL) { |
| 339 | |
| 340 | /* N.B. We can't simply skip the symbols that we fail |
| 341 | * to read or malloc. There may be more than one stub |
| 342 | * per symbol name, and if we failed in one but |
| 343 | * succeeded in another, the PLT enabling code would |
| 344 | * have no way to tell that something is missing. We |
| 345 | * could work around that, of course, but it doesn't |
| Petr Machata | 7b36114 | 2012-03-24 14:27:01 +0100 | [diff] [blame] | 346 | * seem worth the trouble. So if anything fails, we |
| 347 | * just pretend that we don't have stub symbols at |
| 348 | * all, as if the binary is stripped. */ |
| Petr Machata | 37d368e | 2012-03-24 04:58:08 +0100 | [diff] [blame] | 349 | |
| 350 | size_t i; |
| 351 | for (i = 0; i < lte->symtab_count; ++i) { |
| 352 | GElf_Sym sym; |
| Petr Machata | 7b36114 | 2012-03-24 14:27:01 +0100 | [diff] [blame] | 353 | if (gelf_getsym(lte->symtab, i, &sym) == NULL) { |
| 354 | struct library_symbol *sym, *next; |
| 355 | fail: |
| 356 | for (sym = lte->arch.stubs; sym != NULL; ) { |
| 357 | next = sym->next; |
| 358 | library_symbol_destroy(sym); |
| 359 | free(sym); |
| 360 | sym = next; |
| 361 | } |
| 362 | lte->arch.stubs = NULL; |
| Petr Machata | 37d368e | 2012-03-24 04:58:08 +0100 | [diff] [blame] | 363 | break; |
| Petr Machata | 7b36114 | 2012-03-24 14:27:01 +0100 | [diff] [blame] | 364 | } |
| Petr Machata | 37d368e | 2012-03-24 04:58:08 +0100 | [diff] [blame] | 365 | |
| 366 | const char *name = lte->strtab + sym.st_name; |
| 367 | |
| 368 | #define STUBN ".plt_call." |
| 369 | if ((name = strstr(name, STUBN)) == NULL) |
| 370 | continue; |
| 371 | name += sizeof(STUBN) - 1; |
| 372 | #undef STUBN |
| 373 | |
| 374 | size_t len; |
| 375 | const char *ver = strchr(name, '@'); |
| 376 | if (ver != NULL) { |
| 377 | len = ver - name; |
| 378 | |
| 379 | } else { |
| 380 | /* If there is "+" at all, check that |
| 381 | * the symbol name ends in "+0". */ |
| 382 | const char *add = strrchr(name, '+'); |
| 383 | if (add != NULL) { |
| 384 | assert(strcmp(add, "+0") == 0); |
| 385 | len = add - name; |
| 386 | } else { |
| 387 | len = strlen(name); |
| 388 | } |
| 389 | } |
| 390 | |
| 391 | char *sym_name = strndup(name, len); |
| Petr Machata | 7b36114 | 2012-03-24 14:27:01 +0100 | [diff] [blame] | 392 | struct library_symbol *libsym = malloc(sizeof(*libsym)); |
| 393 | if (sym_name == NULL || libsym == NULL) { |
| Petr Machata | e8d9076 | 2012-04-15 04:28:31 +0200 | [diff] [blame] | 394 | fail2: |
| Petr Machata | 37d368e | 2012-03-24 04:58:08 +0100 | [diff] [blame] | 395 | free(sym_name); |
| Petr Machata | 7b36114 | 2012-03-24 14:27:01 +0100 | [diff] [blame] | 396 | free(libsym); |
| 397 | goto fail; |
| Petr Machata | 37d368e | 2012-03-24 04:58:08 +0100 | [diff] [blame] | 398 | } |
| 399 | |
| Petr Machata | ea8eb9a | 2012-04-17 01:32:07 +0200 | [diff] [blame] | 400 | /* XXX The double cast should be removed when |
| 401 | * target_address_t becomes integral type. */ |
| 402 | target_address_t addr = (target_address_t) |
| 403 | (uintptr_t)sym.st_value + lte->bias; |
| Petr Machata | e8d9076 | 2012-04-15 04:28:31 +0200 | [diff] [blame] | 404 | if (library_symbol_init(libsym, addr, sym_name, 1, |
| 405 | LS_TOPLT_EXEC) < 0) |
| 406 | goto fail2; |
| Petr Machata | b64b5c7 | 2012-03-27 03:19:42 +0200 | [diff] [blame] | 407 | libsym->arch.type = PPC64PLT_STUB; |
| Petr Machata | 37d368e | 2012-03-24 04:58:08 +0100 | [diff] [blame] | 408 | libsym->next = lte->arch.stubs; |
| 409 | lte->arch.stubs = libsym; |
| 410 | } |
| 411 | } |
| 412 | |
| Petr Machata | e67635d | 2012-03-21 03:37:39 +0100 | [diff] [blame] | 413 | return 0; |
| 414 | } |
| Petr Machata | 37d368e | 2012-03-24 04:58:08 +0100 | [diff] [blame] | 415 | |
| Petr Machata | 58b2d0f | 2012-03-28 02:19:20 +0200 | [diff] [blame] | 416 | static int |
| 417 | read_plt_slot_value(struct Process *proc, GElf_Addr addr, GElf_Addr *valp) |
| 418 | { |
| 419 | /* on PPC32 we need to do things differently, but PPC64/PPC32 |
| 420 | * is currently not supported anyway. */ |
| 421 | assert(host_powerpc64()); |
| 422 | |
| 423 | long l = ptrace(PTRACE_PEEKTEXT, proc->pid, addr, 0); |
| 424 | if (l == -1 && errno != 0) { |
| 425 | error(0, errno, "ptrace .plt slot value @%#" PRIx64, addr); |
| 426 | return -1; |
| 427 | } |
| 428 | |
| 429 | *valp = (GElf_Addr)l; |
| 430 | return 0; |
| 431 | } |
| 432 | |
| 433 | static int |
| 434 | unresolve_plt_slot(struct Process *proc, GElf_Addr addr, GElf_Addr value) |
| 435 | { |
| 436 | /* We only modify plt_entry[0], which holds the resolved |
| 437 | * address of the routine. We keep the TOC and environment |
| 438 | * pointers intact. Hence the only adjustment that we need to |
| 439 | * do is to IP. */ |
| 440 | if (ptrace(PTRACE_POKETEXT, proc->pid, addr, value) < 0) { |
| 441 | error(0, errno, "unresolve .plt slot"); |
| 442 | return -1; |
| 443 | } |
| 444 | return 0; |
| 445 | } |
| 446 | |
| Petr Machata | 37d368e | 2012-03-24 04:58:08 +0100 | [diff] [blame] | 447 | enum plt_status |
| 448 | arch_elf_add_plt_entry(struct Process *proc, struct ltelf *lte, |
| Petr Machata | d1746d1 | 2012-03-27 03:14:14 +0200 | [diff] [blame] | 449 | const char *a_name, GElf_Rela *rela, size_t ndx, |
| Petr Machata | 37d368e | 2012-03-24 04:58:08 +0100 | [diff] [blame] | 450 | struct library_symbol **ret) |
| 451 | { |
| 452 | if (lte->ehdr.e_machine == EM_PPC) |
| 453 | return plt_default; |
| 454 | |
| 455 | /* PPC64. If we have stubs, we return a chain of breakpoint |
| 456 | * sites, one for each stub that corresponds to this PLT |
| 457 | * entry. */ |
| 458 | struct library_symbol *chain = NULL; |
| 459 | struct library_symbol **symp; |
| 460 | for (symp = <e->arch.stubs; *symp != NULL; ) { |
| 461 | struct library_symbol *sym = *symp; |
| 462 | if (strcmp(sym->name, a_name) != 0) { |
| 463 | symp = &(*symp)->next; |
| 464 | continue; |
| 465 | } |
| 466 | |
| 467 | /* Re-chain the symbol from stubs to CHAIN. */ |
| 468 | *symp = sym->next; |
| 469 | sym->next = chain; |
| 470 | chain = sym; |
| 471 | } |
| 472 | |
| 473 | if (chain != NULL) { |
| Petr Machata | 37d368e | 2012-03-24 04:58:08 +0100 | [diff] [blame] | 474 | *ret = chain; |
| 475 | return plt_ok; |
| 476 | } |
| 477 | |
| Petr Machata | b64b5c7 | 2012-03-27 03:19:42 +0200 | [diff] [blame] | 478 | /* We don't have stub symbols. Find corresponding .plt slot, |
| 479 | * and check whether it contains the corresponding PLT address |
| 480 | * (or 0 if the dynamic linker hasn't run yet). N.B. we don't |
| 481 | * want read this from ELF file, but from process image. That |
| 482 | * makes a difference if we are attaching to a running |
| 483 | * process. */ |
| 484 | |
| 485 | GElf_Addr plt_entry_addr = arch_plt_sym_val(lte, ndx, rela); |
| 486 | GElf_Addr plt_slot_addr = rela->r_offset; |
| 487 | assert(plt_slot_addr >= lte->plt_addr |
| 488 | || plt_slot_addr < lte->plt_addr + lte->plt_size); |
| 489 | |
| Petr Machata | 58b2d0f | 2012-03-28 02:19:20 +0200 | [diff] [blame] | 490 | GElf_Addr plt_slot_value; |
| 491 | if (read_plt_slot_value(proc, plt_slot_addr, &plt_slot_value) < 0) |
| Petr Machata | b64b5c7 | 2012-03-27 03:19:42 +0200 | [diff] [blame] | 492 | return plt_fail; |
| Petr Machata | b64b5c7 | 2012-03-27 03:19:42 +0200 | [diff] [blame] | 493 | |
| 494 | char *name = strdup(a_name); |
| 495 | struct library_symbol *libsym = malloc(sizeof(*libsym)); |
| 496 | if (name == NULL || libsym == NULL) { |
| 497 | error(0, errno, "allocation for .plt slot"); |
| 498 | fail: |
| 499 | free(name); |
| 500 | free(libsym); |
| 501 | return plt_fail; |
| 502 | } |
| 503 | |
| Petr Machata | ea8eb9a | 2012-04-17 01:32:07 +0200 | [diff] [blame] | 504 | /* XXX The double cast should be removed when |
| 505 | * target_address_t becomes integral type. */ |
| 506 | if (library_symbol_init(libsym, |
| 507 | (target_address_t)(uintptr_t)plt_entry_addr, |
| Petr Machata | e8d9076 | 2012-04-15 04:28:31 +0200 | [diff] [blame] | 508 | name, 1, LS_TOPLT_EXEC) < 0) |
| 509 | goto fail; |
| Petr Machata | 58b2d0f | 2012-03-28 02:19:20 +0200 | [diff] [blame] | 510 | libsym->arch.plt_slot_addr = plt_slot_addr; |
| 511 | |
| 512 | if (plt_slot_value == plt_entry_addr || plt_slot_value == 0) { |
| Petr Machata | b64b5c7 | 2012-03-27 03:19:42 +0200 | [diff] [blame] | 513 | libsym->arch.type = PPC64PLT_UNRESOLVED; |
| Petr Machata | 58b2d0f | 2012-03-28 02:19:20 +0200 | [diff] [blame] | 514 | libsym->arch.resolved_value = plt_entry_addr; |
| 515 | |
| Petr Machata | b64b5c7 | 2012-03-27 03:19:42 +0200 | [diff] [blame] | 516 | } else { |
| 517 | /* Unresolve the .plt slot. If the binary was |
| 518 | * prelinked, this makes the code invalid, because in |
| 519 | * case of prelinked binary, the dynamic linker |
| 520 | * doesn't update .plt[0] and .plt[1] with addresses |
| 521 | * of the resover. But we don't care, we will never |
| 522 | * need to enter the resolver. That just means that |
| 523 | * we have to un-un-resolve this back before we |
| Petr Machata | 19c0f29 | 2012-04-15 19:09:02 +0200 | [diff] [blame] | 524 | * detach. */ |
| Petr Machata | 58b2d0f | 2012-03-28 02:19:20 +0200 | [diff] [blame] | 525 | |
| Petr Machata | e5ebe21 | 2012-04-15 04:41:13 +0200 | [diff] [blame] | 526 | if (unresolve_plt_slot(proc, plt_slot_addr, plt_entry_addr) < 0) { |
| 527 | library_symbol_destroy(libsym); |
| Petr Machata | b64b5c7 | 2012-03-27 03:19:42 +0200 | [diff] [blame] | 528 | goto fail; |
| Petr Machata | e5ebe21 | 2012-04-15 04:41:13 +0200 | [diff] [blame] | 529 | } |
| Petr Machata | b64b5c7 | 2012-03-27 03:19:42 +0200 | [diff] [blame] | 530 | libsym->arch.type = PPC64PLT_RESOLVED; |
| Petr Machata | 58b2d0f | 2012-03-28 02:19:20 +0200 | [diff] [blame] | 531 | libsym->arch.resolved_value = plt_slot_value; |
| Petr Machata | b64b5c7 | 2012-03-27 03:19:42 +0200 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | *ret = libsym; |
| 535 | return plt_ok; |
| Petr Machata | 37d368e | 2012-03-24 04:58:08 +0100 | [diff] [blame] | 536 | } |
| 537 | |
| Petr Machata | 4d9a91c | 2012-03-24 04:55:03 +0100 | [diff] [blame] | 538 | void |
| 539 | arch_elf_destroy(struct ltelf *lte) |
| 540 | { |
| Petr Machata | 37d368e | 2012-03-24 04:58:08 +0100 | [diff] [blame] | 541 | struct library_symbol *sym; |
| 542 | for (sym = lte->arch.stubs; sym != NULL; ) { |
| 543 | struct library_symbol *next = sym->next; |
| 544 | library_symbol_destroy(sym); |
| 545 | free(sym); |
| 546 | sym = next; |
| 547 | } |
| Petr Machata | 4d9a91c | 2012-03-24 04:55:03 +0100 | [diff] [blame] | 548 | } |
| Petr Machata | b64b5c7 | 2012-03-27 03:19:42 +0200 | [diff] [blame] | 549 | |
| Petr Machata | 6b31418 | 2012-04-15 04:40:45 +0200 | [diff] [blame] | 550 | static void |
| 551 | dl_plt_update_bp_on_hit(struct breakpoint *bp, struct Process *proc) |
| 552 | { |
| 553 | struct process_stopping_handler *self = proc->arch.handler; |
| 554 | assert(self != NULL); |
| 555 | |
| 556 | struct library_symbol *libsym = self->breakpoint_being_enabled->libsym; |
| 557 | GElf_Addr value; |
| 558 | if (read_plt_slot_value(proc, libsym->arch.plt_slot_addr, &value) < 0) |
| 559 | return; |
| 560 | |
| Petr Machata | 72b5ee8 | 2012-04-17 13:44:06 +0200 | [diff] [blame^] | 561 | unresolve_plt_slot(proc, libsym->arch.plt_slot_addr, |
| 562 | libsym->arch.resolved_value); |
| 563 | |
| Petr Machata | 6b31418 | 2012-04-15 04:40:45 +0200 | [diff] [blame] | 564 | /* cb_on_all_stopped looks if HANDLER is set to NULL as a way |
| 565 | * to check that this was run. It's an error if it |
| 566 | * wasn't. */ |
| 567 | breakpoint_turn_off(bp, proc); |
| 568 | proc->arch.handler = NULL; |
| 569 | } |
| 570 | |
| 571 | static void |
| 572 | cb_on_all_stopped(struct process_stopping_handler *self) |
| 573 | { |
| 574 | /* Put that in for dl_plt_update_bp_on_hit to see. */ |
| 575 | assert(self->task_enabling_breakpoint->arch.handler == NULL); |
| 576 | self->task_enabling_breakpoint->arch.handler = self; |
| 577 | |
| 578 | linux_ptrace_disable_and_continue(self); |
| 579 | } |
| 580 | |
| Petr Machata | 58b2d0f | 2012-03-28 02:19:20 +0200 | [diff] [blame] | 581 | static enum callback_status |
| Petr Machata | 6b31418 | 2012-04-15 04:40:45 +0200 | [diff] [blame] | 582 | cb_keep_stepping_p(struct process_stopping_handler *self) |
| Petr Machata | b64b5c7 | 2012-03-27 03:19:42 +0200 | [diff] [blame] | 583 | { |
| Petr Machata | 58b2d0f | 2012-03-28 02:19:20 +0200 | [diff] [blame] | 584 | struct Process *proc = self->task_enabling_breakpoint; |
| 585 | struct library_symbol *libsym = self->breakpoint_being_enabled->libsym; |
| 586 | GElf_Addr value; |
| 587 | if (read_plt_slot_value(proc, libsym->arch.plt_slot_addr, &value) < 0) |
| 588 | return CBS_FAIL; |
| 589 | |
| 590 | /* In UNRESOLVED state, the RESOLVED_VALUE in fact contains |
| 591 | * the PLT entry value. */ |
| 592 | if (value == libsym->arch.resolved_value) |
| 593 | return CBS_CONT; |
| 594 | |
| 595 | /* The .plt slot got resolved! We can migrate the breakpoint |
| 596 | * to RESOLVED and stop single-stepping. */ |
| 597 | if (unresolve_plt_slot(proc, libsym->arch.plt_slot_addr, |
| 598 | libsym->arch.resolved_value) < 0) |
| 599 | return CBS_FAIL; |
| Petr Machata | 6b31418 | 2012-04-15 04:40:45 +0200 | [diff] [blame] | 600 | |
| 601 | /* Install breakpoint to the address where the change takes |
| 602 | * place. If we fail, then that just means that we'll have to |
| 603 | * singlestep the next time around as well. */ |
| 604 | struct Process *leader = proc->leader; |
| 605 | if (leader == NULL || leader->arch.dl_plt_update_bp != NULL) |
| 606 | goto resolve; |
| 607 | |
| 608 | /* We need to install to the next instruction. ADDR points to |
| 609 | * a store instruction, so moving the breakpoint one |
| 610 | * instruction forward is safe. */ |
| 611 | target_address_t addr = get_instruction_pointer(proc) + 4; |
| 612 | leader->arch.dl_plt_update_bp = insert_breakpoint(proc, addr, NULL); |
| 613 | |
| 614 | /* Turn it off for now. We will turn it on again when we hit |
| 615 | * the PLT entry that needs this. */ |
| 616 | breakpoint_turn_off(leader->arch.dl_plt_update_bp, proc); |
| 617 | |
| 618 | if (leader->arch.dl_plt_update_bp != NULL) { |
| 619 | static struct bp_callbacks dl_plt_update_cbs = { |
| 620 | .on_hit = dl_plt_update_bp_on_hit, |
| 621 | }; |
| 622 | leader->arch.dl_plt_update_bp->cbs = &dl_plt_update_cbs; |
| 623 | } |
| 624 | |
| 625 | resolve: |
| Petr Machata | 58b2d0f | 2012-03-28 02:19:20 +0200 | [diff] [blame] | 626 | libsym->arch.type = PPC64PLT_RESOLVED; |
| 627 | libsym->arch.resolved_value = value; |
| 628 | |
| 629 | return CBS_STOP; |
| Petr Machata | b64b5c7 | 2012-03-27 03:19:42 +0200 | [diff] [blame] | 630 | } |
| 631 | |
| Petr Machata | 58b2d0f | 2012-03-28 02:19:20 +0200 | [diff] [blame] | 632 | static void |
| 633 | ppc64_plt_bp_continue(struct breakpoint *bp, struct Process *proc) |
| 634 | { |
| Petr Machata | 58b2d0f | 2012-03-28 02:19:20 +0200 | [diff] [blame] | 635 | switch (bp->libsym->arch.type) { |
| 636 | target_address_t rv; |
| Petr Machata | 6b31418 | 2012-04-15 04:40:45 +0200 | [diff] [blame] | 637 | struct Process *leader; |
| 638 | void (*on_all_stopped)(struct process_stopping_handler *); |
| 639 | enum callback_status (*keep_stepping_p) |
| 640 | (struct process_stopping_handler *); |
| 641 | |
| Petr Machata | 58b2d0f | 2012-03-28 02:19:20 +0200 | [diff] [blame] | 642 | case PPC64PLT_UNRESOLVED: |
| Petr Machata | 6b31418 | 2012-04-15 04:40:45 +0200 | [diff] [blame] | 643 | on_all_stopped = NULL; |
| 644 | keep_stepping_p = NULL; |
| 645 | leader = proc->leader; |
| 646 | |
| Petr Machata | 05058b7 | 2012-04-17 01:33:03 +0200 | [diff] [blame] | 647 | if (leader != NULL && leader->arch.dl_plt_update_bp != NULL |
| 648 | && breakpoint_turn_on(leader->arch.dl_plt_update_bp, |
| 649 | proc) >= 0) |
| Petr Machata | 6b31418 | 2012-04-15 04:40:45 +0200 | [diff] [blame] | 650 | on_all_stopped = cb_on_all_stopped; |
| Petr Machata | 05058b7 | 2012-04-17 01:33:03 +0200 | [diff] [blame] | 651 | else |
| Petr Machata | 6b31418 | 2012-04-15 04:40:45 +0200 | [diff] [blame] | 652 | keep_stepping_p = cb_keep_stepping_p; |
| Petr Machata | 6b31418 | 2012-04-15 04:40:45 +0200 | [diff] [blame] | 653 | |
| 654 | if (process_install_stopping_handler |
| 655 | (proc, bp, on_all_stopped, keep_stepping_p, NULL) < 0) { |
| Petr Machata | 58b2d0f | 2012-03-28 02:19:20 +0200 | [diff] [blame] | 656 | perror("ppc64_unresolved_bp_continue: couldn't install" |
| 657 | " event handler"); |
| 658 | continue_after_breakpoint(proc, bp); |
| 659 | } |
| 660 | return; |
| 661 | |
| 662 | case PPC64PLT_RESOLVED: |
| Petr Machata | ea8eb9a | 2012-04-17 01:32:07 +0200 | [diff] [blame] | 663 | /* XXX The double cast should be removed when |
| 664 | * target_address_t becomes integral type. */ |
| 665 | rv = (target_address_t) |
| 666 | (uintptr_t)bp->libsym->arch.resolved_value; |
| Petr Machata | 58b2d0f | 2012-03-28 02:19:20 +0200 | [diff] [blame] | 667 | set_instruction_pointer(proc, rv); |
| 668 | continue_process(proc->pid); |
| Petr Machata | 5096962 | 2012-04-06 16:06:26 +0200 | [diff] [blame] | 669 | return; |
| 670 | |
| Petr Machata | fbd9742 | 2012-04-16 21:09:18 +0200 | [diff] [blame] | 671 | case PPC_DEFAULT: |
| Petr Machata | 5096962 | 2012-04-06 16:06:26 +0200 | [diff] [blame] | 672 | case PPC64PLT_STUB: |
| Petr Machata | fbd9742 | 2012-04-16 21:09:18 +0200 | [diff] [blame] | 673 | /* These should never hit here. */ |
| Petr Machata | 5096962 | 2012-04-06 16:06:26 +0200 | [diff] [blame] | 674 | break; |
| Petr Machata | 58b2d0f | 2012-03-28 02:19:20 +0200 | [diff] [blame] | 675 | } |
| Petr Machata | 5096962 | 2012-04-06 16:06:26 +0200 | [diff] [blame] | 676 | |
| 677 | assert(bp->libsym->arch.type != bp->libsym->arch.type); |
| 678 | abort(); |
| Petr Machata | 58b2d0f | 2012-03-28 02:19:20 +0200 | [diff] [blame] | 679 | } |
| 680 | |
| Petr Machata | d957332 | 2012-04-17 05:21:02 +0200 | [diff] [blame] | 681 | void |
| 682 | arch_library_init(struct library *lib) |
| 683 | { |
| 684 | } |
| 685 | |
| 686 | void |
| 687 | arch_library_destroy(struct library *lib) |
| 688 | { |
| 689 | } |
| 690 | |
| 691 | void |
| 692 | arch_library_clone(struct library *retp, struct library *lib) |
| 693 | { |
| 694 | } |
| 695 | |
| Petr Machata | 24c6e9d | 2012-04-15 04:31:34 +0200 | [diff] [blame] | 696 | int |
| 697 | arch_library_symbol_init(struct library_symbol *libsym) |
| 698 | { |
| 699 | /* We set type explicitly in the code above, where we have the |
| 700 | * necessary context. This is for calls from ltrace-elf.c and |
| 701 | * such. */ |
| Petr Machata | fbd9742 | 2012-04-16 21:09:18 +0200 | [diff] [blame] | 702 | libsym->arch.type = PPC_DEFAULT; |
| Petr Machata | 24c6e9d | 2012-04-15 04:31:34 +0200 | [diff] [blame] | 703 | return 0; |
| 704 | } |
| 705 | |
| 706 | void |
| 707 | arch_library_symbol_destroy(struct library_symbol *libsym) |
| 708 | { |
| 709 | } |
| 710 | |
| 711 | int |
| 712 | arch_library_symbol_clone(struct library_symbol *retp, |
| 713 | struct library_symbol *libsym) |
| 714 | { |
| 715 | retp->arch = libsym->arch; |
| 716 | return 0; |
| 717 | } |
| 718 | |
| Petr Machata | 52dbfb1 | 2012-03-29 16:38:26 +0200 | [diff] [blame] | 719 | /* For some symbol types, we need to set up custom callbacks. XXX we |
| 720 | * don't need PROC here, we can store the data in BP if it is of |
| 721 | * interest to us. */ |
| Petr Machata | b64b5c7 | 2012-03-27 03:19:42 +0200 | [diff] [blame] | 722 | int |
| 723 | arch_breakpoint_init(struct Process *proc, struct breakpoint *bp) |
| 724 | { |
| 725 | if (proc->e_machine == EM_PPC |
| Petr Machata | 052b5f1 | 2012-04-06 14:53:07 +0200 | [diff] [blame] | 726 | || bp->libsym == NULL) |
| 727 | return 0; |
| 728 | |
| Petr Machata | fbd9742 | 2012-04-16 21:09:18 +0200 | [diff] [blame] | 729 | /* Entry point breakpoints (LS_TOPLT_NONE) and stub PLT |
| 730 | * breakpoints need no special handling. */ |
| Petr Machata | 052b5f1 | 2012-04-06 14:53:07 +0200 | [diff] [blame] | 731 | if (bp->libsym->plt_type != LS_TOPLT_EXEC |
| Petr Machata | b64b5c7 | 2012-03-27 03:19:42 +0200 | [diff] [blame] | 732 | || bp->libsym->arch.type == PPC64PLT_STUB) |
| 733 | return 0; |
| 734 | |
| Petr Machata | 58b2d0f | 2012-03-28 02:19:20 +0200 | [diff] [blame] | 735 | static struct bp_callbacks cbs = { |
| 736 | .on_continue = ppc64_plt_bp_continue, |
| 737 | }; |
| 738 | breakpoint_set_callbacks(bp, &cbs); |
| Petr Machata | b64b5c7 | 2012-03-27 03:19:42 +0200 | [diff] [blame] | 739 | return 0; |
| 740 | } |
| 741 | |
| 742 | void |
| 743 | arch_breakpoint_destroy(struct breakpoint *bp) |
| 744 | { |
| 745 | } |
| Petr Machata | d3cc988 | 2012-04-13 21:40:23 +0200 | [diff] [blame] | 746 | |
| 747 | int |
| 748 | arch_breakpoint_clone(struct breakpoint *retp, struct breakpoint *sbp) |
| 749 | { |
| 750 | retp->arch = sbp->arch; |
| 751 | return 0; |
| 752 | } |
| Petr Machata | 6b31418 | 2012-04-15 04:40:45 +0200 | [diff] [blame] | 753 | |
| 754 | int |
| 755 | arch_process_init(struct Process *proc) |
| 756 | { |
| 757 | proc->arch.dl_plt_update_bp = NULL; |
| 758 | proc->arch.handler = NULL; |
| 759 | return 0; |
| 760 | } |
| 761 | |
| 762 | void |
| 763 | arch_process_destroy(struct Process *proc) |
| 764 | { |
| 765 | } |
| 766 | |
| 767 | int |
| 768 | arch_process_clone(struct Process *retp, struct Process *proc) |
| 769 | { |
| 770 | retp->arch = proc->arch; |
| 771 | return 0; |
| 772 | } |
| 773 | |
| 774 | int |
| 775 | arch_process_exec(struct Process *proc) |
| 776 | { |
| 777 | return arch_process_init(proc); |
| 778 | } |