| Petr Machata | e99af27 | 2012-10-26 00:29:52 +0200 | [diff] [blame^] | 1 | /* |
| 2 | * This file is part of ltrace. |
| 3 | * Copyright (C) 2010 Zach Welch, CodeSourcery |
| 4 | * Copyright (C) 2004,2008,2009 Juan Cespedes |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License as |
| 8 | * published by the Free Software Foundation; either version 2 of the |
| 9 | * License, or (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, but |
| 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA |
| 19 | * 02110-1301 USA |
| 20 | */ |
| 21 | |
| Juan Cespedes | d914a20 | 2004-11-10 00:15:33 +0100 | [diff] [blame] | 22 | #include <gelf.h> |
| Petr Machata | c0ab286 | 2012-05-05 00:06:17 +0200 | [diff] [blame] | 23 | |
| Petr Machata | 366c2f4 | 2012-02-09 19:34:36 +0100 | [diff] [blame] | 24 | #include "proc.h" |
| Petr Machata | c0ab286 | 2012-05-05 00:06:17 +0200 | [diff] [blame] | 25 | #include "library.h" |
| 26 | #include "ltrace-elf.h" |
| Juan Cespedes | d914a20 | 2004-11-10 00:15:33 +0100 | [diff] [blame] | 27 | |
| Zach Welch | d568f51 | 2010-10-08 14:44:16 -0700 | [diff] [blame] | 28 | static int |
| 29 | arch_plt_entry_has_stub(struct ltelf *lte, size_t off) { |
| 30 | uint16_t op = *(uint16_t *)((char *)lte->relplt->d_buf + off); |
| 31 | return op == 0x4778; |
| 32 | } |
| 33 | |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 34 | GElf_Addr |
| 35 | arch_plt_sym_val(struct ltelf *lte, size_t ndx, GElf_Rela * rela) { |
| Zach Welch | d568f51 | 2010-10-08 14:44:16 -0700 | [diff] [blame] | 36 | size_t start = lte->relplt->d_size + 12; |
| 37 | size_t off = start + 20, i; |
| 38 | for (i = 0; i < ndx; i++) |
| 39 | off += arch_plt_entry_has_stub(lte, off) ? 16 : 12; |
| 40 | if (arch_plt_entry_has_stub(lte, off)) |
| 41 | off += 4; |
| 42 | return lte->plt_addr + off - start; |
| Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame] | 43 | } |
| 44 | |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 45 | void * |
| Juan Cespedes | a8909f7 | 2009-04-28 20:02:41 +0200 | [diff] [blame] | 46 | sym2addr(Process *proc, struct library_symbol *sym) { |
| Paul Gilliam | 76c61f1 | 2006-06-14 06:55:21 +0200 | [diff] [blame] | 47 | return sym->enter_addr; |
| Juan Cespedes | d914a20 | 2004-11-10 00:15:33 +0100 | [diff] [blame] | 48 | } |