Blame sysdeps/unix/sysv/linux/mips/readelflib.c

Packit 6c4009
/* Copyright (C) 1999-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
   Contributed by Alexandre Oliva <aoliva@redhat.com>
Packit 6c4009
   Based on work ../x86_64/readelflib.c,
Packit 6c4009
   contributed by Andreas Jaeger <aj@suse.de>, 1999 and
Packit 6c4009
		  Jakub Jelinek <jakub@redhat.com>, 1999.
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
/* 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
  union
Packit 6c4009
    {
Packit 6c4009
      Elf64_Ehdr *eh64;
Packit 6c4009
      Elf32_Ehdr *eh32;
Packit 6c4009
      ElfW(Ehdr) *eh;
Packit 6c4009
    }
Packit 6c4009
  elf_header;
Packit 6c4009
  int ret;
Packit 6c4009
Packit 6c4009
  elf_header.eh = file_contents;
Packit 6c4009
  if (elf_header.eh->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
      if (!ret)
Packit 6c4009
	{
Packit 6c4009
	  Elf32_Word flags = elf_header.eh32->e_flags;
Packit 6c4009
	  int nan2008 = (flags & EF_MIPS_NAN2008) != 0;
Packit 6c4009
Packit 6c4009
	  /* n32 libraries are always libc.so.6+, o32 only if 2008 NaN.  */
Packit 6c4009
	  if ((flags & EF_MIPS_ABI2) != 0)
Packit 6c4009
	    *flag = (nan2008 ? FLAG_MIPS64_LIBN32_NAN2008
Packit 6c4009
		     : FLAG_MIPS64_LIBN32) | FLAG_ELF_LIBC6;
Packit 6c4009
	  else if (nan2008)
Packit 6c4009
	    *flag = FLAG_MIPS_LIB32_NAN2008 | FLAG_ELF_LIBC6;
Packit 6c4009
	}
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
      /* n64 libraries are always libc.so.6+.  */
Packit 6c4009
      if (!ret)
Packit 6c4009
	{
Packit 6c4009
	  Elf64_Word flags = elf_header.eh64->e_flags;
Packit 6c4009
	  int nan2008 = (flags & EF_MIPS_NAN2008) != 0;
Packit 6c4009
Packit 6c4009
	  *flag = (nan2008 ? FLAG_MIPS64_LIBN64_NAN2008
Packit 6c4009
		   : FLAG_MIPS64_LIBN64) | FLAG_ELF_LIBC6;
Packit 6c4009
	}
Packit 6c4009
    }
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"