]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/mips/readelflib.c
b581ffcfcf6a3e6bb526a4971546edd26979b8e1
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / mips / readelflib.c
1 /* Copyright (C) 1999-2019 Free Software Foundation, Inc.
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
19 License along with the GNU C Library. If not, see
20 <http://www.gnu.org/licenses/>. */
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 {
36 union
37 {
38 Elf64_Ehdr *eh64;
39 Elf32_Ehdr *eh32;
40 ElfW(Ehdr) *eh;
41 }
42 elf_header;
43 int ret;
44
45 elf_header.eh = file_contents;
46 if (elf_header.eh->e_ident [EI_CLASS] == ELFCLASS32)
47 {
48 ret = process_elf32_file (file_name, lib, flag, osversion, soname,
49 file_contents, file_length);
50 if (!ret)
51 {
52 Elf32_Word flags = elf_header.eh32->e_flags;
53 int nan2008 = (flags & EF_MIPS_NAN2008) != 0;
54
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 }
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)
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 }
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
85 #include "elf/readelflib.c"
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
91 #include "elf/readelflib.c"