readelflib.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* Copyright (C) 1999-2019 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. Contributed by Andreas Jaeger <aj@suse.de>, 1999 and
  4. Jakub Jelinek <jakub@redhat.com>, 1999.
  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. 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.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with the GNU C Library; if not, see
  15. <http://www.gnu.org/licenses/>. */
  16. int process_elf32_file (const char *file_name, const char *lib, int *flag,
  17. unsigned int *osversion, char **soname,
  18. void *file_contents, size_t file_length);
  19. int process_elf64_file (const char *file_name, const char *lib, int *flag,
  20. unsigned int *osversion, char **soname,
  21. void *file_contents, size_t file_length);
  22. /* Returns 0 if everything is ok, != 0 in case of error. */
  23. int
  24. process_elf_file (const char *file_name, const char *lib, int *flag,
  25. unsigned int *osversion, char **soname, void *file_contents,
  26. size_t file_length)
  27. {
  28. ElfW(Ehdr) *elf_header = (ElfW(Ehdr) *) file_contents;
  29. int ret;
  30. if (elf_header->e_ident [EI_CLASS] == ELFCLASS32)
  31. return process_elf32_file (file_name, lib, flag, osversion, soname,
  32. file_contents, file_length);
  33. else
  34. {
  35. ret = process_elf64_file (file_name, lib, flag, osversion, soname,
  36. file_contents, file_length);
  37. /* Sparc 64bit libraries are always libc.so.6+. */
  38. if (!ret)
  39. *flag = FLAG_SPARC_LIB64|FLAG_ELF_LIBC6;
  40. return ret;
  41. }
  42. }
  43. #undef __ELF_NATIVE_CLASS
  44. #undef process_elf_file
  45. #define process_elf_file process_elf32_file
  46. #define __ELF_NATIVE_CLASS 32
  47. #include "elf/readelflib.c"
  48. #undef __ELF_NATIVE_CLASS
  49. #undef process_elf_file
  50. #define process_elf_file process_elf64_file
  51. #define __ELF_NATIVE_CLASS 64
  52. #include "elf/readelflib.c"