|
Packit |
6c4009 |
/* Support for reading ELF files.
|
|
Packit |
6c4009 |
Copyright (C) 1999-2018 Free Software Foundation, Inc.
|
|
Packit |
6c4009 |
This file is part of the GNU C Library.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit |
6c4009 |
modify it under the terms of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License as published by the Free Software Foundation; either
|
|
Packit |
6c4009 |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit |
6c4009 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
6c4009 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
6c4009 |
Lesser General Public License for more details.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
You should have received a copy of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License along with the GNU C Library; if not, see
|
|
Packit |
6c4009 |
<http://www.gnu.org/licenses/>. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
int process_elf32_file (const char *file_name, const char *lib, int *flag,
|
|
Packit |
6c4009 |
unsigned int *osversion, char **soname,
|
|
Packit |
6c4009 |
void *file_contents, size_t file_length);
|
|
Packit |
6c4009 |
int process_elf64_file (const char *file_name, const char *lib, int *flag,
|
|
Packit |
6c4009 |
unsigned int *osversion, char **soname,
|
|
Packit |
6c4009 |
void *file_contents, size_t file_length);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* The ELF flags supported by our current glibc port:
|
|
Packit |
6c4009 |
- EF_RISCV_FLOAT_ABI: We support the soft and double ABIs.
|
|
Packit |
6c4009 |
- EF_RISCV_RVC: While the Linux ABI mandates the presence of the C
|
|
Packit |
6c4009 |
extension, we can still support libraries compiled without that extension
|
|
Packit |
6c4009 |
so we just ignore this flag.
|
|
Packit |
6c4009 |
- EF_RISCV_RVE: glibc (and Linux) don't support RV32E based systems.
|
|
Packit |
6c4009 |
- EF_RISCV_TSO: The TSO extension isn't supported, as doing so would require
|
|
Packit |
6c4009 |
some mechanism to ensure that the TSO extension is enabled which doesn't
|
|
Packit |
6c4009 |
currently exist. */
|
|
Packit |
6c4009 |
#define SUPPORTED_ELF_FLAGS (EF_RISCV_FLOAT_ABI | EF_RISCV_RVC)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Returns 0 if everything is ok, != 0 in case of error. */
|
|
Packit |
6c4009 |
int
|
|
Packit |
6c4009 |
process_elf_file (const char *file_name, const char *lib, int *flag,
|
|
Packit |
6c4009 |
unsigned int *osversion, char **soname, void *file_contents,
|
|
Packit |
6c4009 |
size_t file_length)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
ElfW(Ehdr) *elf_header = (ElfW(Ehdr) *) file_contents;
|
|
Packit |
6c4009 |
Elf32_Ehdr *elf32_header = (Elf32_Ehdr *) elf_header;
|
|
Packit |
6c4009 |
Elf64_Ehdr *elf64_header = (Elf64_Ehdr *) elf_header;
|
|
Packit |
6c4009 |
int ret;
|
|
Packit |
6c4009 |
long flags;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* RISC-V libraries are always libc.so.6+. */
|
|
Packit |
6c4009 |
*flag = FLAG_ELF_LIBC6;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
if (elf_header->e_ident [EI_CLASS] == ELFCLASS32)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
ret = process_elf32_file (file_name, lib, flag, osversion, soname,
|
|
Packit |
6c4009 |
file_contents, file_length);
|
|
Packit |
6c4009 |
flags = elf32_header->e_flags;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
else
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
ret = process_elf64_file (file_name, lib, flag, osversion, soname,
|
|
Packit |
6c4009 |
file_contents, file_length);
|
|
Packit |
6c4009 |
flags = elf64_header->e_flags;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* RISC-V linkers encode the floating point ABI as part of the ELF headers. */
|
|
Packit |
6c4009 |
switch (flags & EF_RISCV_FLOAT_ABI)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
case EF_RISCV_FLOAT_ABI_SOFT:
|
|
Packit |
6c4009 |
*flag |= FLAG_RISCV_FLOAT_ABI_SOFT;
|
|
Packit |
6c4009 |
break;
|
|
Packit |
6c4009 |
case EF_RISCV_FLOAT_ABI_DOUBLE:
|
|
Packit |
6c4009 |
*flag |= FLAG_RISCV_FLOAT_ABI_DOUBLE;
|
|
Packit |
6c4009 |
break;
|
|
Packit |
6c4009 |
default:
|
|
Packit |
6c4009 |
return 1;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* If there are any other ELF flags set then glibc doesn't support this
|
|
Packit |
6c4009 |
library. */
|
|
Packit |
6c4009 |
if (flags & ~SUPPORTED_ELF_FLAGS)
|
|
Packit |
6c4009 |
return 1;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
return ret;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#undef __ELF_NATIVE_CLASS
|
|
Packit |
6c4009 |
#undef process_elf_file
|
|
Packit |
6c4009 |
#define process_elf_file process_elf32_file
|
|
Packit |
6c4009 |
#define __ELF_NATIVE_CLASS 32
|
|
Packit |
6c4009 |
#include "elf/readelflib.c"
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#undef __ELF_NATIVE_CLASS
|
|
Packit |
6c4009 |
#undef process_elf_file
|
|
Packit |
6c4009 |
#define process_elf_file process_elf64_file
|
|
Packit |
6c4009 |
#define __ELF_NATIVE_CLASS 64
|
|
Packit |
6c4009 |
#include "elf/readelflib.c"
|