]>
Commit | Line | Data |
---|---|---|
688903eb | 1 | /* Copyright (C) 1999-2018 Free Software Foundation, Inc. |
d2e29db7 AO |
2 | This file is part of the GNU C Library. |
3 | Contributed by Alexandre Oliva <aoliva@redhat.com> | |
4 | Based on work ../x86_64/readelflib.c, | |
5 | contributed by Andreas Jaeger <aj@suse.de>, 1999 and | |
6 | Jakub Jelinek <jakub@redhat.com>, 1999. | |
7 | ||
8 | The GNU C Library is free software; you can redistribute it and/or | |
9 | modify it under the terms of the GNU Lesser General Public | |
10 | License as published by the Free Software Foundation; either | |
11 | version 2.1 of the License, or (at your option) any later version. | |
12 | ||
13 | The GNU C Library is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 | Lesser General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU Lesser General Public | |
ab84e3ff PE |
19 | License along with the GNU C Library. If not, see |
20 | <http://www.gnu.org/licenses/>. */ | |
d2e29db7 AO |
21 | |
22 | ||
23 | int process_elf32_file (const char *file_name, const char *lib, int *flag, | |
24 | unsigned int *osversion, char **soname, | |
25 | void *file_contents, size_t file_length); | |
26 | int process_elf64_file (const char *file_name, const char *lib, int *flag, | |
27 | unsigned int *osversion, char **soname, | |
28 | void *file_contents, size_t file_length); | |
29 | ||
30 | /* Returns 0 if everything is ok, != 0 in case of error. */ | |
31 | int | |
32 | process_elf_file (const char *file_name, const char *lib, int *flag, | |
33 | unsigned int *osversion, char **soname, void *file_contents, | |
34 | size_t file_length) | |
35 | { | |
9c21573c MR |
36 | union |
37 | { | |
38 | Elf64_Ehdr *eh64; | |
39 | Elf32_Ehdr *eh32; | |
40 | ElfW(Ehdr) *eh; | |
41 | } | |
42 | elf_header; | |
d2e29db7 AO |
43 | int ret; |
44 | ||
9c21573c MR |
45 | elf_header.eh = file_contents; |
46 | if (elf_header.eh->e_ident [EI_CLASS] == ELFCLASS32) | |
d2e29db7 AO |
47 | { |
48 | ret = process_elf32_file (file_name, lib, flag, osversion, soname, | |
49 | file_contents, file_length); | |
9c21573c MR |
50 | if (!ret) |
51 | { | |
52 | Elf32_Word flags = elf_header.eh32->e_flags; | |
53 | int nan2008 = (flags & EF_MIPS_NAN2008) != 0; | |
d2e29db7 | 54 | |
9c21573c MR |
55 | /* n32 libraries are always libc.so.6+, o32 only if 2008 NaN. */ |
56 | if ((flags & EF_MIPS_ABI2) != 0) | |
57 | *flag = (nan2008 ? FLAG_MIPS64_LIBN32_NAN2008 | |
58 | : FLAG_MIPS64_LIBN32) | FLAG_ELF_LIBC6; | |
59 | else if (nan2008) | |
60 | *flag = FLAG_MIPS_LIB32_NAN2008 | FLAG_ELF_LIBC6; | |
61 | } | |
d2e29db7 AO |
62 | } |
63 | else | |
64 | { | |
65 | ret = process_elf64_file (file_name, lib, flag, osversion, soname, | |
66 | file_contents, file_length); | |
67 | /* n64 libraries are always libc.so.6+. */ | |
68 | if (!ret) | |
9c21573c MR |
69 | { |
70 | Elf64_Word flags = elf_header.eh64->e_flags; | |
71 | int nan2008 = (flags & EF_MIPS_NAN2008) != 0; | |
72 | ||
73 | *flag = (nan2008 ? FLAG_MIPS64_LIBN64_NAN2008 | |
74 | : FLAG_MIPS64_LIBN64) | FLAG_ELF_LIBC6; | |
75 | } | |
d2e29db7 AO |
76 | } |
77 | ||
78 | return ret; | |
79 | } | |
80 | ||
81 | #undef __ELF_NATIVE_CLASS | |
82 | #undef process_elf_file | |
83 | #define process_elf_file process_elf32_file | |
84 | #define __ELF_NATIVE_CLASS 32 | |
333697c5 | 85 | #include "elf/readelflib.c" |
d2e29db7 AO |
86 | |
87 | #undef __ELF_NATIVE_CLASS | |
88 | #undef process_elf_file | |
89 | #define process_elf_file process_elf64_file | |
90 | #define __ELF_NATIVE_CLASS 64 | |
333697c5 | 91 | #include "elf/readelflib.c" |