check_native: Get rid of alloca
[glibc.git] / sysdeps / x86 / readelflib.c
blob3b8a2281623463f0543d0bedb8130f86e781d4fc
1 /* Copyright (C) 1999-2023 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
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.
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.
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/>. */
18 int process_elf32_file (const char *file_name, const char *lib,
19 int *flag, unsigned int *isa_level, char **soname,
20 void *file_contents, size_t file_length);
21 int process_elf64_file (const char *file_name, const char *lib,
22 int *flag, unsigned int *isa_level, char **soname,
23 void *file_contents, size_t file_length);
25 /* Returns 0 if everything is ok, != 0 in case of error. */
26 int
27 process_elf_file (const char *file_name, const char *lib, int *flag,
28 unsigned int *isa_level, char **soname, void *file_contents,
29 size_t file_length)
31 ElfW(Ehdr) *elf_header = (ElfW(Ehdr) *) file_contents;
32 int ret, file_flag = 0;
34 switch (elf_header->e_machine)
36 case EM_X86_64:
37 if (elf_header->e_ident[EI_CLASS] == ELFCLASS64)
38 /* X86-64 64bit libraries are always libc.so.6+. */
39 file_flag = FLAG_X8664_LIB64|FLAG_ELF_LIBC6;
40 else
41 /* X32 libraries are always libc.so.6+. */
42 file_flag = FLAG_X8664_LIBX32|FLAG_ELF_LIBC6;
43 break;
44 #ifndef __x86_64__
45 case EM_IA_64:
46 if (elf_header->e_ident[EI_CLASS] == ELFCLASS64)
48 /* IA64 64bit libraries are always libc.so.6+. */
49 file_flag = FLAG_IA64_LIB64|FLAG_ELF_LIBC6;
50 break;
52 goto failed;
53 #endif
54 case EM_386:
55 if (elf_header->e_ident[EI_CLASS] == ELFCLASS32)
56 break;
57 /* Fall through. */
58 default:
59 #ifndef __x86_64__
60 failed:
61 #endif
62 error (0, 0, _("%s is for unknown machine %d.\n"),
63 file_name, elf_header->e_machine);
64 return 1;
67 if (elf_header->e_ident[EI_CLASS] == ELFCLASS32)
68 ret = process_elf32_file (file_name, lib, flag, isa_level, soname,
69 file_contents, file_length);
70 else
71 ret = process_elf64_file (file_name, lib, flag, isa_level, soname,
72 file_contents, file_length);
74 if (!ret && file_flag)
75 *flag = file_flag;
77 return ret;
80 #undef __ELF_NATIVE_CLASS
81 #undef process_elf_file
82 #define process_elf_file process_elf32_file
83 #define __ELF_NATIVE_CLASS 32
84 #include "elf/readelflib.c"
86 #undef __ELF_NATIVE_CLASS
87 #undef process_elf_file
88 #define process_elf_file process_elf64_file
89 #define __ELF_NATIVE_CLASS 64
90 #include "elf/readelflib.c"