Mercurial > hg-old > index.cgi
comparison lwlink/map.c @ 185:b89adfb0d174
Added support for outputting a linkmap
author | lost |
---|---|
date | Sat, 21 Mar 2009 19:47:45 +0000 |
parents | |
children | bae1e3ecdce1 |
comparison
equal
deleted
inserted
replaced
184:220a760ec654 | 185:b89adfb0d174 |
---|---|
1 /* | |
2 map.c | |
3 Copyright © 2009 William Astle | |
4 | |
5 This file is part of LWLINK. | |
6 | |
7 LWLINK is free software: you can redistribute it and/or modify it under the | |
8 terms of the GNU General Public License as published by the Free Software | |
9 Foundation, either version 3 of the License, or (at your option) any later | |
10 version. | |
11 | |
12 This program is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
15 more details. | |
16 | |
17 You should have received a copy of the GNU General Public License along with | |
18 this program. If not, see <http://www.gnu.org/licenses/>. | |
19 | |
20 | |
21 Output information about the linking process | |
22 */ | |
23 | |
24 #ifdef HAVE_CONFIG_H | |
25 #include "config.h" | |
26 #endif | |
27 | |
28 #include <errno.h> | |
29 #include <stdio.h> | |
30 #include <stdlib.h> | |
31 | |
32 #include "lwlink.h" | |
33 #include "util.h" | |
34 | |
35 struct symliste | |
36 { | |
37 char *name; | |
38 char *fn; | |
39 int addr; | |
40 int ext; | |
41 struct symliste *next; | |
42 }; | |
43 | |
44 void display_map(void) | |
45 { | |
46 FILE *of; | |
47 int sn; | |
48 int std = 0; | |
49 struct symliste *slist = NULL; | |
50 struct symliste *ce, *pe, *ne; | |
51 symtab_t *sym; | |
52 int i; | |
53 | |
54 if (!strcmp(map_file, "-")) | |
55 { | |
56 std = 1; | |
57 of = stdout; | |
58 } | |
59 else | |
60 { | |
61 of = fopen(map_file, "w"); | |
62 if (!of) | |
63 { | |
64 fprintf(stderr, "Cannot open map file - using stdout\n"); | |
65 std = 1; | |
66 of = stdout; | |
67 } | |
68 } | |
69 | |
70 // display section list | |
71 for (sn = 0; sn < nsects; sn++) | |
72 { | |
73 fprintf(of, "Section: %s (%s) load at %04X, length %04X\n", | |
74 sectlist[sn].ptr -> name, | |
75 sectlist[sn].ptr -> file -> filename, | |
76 sectlist[sn].ptr -> loadaddress, | |
77 sectlist[sn].ptr -> codesize | |
78 ); | |
79 } | |
80 | |
81 // generate a sorted list of symbols and display it | |
82 for (sn = 0; sn < nsects; sn++) | |
83 { | |
84 for (sym = sectlist[sn].ptr -> localsyms; sym; sym = sym -> next) | |
85 { | |
86 for (pe = NULL, ce = slist; ce; ce = ce -> next) | |
87 { | |
88 i = strcmp(ce -> name, sym -> sym); | |
89 if (i == 0) | |
90 { | |
91 i = strcmp(ce -> fn, sectlist[sn].ptr -> file -> filename); | |
92 } | |
93 if (i > 0) | |
94 break; | |
95 pe = ce; | |
96 } | |
97 ne = lw_malloc(sizeof(struct symliste)); | |
98 ne -> ext = 0; | |
99 ne -> addr = sym -> offset + sectlist[sn].ptr -> loadaddress; | |
100 ne -> next = ce; | |
101 ne -> name = sym -> sym; | |
102 ne -> fn = sectlist[sn].ptr -> file -> filename; | |
103 if (pe) | |
104 pe -> next = ne; | |
105 else | |
106 slist = ne; | |
107 } | |
108 } | |
109 | |
110 for (ce = slist; ce; ce = ce -> next) | |
111 { | |
112 fprintf(of, "Symbol: %s (%s) = %04X\n", ce -> name, ce -> fn, ce -> addr); | |
113 } | |
114 | |
115 if (!std) | |
116 fclose(of); | |
117 } |