00001 /* 00002 * Copyright 2005 PathScale, Inc. All Rights Reserved. 00003 */ 00004 00005 /* 00006 getarsym.c - implementation of the elf_getarsym(3) function. 00007 Copyright (C) 1995 - 1998 Michael Riepe <michael@stud.uni-hannover.de> 00008 00009 This library is free software; you can redistribute it and/or 00010 modify it under the terms of the GNU Library General Public 00011 License as published by the Free Software Foundation; either 00012 version 2 of the License, or (at your option) any later version. 00013 00014 This library is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00017 Library General Public License for more details. 00018 00019 You should have received a copy of the GNU Library General Public 00020 License along with this library; if not, write to the Free Software 00021 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00022 */ 00023 00024 #include <private.h> 00025 #include <byteswap.h> 00026 00027 #ifndef lint 00028 static const char rcsid[] = "@(#) $Id: getarsym.c,v 1.1.1.1 2005/10/21 19:00:00 marcel Exp $"; 00029 #endif /* lint */ 00030 00031 Elf_Arsym* 00032 elf_getarsym(Elf *elf, size_t *ptr) { 00033 Elf_Arsym *syms; 00034 size_t count; 00035 size_t tmp; 00036 size_t i; 00037 char *s; 00038 char *e; 00039 00040 if (!ptr) { 00041 ptr = &tmp; 00042 } 00043 *ptr = 0; 00044 if (!elf) { 00045 return NULL; 00046 } 00047 elf_assert(elf->e_magic == ELF_MAGIC); 00048 if (elf->e_kind != ELF_K_AR) { 00049 seterr(ERROR_NOTARCHIVE); 00050 return NULL; 00051 } 00052 if (elf->e_symtab && !elf->e_free_syms) { 00053 if (elf->e_symlen < 4) { 00054 seterr(ERROR_SIZE_ARSYMTAB); 00055 return NULL; 00056 } 00057 count = __load_u32M(elf->e_symtab); 00058 if (elf->e_symlen < 4 * (count + 1)) { 00059 seterr(ERROR_SIZE_ARSYMTAB); 00060 return NULL; 00061 } 00062 if (!(syms = (Elf_Arsym*)malloc((count + 1) * sizeof(*syms)))) { 00063 seterr(ERROR_MEM_ARSYMTAB); 00064 return NULL; 00065 } 00066 s = elf->e_symtab + 4 * (count + 1); 00067 e = elf->e_symtab + elf->e_symlen; 00068 for (i = 0; i < count; i++, s++) { 00069 syms[i].as_name = s; 00070 while (s < e && *s) { 00071 s++; 00072 } 00073 if (s >= e) { 00074 seterr(ERROR_SIZE_ARSYMTAB); 00075 free(syms); 00076 return NULL; 00077 } 00078 elf_assert(!*s); 00079 syms[i].as_hash = elf_hash((unsigned char *) syms[i].as_name); 00080 syms[i].as_off = __load_u32M(elf->e_symtab + 4 * (i + 1)); 00081 } 00082 syms[count].as_name = NULL; 00083 syms[count].as_hash = ~0UL; 00084 syms[count].as_off = 0; 00085 elf->e_symtab = (char*)syms; 00086 elf->e_symlen = count + 1; 00087 elf->e_free_syms = 1; 00088 } 00089 *ptr = elf->e_symlen; 00090 return (Elf_Arsym*)elf->e_symtab; 00091 }
1.5.6