annotate lwlink/map.c @ 265:68fbca173508 2.6

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