Add Changelog ...
[jlayton/glibc.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, see
21    <http://www.gnu.org/licenses/>.  */
22
23
24 int process_elf32_file (const char *file_name, const char *lib, int *flag,
25                         unsigned int *osversion, char **soname,
26                         void *file_contents, size_t file_length);
27 int process_elf64_file (const char *file_name, const char *lib, int *flag,
28                         unsigned int *osversion, char **soname,
29                         void *file_contents, size_t file_length);
30
31 /* Returns 0 if everything is ok, != 0 in case of error.  */
32 int
33 process_elf_file (const char *file_name, const char *lib, int *flag,
34                   unsigned int *osversion, char **soname, void *file_contents,
35                   size_t file_length)
36 {
37   ElfW(Ehdr) *elf_header = (ElfW(Ehdr) *) file_contents;
38   int ret;
39
40   if (elf_header->e_ident [EI_CLASS] == ELFCLASS32)
41     {
42       Elf32_Ehdr *elf32_header = (Elf32_Ehdr *) elf_header;
43
44       ret = process_elf32_file (file_name, lib, flag, osversion, soname,
45                                 file_contents, file_length);
46
47       /* n32 libraries are always libc.so.6+.  */
48       if (!ret && (elf32_header->e_flags & EF_MIPS_ABI2) != 0)
49         *flag = FLAG_MIPS64_LIBN32|FLAG_ELF_LIBC6;
50     }
51   else
52     {
53       ret = process_elf64_file (file_name, lib, flag, osversion, soname,
54                                 file_contents, file_length);
55       /* n64 libraries are always libc.so.6+.  */
56       if (!ret)
57         *flag = FLAG_MIPS64_LIBN64|FLAG_ELF_LIBC6;
58     }
59
60   return ret;
61 }
62
63 #undef __ELF_NATIVE_CLASS
64 #undef process_elf_file
65 #define process_elf_file process_elf32_file
66 #define __ELF_NATIVE_CLASS 32
67 #include "elf/readelflib.c"
68
69 #undef __ELF_NATIVE_CLASS
70 #undef process_elf_file
71 #define process_elf_file process_elf64_file
72 #define __ELF_NATIVE_CLASS 64
73 #include "elf/readelflib.c"