blob: 8c8ed2819a99bf9024ce5c64601a1c070b254d14 [file] [log] [blame]
wdenk89752b92001-10-23 11:55:05 +00001#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4#include <unistd.h>
5#include <fcntl.h>
6#include <bfd.h>
7#include "error.h"
8
9int verbose = 0;
10
11void
12process_section(bfd *abfd, asection *sect, PTR obj)
13{
14 printf("Section '%s':\n", sect->name);
15
16 printf("\tindex=%d, flags=%x\n", sect->index, sect->flags);
17
18#if 0
19 printf("\tuser_set_vma=%u, reloc_done=%u, linker_mark=%u, gc_mark=%u\n",
20 (unsigned long)sect->user_set_vma, (unsigned long)sect->reloc_done,
21 (unsigned long)sect->linker_mark, (unsigned long)sect->gc_mark);
22#else
23 printf("\tuser_set_vma=%u, reloc_done=%u\n",
24 (unsigned int)sect->user_set_vma, (unsigned int)sect->reloc_done);
25#endif
26
27 printf("\tvma=%08lx, lma=%08lx\n",
28 (unsigned long)sect->vma, (unsigned long)sect->lma);
29
30 printf("\tcooked_size=%ld, raw_size=%ld, output_offset=%ld\n",
31 (long)sect->_cooked_size, (long)sect->_raw_size,
32 (long)sect->output_offset);
33
34 printf("\talignment_power=%d, reloc_count=%d, filepos=%ld\n",
35 sect->alignment_power, sect->reloc_count, sect->filepos);
36
37 printf("\trel_filepos=%ld, line_filepos=%ld, lineno_count=%d\n",
38 sect->rel_filepos, sect->line_filepos, sect->lineno_count);
39
40 printf("\tmoving_line_filepos=%ld, target_index=%d\n",
41 sect->moving_line_filepos, sect->target_index);
42}
43
44int
45main(int ac, char **av)
46{
47 int c, ifd;
48 char *ifn;
49 bfd *bfdp;
50
51 if ((pname = strrchr(av[0], '/')) == NULL)
52 pname = av[0];
53 else
54 pname++;
55
56 while ((c = getopt(ac, av, "v")) != EOF)
57 switch (c) {
58
59 case 'v':
60 verbose = 1;
61 break;
62
63 default:
64 usage:
65 fprintf(stderr, "Usage: %s [-v] imagefile\n", pname);
66 exit(1);
67 }
68 if (optind != ac - 1)
69 goto usage;
70
71 ifn = av[optind];
72
73 if (verbose)
74 fprintf(stderr, "Opening file...\n");
75
76 if ((ifd = open(ifn, O_RDONLY)) < 0)
77 Perror("can't open image file '%s'", ifn);
78
79 if ((bfdp = bfd_fdopenr(ifn, "elf32-powerpc", ifd)) == NULL) {
80 bfd_perror(ifn);
81 close(ifd);
82 Error("bfd_fdopenr of file '%s' failed", ifn);
83 }
84 bfdp->cacheable = true;
85
86 if (!bfd_check_format(bfdp, bfd_object) ||
87 (bfd_get_file_flags(bfdp) & EXEC_P) == 0) {
88 bfd_close(bfdp);
89 Error("file '%s' is not an executable object file (%s,0x%x)", ifn,
90 bfd_format_string(bfd_get_format(bfdp)), bfd_get_file_flags(bfdp));
91 }
92
93 printf("file '%s' is type '%s'...\n", ifn, bfd_get_target(bfdp));
94
95 bfd_map_over_sections(bfdp, process_section, NULL);;
96
97 bfd_close(bfdp);
98
99 if (verbose)
100 fprintf(stderr, "Done.\n");
101
102 return (0);
103}