annotate lwlink/map.c @ 405:7bcc50e828ff

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