]> git.sur5r.net Git - cc65/blob - src/ld65/mapfile.c
This commit was generated by cvs2svn to compensate for changes in r2,
[cc65] / src / ld65 / mapfile.c
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                 mapfile.c                                 */
4 /*                                                                           */
5 /*                   Map file creation for the ld65 linker                   */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 1998     Ullrich von Bassewitz                                        */
10 /*              Wacholderweg 14                                              */
11 /*              D-70597 Stuttgart                                            */
12 /* EMail:       uz@musoftware.de                                             */
13 /*                                                                           */
14 /*                                                                           */
15 /* This software is provided 'as-is', without any expressed or implied       */
16 /* warranty.  In no event will the authors be held liable for any damages    */
17 /* arising from the use of this software.                                    */
18 /*                                                                           */
19 /* Permission is granted to anyone to use this software for any purpose,     */
20 /* including commercial applications, and to alter it and redistribute it    */
21 /* freely, subject to the following restrictions:                            */
22 /*                                                                           */
23 /* 1. The origin of this software must not be misrepresented; you must not   */
24 /*    claim that you wrote the original software. If you use this software   */
25 /*    in a product, an acknowledgment in the product documentation would be  */
26 /*    appreciated but is not required.                                       */
27 /* 2. Altered source versions must be plainly marked as such, and must not   */
28 /*    be misrepresented as being the original software.                      */
29 /* 3. This notice may not be removed or altered from any source              */
30 /*    distribution.                                                          */
31 /*                                                                           */
32 /*****************************************************************************/
33
34
35
36 #include <stdio.h>
37 #include <string.h>
38 #include <errno.h>
39
40 #include "global.h"
41 #include "error.h"
42 #include "objdata.h"
43 #include "segments.h"
44 #include "dbgsyms.h"
45 #include "exports.h"
46 #include "config.h"
47 #include "mapfile.h"
48
49
50
51 /*****************************************************************************/
52 /*                                   Code                                    */
53 /*****************************************************************************/
54
55
56
57 void CreateMapFile (void)
58 /* Create a map file */
59 {
60     ObjData* O;
61     unsigned I;
62
63     /* Open the map file */
64     FILE* F = fopen (MapFileName, "w");
65     if (F == 0) {
66         Error ("Cannot create map file `%s': %s", MapFileName, strerror (errno));
67     }
68
69     /* Write a modules list */
70     fprintf (F, "Modules list:\n"
71                 "-------------\n");
72     O = ObjRoot;
73     while (O) {
74         if (O->Flags & OBJ_HAVEDATA) {
75             /* We've linked this module */
76             if (O->LibName) {
77                 /* The file is from a library */
78                 fprintf (F, "%s(%s):\n", O->LibName, O->Name);
79             } else {
80                 fprintf (F, "%s:\n", O->Name);
81             }
82             for (I = 0; I < O->SectionCount; ++I) {
83                 const Section* S = O->Sections [I];
84                 /* Don't include zero sized sections if not explicitly
85                  * requested
86                  */
87                 if (VerboseMap || S->Size > 0) {
88                     fprintf (F, "    %-15s   Offs = %06lX   Size = %06lX\n",
89                              S->Seg->Name, S->Offs, S->Size);
90                 }
91             }
92         }
93         O = O->Next;
94     }
95
96     /* Write the segment list */
97     fprintf (F, "\n\n"
98                 "Segment list:\n"
99                 "-------------\n");
100     PrintSegmentMap (F);
101
102     /* Write the exports list */
103     fprintf (F, "\n\n"
104                 "Exports list:\n"
105                 "-------------\n");
106     PrintExportMap (F);
107
108     /* Write the imports list */
109     fprintf (F, "\n\n"
110                 "Imports list:\n"
111                 "-------------\n");
112     PrintImportMap (F);
113
114     /* Close the file */
115     if (fclose (F) != 0) {
116         Error ("Error closing map file `%s': %s", MapFileName, strerror (errno));
117     }
118 }
119
120
121
122 void CreateLabelFile (void)
123 /* Create a label file */
124 {
125     ObjData* O;
126
127     /* Open the map file */
128     FILE* F = fopen (LabelFileName, "w");
129     if (F == 0) {
130         Error ("Cannot create label file `%s': %s", LabelFileName, strerror (errno));
131     }
132
133     /* Print the labels for the export symbols */
134     PrintExportLabels (F);
135
136     /* Print debug symbols from all modules we have linked into the output file */
137     O = ObjRoot;
138     while (O) {
139         if (O->Flags & OBJ_HAVEDATA) {
140             /* We've linked this module */
141             PrintDbgSymLabels (O, F);
142
143         }
144         O = O->Next;
145     }
146
147     /* If we should mark write protected areas as such, do it */
148     if (WProtSegs) {
149         SegDesc* S = SegDescList;
150         while (S) {
151             /* Is this segment write protected and contains data? */
152             if (S->Flags & SF_WPROT && S->Seg->Size > 0) {
153                 /* Write protect the memory area in VICE */
154                 fprintf (F, "wp %04lX %04lX\n",
155                          S->Seg->PC,
156                          S->Seg->PC + S->Seg->Size - 1);
157             }
158             /* Next segment */
159             S = S->Next;
160         }
161     }
162
163     /* Close the file */
164     if (fclose (F) != 0) {
165         Error ("Error closing map file `%s': %s", LabelFileName, strerror (errno));
166     }
167 }
168
169
170