]>
Commit | Line | Data |
---|---|---|
688903eb | 1 | /* Copyright (C) 1999-2018 Free Software Foundation, Inc. |
aaca11d8 UD |
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 | |
41bdb6e2 AJ |
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. | |
aaca11d8 UD |
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 | |
41bdb6e2 | 14 | Lesser General Public License for more details. |
aaca11d8 | 15 | |
41bdb6e2 | 16 | You should have received a copy of the GNU Lesser General Public |
59ba27a6 PE |
17 | License along with the GNU C Library; if not, see |
18 | <http://www.gnu.org/licenses/>. */ | |
aaca11d8 UD |
19 | |
20 | ||
21 | int process_elf32_file (const char *file_name, const char *lib, int *flag, | |
a986484f UD |
22 | unsigned int *osversion, char **soname, |
23 | void *file_contents, size_t file_length); | |
aaca11d8 | 24 | int process_elf64_file (const char *file_name, const char *lib, int *flag, |
a986484f UD |
25 | unsigned int *osversion, char **soname, |
26 | void *file_contents, size_t file_length); | |
aaca11d8 UD |
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, | |
a986484f UD |
31 | unsigned int *osversion, char **soname, void *file_contents, |
32 | size_t file_length) | |
aaca11d8 UD |
33 | { |
34 | ElfW(Ehdr) *elf_header = (ElfW(Ehdr) *) file_contents; | |
f1a77b01 | 35 | int ret, file_flag = 0; |
aaca11d8 | 36 | |
f1a77b01 | 37 | switch (elf_header->e_machine) |
aaca11d8 | 38 | { |
f1a77b01 L |
39 | case EM_X86_64: |
40 | if (elf_header->e_ident[EI_CLASS] == ELFCLASS64) | |
41 | /* X86-64 64bit libraries are always libc.so.6+. */ | |
42 | file_flag = FLAG_X8664_LIB64|FLAG_ELF_LIBC6; | |
43 | else | |
44 | /* X32 libraries are always libc.so.6+. */ | |
45 | file_flag = FLAG_X8664_LIBX32|FLAG_ELF_LIBC6; | |
46 | break; | |
47 | #ifndef SKIP_EM_IA_64 | |
48 | case EM_IA_64: | |
49 | if (elf_header->e_ident[EI_CLASS] == ELFCLASS64) | |
aaca11d8 | 50 | { |
f1a77b01 L |
51 | /* IA64 64bit libraries are always libc.so.6+. */ |
52 | file_flag = FLAG_IA64_LIB64|FLAG_ELF_LIBC6; | |
aaca11d8 | 53 | break; |
aaca11d8 | 54 | } |
f1a77b01 L |
55 | goto failed; |
56 | #endif | |
57 | case EM_386: | |
58 | if (elf_header->e_ident[EI_CLASS] == ELFCLASS32) | |
59 | break; | |
60 | /* Fall through. */ | |
61 | default: | |
62 | #ifndef SKIP_EM_IA_64 | |
63 | failed: | |
64 | #endif | |
65 | error (0, 0, _("%s is for unknown machine %d.\n"), | |
66 | file_name, elf_header->e_machine); | |
67 | return 1; | |
68 | } | |
aaca11d8 | 69 | |
f1a77b01 L |
70 | if (elf_header->e_ident[EI_CLASS] == ELFCLASS32) |
71 | ret = process_elf32_file (file_name, lib, flag, osversion, soname, | |
72 | file_contents, file_length); | |
73 | else | |
74 | ret = process_elf64_file (file_name, lib, flag, osversion, soname, | |
75 | file_contents, file_length); | |
aaca11d8 | 76 | |
f1a77b01 L |
77 | if (!ret && file_flag) |
78 | *flag = file_flag; | |
79 | ||
80 | return ret; | |
aaca11d8 UD |
81 | } |
82 | ||
83 | #undef __ELF_NATIVE_CLASS | |
84 | #undef process_elf_file | |
85 | #define process_elf_file process_elf32_file | |
86 | #define __ELF_NATIVE_CLASS 32 | |
2826ac7e | 87 | #include "elf/readelflib.c" |
aaca11d8 UD |
88 | |
89 | #undef __ELF_NATIVE_CLASS | |
90 | #undef process_elf_file | |
91 | #define process_elf_file process_elf64_file | |
92 | #define __ELF_NATIVE_CLASS 64 | |
2826ac7e | 93 | #include "elf/readelflib.c" |