Back to index

glibc  2.9
readelflib.c
Go to the documentation of this file.
00001 /* Copyright (C) 1999, 2000, 2001, 2005 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003    Contributed by Andreas Jaeger <aj@suse.de>, 1999 and
00004                 Jakub Jelinek <jakub@redhat.com>, 2000.
00005 
00006    The GNU C Library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Lesser General Public
00008    License as published by the Free Software Foundation; either
00009    version 2.1 of the License, or (at your option) any later version.
00010 
00011    The GNU C Library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Lesser General Public License for more details.
00015 
00016    You should have received a copy of the GNU Lesser General Public
00017    License along with the GNU C Library; if not, write to the Free
00018    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00019    02111-1307 USA.  */
00020 
00021 
00022 int process_elf32_file (const char *file_name, const char *lib, int *flag,
00023                      unsigned int *osversion, char **soname,
00024                      void *file_contents, size_t file_length);
00025 int process_elf64_file (const char *file_name, const char *lib, int *flag,
00026                      unsigned int *osversion, char **soname,
00027                      void *file_contents, size_t file_length);
00028 
00029 /* Returns 0 if everything is ok, != 0 in case of error.  */
00030 int
00031 process_elf_file (const char *file_name, const char *lib, int *flag,
00032                 unsigned int *osversion, char **soname, void *file_contents,
00033                 size_t file_length)
00034 {
00035   ElfW(Ehdr) *elf_header = (ElfW(Ehdr) *) file_contents;
00036   int ret;
00037 
00038   if (elf_header->e_ident [EI_CLASS] == ELFCLASS32)
00039     return process_elf32_file (file_name, lib, flag, osversion, soname,
00040                             file_contents, file_length);
00041   else
00042     {
00043       switch (elf_header->e_machine)
00044        {
00045        case EM_IA_64:
00046        case EM_X86_64:
00047          break;
00048        default:
00049          error (0, 0, _("%s is for unknown machine %d.\n"),
00050                file_name, elf_header->e_machine);
00051          return 1;
00052        }
00053 
00054       ret = process_elf64_file (file_name, lib, flag, osversion, soname,
00055                             file_contents, file_length);
00056       /* IA64/X86-64 64bit libraries are always libc.so.6+.  */
00057       if (!ret)
00058        switch (elf_header->e_machine)
00059          {
00060          case EM_IA_64:
00061            *flag = FLAG_IA64_LIB64|FLAG_ELF_LIBC6;
00062            break;
00063          case EM_X86_64:
00064            *flag = FLAG_X8664_LIB64|FLAG_ELF_LIBC6;
00065            break;
00066          }
00067 
00068       return ret;
00069     }
00070 }
00071 
00072 #undef __ELF_NATIVE_CLASS
00073 #undef process_elf_file
00074 #define process_elf_file process_elf32_file
00075 #define __ELF_NATIVE_CLASS 32
00076 #include "elf/readelflib.c"
00077 
00078 #undef __ELF_NATIVE_CLASS
00079 #undef process_elf_file
00080 #define process_elf_file process_elf64_file
00081 #define __ELF_NATIVE_CLASS 64
00082 #include "elf/readelflib.c"