comparison old-trunk/lwlink/map.c @ 339:eb230fa7d28e

Prepare for migration to hg
author lost
date Fri, 19 Mar 2010 02:54:14 +0000
parents
children
comparison
equal deleted inserted replaced
338:e7885b3ee266 339:eb230fa7d28e
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 #include <config.h>
25
26 #include <errno.h>
27 #include <stdio.h>
28 #include <stdlib.h>
29
30 #include "lwlink.h"
31 #include "util.h"
32
33 struct symliste
34 {
35 char *name;
36 char *fn;
37 int addr;
38 int ext;
39 struct symliste *next;
40 };
41
42 void display_map(void)
43 {
44 FILE *of;
45 int sn;
46 int std = 0;
47 struct symliste *slist = NULL;
48 struct symliste *ce, *pe, *ne;
49 symtab_t *sym;
50 int i;
51
52 if (!strcmp(map_file, "-"))
53 {
54 std = 1;
55 of = stdout;
56 }
57 else
58 {
59 of = fopen(map_file, "w");
60 if (!of)
61 {
62 fprintf(stderr, "Cannot open map file - using stdout\n");
63 std = 1;
64 of = stdout;
65 }
66 }
67
68 // display section list
69 for (sn = 0; sn < nsects; sn++)
70 {
71 fprintf(of, "Section: %s (%s) load at %04X, length %04X\n",
72 sectlist[sn].ptr -> name,
73 sectlist[sn].ptr -> file -> filename,
74 sectlist[sn].ptr -> loadaddress,
75 sectlist[sn].ptr -> codesize
76 );
77 }
78
79 // generate a sorted list of symbols and display it
80 for (sn = 0; sn < nsects; sn++)
81 {
82 for (sym = sectlist[sn].ptr -> localsyms; sym; sym = sym -> next)
83 {
84 for (pe = NULL, ce = slist; ce; ce = ce -> next)
85 {
86 i = strcmp(ce -> name, sym -> sym);
87 if (i == 0)
88 {
89 i = strcmp(ce -> fn, sectlist[sn].ptr -> file -> filename);
90 }
91 if (i > 0)
92 break;
93 pe = ce;
94 }
95 ne = lw_malloc(sizeof(struct symliste));
96 ne -> ext = 0;
97 ne -> addr = sym -> offset + sectlist[sn].ptr -> loadaddress;
98 ne -> next = ce;
99 ne -> name = sym -> sym;
100 ne -> fn = sectlist[sn].ptr -> file -> filename;
101 if (pe)
102 pe -> next = ne;
103 else
104 slist = ne;
105 }
106 }
107
108 for (ce = slist; ce; ce = ce -> next)
109 {
110 fprintf(of, "Symbol: %s (%s) = %04X\n", ce -> name, ce -> fn, ce -> addr);
111 }
112
113 if (!std)
114 fclose(of);
115 }