1 /*****************************************************************************/
5 /* Map file creation for the ld65 linker */
9 /* (C) 1998-2001 Ullrich von Bassewitz */
11 /* D-70597 Stuttgart */
12 /* EMail: uz@cc65.org */
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. */
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: */
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 */
32 /*****************************************************************************/
52 /*****************************************************************************/
54 /*****************************************************************************/
58 void CreateMapFile (void)
59 /* Create a map file */
64 /* Open the map file */
65 FILE* F = fopen (MapFileName, "w");
67 Error ("Cannot create map file `%s': %s", MapFileName, strerror (errno));
70 /* Write a modules list */
71 fprintf (F, "Modules list:\n"
75 if (O->Flags & OBJ_HAVEDATA) {
76 /* We've linked this module */
78 /* The file is from a library */
79 fprintf (F, "%s(%s):\n", O->LibName, GetObjFileName (O));
81 fprintf (F, "%s:\n", GetObjFileName (O));
83 for (I = 0; I < O->SectionCount; ++I) {
84 const Section* S = O->Sections [I];
85 /* Don't include zero sized sections if not explicitly
88 if (VerboseMap || S->Size > 0) {
89 fprintf (F, " %-15s Offs = %06lX Size = %06lX\n",
90 S->Seg->Name, S->Offs, S->Size);
97 /* Write the segment list */
103 /* Write the exports list */
109 /* Write the imports list */
116 if (fclose (F) != 0) {
117 Error ("Error closing map file `%s': %s", MapFileName, strerror (errno));
123 void CreateLabelFile (void)
124 /* Create a label file */
128 /* Open the label file */
129 FILE* F = fopen (LabelFileName, "w");
131 Error ("Cannot create label file `%s': %s", LabelFileName, strerror (errno));
134 /* Print the labels for the export symbols */
135 PrintExportLabels (F);
137 /* Print debug symbols from all modules we have linked into the output file */
140 if (O->Flags & OBJ_HAVEDATA) {
141 /* We've linked this module */
142 PrintDbgSymLabels (O, F);
148 /* If we should mark write protected areas as such, do it */
150 SegDesc* S = SegDescList;
152 /* Is this segment write protected and contains data? */
153 if (S->Flags & SF_WPROT && S->Seg->Size > 0) {
154 /* Write protect the memory area in VICE */
155 fprintf (F, "wp %04lX %04lX\n",
157 S->Seg->PC + S->Seg->Size - 1);
165 if (fclose (F) != 0) {
166 Error ("Error closing map file `%s': %s", LabelFileName, strerror (errno));
172 void CreateDbgFile (void)
173 /* Create a debug info file */
177 /* Open the debug info file */
178 FILE* F = fopen (DbgFileName, "w");
180 Error ("Cannot create label file `%s': %s", DbgFileName, strerror (errno));
183 /* Print line infos from all modules we have linked into the output file */
186 if (O->Flags & OBJ_HAVEDATA) {
187 /* We've linked this module */
195 if (fclose (F) != 0) {
196 Error ("Error closing map file `%s': %s", DbgFileName, strerror (errno));