2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
17 #include "vpx_config.h"
18 #include "vpx/vpx_integer.h"
27 int log_msg(const char *fmt, ...) {
31 res = vfprintf(stderr, fmt, ap);
36 #if defined(__GNUC__) && __GNUC__
39 #include <mach-o/loader.h>
40 #include <mach-o/nlist.h>
42 int print_macho_equ(output_fmt_t mode, uint8_t* name, int val) {
45 printf("%-40s EQU %5d\n", name, val);
48 printf(".set %-40s, %5d\n", name, val);
50 case OUTPUT_FMT_C_HEADER:
51 printf("#define %-40s %5d\n", name, val);
54 log_msg("Unsupported mode: %d", mode);
59 int parse_macho(uint8_t *base_buf, size_t sz, output_fmt_t mode) {
61 struct mach_header header;
62 uint8_t *buf = base_buf;
63 int base_data_section = 0;
66 /* We can read in mach_header for 32 and 64 bit architectures
67 * because it's identical to mach_header_64 except for the last
68 * element (uint32_t reserved), which we don't use. Then, when
69 * we know which architecture we're looking at, increment buf
72 memcpy(&header, buf, sizeof(struct mach_header));
74 if (header.magic == MH_MAGIC) {
75 if (header.cputype == CPU_TYPE_ARM
76 || header.cputype == CPU_TYPE_X86) {
78 buf += sizeof(struct mach_header);
80 log_msg("Bad cputype for object file. Currently only tested for CPU_TYPE_[ARM|X86].\n");
83 } else if (header.magic == MH_MAGIC_64) {
84 if (header.cputype == CPU_TYPE_X86_64) {
86 buf += sizeof(struct mach_header_64);
88 log_msg("Bad cputype for object file. Currently only tested for CPU_TYPE_X86_64.\n");
92 log_msg("Bad magic number for object file. 0x%x or 0x%x expected, 0x%x found.\n",
93 MH_MAGIC, MH_MAGIC_64, header.magic);
97 if (header.filetype != MH_OBJECT) {
98 log_msg("Bad filetype for object file. Currently only tested for MH_OBJECT.\n");
102 for (i = 0; i < header.ncmds; i++) {
103 struct load_command lc;
105 memcpy(&lc, buf, sizeof(struct load_command));
107 if (lc.cmd == LC_SEGMENT) {
108 uint8_t *seg_buf = buf;
110 struct segment_command seg_c;
112 memcpy(&seg_c, seg_buf, sizeof(struct segment_command));
113 seg_buf += sizeof(struct segment_command);
115 /* Although each section is given it's own offset, nlist.n_value
116 * references the offset of the first section. This isn't
117 * apparent without debug information because the offset of the
118 * data section is the same as the first section. However, with
119 * debug sections mixed in, the offset of the debug section
120 * increases but n_value still references the first section.
122 if (seg_c.nsects < 1) {
123 log_msg("Not enough sections\n");
127 memcpy(&s, seg_buf, sizeof(struct section));
128 base_data_section = s.offset;
129 } else if (lc.cmd == LC_SEGMENT_64) {
130 uint8_t *seg_buf = buf;
132 struct segment_command_64 seg_c;
134 memcpy(&seg_c, seg_buf, sizeof(struct segment_command_64));
135 seg_buf += sizeof(struct segment_command_64);
137 /* Explanation in LG_SEGMENT */
138 if (seg_c.nsects < 1) {
139 log_msg("Not enough sections\n");
143 memcpy(&s, seg_buf, sizeof(struct section_64));
144 base_data_section = s.offset;
145 } else if (lc.cmd == LC_SYMTAB) {
146 if (base_data_section != 0) {
147 struct symtab_command sc;
148 uint8_t *sym_buf = base_buf;
149 uint8_t *str_buf = base_buf;
151 memcpy(&sc, buf, sizeof(struct symtab_command));
153 if (sc.cmdsize != sizeof(struct symtab_command)) {
154 log_msg("Can't find symbol table!\n");
158 sym_buf += sc.symoff;
159 str_buf += sc.stroff;
161 for (j = 0; j < sc.nsyms; j++) {
162 /* Location of string is cacluated each time from the
163 * start of the string buffer. On darwin the symbols
164 * are prefixed by "_", so we bump the pointer by 1.
165 * The target value is defined as an int in *_asm_*_offsets.c,
166 * which is 4 bytes on all targets we currently use.
172 memcpy(&nl, sym_buf, sizeof(struct nlist));
173 sym_buf += sizeof(struct nlist);
175 memcpy(&val, base_buf + base_data_section + nl.n_value,
177 print_macho_equ(mode, str_buf + nl.n_un.n_strx + 1, val);
178 } else { /* if (bits == 64) */
182 memcpy(&nl, sym_buf, sizeof(struct nlist_64));
183 sym_buf += sizeof(struct nlist_64);
185 memcpy(&val, base_buf + base_data_section + nl.n_value,
187 print_macho_equ(mode, str_buf + nl.n_un.n_strx + 1, val);
202 #elif defined(__ELF__)
205 #define COPY_STRUCT(dst, buf, ofst, sz) do {\
206 if(ofst + sizeof((*(dst))) > sz) goto bail;\
207 memcpy(dst, buf+ofst, sizeof((*(dst))));\
210 #define ENDIAN_ASSIGN(val, memb) do {\
211 if(!elf->le_data) {log_msg("Big Endian data not supported yet!\n");goto bail;}\
215 #define ENDIAN_ASSIGN_IN_PLACE(memb) do {\
216 ENDIAN_ASSIGN(memb, memb);\
220 uint8_t *buf; /* Buffer containing ELF data */
221 size_t sz; /* Buffer size */
222 int le_data; /* Data is little-endian */
223 unsigned char e_ident[EI_NIDENT]; /* Magic number and other info */
224 int bits; /* 32 or 64 */
229 int parse_elf_header(elf_obj_t *elf) {
231 /* Verify ELF Magic numbers */
232 COPY_STRUCT(&elf->e_ident, elf->buf, 0, elf->sz);
233 res = elf->e_ident[EI_MAG0] == ELFMAG0;
234 res &= elf->e_ident[EI_MAG1] == ELFMAG1;
235 res &= elf->e_ident[EI_MAG2] == ELFMAG2;
236 res &= elf->e_ident[EI_MAG3] == ELFMAG3;
237 res &= elf->e_ident[EI_CLASS] == ELFCLASS32
238 || elf->e_ident[EI_CLASS] == ELFCLASS64;
239 res &= elf->e_ident[EI_DATA] == ELFDATA2LSB;
243 elf->le_data = elf->e_ident[EI_DATA] == ELFDATA2LSB;
245 /* Read in relevant values */
246 if (elf->e_ident[EI_CLASS] == ELFCLASS32) {
248 COPY_STRUCT(&elf->hdr32, elf->buf, 0, elf->sz);
250 ENDIAN_ASSIGN_IN_PLACE(elf->hdr32.e_type);
251 ENDIAN_ASSIGN_IN_PLACE(elf->hdr32.e_machine);
252 ENDIAN_ASSIGN_IN_PLACE(elf->hdr32.e_version);
253 ENDIAN_ASSIGN_IN_PLACE(elf->hdr32.e_entry);
254 ENDIAN_ASSIGN_IN_PLACE(elf->hdr32.e_phoff);
255 ENDIAN_ASSIGN_IN_PLACE(elf->hdr32.e_shoff);
256 ENDIAN_ASSIGN_IN_PLACE(elf->hdr32.e_flags);
257 ENDIAN_ASSIGN_IN_PLACE(elf->hdr32.e_ehsize);
258 ENDIAN_ASSIGN_IN_PLACE(elf->hdr32.e_phentsize);
259 ENDIAN_ASSIGN_IN_PLACE(elf->hdr32.e_phnum);
260 ENDIAN_ASSIGN_IN_PLACE(elf->hdr32.e_shentsize);
261 ENDIAN_ASSIGN_IN_PLACE(elf->hdr32.e_shnum);
262 ENDIAN_ASSIGN_IN_PLACE(elf->hdr32.e_shstrndx);
263 } else { /* if (elf->e_ident[EI_CLASS] == ELFCLASS64) */
265 COPY_STRUCT(&elf->hdr64, elf->buf, 0, elf->sz);
267 ENDIAN_ASSIGN_IN_PLACE(elf->hdr64.e_type);
268 ENDIAN_ASSIGN_IN_PLACE(elf->hdr64.e_machine);
269 ENDIAN_ASSIGN_IN_PLACE(elf->hdr64.e_version);
270 ENDIAN_ASSIGN_IN_PLACE(elf->hdr64.e_entry);
271 ENDIAN_ASSIGN_IN_PLACE(elf->hdr64.e_phoff);
272 ENDIAN_ASSIGN_IN_PLACE(elf->hdr64.e_shoff);
273 ENDIAN_ASSIGN_IN_PLACE(elf->hdr64.e_flags);
274 ENDIAN_ASSIGN_IN_PLACE(elf->hdr64.e_ehsize);
275 ENDIAN_ASSIGN_IN_PLACE(elf->hdr64.e_phentsize);
276 ENDIAN_ASSIGN_IN_PLACE(elf->hdr64.e_phnum);
277 ENDIAN_ASSIGN_IN_PLACE(elf->hdr64.e_shentsize);
278 ENDIAN_ASSIGN_IN_PLACE(elf->hdr64.e_shnum);
279 ENDIAN_ASSIGN_IN_PLACE(elf->hdr64.e_shstrndx);
284 log_msg("Failed to parse ELF file header");
288 int parse_elf_section(elf_obj_t *elf, int idx, Elf32_Shdr *hdr32, Elf64_Shdr *hdr64) {
290 if (idx >= elf->hdr32.e_shnum)
293 COPY_STRUCT(hdr32, elf->buf, elf->hdr32.e_shoff + idx * elf->hdr32.e_shentsize,
295 ENDIAN_ASSIGN_IN_PLACE(hdr32->sh_name);
296 ENDIAN_ASSIGN_IN_PLACE(hdr32->sh_type);
297 ENDIAN_ASSIGN_IN_PLACE(hdr32->sh_flags);
298 ENDIAN_ASSIGN_IN_PLACE(hdr32->sh_addr);
299 ENDIAN_ASSIGN_IN_PLACE(hdr32->sh_offset);
300 ENDIAN_ASSIGN_IN_PLACE(hdr32->sh_size);
301 ENDIAN_ASSIGN_IN_PLACE(hdr32->sh_link);
302 ENDIAN_ASSIGN_IN_PLACE(hdr32->sh_info);
303 ENDIAN_ASSIGN_IN_PLACE(hdr32->sh_addralign);
304 ENDIAN_ASSIGN_IN_PLACE(hdr32->sh_entsize);
305 } else { /* if (hdr64) */
306 if (idx >= elf->hdr64.e_shnum)
309 COPY_STRUCT(hdr64, elf->buf, elf->hdr64.e_shoff + idx * elf->hdr64.e_shentsize,
311 ENDIAN_ASSIGN_IN_PLACE(hdr64->sh_name);
312 ENDIAN_ASSIGN_IN_PLACE(hdr64->sh_type);
313 ENDIAN_ASSIGN_IN_PLACE(hdr64->sh_flags);
314 ENDIAN_ASSIGN_IN_PLACE(hdr64->sh_addr);
315 ENDIAN_ASSIGN_IN_PLACE(hdr64->sh_offset);
316 ENDIAN_ASSIGN_IN_PLACE(hdr64->sh_size);
317 ENDIAN_ASSIGN_IN_PLACE(hdr64->sh_link);
318 ENDIAN_ASSIGN_IN_PLACE(hdr64->sh_info);
319 ENDIAN_ASSIGN_IN_PLACE(hdr64->sh_addralign);
320 ENDIAN_ASSIGN_IN_PLACE(hdr64->sh_entsize);
328 const char *parse_elf_string_table(elf_obj_t *elf, int s_idx, int idx) {
329 if (elf->bits == 32) {
332 if (parse_elf_section(elf, s_idx, &shdr, NULL)) {
333 log_msg("Failed to parse ELF string table: section %d, index %d\n",
338 return (char *)(elf->buf + shdr.sh_offset + idx);
339 } else { /* if (elf->bits == 64) */
342 if (parse_elf_section(elf, s_idx, NULL, &shdr)) {
343 log_msg("Failed to parse ELF string table: section %d, index %d\n",
348 return (char *)(elf->buf + shdr.sh_offset + idx);
352 int parse_elf_symbol(elf_obj_t *elf, unsigned int ofst, Elf32_Sym *sym32, Elf64_Sym *sym64) {
354 COPY_STRUCT(sym32, elf->buf, ofst, elf->sz);
355 ENDIAN_ASSIGN_IN_PLACE(sym32->st_name);
356 ENDIAN_ASSIGN_IN_PLACE(sym32->st_value);
357 ENDIAN_ASSIGN_IN_PLACE(sym32->st_size);
358 ENDIAN_ASSIGN_IN_PLACE(sym32->st_info);
359 ENDIAN_ASSIGN_IN_PLACE(sym32->st_other);
360 ENDIAN_ASSIGN_IN_PLACE(sym32->st_shndx);
361 } else { /* if (sym64) */
362 COPY_STRUCT(sym64, elf->buf, ofst, elf->sz);
363 ENDIAN_ASSIGN_IN_PLACE(sym64->st_name);
364 ENDIAN_ASSIGN_IN_PLACE(sym64->st_value);
365 ENDIAN_ASSIGN_IN_PLACE(sym64->st_size);
366 ENDIAN_ASSIGN_IN_PLACE(sym64->st_info);
367 ENDIAN_ASSIGN_IN_PLACE(sym64->st_other);
368 ENDIAN_ASSIGN_IN_PLACE(sym64->st_shndx);
375 int parse_elf(uint8_t *buf, size_t sz, output_fmt_t mode) {
379 Elf32_Off strtab_off32;
380 Elf64_Off strtab_off64; /* save String Table offset for later use */
382 memset(&elf, 0, sizeof(elf));
387 if (parse_elf_header(&elf))
390 if (elf.bits == 32) {
392 for (i = 0; i < elf.hdr32.e_shnum; i++) {
393 parse_elf_section(&elf, i, &shdr, NULL);
395 if (shdr.sh_type == SHT_STRTAB) {
396 char strtsb_name[128];
398 strcpy(strtsb_name, (char *)(elf.buf + shdr.sh_offset + shdr.sh_name));
400 if (!(strcmp(strtsb_name, ".shstrtab"))) {
401 /* log_msg("found section: %s\n", strtsb_name); */
402 strtab_off32 = shdr.sh_offset;
407 } else { /* if (elf.bits == 64) */
409 for (i = 0; i < elf.hdr64.e_shnum; i++) {
410 parse_elf_section(&elf, i, NULL, &shdr);
412 if (shdr.sh_type == SHT_STRTAB) {
413 char strtsb_name[128];
415 strcpy(strtsb_name, (char *)(elf.buf + shdr.sh_offset + shdr.sh_name));
417 if (!(strcmp(strtsb_name, ".shstrtab"))) {
418 /* log_msg("found section: %s\n", strtsb_name); */
419 strtab_off64 = shdr.sh_offset;
426 /* Parse all Symbol Tables */
427 if (elf.bits == 32) {
429 for (i = 0; i < elf.hdr32.e_shnum; i++) {
430 parse_elf_section(&elf, i, &shdr, NULL);
432 if (shdr.sh_type == SHT_SYMTAB) {
433 for (ofst = shdr.sh_offset;
434 ofst < shdr.sh_offset + shdr.sh_size;
435 ofst += shdr.sh_entsize) {
438 parse_elf_symbol(&elf, ofst, &sym, NULL);
440 /* For all OBJECTS (data objects), extract the value from the
441 * proper data segment.
443 /* if (ELF32_ST_TYPE(sym.st_info) == STT_OBJECT && sym.st_name)
444 log_msg("found data object %s\n",
445 parse_elf_string_table(&elf,
450 if (ELF32_ST_TYPE(sym.st_info) == STT_OBJECT
451 && sym.st_size == 4) {
454 char section_name[128];
456 parse_elf_section(&elf, sym.st_shndx, &dhdr, NULL);
458 /* For explanition - refer to _MSC_VER version of code */
459 strcpy(section_name, (char *)(elf.buf + strtab_off32 + dhdr.sh_name));
460 /* log_msg("Section_name: %s, Section_type: %d\n", section_name, dhdr.sh_type); */
462 if (strcmp(section_name, ".bss")) {
463 if (sizeof(val) != sym.st_size) {
464 /* The target value is declared as an int in
465 * *_asm_*_offsets.c, which is 4 bytes on all
466 * targets we currently use. Complain loudly if
469 log_msg("Symbol size is wrong\n");
474 elf.buf + dhdr.sh_offset + sym.st_value,
479 log_msg("Big Endian data not supported yet!\n");
484 case OUTPUT_FMT_RVDS:
485 printf("%-40s EQU %5d\n",
486 parse_elf_string_table(&elf,
492 printf(".equ %-40s, %5d\n",
493 parse_elf_string_table(&elf,
498 case OUTPUT_FMT_C_HEADER:
499 printf("#define %-40s %5d\n",
500 parse_elf_string_table(&elf,
507 parse_elf_string_table(&elf,
516 } else { /* if (elf.bits == 64) */
518 for (i = 0; i < elf.hdr64.e_shnum; i++) {
519 parse_elf_section(&elf, i, NULL, &shdr);
521 if (shdr.sh_type == SHT_SYMTAB) {
522 for (ofst = shdr.sh_offset;
523 ofst < shdr.sh_offset + shdr.sh_size;
524 ofst += shdr.sh_entsize) {
527 parse_elf_symbol(&elf, ofst, NULL, &sym);
529 /* For all OBJECTS (data objects), extract the value from the
530 * proper data segment.
532 /* if (ELF64_ST_TYPE(sym.st_info) == STT_OBJECT && sym.st_name)
533 log_msg("found data object %s\n",
534 parse_elf_string_table(&elf,
539 if (ELF64_ST_TYPE(sym.st_info) == STT_OBJECT
540 && sym.st_size == 4) {
543 char section_name[128];
545 parse_elf_section(&elf, sym.st_shndx, NULL, &dhdr);
547 /* For explanition - refer to _MSC_VER version of code */
548 strcpy(section_name, (char *)(elf.buf + strtab_off64 + dhdr.sh_name));
549 /* log_msg("Section_name: %s, Section_type: %d\n", section_name, dhdr.sh_type); */
551 if ((strcmp(section_name, ".bss"))) {
552 if (sizeof(val) != sym.st_size) {
553 /* The target value is declared as an int in
554 * *_asm_*_offsets.c, which is 4 bytes on all
555 * targets we currently use. Complain loudly if
558 log_msg("Symbol size is wrong\n");
563 elf.buf + dhdr.sh_offset + sym.st_value,
568 log_msg("Big Endian data not supported yet!\n");
573 case OUTPUT_FMT_RVDS:
574 printf("%-40s EQU %5d\n",
575 parse_elf_string_table(&elf,
581 printf(".equ %-40s, %5d\n",
582 parse_elf_string_table(&elf,
589 parse_elf_string_table(&elf,
600 if (mode == OUTPUT_FMT_RVDS)
605 log_msg("Parse error: File does not appear to be valid ELF32 or ELF64\n");
610 #endif /* defined(__GNUC__) && __GNUC__ */
613 #if defined(_MSC_VER) || defined(__MINGW32__) || defined(__CYGWIN__)
614 /* See "Microsoft Portable Executable and Common Object File Format Specification"
617 #define get_le32(x) ((*(x)) | (*(x+1)) << 8 |(*(x+2)) << 16 | (*(x+3)) << 24 )
618 #define get_le16(x) ((*(x)) | (*(x+1)) << 8)
620 int parse_coff(uint8_t *buf, size_t sz) {
621 unsigned int nsections, symtab_ptr, symtab_sz, strtab_ptr;
622 unsigned int sectionrawdata_ptr;
627 char **sectionlist; // this array holds all section names in their correct order.
628 // it is used to check if the symbol is in .bss or .rdata section.
630 nsections = get_le16(buf + 2);
631 symtab_ptr = get_le32(buf + 8);
632 symtab_sz = get_le32(buf + 12);
633 strtab_ptr = symtab_ptr + symtab_sz * 18;
635 if (nsections > 96) {
636 log_msg("Too many sections\n");
640 sectionlist = malloc(nsections * sizeof(sectionlist));
642 if (sectionlist == NULL) {
643 log_msg("Allocating first level of section list failed\n");
647 // log_msg("COFF: Found %u symbols in %u sections.\n", symtab_sz, nsections);
650 The size of optional header is always zero for an obj file. So, the section header
651 follows the file header immediately.
654 ptr = buf + 20; // section header
656 for (i = 0; i < nsections; i++) {
657 char sectionname[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
658 strncpy(sectionname, ptr, 8);
659 // log_msg("COFF: Parsing section %s\n",sectionname);
661 sectionlist[i] = malloc(strlen(sectionname) + 1);
663 if (sectionlist[i] == NULL) {
664 log_msg("Allocating storage for %s failed\n", sectionname);
667 strcpy(sectionlist[i], sectionname);
669 // check if it's .rdata and is not a COMDAT section.
670 if (!strcmp(sectionname, ".rdata") &&
671 (get_le32(ptr + 36) & 0x1000) == 0) {
672 sectionrawdata_ptr = get_le32(ptr + 20);
678 // log_msg("COFF: Symbol table at offset %u\n", symtab_ptr);
679 // log_msg("COFF: raw data pointer ofset for section .rdata is %u\n", sectionrawdata_ptr);
681 /* The compiler puts the data with non-zero offset in .rdata section, but puts the data with
682 zero offset in .bss section. So, if the data in in .bss section, set offset=0.
683 Note from Wiki: In an object module compiled from C, the bss section contains
684 the local variables (but not functions) that were declared with the static keyword,
685 except for those with non-zero initial values. (In C, static variables are initialized
686 to zero by default.) It also contains the non-local (both extern and static) variables
687 that are also initialized to zero (either explicitly or by default).
689 // move to symbol table
690 /* COFF symbol table:
697 17 NumberOfAuxSymbols
699 ptr = buf + symtab_ptr;
701 for (i = 0; i < symtab_sz; i++) {
702 int16_t section = get_le16(ptr + 12); // section number
704 if (section > 0 && ptr[16] == 2) {
705 // if(section > 0 && ptr[16] == 3 && get_le32(ptr+8)) {
708 char name[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
709 strncpy(name, ptr, 8);
710 // log_msg("COFF: Parsing symbol %s\n",name);
711 /* The 64bit Windows compiler doesn't prefix with an _.
712 * Check what's there, and bump if necessary
715 printf("%-40s EQU ", name + 1);
717 printf("%-40s EQU ", name);
719 // log_msg("COFF: Parsing symbol %s\n",
720 // buf + strtab_ptr + get_le32(ptr+4));
721 if ((buf + strtab_ptr + get_le32(ptr + 4))[0] == '_')
723 buf + strtab_ptr + get_le32(ptr + 4) + 1);
725 printf("%-40s EQU ", buf + strtab_ptr + get_le32(ptr + 4));
728 if (!(strcmp(sectionlist[section - 1], ".bss"))) {
731 symoffset = get_le32(buf + sectionrawdata_ptr + get_le32(ptr + 8));
734 // log_msg(" Section: %d\n",section);
735 // log_msg(" Class: %d\n",ptr[16]);
736 // log_msg(" Address: %u\n",get_le32(ptr+8));
737 // log_msg(" Offset: %u\n", symoffset);
739 printf("%5d\n", symoffset);
747 for (i = 0; i < nsections; i++) {
748 free(sectionlist[i]);
756 for (i = 0; i < nsections; i++) {
757 free(sectionlist[i]);
764 #endif /* defined(_MSC_VER) || defined(__MINGW32__) || defined(__CYGWIN__) */
766 int main(int argc, char **argv) {
767 output_fmt_t mode = OUTPUT_FMT_PLAIN;
774 if (argc < 2 || argc > 3) {
775 fprintf(stderr, "Usage: %s [output format] <obj file>\n\n", argv[0]);
776 fprintf(stderr, " <obj file>\tobject file to parse\n");
777 fprintf(stderr, "Output Formats:\n");
778 fprintf(stderr, " gas - compatible with GNU assembler\n");
779 fprintf(stderr, " rvds - compatible with armasm\n");
780 fprintf(stderr, " cheader - c/c++ header file\n");
786 if (!strcmp(argv[1], "rvds"))
787 mode = OUTPUT_FMT_RVDS;
788 else if (!strcmp(argv[1], "gas"))
789 mode = OUTPUT_FMT_GAS;
790 else if (!strcmp(argv[1], "cheader"))
791 mode = OUTPUT_FMT_C_HEADER;
798 perror("Unable to open file");
802 if (fseek(fp, 0, SEEK_END)) {
807 file_size = ftell(fp);
808 file_buf = malloc(file_size);
817 if (fread(file_buf, sizeof(char), file_size, fp) != file_size) {
827 #if defined(__GNUC__) && __GNUC__
828 #if defined(__MACH__)
829 res = parse_macho(file_buf, file_size, mode);
830 #elif defined(__ELF__)
831 res = parse_elf(file_buf, file_size, mode);
834 #if defined(_MSC_VER) || defined(__MINGW32__) || defined(__CYGWIN__)
835 res = parse_coff(file_buf, file_size);