1 /* Support for reading ELF files.
2 Copyright (C) 1999-2019 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
20 int process_elf32_file (const char *file_name
, const char *lib
, int *flag
,
21 unsigned int *osversion
, char **soname
,
22 void *file_contents
, size_t file_length
);
23 int process_elf64_file (const char *file_name
, const char *lib
, int *flag
,
24 unsigned int *osversion
, char **soname
,
25 void *file_contents
, size_t file_length
);
27 /* The ELF flags supported by our current glibc port:
28 - EF_RISCV_FLOAT_ABI: We support the soft and double ABIs.
29 - EF_RISCV_RVC: While the Linux ABI mandates the presence of the C
30 extension, we can still support libraries compiled without that extension
31 so we just ignore this flag.
32 - EF_RISCV_RVE: glibc (and Linux) don't support RV32E based systems.
33 - EF_RISCV_TSO: The TSO extension isn't supported, as doing so would require
34 some mechanism to ensure that the TSO extension is enabled which doesn't
36 #define SUPPORTED_ELF_FLAGS (EF_RISCV_FLOAT_ABI | EF_RISCV_RVC)
38 /* Returns 0 if everything is ok, != 0 in case of error. */
40 process_elf_file (const char *file_name
, const char *lib
, int *flag
,
41 unsigned int *osversion
, char **soname
, void *file_contents
,
44 ElfW(Ehdr
) *elf_header
= (ElfW(Ehdr
) *) file_contents
;
45 Elf32_Ehdr
*elf32_header
= (Elf32_Ehdr
*) elf_header
;
46 Elf64_Ehdr
*elf64_header
= (Elf64_Ehdr
*) elf_header
;
50 /* RISC-V libraries are always libc.so.6+. */
51 *flag
= FLAG_ELF_LIBC6
;
53 if (elf_header
->e_ident
[EI_CLASS
] == ELFCLASS32
)
55 ret
= process_elf32_file (file_name
, lib
, flag
, osversion
, soname
,
56 file_contents
, file_length
);
57 flags
= elf32_header
->e_flags
;
61 ret
= process_elf64_file (file_name
, lib
, flag
, osversion
, soname
,
62 file_contents
, file_length
);
63 flags
= elf64_header
->e_flags
;
66 /* RISC-V linkers encode the floating point ABI as part of the ELF headers. */
67 switch (flags
& EF_RISCV_FLOAT_ABI
)
69 case EF_RISCV_FLOAT_ABI_SOFT
:
70 *flag
|= FLAG_RISCV_FLOAT_ABI_SOFT
;
72 case EF_RISCV_FLOAT_ABI_DOUBLE
:
73 *flag
|= FLAG_RISCV_FLOAT_ABI_DOUBLE
;
79 /* If there are any other ELF flags set then glibc doesn't support this
81 if (flags
& ~SUPPORTED_ELF_FLAGS
)
87 #undef __ELF_NATIVE_CLASS
88 #undef process_elf_file
89 #define process_elf_file process_elf32_file
90 #define __ELF_NATIVE_CLASS 32
91 #include "elf/readelflib.c"
93 #undef __ELF_NATIVE_CLASS
94 #undef process_elf_file
95 #define process_elf_file process_elf64_file
96 #define __ELF_NATIVE_CLASS 64
97 #include "elf/readelflib.c"