ltrace-elf.c revision 074f68fb8f57f93de3d94552a855b296b7a25906
1#include "config.h" 2 3#include <assert.h> 4#include <endian.h> 5#include <errno.h> 6#include <error.h> 7#include <fcntl.h> 8#include <gelf.h> 9#include <inttypes.h> 10#include <search.h> 11#include <stdint.h> 12#include <stdlib.h> 13#include <string.h> 14#include <unistd.h> 15 16#include "common.h" 17#include "proc.h" 18#include "library.h" 19#include "filter.h" 20 21#ifdef PLT_REINITALISATION_BP 22extern char *PLTs_initialized_by_here; 23#endif 24 25#ifndef DT_PPC_GOT 26# define DT_PPC_GOT (DT_LOPROC + 0) 27#endif 28 29 30#ifndef ARCH_HAVE_LTELF_DATA 31int 32arch_elf_init(struct ltelf *lte) 33{ 34 return 0; 35} 36 37void 38arch_elf_destroy(struct ltelf *lte) 39{ 40} 41#endif 42 43int 44default_elf_add_plt_entry(struct Process *proc, struct ltelf *lte, 45 const char *a_name, GElf_Rela *rela, size_t ndx, 46 struct library_symbol **ret) 47{ 48 char *name = strdup(a_name); 49 if (name == NULL) { 50 fail: 51 free(name); 52 return -1; 53 } 54 55 enum toplt pltt = PLTS_ARE_EXECUTABLE(lte) 56 ? LS_TOPLT_EXEC : LS_TOPLT_POINT; 57 GElf_Addr addr = arch_plt_sym_val(lte, ndx, rela); 58 59 struct library_symbol *libsym = malloc(sizeof(*libsym)); 60 if (libsym == NULL) 61 goto fail; 62 63 target_address_t taddr = (target_address_t)(addr + lte->bias); 64 65 /* The logic behind this conditional translation is as 66 * follows. PLT entries do not typically need custom TOC 67 * pointer, and therefore aren't redirected via OPD. POINT 68 * PLT, on the other hand, most likely contains addresses of 69 * target functions, not PLT entries themselves, and would 70 * need the OPD redirection. */ 71 if (pltt == LS_TOPLT_POINT 72 && arch_translate_address(proc, taddr, &taddr) < 0) { 73 free(libsym); 74 goto fail; 75 } 76 77 library_symbol_init(libsym, taddr, name, 1, pltt); 78 *ret = libsym; 79 return 0; 80} 81 82#ifndef ARCH_HAVE_ADD_PLT_ENTRY 83enum plt_status 84arch_elf_add_plt_entry(struct Process *proc, struct ltelf *lte, 85 const char *a_name, GElf_Rela *rela, size_t ndx, 86 struct library_symbol **ret) 87{ 88 return plt_default; 89} 90#endif 91 92Elf_Data * 93elf_loaddata(Elf_Scn *scn, GElf_Shdr *shdr) 94{ 95 Elf_Data *data = elf_getdata(scn, NULL); 96 if (data == NULL || elf_getdata(scn, data) != NULL 97 || data->d_off || data->d_size != shdr->sh_size) 98 return NULL; 99 return data; 100} 101 102static int 103elf_get_section_if(struct ltelf *lte, Elf_Scn **tgt_sec, GElf_Shdr *tgt_shdr, 104 int (*predicate)(Elf_Scn *, GElf_Shdr *, void *data), 105 void *data) 106{ 107 int i; 108 for (i = 1; i < lte->ehdr.e_shnum; ++i) { 109 Elf_Scn *scn; 110 GElf_Shdr shdr; 111 112 scn = elf_getscn(lte->elf, i); 113 if (scn == NULL || gelf_getshdr(scn, &shdr) == NULL) { 114 debug(1, "Couldn't read section or header."); 115 return -1; 116 } 117 if (predicate(scn, &shdr, data)) { 118 *tgt_sec = scn; 119 *tgt_shdr = shdr; 120 return 0; 121 } 122 } 123 return -1; 124 125} 126 127static int 128inside_p(Elf_Scn *scn, GElf_Shdr *shdr, void *data) 129{ 130 GElf_Addr addr = *(GElf_Addr *)data; 131 return addr >= shdr->sh_addr 132 && addr < shdr->sh_addr + shdr->sh_size; 133} 134 135int 136elf_get_section_covering(struct ltelf *lte, GElf_Addr addr, 137 Elf_Scn **tgt_sec, GElf_Shdr *tgt_shdr) 138{ 139 return elf_get_section_if(lte, tgt_sec, tgt_shdr, 140 &inside_p, &addr); 141} 142 143static int 144type_p(Elf_Scn *scn, GElf_Shdr *shdr, void *data) 145{ 146 GElf_Word type = *(GElf_Word *)data; 147 return shdr->sh_type == type; 148} 149 150int 151elf_get_section_type(struct ltelf *lte, GElf_Word type, 152 Elf_Scn **tgt_sec, GElf_Shdr *tgt_shdr) 153{ 154 return elf_get_section_if(lte, tgt_sec, tgt_shdr, 155 &type_p, &type); 156} 157 158static int 159need_data(Elf_Data *data, size_t offset, size_t size) 160{ 161 assert(data != NULL); 162 if (data->d_size < size || offset > data->d_size - size) { 163 debug(1, "Not enough data to read %zd-byte value" 164 " at offset %zd.", size, offset); 165 return -1; 166 } 167 return 0; 168} 169 170#define DEF_READER(NAME, SIZE) \ 171 int \ 172 NAME(Elf_Data *data, size_t offset, uint##SIZE##_t *retp) \ 173 { \ 174 if (!need_data(data, offset, SIZE / 8) < 0) \ 175 return -1; \ 176 \ 177 if (data->d_buf == NULL) /* NODATA section */ { \ 178 *retp = 0; \ 179 return 0; \ 180 } \ 181 \ 182 union { \ 183 uint##SIZE##_t dst; \ 184 char buf[0]; \ 185 } u; \ 186 memcpy(u.buf, data->d_buf + offset, sizeof(u.dst)); \ 187 *retp = u.dst; \ 188 return 0; \ 189 } 190 191DEF_READER(elf_read_u16, 16) 192DEF_READER(elf_read_u32, 32) 193DEF_READER(elf_read_u64, 64) 194 195#undef DEF_READER 196 197int 198open_elf(struct ltelf *lte, const char *filename) 199{ 200 lte->fd = open(filename, O_RDONLY); 201 if (lte->fd == -1) 202 return 1; 203 204 elf_version(EV_CURRENT); 205 206#ifdef HAVE_ELF_C_READ_MMAP 207 lte->elf = elf_begin(lte->fd, ELF_C_READ_MMAP, NULL); 208#else 209 lte->elf = elf_begin(lte->fd, ELF_C_READ, NULL); 210#endif 211 212 if (lte->elf == NULL || elf_kind(lte->elf) != ELF_K_ELF) 213 error(EXIT_FAILURE, 0, "Can't open ELF file \"%s\"", filename); 214 215 if (gelf_getehdr(lte->elf, <e->ehdr) == NULL) 216 error(EXIT_FAILURE, 0, "Can't read ELF header of \"%s\"", 217 filename); 218 219 if (lte->ehdr.e_type != ET_EXEC && lte->ehdr.e_type != ET_DYN) 220 error(EXIT_FAILURE, 0, 221 "\"%s\" is not an ELF executable nor shared library", 222 filename); 223 224 if ((lte->ehdr.e_ident[EI_CLASS] != LT_ELFCLASS 225 || lte->ehdr.e_machine != LT_ELF_MACHINE) 226#ifdef LT_ELF_MACHINE2 227 && (lte->ehdr.e_ident[EI_CLASS] != LT_ELFCLASS2 228 || lte->ehdr.e_machine != LT_ELF_MACHINE2) 229#endif 230#ifdef LT_ELF_MACHINE3 231 && (lte->ehdr.e_ident[EI_CLASS] != LT_ELFCLASS3 232 || lte->ehdr.e_machine != LT_ELF_MACHINE3) 233#endif 234 ) 235 error(EXIT_FAILURE, 0, 236 "\"%s\" is ELF from incompatible architecture", filename); 237 238 return 0; 239} 240 241static int 242do_init_elf(struct ltelf *lte, const char *filename, GElf_Addr bias) 243{ 244 int i; 245 GElf_Addr relplt_addr = 0; 246 GElf_Addr soname_offset = 0; 247 248 debug(DEBUG_FUNCTION, "do_init_elf(filename=%s)", filename); 249 debug(1, "Reading ELF from %s...", filename); 250 251 if (open_elf(lte, filename) < 0) 252 return -1; 253 254 /* Find out the base address. */ 255 { 256 GElf_Phdr phdr; 257 for (i = 0; gelf_getphdr (lte->elf, i, &phdr) != NULL; ++i) { 258 if (phdr.p_type == PT_LOAD) { 259 lte->base_addr = phdr.p_vaddr + bias; 260 break; 261 } 262 } 263 } 264 265 if (lte->base_addr == 0) { 266 fprintf(stderr, "Couldn't determine base address of %s\n", 267 filename); 268 return -1; 269 } 270 271 lte->bias = bias; 272 lte->entry_addr = lte->ehdr.e_entry + lte->bias; 273 274 for (i = 1; i < lte->ehdr.e_shnum; ++i) { 275 Elf_Scn *scn; 276 GElf_Shdr shdr; 277 const char *name; 278 279 scn = elf_getscn(lte->elf, i); 280 if (scn == NULL || gelf_getshdr(scn, &shdr) == NULL) 281 error(EXIT_FAILURE, 0, 282 "Couldn't get section header from \"%s\"", 283 filename); 284 285 name = elf_strptr(lte->elf, lte->ehdr.e_shstrndx, shdr.sh_name); 286 if (name == NULL) 287 error(EXIT_FAILURE, 0, 288 "Couldn't get section header from \"%s\"", 289 filename); 290 291 if (shdr.sh_type == SHT_SYMTAB) { 292 Elf_Data *data; 293 294 lte->symtab = elf_getdata(scn, NULL); 295 lte->symtab_count = shdr.sh_size / shdr.sh_entsize; 296 if ((lte->symtab == NULL 297 || elf_getdata(scn, lte->symtab) != NULL) 298 && options.static_filter != NULL) 299 error(EXIT_FAILURE, 0, 300 "Couldn't get .symtab data from \"%s\"", 301 filename); 302 303 scn = elf_getscn(lte->elf, shdr.sh_link); 304 if (scn == NULL || gelf_getshdr(scn, &shdr) == NULL) 305 error(EXIT_FAILURE, 0, 306 "Couldn't get section header from \"%s\"", 307 filename); 308 309 data = elf_getdata(scn, NULL); 310 if (data == NULL || elf_getdata(scn, data) != NULL 311 || shdr.sh_size != data->d_size || data->d_off) 312 error(EXIT_FAILURE, 0, 313 "Couldn't get .strtab data from \"%s\"", 314 filename); 315 316 lte->strtab = data->d_buf; 317 } else if (shdr.sh_type == SHT_DYNSYM) { 318 Elf_Data *data; 319 320 lte->dynsym = elf_getdata(scn, NULL); 321 lte->dynsym_count = shdr.sh_size / shdr.sh_entsize; 322 if (lte->dynsym == NULL 323 || elf_getdata(scn, lte->dynsym) != NULL) 324 error(EXIT_FAILURE, 0, 325 "Couldn't get .dynsym data from \"%s\"", 326 filename); 327 328 scn = elf_getscn(lte->elf, shdr.sh_link); 329 if (scn == NULL || gelf_getshdr(scn, &shdr) == NULL) 330 error(EXIT_FAILURE, 0, 331 "Couldn't get section header from \"%s\"", 332 filename); 333 334 data = elf_getdata(scn, NULL); 335 if (data == NULL || elf_getdata(scn, data) != NULL 336 || shdr.sh_size != data->d_size || data->d_off) 337 error(EXIT_FAILURE, 0, 338 "Couldn't get .dynstr data from \"%s\"", 339 filename); 340 341 lte->dynstr = data->d_buf; 342 } else if (shdr.sh_type == SHT_DYNAMIC) { 343 Elf_Data *data; 344 size_t j; 345 346 lte->dyn_addr = shdr.sh_addr; 347 lte->dyn_sz = shdr.sh_size; 348 349 data = elf_getdata(scn, NULL); 350 if (data == NULL || elf_getdata(scn, data) != NULL) 351 error(EXIT_FAILURE, 0, 352 "Couldn't get .dynamic data from \"%s\"", 353 filename); 354 355 for (j = 0; j < shdr.sh_size / shdr.sh_entsize; ++j) { 356 GElf_Dyn dyn; 357 358 if (gelf_getdyn(data, j, &dyn) == NULL) 359 error(EXIT_FAILURE, 0, 360 "Couldn't get .dynamic data from \"%s\"", 361 filename); 362 if (dyn.d_tag == DT_JMPREL) 363 relplt_addr = dyn.d_un.d_ptr; 364 else if (dyn.d_tag == DT_PLTRELSZ) 365 lte->relplt_size = dyn.d_un.d_val; 366 else if (dyn.d_tag == DT_SONAME) 367 soname_offset = dyn.d_un.d_val; 368 } 369 } else if (shdr.sh_type == SHT_PROGBITS 370 || shdr.sh_type == SHT_NOBITS) { 371 if (strcmp(name, ".plt") == 0) { 372 lte->plt_addr = shdr.sh_addr; 373 lte->plt_size = shdr.sh_size; 374 lte->plt_data = elf_loaddata(scn, &shdr); 375 if (lte->plt_data == NULL) 376 fprintf(stderr, 377 "Can't load .plt data\n"); 378 if (shdr.sh_flags & SHF_EXECINSTR) 379 lte->lte_flags |= LTE_PLT_EXECUTABLE; 380 } 381#ifdef ARCH_SUPPORTS_OPD 382 else if (strcmp(name, ".opd") == 0) { 383 lte->opd_addr = (GElf_Addr *) (long) shdr.sh_addr; 384 lte->opd_size = shdr.sh_size; 385 lte->opd = elf_rawdata(scn, NULL); 386 } 387#endif 388 } 389 } 390 391 if (lte->dynsym == NULL || lte->dynstr == NULL) 392 error(EXIT_FAILURE, 0, 393 "Couldn't find .dynsym or .dynstr in \"%s\"", filename); 394 395 if (!relplt_addr || !lte->plt_addr) { 396 debug(1, "%s has no PLT relocations", filename); 397 lte->relplt = NULL; 398 lte->relplt_count = 0; 399 } else if (lte->relplt_size == 0) { 400 debug(1, "%s has unknown PLT size", filename); 401 lte->relplt = NULL; 402 lte->relplt_count = 0; 403 } else { 404 405 for (i = 1; i < lte->ehdr.e_shnum; ++i) { 406 Elf_Scn *scn; 407 GElf_Shdr shdr; 408 409 scn = elf_getscn(lte->elf, i); 410 if (scn == NULL || gelf_getshdr(scn, &shdr) == NULL) 411 error(EXIT_FAILURE, 0, 412 "Couldn't get section header from \"%s\"", 413 filename); 414 if (shdr.sh_addr == relplt_addr 415 && shdr.sh_size == lte->relplt_size) { 416 lte->relplt = elf_getdata(scn, NULL); 417 lte->relplt_count = 418 shdr.sh_size / shdr.sh_entsize; 419 if (lte->relplt == NULL 420 || elf_getdata(scn, lte->relplt) != NULL) 421 error(EXIT_FAILURE, 0, 422 "Couldn't get .rel*.plt data from \"%s\"", 423 filename); 424 break; 425 } 426 } 427 428 if (i == lte->ehdr.e_shnum) 429 error(EXIT_FAILURE, 0, 430 "Couldn't find .rel*.plt section in \"%s\"", 431 filename); 432 433 debug(1, "%s %zd PLT relocations", filename, lte->relplt_count); 434 } 435 436 if (soname_offset != 0) 437 lte->soname = lte->dynstr + soname_offset; 438 439 if (arch_elf_init(lte) < 0) { 440 fprintf(stderr, "Backend initialization failed.\n"); 441 return -1; 442 } 443 444 return 0; 445} 446 447/* XXX temporarily non-static */ 448void 449do_close_elf(struct ltelf *lte) { 450 debug(DEBUG_FUNCTION, "do_close_elf()"); 451 arch_elf_destroy(lte); 452 elf_end(lte->elf); 453 close(lte->fd); 454} 455 456static int 457populate_plt(struct Process *proc, const char *filename, 458 struct ltelf *lte, struct library *lib) 459{ 460 size_t i; 461 for (i = 0; i < lte->relplt_count; ++i) { 462 GElf_Rel rel; 463 GElf_Rela rela; 464 GElf_Sym sym; 465 void *ret; 466 467 if (lte->relplt->d_type == ELF_T_REL) { 468 ret = gelf_getrel(lte->relplt, i, &rel); 469 rela.r_offset = rel.r_offset; 470 rela.r_info = rel.r_info; 471 rela.r_addend = 0; 472 } else { 473 ret = gelf_getrela(lte->relplt, i, &rela); 474 } 475 476 if (ret == NULL 477 || ELF64_R_SYM(rela.r_info) >= lte->dynsym_count 478 || gelf_getsym(lte->dynsym, ELF64_R_SYM(rela.r_info), 479 &sym) == NULL) 480 error(EXIT_FAILURE, 0, 481 "Couldn't get relocation from \"%s\"", 482 filename); 483 484 char const *name = lte->dynstr + sym.st_name; 485 486 if (!filter_matches_symbol(options.plt_filter, name, lib)) 487 continue; 488 489 struct library_symbol *libsym; 490 switch (arch_elf_add_plt_entry(proc, lte, name, 491 &rela, i, &libsym)) { 492 case plt_default: 493 if (default_elf_add_plt_entry(proc, lte, name, 494 &rela, i, &libsym) < 0) 495 case plt_fail: 496 return -1; 497 case plt_ok: 498 if (libsym != NULL) 499 library_add_symbol(lib, libsym); 500 } 501 } 502 return 0; 503} 504 505/* When -x rules result in request to trace several aliases, we only 506 * want to add such symbol once. The only way that those symbols 507 * differ in is their name, e.g. in glibc you have __GI___libc_free, 508 * __cfree, __free, __libc_free, cfree and free all defined on the 509 * same address. So instead we keep this unique symbol struct for 510 * each address, and replace name in libsym with a shorter variant if 511 * we find it. */ 512struct unique_symbol { 513 target_address_t addr; 514 struct library_symbol *libsym; 515}; 516 517static int 518unique_symbol_cmp(const void *key, const void *val) 519{ 520 const struct unique_symbol *sym_key = key; 521 const struct unique_symbol *sym_val = val; 522 return sym_key->addr != sym_val->addr; 523} 524 525static int 526populate_this_symtab(struct Process *proc, const char *filename, 527 struct ltelf *lte, struct library *lib, 528 Elf_Data *symtab, const char *strtab, size_t size) 529{ 530 /* Using sorted array would be arguably better, but this 531 * should be well enough for the number of symbols that we 532 * typically deal with. */ 533 size_t num_symbols = 0; 534 struct unique_symbol *symbols = malloc(sizeof(*symbols) * size); 535 if (symbols == NULL) { 536 error(0, errno, "couldn't insert symbols for -x"); 537 return -1; 538 } 539 540 size_t lib_len = strlen(lib->soname); 541 size_t i; 542 for (i = 0; i < size; ++i) { 543 GElf_Sym sym; 544 if (gelf_getsym(symtab, i, &sym) == NULL) { 545 fail: 546 error(0, errno, "couldn't get symbol #%zd from %s: %s", 547 i, filename, elf_errmsg(-1)); 548 continue; 549 } 550 551 /* XXX support IFUNC as well. */ 552 if (GELF_ST_TYPE(sym.st_info) != STT_FUNC 553 || sym.st_value == 0) 554 continue; 555 556 const char *name = strtab + sym.st_name; 557 if (!filter_matches_symbol(options.static_filter, name, lib)) 558 continue; 559 560 target_address_t addr 561 = (target_address_t)(sym.st_value + lte->bias); 562 target_address_t naddr; 563 if (arch_translate_address(proc, addr, &naddr) < 0) { 564 error(0, errno, "couldn't translate address of %s@%s", 565 name, lib->soname); 566 continue; 567 } 568 if (addr != naddr) 569 naddr += lte->bias; 570 571 char *full_name; 572 if (lib->type != LT_LIBTYPE_MAIN) { 573 full_name = malloc(strlen(name) + 1 + lib_len + 1); 574 if (full_name == NULL) 575 goto fail; 576 sprintf(full_name, "%s@%s", name, lib->soname); 577 } else { 578 full_name = strdup(name); 579 if (full_name == NULL) 580 goto fail; 581 } 582 583 /* Look whether we already have a symbol for this 584 * address. If not, add this one. */ 585 struct unique_symbol key = { naddr, NULL }; 586 struct unique_symbol *unique 587 = lsearch(&key, symbols, &num_symbols, 588 sizeof(*symbols), &unique_symbol_cmp); 589 590 if (unique->libsym == NULL) { 591 struct library_symbol *libsym = malloc(sizeof(*libsym)); 592 if (libsym == NULL) { 593 --num_symbols; 594 goto fail; 595 } 596 library_symbol_init(libsym, naddr, full_name, 597 1, LS_TOPLT_NONE); 598 unique->libsym = libsym; 599 unique->addr = naddr; 600 601 } else if (strlen(full_name) < strlen(unique->libsym->name)) { 602 library_symbol_set_name(unique->libsym, full_name, 1); 603 604 } else { 605 free(full_name); 606 } 607 } 608 609 for (i = 0; i < num_symbols; ++i) { 610 assert(symbols[i].libsym != NULL); 611 library_add_symbol(lib, symbols[i].libsym); 612 } 613 614 free(symbols); 615 616 return 0; 617} 618 619static int 620populate_symtab(struct Process *proc, const char *filename, 621 struct ltelf *lte, struct library *lib) 622{ 623 if (lte->symtab != NULL && lte->strtab != NULL) 624 return populate_this_symtab(proc, filename, lte, lib, 625 lte->symtab, lte->strtab, 626 lte->symtab_count); 627 else 628 return populate_this_symtab(proc, filename, lte, lib, 629 lte->dynsym, lte->dynstr, 630 lte->dynsym_count); 631} 632 633int 634ltelf_read_library(struct library *lib, struct Process *proc, 635 const char *filename, GElf_Addr bias) 636{ 637 struct ltelf lte = {}; 638 if (do_init_elf(<e, filename, bias) < 0) 639 return -1; 640 proc->e_machine = lte.ehdr.e_machine; 641 642 int status = 0; 643 if (lib == NULL) 644 goto fail; 645 646 /* Note that we set soname and pathname as soon as they are 647 * allocated, so in case of further errors, this get released 648 * when LIB is release, which should happen in the caller when 649 * we return error. */ 650 651 if (lib->pathname == NULL) { 652 char *pathname = strdup(filename); 653 if (pathname == NULL) 654 goto fail; 655 library_set_pathname(lib, filename, 1); 656 } 657 658 if (lte.soname != NULL) { 659 char *soname = strdup(lte.soname); 660 if (soname == NULL) 661 goto fail; 662 library_set_soname(lib, soname, 1); 663 } else { 664 const char *soname = rindex(lib->pathname, '/') + 1; 665 if (soname == NULL) 666 soname = lib->pathname; 667 library_set_soname(lib, soname, 0); 668 } 669 670 target_address_t entry = (target_address_t)lte.entry_addr; 671 if (arch_translate_address(proc, entry, &entry) < 0) 672 goto fail; 673 674 lib->base = (target_address_t)lte.base_addr; 675 lib->entry = entry; 676 lib->dyn_addr = (target_address_t)lte.dyn_addr; 677 678 if (filter_matches_library(options.plt_filter, lib) 679 && populate_plt(proc, filename, <e, lib) < 0) 680 goto fail; 681 682 if (filter_matches_library(options.static_filter, lib) 683 && populate_symtab(proc, filename, <e, lib) < 0) 684 goto fail; 685 686done: 687 do_close_elf(<e); 688 return status; 689 690fail: 691 status = -1; 692 goto done; 693} 694 695struct library * 696ltelf_read_main_binary(struct Process *proc, const char *path) 697{ 698 struct library *lib = malloc(sizeof(*lib)); 699 if (lib == NULL) 700 return NULL; 701 library_init(lib, LT_LIBTYPE_MAIN); 702 library_set_pathname(lib, path, 0); 703 704 /* There is a race between running the process and reading its 705 * binary for internal consumption. So open the binary from 706 * the /proc filesystem. XXX Note that there is similar race 707 * for libraries, but there we don't have a nice answer like 708 * that. Presumably we could read the DSOs from the process 709 * memory image, but that's not currently done. */ 710 char *fname = pid2name(proc->pid); 711 if (ltelf_read_library(lib, proc, fname, 0) < 0) { 712 library_destroy(lib); 713 free(lib); 714 return NULL; 715 } 716 717 return lib; 718} 719