| Petr Machata | 6426260 | 2012-01-07 03:41:36 +0100 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of ltrace. |
| 3 | * Copyright (C) 2006,2010,2011,2012 Petr Machata, Red Hat Inc. |
| 4 | * Copyright (C) 2010 Zachary T Welch, CodeSourcery |
| 5 | * Copyright (C) 2010 Joe Damato |
| 6 | * Copyright (C) 1997,1998,2001,2004,2007,2008,2009 Juan Cespedes |
| 7 | * Copyright (C) 2006 Olaf Hering, SUSE Linux GmbH |
| 8 | * Copyright (C) 2006 Eric Vaitl, Cisco Systems, Inc. |
| 9 | * Copyright (C) 2006 Paul Gilliam, IBM Corporation |
| 10 | * Copyright (C) 2006 Ian Wienand |
| 11 | * |
| 12 | * This program is free software; you can redistribute it and/or |
| 13 | * modify it under the terms of the GNU General Public License as |
| 14 | * published by the Free Software Foundation; either version 2 of the |
| 15 | * License, or (at your option) any later version. |
| 16 | * |
| 17 | * This program is distributed in the hope that it will be useful, but |
| 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 20 | * General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License |
| 23 | * along with this program; if not, write to the Free Software |
| 24 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA |
| 25 | * 02110-1301 USA |
| 26 | */ |
| 27 | |
| Joe Damato | f0bd98b | 2010-11-08 15:47:42 -0800 | [diff] [blame] | 28 | #include "config.h" |
| Juan Cespedes | d44c6b8 | 1998-09-25 14:48:42 +0200 | [diff] [blame] | 29 | |
| Petr Machata | 157cc4d | 2012-04-04 19:00:34 +0200 | [diff] [blame] | 30 | #include <assert.h> |
| Andrey Zonov | 9d878c9 | 2012-08-05 00:19:51 +0400 | [diff] [blame] | 31 | #ifdef __linux__ |
| Juan Cespedes | d914a20 | 2004-11-10 00:15:33 +0100 | [diff] [blame] | 32 | #include <endian.h> |
| Andrey Zonov | 9d878c9 | 2012-08-05 00:19:51 +0400 | [diff] [blame] | 33 | #endif |
| Juan Cespedes | 96935a9 | 1997-08-09 23:45:39 +0200 | [diff] [blame] | 34 | #include <errno.h> |
| Juan Cespedes | 96935a9 | 1997-08-09 23:45:39 +0200 | [diff] [blame] | 35 | #include <fcntl.h> |
| Juan Cespedes | d914a20 | 2004-11-10 00:15:33 +0100 | [diff] [blame] | 36 | #include <gelf.h> |
| Zachary T Welch | bfb26c7 | 2010-12-06 23:21:00 -0800 | [diff] [blame] | 37 | #include <inttypes.h> |
| Petr Machata | 157cc4d | 2012-04-04 19:00:34 +0200 | [diff] [blame] | 38 | #include <search.h> |
| Juan Cespedes | d914a20 | 2004-11-10 00:15:33 +0100 | [diff] [blame] | 39 | #include <stdint.h> |
| Petr Machata | cc0e1e4 | 2012-04-25 13:42:07 +0200 | [diff] [blame] | 40 | #include <stdio.h> |
| Juan Cespedes | d914a20 | 2004-11-10 00:15:33 +0100 | [diff] [blame] | 41 | #include <stdlib.h> |
| Juan Cespedes | 96935a9 | 1997-08-09 23:45:39 +0200 | [diff] [blame] | 42 | #include <string.h> |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 43 | #include <unistd.h> |
| Juan Cespedes | 96935a9 | 1997-08-09 23:45:39 +0200 | [diff] [blame] | 44 | |
| Petr Machata | 6426260 | 2012-01-07 03:41:36 +0100 | [diff] [blame] | 45 | #include "backend.h" |
| Petr Machata | ba1664b | 2012-04-28 14:59:05 +0200 | [diff] [blame] | 46 | #include "filter.h" |
| 47 | #include "library.h" |
| 48 | #include "ltrace-elf.h" |
| 49 | #include "proc.h" |
| 50 | #include "debug.h" |
| 51 | #include "options.h" |
| Joe Damato | f0bd98b | 2010-11-08 15:47:42 -0800 | [diff] [blame] | 52 | |
| Petr Machata | e67635d | 2012-03-21 03:37:39 +0100 | [diff] [blame] | 53 | #ifndef ARCH_HAVE_LTELF_DATA |
| 54 | int |
| Petr Machata | e0615ab | 2012-04-17 05:17:48 +0200 | [diff] [blame] | 55 | arch_elf_init(struct ltelf *lte, struct library *lib) |
| Petr Machata | e67635d | 2012-03-21 03:37:39 +0100 | [diff] [blame] | 56 | { |
| 57 | return 0; |
| 58 | } |
| Petr Machata | c67a6e6 | 2012-03-28 02:39:49 +0200 | [diff] [blame] | 59 | |
| 60 | void |
| 61 | arch_elf_destroy(struct ltelf *lte) |
| 62 | { |
| 63 | } |
| Petr Machata | e67635d | 2012-03-21 03:37:39 +0100 | [diff] [blame] | 64 | #endif |
| 65 | |
| Petr Machata | 8bda1ee | 2012-09-26 01:52:23 +0200 | [diff] [blame] | 66 | static int |
| Petr Machata | e6523e6 | 2012-03-24 04:54:06 +0100 | [diff] [blame] | 67 | default_elf_add_plt_entry(struct Process *proc, struct ltelf *lte, |
| Petr Machata | 1be2291 | 2012-03-27 03:11:33 +0200 | [diff] [blame] | 68 | const char *a_name, GElf_Rela *rela, size_t ndx, |
| Petr Machata | e6523e6 | 2012-03-24 04:54:06 +0100 | [diff] [blame] | 69 | struct library_symbol **ret) |
| 70 | { |
| 71 | char *name = strdup(a_name); |
| 72 | if (name == NULL) { |
| 73 | fail: |
| 74 | free(name); |
| 75 | return -1; |
| 76 | } |
| 77 | |
| Petr Machata | 1be2291 | 2012-03-27 03:11:33 +0200 | [diff] [blame] | 78 | GElf_Addr addr = arch_plt_sym_val(lte, ndx, rela); |
| Petr Machata | e6523e6 | 2012-03-24 04:54:06 +0100 | [diff] [blame] | 79 | |
| 80 | struct library_symbol *libsym = malloc(sizeof(*libsym)); |
| 81 | if (libsym == NULL) |
| 82 | goto fail; |
| 83 | |
| Petr Machata | ea8eb9a | 2012-04-17 01:32:07 +0200 | [diff] [blame] | 84 | /* XXX The double cast should be removed when |
| Petr Machata | bac2da5 | 2012-05-29 00:42:59 +0200 | [diff] [blame] | 85 | * arch_addr_t becomes integral type. */ |
| 86 | arch_addr_t taddr = (arch_addr_t) |
| Petr Machata | ea8eb9a | 2012-04-17 01:32:07 +0200 | [diff] [blame] | 87 | (uintptr_t)(addr + lte->bias); |
| Petr Machata | bb79060 | 2012-03-25 01:41:59 +0100 | [diff] [blame] | 88 | |
| Petr Machata | e8d9076 | 2012-04-15 04:28:31 +0200 | [diff] [blame] | 89 | if (library_symbol_init(libsym, taddr, name, 1, LS_TOPLT_EXEC) < 0) { |
| 90 | free(libsym); |
| 91 | goto fail; |
| 92 | } |
| 93 | |
| Petr Machata | 0fa7904 | 2012-09-27 23:33:44 +0200 | [diff] [blame] | 94 | libsym->next = *ret; |
| Petr Machata | e6523e6 | 2012-03-24 04:54:06 +0100 | [diff] [blame] | 95 | *ret = libsym; |
| 96 | return 0; |
| 97 | } |
| 98 | |
| 99 | #ifndef ARCH_HAVE_ADD_PLT_ENTRY |
| 100 | enum plt_status |
| 101 | arch_elf_add_plt_entry(struct Process *proc, struct ltelf *lte, |
| Petr Machata | 1be2291 | 2012-03-27 03:11:33 +0200 | [diff] [blame] | 102 | const char *a_name, GElf_Rela *rela, size_t ndx, |
| Petr Machata | e6523e6 | 2012-03-24 04:54:06 +0100 | [diff] [blame] | 103 | struct library_symbol **ret) |
| 104 | { |
| 105 | return plt_default; |
| 106 | } |
| 107 | #endif |
| 108 | |
| Petr Machata | e67635d | 2012-03-21 03:37:39 +0100 | [diff] [blame] | 109 | Elf_Data * |
| 110 | elf_loaddata(Elf_Scn *scn, GElf_Shdr *shdr) |
| Petr Machata | fe1c171 | 2010-10-27 16:57:34 +0200 | [diff] [blame] | 111 | { |
| 112 | Elf_Data *data = elf_getdata(scn, NULL); |
| 113 | if (data == NULL || elf_getdata(scn, data) != NULL |
| 114 | || data->d_off || data->d_size != shdr->sh_size) |
| 115 | return NULL; |
| 116 | return data; |
| 117 | } |
| 118 | |
| Petr Machata | e67635d | 2012-03-21 03:37:39 +0100 | [diff] [blame] | 119 | static int |
| Petr Machata | ffd5aab | 2012-03-24 02:03:33 +0100 | [diff] [blame] | 120 | elf_get_section_if(struct ltelf *lte, Elf_Scn **tgt_sec, GElf_Shdr *tgt_shdr, |
| 121 | int (*predicate)(Elf_Scn *, GElf_Shdr *, void *data), |
| 122 | void *data) |
| Petr Machata | fe1c171 | 2010-10-27 16:57:34 +0200 | [diff] [blame] | 123 | { |
| 124 | int i; |
| 125 | for (i = 1; i < lte->ehdr.e_shnum; ++i) { |
| 126 | Elf_Scn *scn; |
| 127 | GElf_Shdr shdr; |
| 128 | |
| 129 | scn = elf_getscn(lte->elf, i); |
| 130 | if (scn == NULL || gelf_getshdr(scn, &shdr) == NULL) { |
| 131 | debug(1, "Couldn't read section or header."); |
| Petr Machata | e67635d | 2012-03-21 03:37:39 +0100 | [diff] [blame] | 132 | return -1; |
| 133 | } |
| Petr Machata | ffd5aab | 2012-03-24 02:03:33 +0100 | [diff] [blame] | 134 | if (predicate(scn, &shdr, data)) { |
| 135 | *tgt_sec = scn; |
| 136 | *tgt_shdr = shdr; |
| Petr Machata | fe1c171 | 2010-10-27 16:57:34 +0200 | [diff] [blame] | 137 | return 0; |
| Petr Machata | ffd5aab | 2012-03-24 02:03:33 +0100 | [diff] [blame] | 138 | } |
| Petr Machata | fe1c171 | 2010-10-27 16:57:34 +0200 | [diff] [blame] | 139 | } |
| Petr Machata | e67635d | 2012-03-21 03:37:39 +0100 | [diff] [blame] | 140 | return -1; |
| Petr Machata | ffd5aab | 2012-03-24 02:03:33 +0100 | [diff] [blame] | 141 | |
| 142 | } |
| 143 | |
| 144 | static int |
| 145 | inside_p(Elf_Scn *scn, GElf_Shdr *shdr, void *data) |
| 146 | { |
| 147 | GElf_Addr addr = *(GElf_Addr *)data; |
| 148 | return addr >= shdr->sh_addr |
| 149 | && addr < shdr->sh_addr + shdr->sh_size; |
| 150 | } |
| 151 | |
| 152 | int |
| 153 | elf_get_section_covering(struct ltelf *lte, GElf_Addr addr, |
| 154 | Elf_Scn **tgt_sec, GElf_Shdr *tgt_shdr) |
| 155 | { |
| 156 | return elf_get_section_if(lte, tgt_sec, tgt_shdr, |
| 157 | &inside_p, &addr); |
| 158 | } |
| 159 | |
| 160 | static int |
| 161 | type_p(Elf_Scn *scn, GElf_Shdr *shdr, void *data) |
| 162 | { |
| 163 | GElf_Word type = *(GElf_Word *)data; |
| 164 | return shdr->sh_type == type; |
| 165 | } |
| 166 | |
| 167 | int |
| 168 | elf_get_section_type(struct ltelf *lte, GElf_Word type, |
| 169 | Elf_Scn **tgt_sec, GElf_Shdr *tgt_shdr) |
| 170 | { |
| 171 | return elf_get_section_if(lte, tgt_sec, tgt_shdr, |
| 172 | &type_p, &type); |
| Petr Machata | e67635d | 2012-03-21 03:37:39 +0100 | [diff] [blame] | 173 | } |
| 174 | |
| Petr Machata | 5b3e26a | 2012-04-30 20:53:22 +0200 | [diff] [blame] | 175 | struct section_named_data { |
| 176 | struct ltelf *lte; |
| 177 | const char *name; |
| 178 | }; |
| 179 | |
| 180 | static int |
| 181 | name_p(Elf_Scn *scn, GElf_Shdr *shdr, void *d) |
| 182 | { |
| 183 | struct section_named_data *data = d; |
| 184 | const char *name = elf_strptr(data->lte->elf, |
| 185 | data->lte->ehdr.e_shstrndx, |
| 186 | shdr->sh_name); |
| 187 | return strcmp(name, data->name) == 0; |
| 188 | } |
| 189 | |
| 190 | int |
| 191 | elf_get_section_named(struct ltelf *lte, const char *name, |
| 192 | Elf_Scn **tgt_sec, GElf_Shdr *tgt_shdr) |
| 193 | { |
| 194 | struct section_named_data data = { |
| 195 | .lte = lte, |
| 196 | .name = name, |
| 197 | }; |
| 198 | return elf_get_section_if(lte, tgt_sec, tgt_shdr, |
| 199 | &name_p, &data); |
| 200 | } |
| 201 | |
| Petr Machata | e67635d | 2012-03-21 03:37:39 +0100 | [diff] [blame] | 202 | static int |
| Petr Machata | 3a01cd7 | 2012-04-30 20:50:20 +0200 | [diff] [blame] | 203 | need_data(Elf_Data *data, GElf_Xword offset, GElf_Xword size) |
| Petr Machata | e67635d | 2012-03-21 03:37:39 +0100 | [diff] [blame] | 204 | { |
| 205 | assert(data != NULL); |
| 206 | if (data->d_size < size || offset > data->d_size - size) { |
| Petr Machata | a82d322 | 2012-05-01 01:04:27 +0200 | [diff] [blame] | 207 | debug(1, "Not enough data to read %"PRId64"-byte value" |
| 208 | " at offset %"PRId64".", size, offset); |
| Petr Machata | e67635d | 2012-03-21 03:37:39 +0100 | [diff] [blame] | 209 | return -1; |
| 210 | } |
| Petr Machata | fe1c171 | 2010-10-27 16:57:34 +0200 | [diff] [blame] | 211 | return 0; |
| 212 | } |
| 213 | |
| Petr Machata | e67635d | 2012-03-21 03:37:39 +0100 | [diff] [blame] | 214 | #define DEF_READER(NAME, SIZE) \ |
| 215 | int \ |
| Petr Machata | 3a01cd7 | 2012-04-30 20:50:20 +0200 | [diff] [blame] | 216 | NAME(Elf_Data *data, GElf_Xword offset, uint##SIZE##_t *retp) \ |
| Petr Machata | e67635d | 2012-03-21 03:37:39 +0100 | [diff] [blame] | 217 | { \ |
| 218 | if (!need_data(data, offset, SIZE / 8) < 0) \ |
| 219 | return -1; \ |
| 220 | \ |
| Petr Machata | 6d8ccb2 | 2012-03-27 03:11:57 +0200 | [diff] [blame] | 221 | if (data->d_buf == NULL) /* NODATA section */ { \ |
| 222 | *retp = 0; \ |
| 223 | return 0; \ |
| 224 | } \ |
| 225 | \ |
| Petr Machata | e67635d | 2012-03-21 03:37:39 +0100 | [diff] [blame] | 226 | union { \ |
| 227 | uint##SIZE##_t dst; \ |
| 228 | char buf[0]; \ |
| 229 | } u; \ |
| 230 | memcpy(u.buf, data->d_buf + offset, sizeof(u.dst)); \ |
| 231 | *retp = u.dst; \ |
| 232 | return 0; \ |
| Petr Machata | fe1c171 | 2010-10-27 16:57:34 +0200 | [diff] [blame] | 233 | } |
| 234 | |
| Petr Machata | e67635d | 2012-03-21 03:37:39 +0100 | [diff] [blame] | 235 | DEF_READER(elf_read_u16, 16) |
| 236 | DEF_READER(elf_read_u32, 32) |
| 237 | DEF_READER(elf_read_u64, 64) |
| Petr Machata | fe1c171 | 2010-10-27 16:57:34 +0200 | [diff] [blame] | 238 | |
| Petr Machata | e67635d | 2012-03-21 03:37:39 +0100 | [diff] [blame] | 239 | #undef DEF_READER |
| Petr Machata | fe1c171 | 2010-10-27 16:57:34 +0200 | [diff] [blame] | 240 | |
| Petr Machata | 1974dbc | 2011-08-19 18:58:01 +0200 | [diff] [blame] | 241 | int |
| Petr Machata | 02bd9ec | 2011-09-21 17:38:59 +0200 | [diff] [blame] | 242 | open_elf(struct ltelf *lte, const char *filename) |
| 243 | { |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 244 | lte->fd = open(filename, O_RDONLY); |
| 245 | if (lte->fd == -1) |
| Petr Machata | 1974dbc | 2011-08-19 18:58:01 +0200 | [diff] [blame] | 246 | return 1; |
| Juan Cespedes | 96935a9 | 1997-08-09 23:45:39 +0200 | [diff] [blame] | 247 | |
| Petr Machata | 02bd9ec | 2011-09-21 17:38:59 +0200 | [diff] [blame] | 248 | elf_version(EV_CURRENT); |
| 249 | |
| Juan Cespedes | d914a20 | 2004-11-10 00:15:33 +0100 | [diff] [blame] | 250 | #ifdef HAVE_ELF_C_READ_MMAP |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 251 | lte->elf = elf_begin(lte->fd, ELF_C_READ_MMAP, NULL); |
| Juan Cespedes | 5c3fe06 | 2004-06-14 18:08:37 +0200 | [diff] [blame] | 252 | #else |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 253 | lte->elf = elf_begin(lte->fd, ELF_C_READ, NULL); |
| Juan Cespedes | 5c3fe06 | 2004-06-14 18:08:37 +0200 | [diff] [blame] | 254 | #endif |
| Juan Cespedes | 1cd999a | 2001-07-03 00:46:04 +0200 | [diff] [blame] | 255 | |
| Petr Machata | cc0e1e4 | 2012-04-25 13:42:07 +0200 | [diff] [blame] | 256 | if (lte->elf == NULL || elf_kind(lte->elf) != ELF_K_ELF) { |
| 257 | fprintf(stderr, "\"%s\" is not an ELF file\n", filename); |
| 258 | exit(EXIT_FAILURE); |
| 259 | } |
| Juan Cespedes | 1cd999a | 2001-07-03 00:46:04 +0200 | [diff] [blame] | 260 | |
| Petr Machata | cc0e1e4 | 2012-04-25 13:42:07 +0200 | [diff] [blame] | 261 | if (gelf_getehdr(lte->elf, <e->ehdr) == NULL) { |
| 262 | fprintf(stderr, "can't read ELF header of \"%s\": %s\n", |
| 263 | filename, elf_errmsg(-1)); |
| 264 | exit(EXIT_FAILURE); |
| 265 | } |
| Juan Cespedes | 1cd999a | 2001-07-03 00:46:04 +0200 | [diff] [blame] | 266 | |
| Petr Machata | cc0e1e4 | 2012-04-25 13:42:07 +0200 | [diff] [blame] | 267 | if (lte->ehdr.e_type != ET_EXEC && lte->ehdr.e_type != ET_DYN) { |
| 268 | fprintf(stderr, "\"%s\" is neither an ELF executable" |
| 269 | " nor a shared library\n", filename); |
| 270 | exit(EXIT_FAILURE); |
| 271 | } |
| Juan Cespedes | 1cd999a | 2001-07-03 00:46:04 +0200 | [diff] [blame] | 272 | |
| Petr Machata | ddd96a3 | 2012-05-17 23:35:26 +0200 | [diff] [blame] | 273 | if (1 |
| 274 | #ifdef LT_ELF_MACHINE |
| 275 | && (lte->ehdr.e_ident[EI_CLASS] != LT_ELFCLASS |
| 276 | || lte->ehdr.e_machine != LT_ELF_MACHINE) |
| 277 | #endif |
| Juan Cespedes | d914a20 | 2004-11-10 00:15:33 +0100 | [diff] [blame] | 278 | #ifdef LT_ELF_MACHINE2 |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 279 | && (lte->ehdr.e_ident[EI_CLASS] != LT_ELFCLASS2 |
| 280 | || lte->ehdr.e_machine != LT_ELF_MACHINE2) |
| Juan Cespedes | d914a20 | 2004-11-10 00:15:33 +0100 | [diff] [blame] | 281 | #endif |
| 282 | #ifdef LT_ELF_MACHINE3 |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 283 | && (lte->ehdr.e_ident[EI_CLASS] != LT_ELFCLASS3 |
| 284 | || lte->ehdr.e_machine != LT_ELF_MACHINE3) |
| Juan Cespedes | d914a20 | 2004-11-10 00:15:33 +0100 | [diff] [blame] | 285 | #endif |
| Petr Machata | cc0e1e4 | 2012-04-25 13:42:07 +0200 | [diff] [blame] | 286 | ) { |
| 287 | fprintf(stderr, |
| 288 | "\"%s\" is ELF from incompatible architecture\n", |
| 289 | filename); |
| 290 | exit(EXIT_FAILURE); |
| 291 | } |
| Juan Cespedes | d914a20 | 2004-11-10 00:15:33 +0100 | [diff] [blame] | 292 | |
| Petr Machata | 02bd9ec | 2011-09-21 17:38:59 +0200 | [diff] [blame] | 293 | return 0; |
| 294 | } |
| 295 | |
| Petr Machata | cc0e1e4 | 2012-04-25 13:42:07 +0200 | [diff] [blame] | 296 | static void |
| 297 | read_symbol_table(struct ltelf *lte, const char *filename, |
| 298 | Elf_Scn *scn, GElf_Shdr *shdr, const char *name, |
| 299 | Elf_Data **datap, size_t *countp, const char **strsp) |
| 300 | { |
| 301 | *datap = elf_getdata(scn, NULL); |
| 302 | *countp = shdr->sh_size / shdr->sh_entsize; |
| 303 | if ((*datap == NULL || elf_getdata(scn, *datap) != NULL) |
| 304 | && options.static_filter != NULL) { |
| 305 | fprintf(stderr, "Couldn't get data of section" |
| 306 | " %s from \"%s\": %s\n", |
| 307 | name, filename, elf_errmsg(-1)); |
| 308 | exit(EXIT_FAILURE); |
| 309 | } |
| 310 | |
| 311 | scn = elf_getscn(lte->elf, shdr->sh_link); |
| 312 | GElf_Shdr shdr2; |
| 313 | if (scn == NULL || gelf_getshdr(scn, &shdr2) == NULL) { |
| 314 | fprintf(stderr, "Couldn't get header of section" |
| 315 | " #%d from \"%s\": %s\n", |
| 316 | shdr2.sh_link, filename, elf_errmsg(-1)); |
| 317 | exit(EXIT_FAILURE); |
| 318 | } |
| 319 | |
| 320 | Elf_Data *data = elf_getdata(scn, NULL); |
| 321 | if (data == NULL || elf_getdata(scn, data) != NULL |
| 322 | || shdr2.sh_size != data->d_size || data->d_off) { |
| 323 | fprintf(stderr, "Couldn't get data of section" |
| 324 | " #%d from \"%s\": %s\n", |
| 325 | shdr2.sh_link, filename, elf_errmsg(-1)); |
| 326 | exit(EXIT_FAILURE); |
| 327 | } |
| 328 | |
| 329 | *strsp = data->d_buf; |
| 330 | } |
| 331 | |
| Petr Machata | e67635d | 2012-03-21 03:37:39 +0100 | [diff] [blame] | 332 | static int |
| 333 | do_init_elf(struct ltelf *lte, const char *filename, GElf_Addr bias) |
| Petr Machata | 2b46cfc | 2012-02-18 11:17:29 +0100 | [diff] [blame] | 334 | { |
| Petr Machata | 02bd9ec | 2011-09-21 17:38:59 +0200 | [diff] [blame] | 335 | int i; |
| 336 | GElf_Addr relplt_addr = 0; |
| Petr Machata | 2b46cfc | 2012-02-18 11:17:29 +0100 | [diff] [blame] | 337 | GElf_Addr soname_offset = 0; |
| Petr Machata | 02bd9ec | 2011-09-21 17:38:59 +0200 | [diff] [blame] | 338 | |
| 339 | debug(DEBUG_FUNCTION, "do_init_elf(filename=%s)", filename); |
| 340 | debug(1, "Reading ELF from %s...", filename); |
| 341 | |
| 342 | if (open_elf(lte, filename) < 0) |
| 343 | return -1; |
| 344 | |
| Petr Machata | b120fdf | 2012-03-21 05:05:46 +0100 | [diff] [blame] | 345 | /* Find out the base address. */ |
| Petr Machata | 29add4f | 2012-02-18 16:38:05 +0100 | [diff] [blame] | 346 | { |
| Petr Machata | 2b46cfc | 2012-02-18 11:17:29 +0100 | [diff] [blame] | 347 | GElf_Phdr phdr; |
| 348 | for (i = 0; gelf_getphdr (lte->elf, i, &phdr) != NULL; ++i) { |
| 349 | if (phdr.p_type == PT_LOAD) { |
| Petr Machata | 49275b0 | 2012-04-03 12:38:51 +0200 | [diff] [blame] | 350 | lte->base_addr = phdr.p_vaddr + bias; |
| Petr Machata | 2b46cfc | 2012-02-18 11:17:29 +0100 | [diff] [blame] | 351 | break; |
| 352 | } |
| 353 | } |
| 354 | } |
| 355 | |
| Petr Machata | b120fdf | 2012-03-21 05:05:46 +0100 | [diff] [blame] | 356 | if (lte->base_addr == 0) { |
| 357 | fprintf(stderr, "Couldn't determine base address of %s\n", |
| 358 | filename); |
| 359 | return -1; |
| 360 | } |
| 361 | |
| 362 | lte->bias = bias; |
| Petr Machata | 29add4f | 2012-02-18 16:38:05 +0100 | [diff] [blame] | 363 | lte->entry_addr = lte->ehdr.e_entry + lte->bias; |
| Petr Machata | 2b46cfc | 2012-02-18 11:17:29 +0100 | [diff] [blame] | 364 | |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 365 | for (i = 1; i < lte->ehdr.e_shnum; ++i) { |
| 366 | Elf_Scn *scn; |
| 367 | GElf_Shdr shdr; |
| 368 | const char *name; |
| Juan Cespedes | d914a20 | 2004-11-10 00:15:33 +0100 | [diff] [blame] | 369 | |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 370 | scn = elf_getscn(lte->elf, i); |
| Petr Machata | cc0e1e4 | 2012-04-25 13:42:07 +0200 | [diff] [blame] | 371 | if (scn == NULL || gelf_getshdr(scn, &shdr) == NULL) { |
| 372 | fprintf(stderr, "Couldn't get section #%d from" |
| 373 | " \"%s\": %s\n", i, filename, elf_errmsg(-1)); |
| 374 | exit(EXIT_FAILURE); |
| 375 | } |
| Juan Cespedes | d914a20 | 2004-11-10 00:15:33 +0100 | [diff] [blame] | 376 | |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 377 | name = elf_strptr(lte->elf, lte->ehdr.e_shstrndx, shdr.sh_name); |
| Petr Machata | cc0e1e4 | 2012-04-25 13:42:07 +0200 | [diff] [blame] | 378 | if (name == NULL) { |
| 379 | fprintf(stderr, "Couldn't get name of section #%d from" |
| 380 | " \"%s\": %s\n", i, filename, elf_errmsg(-1)); |
| 381 | exit(EXIT_FAILURE); |
| 382 | } |
| Juan Cespedes | d914a20 | 2004-11-10 00:15:33 +0100 | [diff] [blame] | 383 | |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 384 | if (shdr.sh_type == SHT_SYMTAB) { |
| Petr Machata | cc0e1e4 | 2012-04-25 13:42:07 +0200 | [diff] [blame] | 385 | read_symbol_table(lte, filename, |
| 386 | scn, &shdr, name, <e->symtab, |
| 387 | <e->symtab_count, <e->strtab); |
| Juan Cespedes | d914a20 | 2004-11-10 00:15:33 +0100 | [diff] [blame] | 388 | |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 389 | } else if (shdr.sh_type == SHT_DYNSYM) { |
| Petr Machata | cc0e1e4 | 2012-04-25 13:42:07 +0200 | [diff] [blame] | 390 | read_symbol_table(lte, filename, |
| 391 | scn, &shdr, name, <e->dynsym, |
| 392 | <e->dynsym_count, <e->dynstr); |
| Juan Cespedes | d914a20 | 2004-11-10 00:15:33 +0100 | [diff] [blame] | 393 | |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 394 | } else if (shdr.sh_type == SHT_DYNAMIC) { |
| 395 | Elf_Data *data; |
| 396 | size_t j; |
| Juan Cespedes | d914a20 | 2004-11-10 00:15:33 +0100 | [diff] [blame] | 397 | |
| Joe Damato | 87f4f58 | 2010-11-08 15:47:36 -0800 | [diff] [blame] | 398 | lte->dyn_addr = shdr.sh_addr; |
| 399 | lte->dyn_sz = shdr.sh_size; |
| 400 | |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 401 | data = elf_getdata(scn, NULL); |
| Petr Machata | cc0e1e4 | 2012-04-25 13:42:07 +0200 | [diff] [blame] | 402 | if (data == NULL || elf_getdata(scn, data) != NULL) { |
| 403 | fprintf(stderr, "Couldn't get .dynamic data" |
| 404 | " from \"%s\": %s\n", |
| 405 | filename, strerror(errno)); |
| 406 | exit(EXIT_FAILURE); |
| 407 | } |
| Juan Cespedes | d914a20 | 2004-11-10 00:15:33 +0100 | [diff] [blame] | 408 | |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 409 | for (j = 0; j < shdr.sh_size / shdr.sh_entsize; ++j) { |
| 410 | GElf_Dyn dyn; |
| Juan Cespedes | d914a20 | 2004-11-10 00:15:33 +0100 | [diff] [blame] | 411 | |
| Petr Machata | cc0e1e4 | 2012-04-25 13:42:07 +0200 | [diff] [blame] | 412 | if (gelf_getdyn(data, j, &dyn) == NULL) { |
| 413 | fprintf(stderr, "Couldn't get .dynamic" |
| 414 | " data from \"%s\": %s\n", |
| 415 | filename, strerror(errno)); |
| 416 | exit(EXIT_FAILURE); |
| 417 | } |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 418 | if (dyn.d_tag == DT_JMPREL) |
| 419 | relplt_addr = dyn.d_un.d_ptr; |
| 420 | else if (dyn.d_tag == DT_PLTRELSZ) |
| Petr Machata | e67635d | 2012-03-21 03:37:39 +0100 | [diff] [blame] | 421 | lte->relplt_size = dyn.d_un.d_val; |
| 422 | else if (dyn.d_tag == DT_SONAME) |
| Petr Machata | 2b46cfc | 2012-02-18 11:17:29 +0100 | [diff] [blame] | 423 | soname_offset = dyn.d_un.d_val; |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 424 | } |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 425 | } else if (shdr.sh_type == SHT_PROGBITS |
| 426 | || shdr.sh_type == SHT_NOBITS) { |
| 427 | if (strcmp(name, ".plt") == 0) { |
| 428 | lte->plt_addr = shdr.sh_addr; |
| 429 | lte->plt_size = shdr.sh_size; |
| Petr Machata | e67635d | 2012-03-21 03:37:39 +0100 | [diff] [blame] | 430 | lte->plt_data = elf_loaddata(scn, &shdr); |
| 431 | if (lte->plt_data == NULL) |
| 432 | fprintf(stderr, |
| 433 | "Can't load .plt data\n"); |
| Petr Machata | 18c801c | 2012-04-07 01:24:08 +0200 | [diff] [blame] | 434 | lte->plt_flags = shdr.sh_flags; |
| Petr Machata | b3f8fef | 2006-11-30 14:45:07 +0100 | [diff] [blame] | 435 | } |
| 436 | #ifdef ARCH_SUPPORTS_OPD |
| 437 | else if (strcmp(name, ".opd") == 0) { |
| Paul Gilliam | 3f1219f | 2006-04-24 18:25:38 +0200 | [diff] [blame] | 438 | lte->opd_addr = (GElf_Addr *) (long) shdr.sh_addr; |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 439 | lte->opd_size = shdr.sh_size; |
| 440 | lte->opd = elf_rawdata(scn, NULL); |
| 441 | } |
| Petr Machata | b3f8fef | 2006-11-30 14:45:07 +0100 | [diff] [blame] | 442 | #endif |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 443 | } |
| Juan Cespedes | d914a20 | 2004-11-10 00:15:33 +0100 | [diff] [blame] | 444 | } |
| 445 | |
| Petr Machata | cc0e1e4 | 2012-04-25 13:42:07 +0200 | [diff] [blame] | 446 | if (lte->dynsym == NULL || lte->dynstr == NULL) { |
| 447 | fprintf(stderr, "Couldn't find .dynsym or .dynstr in \"%s\"\n", |
| 448 | filename); |
| 449 | exit(EXIT_FAILURE); |
| 450 | } |
| Juan Cespedes | d914a20 | 2004-11-10 00:15:33 +0100 | [diff] [blame] | 451 | |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 452 | if (!relplt_addr || !lte->plt_addr) { |
| 453 | debug(1, "%s has no PLT relocations", filename); |
| 454 | lte->relplt = NULL; |
| 455 | lte->relplt_count = 0; |
| Petr Machata | e67635d | 2012-03-21 03:37:39 +0100 | [diff] [blame] | 456 | } else if (lte->relplt_size == 0) { |
| Petr Machata | fe1c171 | 2010-10-27 16:57:34 +0200 | [diff] [blame] | 457 | debug(1, "%s has unknown PLT size", filename); |
| 458 | lte->relplt = NULL; |
| 459 | lte->relplt_count = 0; |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 460 | } else { |
| Petr Machata | fe1c171 | 2010-10-27 16:57:34 +0200 | [diff] [blame] | 461 | |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 462 | for (i = 1; i < lte->ehdr.e_shnum; ++i) { |
| 463 | Elf_Scn *scn; |
| 464 | GElf_Shdr shdr; |
| 465 | |
| 466 | scn = elf_getscn(lte->elf, i); |
| Petr Machata | cc0e1e4 | 2012-04-25 13:42:07 +0200 | [diff] [blame] | 467 | if (scn == NULL || gelf_getshdr(scn, &shdr) == NULL) { |
| 468 | fprintf(stderr, "Couldn't get section header" |
| 469 | " from \"%s\": %s\n", |
| 470 | filename, elf_errmsg(-1)); |
| 471 | exit(EXIT_FAILURE); |
| 472 | } |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 473 | if (shdr.sh_addr == relplt_addr |
| Petr Machata | e67635d | 2012-03-21 03:37:39 +0100 | [diff] [blame] | 474 | && shdr.sh_size == lte->relplt_size) { |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 475 | lte->relplt = elf_getdata(scn, NULL); |
| 476 | lte->relplt_count = |
| 477 | shdr.sh_size / shdr.sh_entsize; |
| 478 | if (lte->relplt == NULL |
| Petr Machata | cc0e1e4 | 2012-04-25 13:42:07 +0200 | [diff] [blame] | 479 | || elf_getdata(scn, lte->relplt) != NULL) { |
| 480 | fprintf(stderr, "Couldn't get .rel*.plt" |
| 481 | " data from \"%s\": %s\n", |
| 482 | filename, elf_errmsg(-1)); |
| 483 | exit(EXIT_FAILURE); |
| 484 | } |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 485 | break; |
| 486 | } |
| 487 | } |
| 488 | |
| Petr Machata | cc0e1e4 | 2012-04-25 13:42:07 +0200 | [diff] [blame] | 489 | if (i == lte->ehdr.e_shnum) { |
| 490 | fprintf(stderr, |
| 491 | "Couldn't find .rel*.plt section in \"%s\"\n", |
| 492 | filename); |
| 493 | exit(EXIT_FAILURE); |
| 494 | } |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 495 | |
| 496 | debug(1, "%s %zd PLT relocations", filename, lte->relplt_count); |
| 497 | } |
| Petr Machata | 2b46cfc | 2012-02-18 11:17:29 +0100 | [diff] [blame] | 498 | |
| 499 | if (soname_offset != 0) |
| 500 | lte->soname = lte->dynstr + soname_offset; |
| 501 | |
| Petr Machata | 1974dbc | 2011-08-19 18:58:01 +0200 | [diff] [blame] | 502 | return 0; |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 503 | } |
| 504 | |
| Petr Machata | 2b46cfc | 2012-02-18 11:17:29 +0100 | [diff] [blame] | 505 | /* XXX temporarily non-static */ |
| Joe Damato | 7a2bdf8 | 2010-11-08 15:47:41 -0800 | [diff] [blame] | 506 | void |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 507 | do_close_elf(struct ltelf *lte) { |
| Juan Cespedes | cd8976d | 2009-05-14 13:47:58 +0200 | [diff] [blame] | 508 | debug(DEBUG_FUNCTION, "do_close_elf()"); |
| Petr Machata | 4d9a91c | 2012-03-24 04:55:03 +0100 | [diff] [blame] | 509 | arch_elf_destroy(lte); |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 510 | elf_end(lte->elf); |
| 511 | close(lte->fd); |
| Juan Cespedes | 1cd999a | 2001-07-03 00:46:04 +0200 | [diff] [blame] | 512 | } |
| 513 | |
| Edgar E. Iglesias | b5920d1 | 2012-09-27 12:07:35 +0200 | [diff] [blame] | 514 | #ifndef ARCH_HAVE_GET_SYMINFO |
| 515 | int |
| 516 | arch_get_sym_info(struct ltelf *lte, const char *filename, |
| 517 | size_t sym_index, GElf_Rela *rela, GElf_Sym *sym) |
| 518 | { |
| 519 | int i = sym_index; |
| 520 | GElf_Rel rel; |
| 521 | void *ret; |
| 522 | |
| 523 | if (lte->relplt->d_type == ELF_T_REL) { |
| 524 | ret = gelf_getrel(lte->relplt, i, &rel); |
| 525 | rela->r_offset = rel.r_offset; |
| 526 | rela->r_info = rel.r_info; |
| 527 | rela->r_addend = 0; |
| 528 | } else { |
| 529 | ret = gelf_getrela(lte->relplt, i, rela); |
| 530 | } |
| 531 | |
| 532 | if (ret == NULL |
| 533 | || ELF64_R_SYM(rela->r_info) >= lte->dynsym_count |
| 534 | || gelf_getsym(lte->dynsym, ELF64_R_SYM(rela->r_info), |
| 535 | sym) == NULL) { |
| 536 | fprintf(stderr, |
| 537 | "Couldn't get relocation from \"%s\": %s\n", |
| 538 | filename, elf_errmsg(-1)); |
| 539 | exit(EXIT_FAILURE); |
| 540 | } |
| 541 | |
| 542 | return 0; |
| 543 | } |
| 544 | #endif |
| 545 | |
| Petr Machata | e80cace | 2012-09-28 00:05:08 +0200 | [diff] [blame] | 546 | static void |
| 547 | mark_chain_latent(struct library_symbol *libsym) |
| 548 | { |
| 549 | for (; libsym != NULL; libsym = libsym->next) { |
| 550 | debug(DEBUG_FUNCTION, "marking %s latent", libsym->name); |
| 551 | libsym->latent = 1; |
| 552 | } |
| 553 | } |
| 554 | |
| Petr Machata | b5f80ac | 2012-04-04 01:46:18 +0200 | [diff] [blame] | 555 | static int |
| 556 | populate_plt(struct Process *proc, const char *filename, |
| Petr Machata | e80cace | 2012-09-28 00:05:08 +0200 | [diff] [blame] | 557 | struct ltelf *lte, struct library *lib, |
| 558 | int latent_plts) |
| Petr Machata | b5f80ac | 2012-04-04 01:46:18 +0200 | [diff] [blame] | 559 | { |
| 560 | size_t i; |
| 561 | for (i = 0; i < lte->relplt_count; ++i) { |
| Petr Machata | b5f80ac | 2012-04-04 01:46:18 +0200 | [diff] [blame] | 562 | GElf_Rela rela; |
| 563 | GElf_Sym sym; |
| Petr Machata | b5f80ac | 2012-04-04 01:46:18 +0200 | [diff] [blame] | 564 | |
| Edgar E. Iglesias | b5920d1 | 2012-09-27 12:07:35 +0200 | [diff] [blame] | 565 | if (arch_get_sym_info(lte, filename, i, &rela, &sym) < 0) |
| 566 | continue; /* Skip this entry. */ |
| Petr Machata | b5f80ac | 2012-04-04 01:46:18 +0200 | [diff] [blame] | 567 | |
| 568 | char const *name = lte->dynstr + sym.st_name; |
| 569 | |
| Petr Machata | e80cace | 2012-09-28 00:05:08 +0200 | [diff] [blame] | 570 | /* If the symbol wasn't matched, reject it, unless we |
| 571 | * need to keep latent PLT breakpoints for tracing |
| 572 | * exports. */ |
| 573 | int matched = filter_matches_symbol(options.plt_filter, |
| 574 | name, lib); |
| 575 | if (!matched && !latent_plts) |
| Petr Machata | b5f80ac | 2012-04-04 01:46:18 +0200 | [diff] [blame] | 576 | continue; |
| 577 | |
| Petr Machata | 218c5ff | 2012-04-15 04:22:39 +0200 | [diff] [blame] | 578 | struct library_symbol *libsym = NULL; |
| Petr Machata | b5f80ac | 2012-04-04 01:46:18 +0200 | [diff] [blame] | 579 | switch (arch_elf_add_plt_entry(proc, lte, name, |
| 580 | &rela, i, &libsym)) { |
| 581 | case plt_default: |
| 582 | if (default_elf_add_plt_entry(proc, lte, name, |
| 583 | &rela, i, &libsym) < 0) |
| Petr Machata | 8eb0d93 | 2012-04-17 05:18:18 +0200 | [diff] [blame] | 584 | /* fall-through */ |
| Petr Machata | b5f80ac | 2012-04-04 01:46:18 +0200 | [diff] [blame] | 585 | case plt_fail: |
| 586 | return -1; |
| Petr Machata | 8eb0d93 | 2012-04-17 05:18:18 +0200 | [diff] [blame] | 587 | /* fall-through */ |
| Petr Machata | b5f80ac | 2012-04-04 01:46:18 +0200 | [diff] [blame] | 588 | case plt_ok: |
| Petr Machata | e80cace | 2012-09-28 00:05:08 +0200 | [diff] [blame] | 589 | if (libsym != NULL) { |
| 590 | /* If we are adding those symbols just |
| 591 | * for tracing exports, mark them all |
| 592 | * latent. */ |
| 593 | if (!matched) |
| 594 | mark_chain_latent(libsym); |
| Petr Machata | b5f80ac | 2012-04-04 01:46:18 +0200 | [diff] [blame] | 595 | library_add_symbol(lib, libsym); |
| Petr Machata | e80cace | 2012-09-28 00:05:08 +0200 | [diff] [blame] | 596 | } |
| Petr Machata | b5f80ac | 2012-04-04 01:46:18 +0200 | [diff] [blame] | 597 | } |
| 598 | } |
| 599 | return 0; |
| 600 | } |
| 601 | |
| Petr Machata | 157cc4d | 2012-04-04 19:00:34 +0200 | [diff] [blame] | 602 | /* When -x rules result in request to trace several aliases, we only |
| 603 | * want to add such symbol once. The only way that those symbols |
| 604 | * differ in is their name, e.g. in glibc you have __GI___libc_free, |
| 605 | * __cfree, __free, __libc_free, cfree and free all defined on the |
| 606 | * same address. So instead we keep this unique symbol struct for |
| 607 | * each address, and replace name in libsym with a shorter variant if |
| 608 | * we find it. */ |
| 609 | struct unique_symbol { |
| Petr Machata | bac2da5 | 2012-05-29 00:42:59 +0200 | [diff] [blame] | 610 | arch_addr_t addr; |
| Petr Machata | 157cc4d | 2012-04-04 19:00:34 +0200 | [diff] [blame] | 611 | struct library_symbol *libsym; |
| 612 | }; |
| 613 | |
| 614 | static int |
| 615 | unique_symbol_cmp(const void *key, const void *val) |
| 616 | { |
| 617 | const struct unique_symbol *sym_key = key; |
| 618 | const struct unique_symbol *sym_val = val; |
| 619 | return sym_key->addr != sym_val->addr; |
| 620 | } |
| 621 | |
| Petr Machata | 10bd7a9 | 2012-09-28 00:06:56 +0200 | [diff] [blame^] | 622 | static enum callback_status |
| 623 | symbol_with_address(struct library_symbol *sym, void *addrptr) |
| 624 | { |
| 625 | return sym->enter_addr == *(arch_addr_t *)addrptr |
| 626 | ? CBS_STOP : CBS_CONT; |
| 627 | } |
| 628 | |
| Petr Machata | da3edbf | 2012-04-04 02:20:21 +0200 | [diff] [blame] | 629 | static int |
| 630 | populate_this_symtab(struct Process *proc, const char *filename, |
| 631 | struct ltelf *lte, struct library *lib, |
| Petr Machata | 013ef5b | 2012-09-28 00:00:55 +0200 | [diff] [blame] | 632 | Elf_Data *symtab, const char *strtab, size_t size, |
| 633 | struct library_exported_name **names) |
| Petr Machata | da3edbf | 2012-04-04 02:20:21 +0200 | [diff] [blame] | 634 | { |
| Petr Machata | 013ef5b | 2012-09-28 00:00:55 +0200 | [diff] [blame] | 635 | /* If a valid NAMES is passed, we pass in *NAMES a list of |
| 636 | * symbol names that this library exports. */ |
| 637 | if (names != NULL) |
| 638 | *names = NULL; |
| 639 | |
| Petr Machata | 157cc4d | 2012-04-04 19:00:34 +0200 | [diff] [blame] | 640 | /* Using sorted array would be arguably better, but this |
| 641 | * should be well enough for the number of symbols that we |
| 642 | * typically deal with. */ |
| 643 | size_t num_symbols = 0; |
| 644 | struct unique_symbol *symbols = malloc(sizeof(*symbols) * size); |
| 645 | if (symbols == NULL) { |
| Petr Machata | cc0e1e4 | 2012-04-25 13:42:07 +0200 | [diff] [blame] | 646 | fprintf(stderr, "couldn't insert symbols for -x: %s\n", |
| 647 | strerror(errno)); |
| Petr Machata | 157cc4d | 2012-04-04 19:00:34 +0200 | [diff] [blame] | 648 | return -1; |
| 649 | } |
| 650 | |
| Petr Machata | 40cc53b | 2012-04-07 01:25:38 +0200 | [diff] [blame] | 651 | GElf_Word secflags[lte->ehdr.e_shnum]; |
| Petr Machata | da3edbf | 2012-04-04 02:20:21 +0200 | [diff] [blame] | 652 | size_t i; |
| Petr Machata | 40cc53b | 2012-04-07 01:25:38 +0200 | [diff] [blame] | 653 | for (i = 1; i < lte->ehdr.e_shnum; ++i) { |
| 654 | Elf_Scn *scn = elf_getscn(lte->elf, i); |
| 655 | if (scn == NULL) |
| 656 | continue; |
| 657 | GElf_Shdr shdr; |
| 658 | if (gelf_getshdr(scn, &shdr) == NULL) |
| 659 | continue; |
| 660 | secflags[i] = shdr.sh_flags; |
| 661 | } |
| 662 | |
| 663 | size_t lib_len = strlen(lib->soname); |
| Petr Machata | da3edbf | 2012-04-04 02:20:21 +0200 | [diff] [blame] | 664 | for (i = 0; i < size; ++i) { |
| 665 | GElf_Sym sym; |
| Petr Machata | 074f68f | 2012-04-07 01:01:02 +0200 | [diff] [blame] | 666 | if (gelf_getsym(symtab, i, &sym) == NULL) { |
| Petr Machata | da3edbf | 2012-04-04 02:20:21 +0200 | [diff] [blame] | 667 | fail: |
| Petr Machata | cc0e1e4 | 2012-04-25 13:42:07 +0200 | [diff] [blame] | 668 | fprintf(stderr, |
| 669 | "couldn't get symbol #%zd from %s: %s\n", |
| 670 | i, filename, elf_errmsg(-1)); |
| Petr Machata | da3edbf | 2012-04-04 02:20:21 +0200 | [diff] [blame] | 671 | continue; |
| 672 | } |
| 673 | |
| Petr Machata | 4de6b6b | 2012-04-04 14:06:09 +0200 | [diff] [blame] | 674 | /* XXX support IFUNC as well. */ |
| 675 | if (GELF_ST_TYPE(sym.st_info) != STT_FUNC |
| Petr Machata | 6c1c0bb | 2012-05-18 16:49:34 +0200 | [diff] [blame] | 676 | || sym.st_value == 0 |
| 677 | || sym.st_shndx == STN_UNDEF) |
| Petr Machata | 4de6b6b | 2012-04-04 14:06:09 +0200 | [diff] [blame] | 678 | continue; |
| 679 | |
| Petr Machata | 013ef5b | 2012-09-28 00:00:55 +0200 | [diff] [blame] | 680 | /* Find symbol name and snip version. */ |
| Petr Machata | 2bbeac4 | 2012-04-30 20:48:34 +0200 | [diff] [blame] | 681 | const char *orig_name = strtab + sym.st_name; |
| 682 | const char *version = strchr(orig_name, '@'); |
| 683 | size_t len = version != NULL ? (assert(version > orig_name), |
| 684 | (size_t)(version - orig_name)) |
| 685 | : strlen(orig_name); |
| 686 | char name[len + 1]; |
| 687 | memcpy(name, orig_name, len); |
| 688 | name[len] = 0; |
| 689 | |
| Petr Machata | 013ef5b | 2012-09-28 00:00:55 +0200 | [diff] [blame] | 690 | /* If we are interested in exports, store this name. */ |
| 691 | char *name_copy = NULL; |
| 692 | if (names != NULL) { |
| 693 | struct library_exported_name *export = NULL; |
| 694 | name_copy = strdup(name); |
| 695 | |
| 696 | if (name_copy == NULL |
| 697 | || (export = malloc(sizeof(*export))) == NULL) { |
| 698 | free(name_copy); |
| 699 | fprintf(stderr, "Couldn't store symbol %s. " |
| 700 | "Tracing may be incomplete.\n", name); |
| 701 | } else { |
| 702 | export->name = name_copy; |
| 703 | export->own_name = 1; |
| 704 | export->next = *names; |
| 705 | *names = export; |
| 706 | } |
| 707 | } |
| 708 | |
| 709 | /* If the symbol is not matched, skip it. We already |
| 710 | * stored it to export list above. */ |
| Petr Machata | da3edbf | 2012-04-04 02:20:21 +0200 | [diff] [blame] | 711 | if (!filter_matches_symbol(options.static_filter, name, lib)) |
| 712 | continue; |
| Petr Machata | da3edbf | 2012-04-04 02:20:21 +0200 | [diff] [blame] | 713 | |
| Petr Machata | bac2da5 | 2012-05-29 00:42:59 +0200 | [diff] [blame] | 714 | arch_addr_t addr = (arch_addr_t) |
| Petr Machata | ea8eb9a | 2012-04-17 01:32:07 +0200 | [diff] [blame] | 715 | (uintptr_t)(sym.st_value + lte->bias); |
| Petr Machata | bac2da5 | 2012-05-29 00:42:59 +0200 | [diff] [blame] | 716 | arch_addr_t naddr; |
| Petr Machata | 40cc53b | 2012-04-07 01:25:38 +0200 | [diff] [blame] | 717 | |
| 718 | /* On arches that support OPD, the value of typical |
| 719 | * function symbol will be a pointer to .opd, but some |
| 720 | * will point directly to .text. We don't want to |
| 721 | * translate those. */ |
| 722 | if (secflags[sym.st_shndx] & SHF_EXECINSTR) { |
| 723 | naddr = addr; |
| Petr Machata | b1492df | 2012-04-30 21:01:40 +0200 | [diff] [blame] | 724 | } else if (arch_translate_address(lte, addr, &naddr) < 0) { |
| Petr Machata | cc0e1e4 | 2012-04-25 13:42:07 +0200 | [diff] [blame] | 725 | fprintf(stderr, |
| 726 | "couldn't translate address of %s@%s: %s\n", |
| 727 | name, lib->soname, strerror(errno)); |
| Petr Machata | da3edbf | 2012-04-04 02:20:21 +0200 | [diff] [blame] | 728 | continue; |
| 729 | } |
| Petr Machata | 40cc53b | 2012-04-07 01:25:38 +0200 | [diff] [blame] | 730 | |
| Petr Machata | 3840f68 | 2012-04-06 16:05:41 +0200 | [diff] [blame] | 731 | char *full_name; |
| Petr Machata | 013ef5b | 2012-09-28 00:00:55 +0200 | [diff] [blame] | 732 | int own_full_name = 1; |
| Petr Machata | 3840f68 | 2012-04-06 16:05:41 +0200 | [diff] [blame] | 733 | if (lib->type != LT_LIBTYPE_MAIN) { |
| 734 | full_name = malloc(strlen(name) + 1 + lib_len + 1); |
| 735 | if (full_name == NULL) |
| 736 | goto fail; |
| 737 | sprintf(full_name, "%s@%s", name, lib->soname); |
| 738 | } else { |
| Petr Machata | 013ef5b | 2012-09-28 00:00:55 +0200 | [diff] [blame] | 739 | if (name_copy == NULL) { |
| 740 | full_name = strdup(name); |
| 741 | if (full_name == NULL) |
| 742 | goto fail; |
| 743 | } else { |
| 744 | full_name = name_copy; |
| 745 | own_full_name = 0; |
| 746 | } |
| Petr Machata | 3840f68 | 2012-04-06 16:05:41 +0200 | [diff] [blame] | 747 | } |
| Petr Machata | 4de6b6b | 2012-04-04 14:06:09 +0200 | [diff] [blame] | 748 | |
| Petr Machata | 157cc4d | 2012-04-04 19:00:34 +0200 | [diff] [blame] | 749 | /* Look whether we already have a symbol for this |
| 750 | * address. If not, add this one. */ |
| 751 | struct unique_symbol key = { naddr, NULL }; |
| 752 | struct unique_symbol *unique |
| 753 | = lsearch(&key, symbols, &num_symbols, |
| 754 | sizeof(*symbols), &unique_symbol_cmp); |
| Petr Machata | da3edbf | 2012-04-04 02:20:21 +0200 | [diff] [blame] | 755 | |
| Petr Machata | 157cc4d | 2012-04-04 19:00:34 +0200 | [diff] [blame] | 756 | if (unique->libsym == NULL) { |
| 757 | struct library_symbol *libsym = malloc(sizeof(*libsym)); |
| Petr Machata | e8d9076 | 2012-04-15 04:28:31 +0200 | [diff] [blame] | 758 | if (libsym == NULL |
| Petr Machata | 013ef5b | 2012-09-28 00:00:55 +0200 | [diff] [blame] | 759 | || library_symbol_init(libsym, naddr, |
| 760 | full_name, own_full_name, |
| 761 | LS_TOPLT_NONE) < 0) { |
| Petr Machata | 157cc4d | 2012-04-04 19:00:34 +0200 | [diff] [blame] | 762 | --num_symbols; |
| 763 | goto fail; |
| 764 | } |
| Petr Machata | 157cc4d | 2012-04-04 19:00:34 +0200 | [diff] [blame] | 765 | unique->libsym = libsym; |
| 766 | unique->addr = naddr; |
| 767 | |
| 768 | } else if (strlen(full_name) < strlen(unique->libsym->name)) { |
| Petr Machata | 013ef5b | 2012-09-28 00:00:55 +0200 | [diff] [blame] | 769 | library_symbol_set_name(unique->libsym, |
| 770 | full_name, own_full_name); |
| Petr Machata | 157cc4d | 2012-04-04 19:00:34 +0200 | [diff] [blame] | 771 | |
| Petr Machata | 013ef5b | 2012-09-28 00:00:55 +0200 | [diff] [blame] | 772 | } else if (own_full_name) { |
| Petr Machata | 157cc4d | 2012-04-04 19:00:34 +0200 | [diff] [blame] | 773 | free(full_name); |
| 774 | } |
| Petr Machata | da3edbf | 2012-04-04 02:20:21 +0200 | [diff] [blame] | 775 | } |
| Petr Machata | 157cc4d | 2012-04-04 19:00:34 +0200 | [diff] [blame] | 776 | |
| Petr Machata | 10bd7a9 | 2012-09-28 00:06:56 +0200 | [diff] [blame^] | 777 | /* Now we do the union of this set of unique symbols with |
| 778 | * what's already in the library. */ |
| Petr Machata | 157cc4d | 2012-04-04 19:00:34 +0200 | [diff] [blame] | 779 | for (i = 0; i < num_symbols; ++i) { |
| Petr Machata | 10bd7a9 | 2012-09-28 00:06:56 +0200 | [diff] [blame^] | 780 | struct library_symbol *this_sym = symbols[i].libsym; |
| 781 | assert(this_sym != NULL); |
| 782 | struct library_symbol *other |
| 783 | = library_each_symbol(lib, NULL, symbol_with_address, |
| 784 | &this_sym->enter_addr); |
| 785 | if (other != NULL) { |
| 786 | library_symbol_destroy(this_sym); |
| 787 | free(this_sym); |
| 788 | symbols[i].libsym = NULL; |
| 789 | } |
| Petr Machata | 157cc4d | 2012-04-04 19:00:34 +0200 | [diff] [blame] | 790 | } |
| 791 | |
| Petr Machata | 10bd7a9 | 2012-09-28 00:06:56 +0200 | [diff] [blame^] | 792 | for (i = 0; i < num_symbols; ++i) |
| 793 | if (symbols[i].libsym != NULL) |
| 794 | library_add_symbol(lib, symbols[i].libsym); |
| Petr Machata | 157cc4d | 2012-04-04 19:00:34 +0200 | [diff] [blame] | 795 | |
| Petr Machata | 10bd7a9 | 2012-09-28 00:06:56 +0200 | [diff] [blame^] | 796 | free(symbols); |
| Petr Machata | da3edbf | 2012-04-04 02:20:21 +0200 | [diff] [blame] | 797 | return 0; |
| 798 | } |
| 799 | |
| 800 | static int |
| 801 | populate_symtab(struct Process *proc, const char *filename, |
| Petr Machata | 013ef5b | 2012-09-28 00:00:55 +0200 | [diff] [blame] | 802 | struct ltelf *lte, struct library *lib, |
| 803 | int symtabs, int exports) |
| Petr Machata | da3edbf | 2012-04-04 02:20:21 +0200 | [diff] [blame] | 804 | { |
| Petr Machata | 013ef5b | 2012-09-28 00:00:55 +0200 | [diff] [blame] | 805 | int status; |
| 806 | if (symtabs && lte->symtab != NULL && lte->strtab != NULL |
| 807 | && (status = populate_this_symtab(proc, filename, lte, lib, |
| 808 | lte->symtab, lte->strtab, |
| 809 | lte->symtab_count, NULL)) < 0) |
| 810 | return status; |
| 811 | |
| 812 | /* Check whether we want to trace symbols implemented by this |
| 813 | * library (-l). */ |
| 814 | struct library_exported_name **names = NULL; |
| 815 | if (exports) { |
| 816 | debug(DEBUG_FUNCTION, "-l matches %s", lib->soname); |
| 817 | names = &lib->exported_names; |
| 818 | } |
| 819 | |
| 820 | return populate_this_symtab(proc, filename, lte, lib, |
| 821 | lte->dynsym, lte->dynstr, |
| 822 | lte->dynsym_count, names); |
| Petr Machata | da3edbf | 2012-04-04 02:20:21 +0200 | [diff] [blame] | 823 | } |
| 824 | |
| Petr Machata | b5f80ac | 2012-04-04 01:46:18 +0200 | [diff] [blame] | 825 | int |
| 826 | ltelf_read_library(struct library *lib, struct Process *proc, |
| 827 | const char *filename, GElf_Addr bias) |
| Petr Machata | e84fa00 | 2012-02-07 13:43:03 +0100 | [diff] [blame] | 828 | { |
| Petr Machata | 29add4f | 2012-02-18 16:38:05 +0100 | [diff] [blame] | 829 | struct ltelf lte = {}; |
| Petr Machata | b120fdf | 2012-03-21 05:05:46 +0100 | [diff] [blame] | 830 | if (do_init_elf(<e, filename, bias) < 0) |
| Petr Machata | b5f80ac | 2012-04-04 01:46:18 +0200 | [diff] [blame] | 831 | return -1; |
| Petr Machata | e0615ab | 2012-04-17 05:17:48 +0200 | [diff] [blame] | 832 | if (arch_elf_init(<e, lib) < 0) { |
| 833 | fprintf(stderr, "Backend initialization failed.\n"); |
| 834 | return -1; |
| 835 | } |
| 836 | |
| Petr Machata | e67635d | 2012-03-21 03:37:39 +0100 | [diff] [blame] | 837 | proc->e_machine = lte.ehdr.e_machine; |
| Petr Machata | 4d4e1b8 | 2012-05-30 11:08:39 -0400 | [diff] [blame] | 838 | proc->e_class = lte.ehdr.e_ident[EI_CLASS]; |
| Joe Damato | f0bd98b | 2010-11-08 15:47:42 -0800 | [diff] [blame] | 839 | |
| Petr Machata | b5f80ac | 2012-04-04 01:46:18 +0200 | [diff] [blame] | 840 | int status = 0; |
| Petr Machata | fc6ff18 | 2012-04-04 13:11:50 +0200 | [diff] [blame] | 841 | if (lib == NULL) |
| 842 | goto fail; |
| 843 | |
| 844 | /* Note that we set soname and pathname as soon as they are |
| 845 | * allocated, so in case of further errors, this get released |
| 846 | * when LIB is release, which should happen in the caller when |
| 847 | * we return error. */ |
| 848 | |
| 849 | if (lib->pathname == NULL) { |
| 850 | char *pathname = strdup(filename); |
| 851 | if (pathname == NULL) |
| 852 | goto fail; |
| Petr Machata | f13afd5 | 2012-04-14 02:30:31 +0200 | [diff] [blame] | 853 | library_set_pathname(lib, pathname, 1); |
| Joe Damato | f0bd98b | 2010-11-08 15:47:42 -0800 | [diff] [blame] | 854 | } |
| 855 | |
| Petr Machata | 0b55b58 | 2012-04-02 00:38:46 +0200 | [diff] [blame] | 856 | if (lte.soname != NULL) { |
| Petr Machata | fc6ff18 | 2012-04-04 13:11:50 +0200 | [diff] [blame] | 857 | char *soname = strdup(lte.soname); |
| 858 | if (soname == NULL) |
| 859 | goto fail; |
| 860 | library_set_soname(lib, soname, 1); |
| Petr Machata | 0b55b58 | 2012-04-02 00:38:46 +0200 | [diff] [blame] | 861 | } else { |
| Petr Machata | fc6ff18 | 2012-04-04 13:11:50 +0200 | [diff] [blame] | 862 | const char *soname = rindex(lib->pathname, '/') + 1; |
| 863 | if (soname == NULL) |
| 864 | soname = lib->pathname; |
| 865 | library_set_soname(lib, soname, 0); |
| Petr Machata | 0b55b58 | 2012-04-02 00:38:46 +0200 | [diff] [blame] | 866 | } |
| Joe Damato | fa2aefc | 2010-10-30 19:56:50 -0700 | [diff] [blame] | 867 | |
| Petr Machata | ea8eb9a | 2012-04-17 01:32:07 +0200 | [diff] [blame] | 868 | /* XXX The double cast should be removed when |
| Petr Machata | bac2da5 | 2012-05-29 00:42:59 +0200 | [diff] [blame] | 869 | * arch_addr_t becomes integral type. */ |
| 870 | arch_addr_t entry = (arch_addr_t)(uintptr_t)lte.entry_addr; |
| Petr Machata | b1492df | 2012-04-30 21:01:40 +0200 | [diff] [blame] | 871 | if (arch_translate_address(<e, entry, &entry) < 0) |
| Petr Machata | b120fdf | 2012-03-21 05:05:46 +0100 | [diff] [blame] | 872 | goto fail; |
| 873 | |
| Petr Machata | ea8eb9a | 2012-04-17 01:32:07 +0200 | [diff] [blame] | 874 | /* XXX The double cast should be removed when |
| Petr Machata | bac2da5 | 2012-05-29 00:42:59 +0200 | [diff] [blame] | 875 | * arch_addr_t becomes integral type. */ |
| 876 | lib->base = (arch_addr_t)(uintptr_t)lte.base_addr; |
| Petr Machata | b120fdf | 2012-03-21 05:05:46 +0100 | [diff] [blame] | 877 | lib->entry = entry; |
| Petr Machata | ea8eb9a | 2012-04-17 01:32:07 +0200 | [diff] [blame] | 878 | /* XXX The double cast should be removed when |
| Petr Machata | bac2da5 | 2012-05-29 00:42:59 +0200 | [diff] [blame] | 879 | * arch_addr_t becomes integral type. */ |
| 880 | lib->dyn_addr = (arch_addr_t)(uintptr_t)lte.dyn_addr; |
| Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame] | 881 | |
| Petr Machata | 013ef5b | 2012-09-28 00:00:55 +0200 | [diff] [blame] | 882 | /* There are two reasons that we need to inspect symbol tables |
| 883 | * or populate PLT entries. Either the user requested |
| 884 | * corresponding tracing features (respectively -x and -e), or |
| 885 | * they requested tracing exported symbols (-l). |
| 886 | * |
| 887 | * In the latter case we need to keep even those PLT slots |
| 888 | * that are not requested by -e (but we keep them latent). We |
| 889 | * also need to inspect .dynsym to find what exports this |
| 890 | * library provide, to turn on existing latent PLT |
| 891 | * entries. */ |
| 892 | |
| 893 | int plts = filter_matches_library(options.plt_filter, lib); |
| 894 | if ((plts || options.export_filter != NULL) |
| Petr Machata | e80cace | 2012-09-28 00:05:08 +0200 | [diff] [blame] | 895 | && populate_plt(proc, filename, <e, lib, |
| 896 | options.export_filter != NULL) < 0) |
| Petr Machata | b5f80ac | 2012-04-04 01:46:18 +0200 | [diff] [blame] | 897 | goto fail; |
| Joe Damato | e2a8f57 | 2010-11-08 15:47:40 -0800 | [diff] [blame] | 898 | |
| Petr Machata | 013ef5b | 2012-09-28 00:00:55 +0200 | [diff] [blame] | 899 | int exports = filter_matches_library(options.export_filter, lib); |
| 900 | int symtabs = filter_matches_library(options.static_filter, lib); |
| 901 | if ((symtabs || exports) |
| 902 | && populate_symtab(proc, filename, <e, lib, |
| 903 | symtabs, exports) < 0) |
| Petr Machata | da3edbf | 2012-04-04 02:20:21 +0200 | [diff] [blame] | 904 | goto fail; |
| 905 | |
| Petr Machata | 2b46cfc | 2012-02-18 11:17:29 +0100 | [diff] [blame] | 906 | done: |
| 907 | do_close_elf(<e); |
| Petr Machata | b5f80ac | 2012-04-04 01:46:18 +0200 | [diff] [blame] | 908 | return status; |
| Petr Machata | fc6ff18 | 2012-04-04 13:11:50 +0200 | [diff] [blame] | 909 | |
| 910 | fail: |
| 911 | status = -1; |
| 912 | goto done; |
| Petr Machata | 2b46cfc | 2012-02-18 11:17:29 +0100 | [diff] [blame] | 913 | } |
| Petr Machata | e84fa00 | 2012-02-07 13:43:03 +0100 | [diff] [blame] | 914 | |
| Petr Machata | 2b46cfc | 2012-02-18 11:17:29 +0100 | [diff] [blame] | 915 | struct library * |
| 916 | ltelf_read_main_binary(struct Process *proc, const char *path) |
| 917 | { |
| Petr Machata | b5f80ac | 2012-04-04 01:46:18 +0200 | [diff] [blame] | 918 | struct library *lib = malloc(sizeof(*lib)); |
| 919 | if (lib == NULL) |
| 920 | return NULL; |
| 921 | library_init(lib, LT_LIBTYPE_MAIN); |
| Petr Machata | fc6ff18 | 2012-04-04 13:11:50 +0200 | [diff] [blame] | 922 | library_set_pathname(lib, path, 0); |
| Petr Machata | b5f80ac | 2012-04-04 01:46:18 +0200 | [diff] [blame] | 923 | |
| Petr Machata | fc6ff18 | 2012-04-04 13:11:50 +0200 | [diff] [blame] | 924 | /* There is a race between running the process and reading its |
| 925 | * binary for internal consumption. So open the binary from |
| 926 | * the /proc filesystem. XXX Note that there is similar race |
| 927 | * for libraries, but there we don't have a nice answer like |
| 928 | * that. Presumably we could read the DSOs from the process |
| 929 | * memory image, but that's not currently done. */ |
| Petr Machata | 2b46cfc | 2012-02-18 11:17:29 +0100 | [diff] [blame] | 930 | char *fname = pid2name(proc->pid); |
| Petr Machata | b5f80ac | 2012-04-04 01:46:18 +0200 | [diff] [blame] | 931 | if (ltelf_read_library(lib, proc, fname, 0) < 0) { |
| 932 | library_destroy(lib); |
| 933 | free(lib); |
| 934 | return NULL; |
| Petr Machata | 0b55b58 | 2012-04-02 00:38:46 +0200 | [diff] [blame] | 935 | } |
| Petr Machata | b5f80ac | 2012-04-04 01:46:18 +0200 | [diff] [blame] | 936 | |
| Petr Machata | 2b46cfc | 2012-02-18 11:17:29 +0100 | [diff] [blame] | 937 | return lib; |
| Juan Cespedes | 96935a9 | 1997-08-09 23:45:39 +0200 | [diff] [blame] | 938 | } |