plt.c revision 929bd57ca202fd2f2e8485ebf65d683e664f67b5
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 22#include <gelf.h> 23 24#include "proc.h" 25#include "library.h" 26#include "ltrace-elf.h" 27 28static int 29arch_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 34GElf_Addr 35arch_plt_sym_val(struct ltelf *lte, size_t ndx, GElf_Rela * rela) { 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; 43} 44 45void * 46sym2addr(struct process *proc, struct library_symbol *sym) 47{ 48 return sym->enter_addr; 49} 50