(root)/
glibc-2.38/
sysdeps/
unix/
sysv/
linux/
loongarch/
readelflib.c
       1  /* Support for reading ELF files.
       2     Copyright (C) 2022-2023 Free Software Foundation, Inc.
       3     This file is part of the GNU C Library.
       4  
       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.
       9  
      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.
      14  
      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     <https://www.gnu.org/licenses/>.  */
      18  
      19  
      20  int process_elf64_file (const char *file_name, const char *lib,
      21  			int *flag, unsigned int *isa_level, char **soname,
      22  			void *file_contents, size_t file_length);
      23  
      24  #define SUPPORTED_ELF_FLAGS \
      25    (EF_LARCH_ABI_DOUBLE_FLOAT | EF_LARCH_ABI_SOFT_FLOAT)
      26  
      27  /* Returns 0 if everything is ok, != 0 in case of error.  */
      28  int
      29  process_elf_file (const char *file_name, const char *lib, int *flag,
      30  		  unsigned int *isa_level, char **soname, void *file_contents,
      31  		  size_t file_length)
      32  {
      33    ElfW(Ehdr) *elf_header = (ElfW(Ehdr) *) file_contents;
      34    Elf64_Ehdr *elf64_header = (Elf64_Ehdr *) elf_header;
      35    int ret;
      36    long flags;
      37  
      38    /* LoongArch libraries are always libc.so.6+.  */
      39    *flag = FLAG_ELF_LIBC6;
      40  
      41    ret = process_elf64_file (file_name, lib, flag, isa_level, soname,
      42  				file_contents, file_length);
      43  
      44    /* The EF_LARCH_OBJABI_V1 flag indicate which set of static relocations
      45     the object might use and it only considered during static linking,
      46     it does not reflect in runtime relocations.  However some binutils
      47     version might set it on dynamic shared object, so clear it to avoid
      48     see the SO as unsupported.  */
      49    flags = elf64_header->e_flags & ~EF_LARCH_OBJABI_V1;
      50  
      51    /* LoongArch linkers encode the floating point ABI as part of the ELF headers.  */
      52    switch (flags & SUPPORTED_ELF_FLAGS)
      53      {
      54        case EF_LARCH_ABI_SOFT_FLOAT:
      55          *flag |= FLAG_LARCH_FLOAT_ABI_SOFT;
      56  	break;
      57        case EF_LARCH_ABI_DOUBLE_FLOAT:
      58          *flag |= FLAG_LARCH_FLOAT_ABI_DOUBLE;
      59  	break;
      60        default:
      61          return 1;
      62      }
      63  
      64    /* If there are any other ELF flags set then glibc doesn't support this
      65       library.  */
      66    if (flags & ~SUPPORTED_ELF_FLAGS)
      67      return 1;
      68  
      69    return ret;
      70  }
      71  
      72  #undef __ELF_NATIVE_CLASS
      73  #undef process_elf_file
      74  #define process_elf_file process_elf64_file
      75  #define __ELF_NATIVE_CLASS 64
      76  #include "elf/readelflib.c"