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