chiark / gitweb /
eglibc (2.11.3-4+deb6u3) squeeze-lts; urgency=medium
[eglibc.git] / ports / sysdeps / unix / sysv / linux / mips / readelflib.c
1 /* Copyright (C) 1999, 2001, 2002, 2003, 2005, 2009
2    Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
4    Contributed by Alexandre Oliva <aoliva@redhat.com>
5    Based on work ../x86_64/readelflib.c,
6    contributed by Andreas Jaeger <aj@suse.de>, 1999 and
7                   Jakub Jelinek <jakub@redhat.com>, 1999.
8
9    The GNU C Library is free software; you can redistribute it and/or
10    modify it under the terms of the GNU Lesser General Public
11    License as published by the Free Software Foundation; either
12    version 2.1 of the License, or (at your option) any later version.
13
14    The GNU C Library is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17    Lesser General Public License for more details.
18
19    You should have received a copy of the GNU Lesser General Public
20    License along with the GNU C Library; if not, write to the Free
21    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
22    02111-1307 USA.  */
23
24
25 int process_elf32_file (const char *file_name, const char *lib, int *flag,
26                         unsigned int *osversion, char **soname,
27                         void *file_contents, size_t file_length);
28 int process_elf64_file (const char *file_name, const char *lib, int *flag,
29                         unsigned int *osversion, char **soname,
30                         void *file_contents, size_t file_length);
31
32 /* Returns 0 if everything is ok, != 0 in case of error.  */
33 int
34 process_elf_file (const char *file_name, const char *lib, int *flag,
35                   unsigned int *osversion, char **soname, void *file_contents,
36                   size_t file_length)
37 {
38   ElfW(Ehdr) *elf_header = (ElfW(Ehdr) *) file_contents;
39   int ret;
40
41   if (elf_header->e_ident [EI_CLASS] == ELFCLASS32)
42     {
43       Elf32_Ehdr *elf32_header = (Elf32_Ehdr *) elf_header;
44
45       ret = process_elf32_file (file_name, lib, flag, osversion, soname,
46                                 file_contents, file_length);
47
48       /* n32 libraries are always libc.so.6+.  */
49       if (!ret && (elf32_header->e_flags & EF_MIPS_ABI2) != 0)
50         *flag = FLAG_MIPS64_LIBN32|FLAG_ELF_LIBC6;
51     }
52   else
53     {
54       ret = process_elf64_file (file_name, lib, flag, osversion, soname,
55                                 file_contents, file_length);
56       /* n64 libraries are always libc.so.6+.  */
57       if (!ret)
58         *flag = FLAG_MIPS64_LIBN64|FLAG_ELF_LIBC6;
59     }
60
61   return ret;
62 }
63
64 #undef __ELF_NATIVE_CLASS
65 #undef process_elf_file
66 #define process_elf_file process_elf32_file
67 #define __ELF_NATIVE_CLASS 32
68 #include "elf/readelflib.c"
69
70 #undef __ELF_NATIVE_CLASS
71 #undef process_elf_file
72 #define process_elf_file process_elf64_file
73 #define __ELF_NATIVE_CLASS 64
74 #include "elf/readelflib.c"