]> git.sur5r.net Git - cc65/blob - src/ld65/mapfile.c
Fixed an error: The amount of fill bytes for a section was declared as an
[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-2010, Ullrich von Bassewitz                                      */
10 /*                Roemerstrasse 52                                           */
11 /*                D-70794 Filderstadt                                        */
12 /* EMail:         uz@cc65.org                                                */
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 /* ld65 */
41 #include "config.h"
42 #include "dbgsyms.h"
43 #include "exports.h"
44 #include "global.h"
45 #include "error.h"
46 #include "mapfile.h"
47 #include "objdata.h"
48 #include "segments.h"
49 #include "spool.h"
50
51
52
53 /*****************************************************************************/
54 /*                                   Code                                    */
55 /*****************************************************************************/
56
57
58
59 void CreateMapFile (int ShortMap)
60 /* Create a map file. If ShortMap is true, only the segment lists are
61  * generated, not the import/export lists.
62  */
63 {
64     unsigned I;
65
66     /* Open the map file */
67     FILE* F = fopen (MapFileName, "w");
68     if (F == 0) {
69         Error ("Cannot create map file `%s': %s", MapFileName, strerror (errno));
70     }
71
72     /* Write a modules list */
73     fprintf (F, "Modules list:\n"
74                 "-------------\n");
75     for (I = 0; I < CollCount (&ObjDataList); ++I) {
76
77         unsigned J;
78
79         /* Get the object file */
80         const ObjData* O = CollConstAt (&ObjDataList, I);
81
82         /* Output the data */
83         if (O->LibName != INVALID_STRING_ID) {
84             /* The file is from a library */
85             fprintf (F, "%s(%s):\n", GetString (O->LibName), GetObjFileName (O));
86         } else {
87             fprintf (F, "%s:\n", GetObjFileName (O));
88         }
89         for (J = 0; J < CollCount (&O->Sections); ++J) {
90             const Section* S = CollConstAt (&O->Sections, J);
91             /* Don't include zero sized sections if not explicitly
92              * requested
93              */
94             if (VerboseMap || S->Size > 0) {
95                 fprintf (F, "    %-17s Offs = %06lX   Size = %06lX\n",
96                          GetString (S->Seg->Name), S->Offs, S->Size);
97             }
98         }
99     }
100
101     /* Write the segment list */
102     fprintf (F, "\n\n"
103                 "Segment list:\n"
104                 "-------------\n");
105     PrintSegmentMap (F);
106
107     /* The remainder is not written for short map files */
108     if (!ShortMap) {
109
110         /* Write the exports list */
111         fprintf (F, "\n\n"
112                     "Exports list:\n"
113                     "-------------\n");
114         PrintExportMap (F);
115
116         /* Write the imports list */
117         fprintf (F, "\n\n"
118                     "Imports list:\n"
119                     "-------------\n");
120         PrintImportMap (F);
121     }
122
123     /* Close the file */
124     if (fclose (F) != 0) {
125         Error ("Error closing map file `%s': %s", MapFileName, strerror (errno));
126     }
127 }
128
129
130
131 void CreateLabelFile (void)
132 /* Create a label file */
133 {
134     unsigned I;
135
136     /* Open the label file */
137     FILE* F = fopen (LabelFileName, "w");
138     if (F == 0) {
139         Error ("Cannot create label file `%s': %s", LabelFileName, strerror (errno));
140     }
141
142     /* Clear the debug sym table (used to detect duplicates) */
143     ClearDbgSymTable ();
144
145     /* Print the labels for the export symbols */
146     PrintExportLabels (F);
147
148     /* Create labels from all modules we have linked into the output file */
149     for (I = 0; I < CollCount (&ObjDataList); ++I) {
150
151         /* Get the object file */
152         ObjData* O = CollAtUnchecked (&ObjDataList, I);
153
154         /* Output the labels */
155         PrintDbgSymLabels (O, F);
156     }
157
158     /* Close the file */
159     if (fclose (F) != 0) {
160         Error ("Error closing label file `%s': %s", LabelFileName, strerror (errno));
161     }
162 }
163
164
165