blob: 1b97705d920323bede8bf0d962b45b49c5e97ac0 [file] [log] [blame]
Petr Machatae99af272012-10-26 00:29:52 +02001/*
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 Cespedesd914a202004-11-10 00:15:33 +010022#include <gelf.h>
Petr Machatac0ab2862012-05-05 00:06:17 +020023
Petr Machata366c2f42012-02-09 19:34:36 +010024#include "proc.h"
Petr Machatac0ab2862012-05-05 00:06:17 +020025#include "library.h"
26#include "ltrace-elf.h"
Juan Cespedesd914a202004-11-10 00:15:33 +010027
Zach Welchd568f512010-10-08 14:44:16 -070028static 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
Juan Cespedesf1350522008-12-16 18:19:58 +010034GElf_Addr
35arch_plt_sym_val(struct ltelf *lte, size_t ndx, GElf_Rela * rela) {
Zach Welchd568f512010-10-08 14:44:16 -070036 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 Wienand9a2ad352006-02-20 22:44:45 +010043}
44
Juan Cespedesf1350522008-12-16 18:19:58 +010045void *
Juan Cespedesa8909f72009-04-28 20:02:41 +020046sym2addr(Process *proc, struct library_symbol *sym) {
Paul Gilliam76c61f12006-06-14 06:55:21 +020047 return sym->enter_addr;
Juan Cespedesd914a202004-11-10 00:15:33 +010048}