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 "library.h" |
47 | #include "mapfile.h" |
48 | #include "objdata.h" |
49 | #include "segments.h" |
50 | #include "spool.h" |
51 | |
52 | |
53 | |
54 | /*****************************************************************************/ |
55 | /* Code */ |
56 | /*****************************************************************************/ |
57 | |
58 | |
59 | |
60 | void CreateMapFile (int ShortMap) |
61 | /* Create a map file. If ShortMap is true, only the segment lists are |
62 | ** generated, not the import/export lists. |
63 | */ |
64 | { |
65 | unsigned I; |
66 | |
67 | /* Open the map file */ |
68 | FILE* F = fopen (MapFileName, "w" ); |
69 | if (F == 0) { |
70 | Error ("Cannot create map file '%s': %s" , MapFileName, strerror (errno)); |
71 | } |
72 | |
73 | /* Write a modules list */ |
74 | fprintf (F, "Modules list:\n" |
75 | "-------------\n" ); |
76 | for (I = 0; I < CollCount (&ObjDataList); ++I) { |
77 | |
78 | unsigned J; |
79 | |
80 | /* Get the object file */ |
81 | const ObjData* O = CollConstAt (&ObjDataList, I); |
82 | |
83 | /* Output the data */ |
84 | if (O->Lib) { |
85 | /* The file is from a library */ |
86 | fprintf (F, "%s(%s):\n" , GetLibFileName (O->Lib), GetObjFileName (O)); |
87 | } else { |
88 | fprintf (F, "%s:\n" , GetObjFileName (O)); |
89 | } |
90 | for (J = 0; J < CollCount (&O->Sections); ++J) { |
91 | const Section* S = CollConstAt (&O->Sections, J); |
92 | /* Don't include zero sized sections if not explicitly |
93 | ** requested |
94 | */ |
95 | if (VerboseMap || S->Size > 0) { |
96 | fprintf (F, |
97 | " %-17s Offs=%06lX Size=%06lX " |
98 | "Align=%05lX Fill=%04lX\n" , |
99 | GetString (S->Seg->Name), S->Offs, S->Size, |
100 | S->Alignment, S->Fill); |
101 | } |
102 | } |
103 | } |
104 | |
105 | /* Write the segment list */ |
106 | fprintf (F, "\n\n" |
107 | "Segment list:\n" |
108 | "-------------\n" ); |
109 | PrintSegmentMap (F); |
110 | |
111 | /* The remainder is not written for short map files */ |
112 | if (!ShortMap) { |
113 | |
114 | /* Write the exports list by name */ |
115 | fprintf (F, "\n\n" |
116 | "Exports list by name:\n" |
117 | "---------------------\n" ); |
118 | PrintExportMapByName (F); |
119 | |
120 | /* Write the exports list by value */ |
121 | fprintf (F, "\n\n" |
122 | "Exports list by value:\n" |
123 | "----------------------\n" ); |
124 | PrintExportMapByValue (F); |
125 | |
126 | /* Write the imports list */ |
127 | fprintf (F, "\n\n" |
128 | "Imports list:\n" |
129 | "-------------\n" ); |
130 | PrintImportMap (F); |
131 | } |
132 | |
133 | /* Close the file */ |
134 | if (fclose (F) != 0) { |
135 | Error ("Error closing map file '%s': %s" , MapFileName, strerror (errno)); |
136 | } |
137 | } |
138 | |
139 | |
140 | |
141 | void CreateLabelFile (void) |
142 | /* Create a label file */ |
143 | { |
144 | /* Open the label file */ |
145 | FILE* F = fopen (LabelFileName, "w" ); |
146 | if (F == 0) { |
147 | Error ("Cannot create label file '%s': %s" , LabelFileName, strerror (errno)); |
148 | } |
149 | |
150 | /* Print the labels for the export symbols */ |
151 | PrintExportLabels (F); |
152 | |
153 | /* Output the labels */ |
154 | PrintDbgSymLabels (F); |
155 | |
156 | /* Close the file */ |
157 | if (fclose (F) != 0) { |
158 | Error ("Error closing label file '%s': %s" , LabelFileName, strerror (errno)); |
159 | } |
160 | } |
161 | |