FreeCalypso > hg > freecalypso-reveng
comparison ticoff/reloc.c @ 110:e650fdc743fe
tiobjd: higher-level reloc handling
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Thu, 03 Apr 2014 03:03:41 +0000 |
parents | c20dc315a9d4 |
children | d97fbe98600b |
comparison
equal
deleted
inserted
replaced
109:e40592990516 | 110:e650fdc743fe |
---|---|
5 #include <sys/types.h> | 5 #include <sys/types.h> |
6 #include <stdio.h> | 6 #include <stdio.h> |
7 #include <stdlib.h> | 7 #include <stdlib.h> |
8 #include "filestruct.h" | 8 #include "filestruct.h" |
9 #include "intstruct.h" | 9 #include "intstruct.h" |
10 #include "coffconst.h" | |
10 #include "globals.h" | 11 #include "globals.h" |
11 | 12 |
12 extern unsigned get_u16(), get_u32(); | 13 extern unsigned get_u16(), get_u32(); |
13 | 14 |
14 cmd_rawrel() | 15 cmd_rawrel() |
31 get_u16(rel->r_reserved), get_u16(rel->r_type)); | 32 get_u16(rel->r_reserved), get_u16(rel->r_type)); |
32 putchar('\n'); | 33 putchar('\n'); |
33 } | 34 } |
34 exit(0); | 35 exit(0); |
35 } | 36 } |
37 | |
38 void | |
39 get_relocs_of_sec(sec) | |
40 struct internal_scnhdr *sec; | |
41 { | |
42 unsigned n; | |
43 struct external_reloc *extrel; | |
44 struct internal_reloc *intrel; | |
45 unsigned lastloc, symidx; | |
46 | |
47 if (sec->int_relocs) | |
48 return; | |
49 if (!sec->nreloc) { | |
50 fprintf(stderr, | |
51 "BUG: get_relocs_of_sec() called for section \"%s\" w/o relocs\n", | |
52 sec->name); | |
53 exit(1); | |
54 } | |
55 intrel = malloc(sizeof(struct internal_reloc) * sec->nreloc); | |
56 if (!intrel) { | |
57 perror("malloc"); | |
58 exit(1); | |
59 } | |
60 sec->int_relocs = intrel; | |
61 extrel = (struct external_reloc *)(filemap + sec->reloc_offset); | |
62 for (n = 0; n < sec->nreloc; n++, extrel++, intrel++) { | |
63 intrel->location = get_u32(extrel->r_vaddr); | |
64 if (n && intrel->location <= lastloc) { | |
65 fprintf(stderr, | |
66 "error: non-increasing reloc order in section \"%s\"\n", | |
67 sec->name); | |
68 exit(1); | |
69 } | |
70 lastloc = intrel->location; | |
71 symidx = get_u32(extrel->r_symndx); | |
72 if (symidx >= nsymtab || !symtab[symidx]) { | |
73 fprintf(stderr, | |
74 "error: reloc references invalid symbol #%u in section \"%s\"\n", | |
75 symidx, sec->name); | |
76 exit(1); | |
77 } | |
78 intrel->sym = symtab[symidx]; | |
79 intrel->type = get_u16(extrel->r_type); | |
80 switch (intrel->type) { | |
81 case RTYPE_LONG: | |
82 intrel->typestr = "Word32"; | |
83 break; | |
84 case RTYPE_THUMB_BL: | |
85 intrel->typestr = "Thumb_BL"; | |
86 break; | |
87 case RTYPE_ARM_B: | |
88 intrel->typestr = "ARM_B"; | |
89 break; | |
90 default: | |
91 fprintf(stderr, | |
92 "error: reloc in section \"%s\" of unexpected type 0x%x\n", | |
93 sec->name, intrel->type); | |
94 exit(1); | |
95 } | |
96 if (get_u16(extrel->r_reserved)) | |
97 fprintf(stderr, | |
98 "warning: reloc in section \"%s\" has non-zero reserved field\n", | |
99 sec->name); | |
100 } | |
101 } | |
102 | |
103 cmd_reloc() | |
104 { | |
105 unsigned n, m; | |
106 struct internal_scnhdr *sec; | |
107 struct internal_reloc *rel; | |
108 | |
109 get_int_section_table(); | |
110 get_int_symbol_table(); | |
111 for (n = 0; n < nsections; n++) { | |
112 sec = sections + n; | |
113 if (!sec->nreloc) | |
114 continue; | |
115 printf("%s:\n\n", sec->name); | |
116 get_relocs_of_sec(sec); | |
117 rel = sec->int_relocs; | |
118 printf("Location Type Symbol relative to\n"); | |
119 for (m = 0; m < sec->nreloc; m++, rel++) | |
120 printf("%08X %-8s %s\n", rel->location, rel->typestr, | |
121 rel->sym->name); | |
122 putchar('\n'); | |
123 } | |
124 exit(0); | |
125 } |