1 | /* Copyright (C) 1999-2021 Free Software Foundation, Inc. |
2 | This file is part of the GNU C Library. |
3 | Contributed by Andreas Jaeger <aj@suse.de>, 1999 and |
4 | Jakub Jelinek <jakub@redhat.com>, 2000. |
5 | |
6 | The GNU C Library is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU Lesser General Public |
8 | License as published by the Free Software Foundation; either |
9 | version 2.1 of the License, or (at your option) any later version. |
10 | |
11 | The GNU C Library is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | Lesser General Public License for more details. |
15 | |
16 | You should have received a copy of the GNU Lesser General Public |
17 | License along with the GNU C Library; if not, see |
18 | <https://www.gnu.org/licenses/>. */ |
19 | |
20 | int process_elf32_file (const char *file_name, const char *lib, |
21 | int *flag, unsigned int *osversion, |
22 | unsigned int *isa_level, char **soname, |
23 | void *file_contents, size_t file_length); |
24 | int process_elf64_file (const char *file_name, const char *lib, |
25 | int *flag, unsigned int *osversion, |
26 | unsigned int *isa_level, char **soname, |
27 | void *file_contents, size_t file_length); |
28 | |
29 | /* Returns 0 if everything is ok, != 0 in case of error. */ |
30 | int |
31 | process_elf_file (const char *file_name, const char *lib, int *flag, |
32 | unsigned int *osversion, unsigned int *isa_level, |
33 | char **soname, void *file_contents, size_t file_length) |
34 | { |
35 | ElfW(Ehdr) * = (ElfW(Ehdr) *) file_contents; |
36 | int ret, file_flag = 0; |
37 | |
38 | switch (elf_header->e_machine) |
39 | { |
40 | case EM_X86_64: |
41 | if (elf_header->e_ident[EI_CLASS] == ELFCLASS64) |
42 | /* X86-64 64bit libraries are always libc.so.6+. */ |
43 | file_flag = FLAG_X8664_LIB64|FLAG_ELF_LIBC6; |
44 | else |
45 | /* X32 libraries are always libc.so.6+. */ |
46 | file_flag = FLAG_X8664_LIBX32|FLAG_ELF_LIBC6; |
47 | break; |
48 | #ifndef __x86_64__ |
49 | case EM_IA_64: |
50 | if (elf_header->e_ident[EI_CLASS] == ELFCLASS64) |
51 | { |
52 | /* IA64 64bit libraries are always libc.so.6+. */ |
53 | file_flag = FLAG_IA64_LIB64|FLAG_ELF_LIBC6; |
54 | break; |
55 | } |
56 | goto failed; |
57 | #endif |
58 | case EM_386: |
59 | if (elf_header->e_ident[EI_CLASS] == ELFCLASS32) |
60 | break; |
61 | /* Fall through. */ |
62 | default: |
63 | #ifndef __x86_64__ |
64 | failed: |
65 | #endif |
66 | error (0, 0, _("%s is for unknown machine %d.\n" ), |
67 | file_name, elf_header->e_machine); |
68 | return 1; |
69 | } |
70 | |
71 | if (elf_header->e_ident[EI_CLASS] == ELFCLASS32) |
72 | ret = process_elf32_file (file_name, lib, flag, osversion, isa_level, |
73 | soname, file_contents, file_length); |
74 | else |
75 | ret = process_elf64_file (file_name, lib, flag, osversion, isa_level, |
76 | soname, file_contents, file_length); |
77 | |
78 | if (!ret && file_flag) |
79 | *flag = file_flag; |
80 | |
81 | return ret; |
82 | } |
83 | |
84 | #undef __ELF_NATIVE_CLASS |
85 | #undef process_elf_file |
86 | #define process_elf_file process_elf32_file |
87 | #define __ELF_NATIVE_CLASS 32 |
88 | #include "elf/readelflib.c" |
89 | |
90 | #undef __ELF_NATIVE_CLASS |
91 | #undef process_elf_file |
92 | #define process_elf_file process_elf64_file |
93 | #define __ELF_NATIVE_CLASS 64 |
94 | #include "elf/readelflib.c" |
95 | |