The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1 | /* TODO: |
| 2 | 1. check the ARM EABI version--this works for versions 1 and 2. |
| 3 | 2. use a more-intelligent approach to finding the symbol table, symbol-string |
| 4 | table, and the .dynamic section. |
| 5 | 3. fix the determination of the host and ELF-file endianness |
| 6 | 4. write the help screen |
| 7 | */ |
| 8 | |
| 9 | #include <stdio.h> |
| 10 | #include <common.h> |
| 11 | #include <debug.h> |
| 12 | #include <libelf.h> |
| 13 | #include <libebl.h> |
| 14 | #ifdef ARM_SPECIFIC_HACKS |
| 15 | #include <libebl_arm.h> |
| 16 | #endif/*ARM_SPECIFIC_HACKS*/ |
| 17 | #include <elf.h> |
| 18 | #include <gelf.h> |
| 19 | #include <string.h> |
| 20 | #include <errno.h> |
| 21 | #include <string.h> |
| 22 | #include <sys/types.h> |
| 23 | #include <sys/stat.h> |
| 24 | #include <fcntl.h> |
| 25 | #include <unistd.h> |
| 26 | #include <rangesort.h> |
| 27 | #include <prelink_info.h> |
| 28 | #include <libgen.h> |
| 29 | |
| 30 | |
| 31 | /* Flag set by --verbose. This variable is global as it is accessed by the |
| 32 | macro INFO() in multiple compilation unites. */ |
| 33 | int verbose_flag = 0; |
| 34 | /* Flag set by --quiet. This variable is global as it is accessed by the |
| 35 | macro PRINT() in multiple compilation unites. */ |
| 36 | int quiet_flag = 0; |
| 37 | |
| 38 | int main(int argc, char **argv) { |
| 39 | |
| 40 | argc--, argv++; |
| 41 | if (!argc) |
| 42 | return 0; |
| 43 | |
| 44 | /* Check to see whether the ELF library is current. */ |
| 45 | FAILIF (elf_version(EV_CURRENT) == EV_NONE, "libelf is out of date!\n"); |
| 46 | |
| 47 | const char *filename; |
| 48 | for (; argc; argc--) { |
| 49 | filename = *argv++; |
| 50 | |
| 51 | Elf *elf; |
| 52 | GElf_Ehdr elf_hdr; |
| 53 | int fd; |
| 54 | int prelinked; |
| 55 | long prelink_addr = 0; |
| 56 | |
| 57 | INFO("Processing file [%s]\n", filename); |
| 58 | |
| 59 | fd = open(filename, O_RDONLY); |
| 60 | FAILIF(fd < 0, "open(%d): %s (%d).\n", |
| 61 | filename, |
| 62 | strerror(errno), |
| 63 | errno); |
| 64 | |
| 65 | elf = elf_begin(fd, ELF_C_READ_MMAP_PRIVATE, NULL); |
| 66 | FAILIF_LIBELF(elf == NULL, elf_begin); |
| 67 | |
| 68 | FAILIF_LIBELF(0 == gelf_getehdr(elf, &elf_hdr), |
| 69 | gelf_getehdr); |
| 70 | |
| 71 | #ifdef SUPPORT_ANDROID_PRELINK_TAGS |
| 72 | prelinked = check_prelinked(filename, elf_hdr.e_ident[EI_DATA] == ELFDATA2LSB, |
| 73 | &prelink_addr); |
| 74 | #else |
| 75 | #error 'SUPPORT_ANDROID_PRELINK_TAGS is not defined!' |
| 76 | #endif |
| 77 | |
| 78 | if (prelinked) |
| 79 | PRINT("%s: 0x%08x\n", filename, prelink_addr); |
| 80 | else |
| 81 | PRINT("%s: not prelinked\n", filename); |
| 82 | |
| 83 | FAILIF_LIBELF(elf_end(elf), elf_end); |
| 84 | close(fd); |
| 85 | } |
| 86 | |
| 87 | return 0; |
| 88 | } |
| 89 | |