2000-05-28 13:40:48 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* */
|
2013-05-09 11:56:54 +00:00
|
|
|
/* mapfile.c */
|
2000-05-28 13:40:48 +00:00
|
|
|
/* */
|
2013-05-09 11:56:54 +00:00
|
|
|
/* Map file creation for the ld65 linker */
|
2000-05-28 13:40:48 +00:00
|
|
|
/* */
|
|
|
|
/* */
|
|
|
|
/* */
|
2010-07-30 20:58:51 +00:00
|
|
|
/* (C) 1998-2010, Ullrich von Bassewitz */
|
|
|
|
/* Roemerstrasse 52 */
|
|
|
|
/* D-70794 Filderstadt */
|
|
|
|
/* EMail: uz@cc65.org */
|
2000-05-28 13:40:48 +00:00
|
|
|
/* */
|
|
|
|
/* */
|
|
|
|
/* This software is provided 'as-is', without any expressed or implied */
|
|
|
|
/* warranty. In no event will the authors be held liable for any damages */
|
|
|
|
/* arising from the use of this software. */
|
|
|
|
/* */
|
|
|
|
/* Permission is granted to anyone to use this software for any purpose, */
|
|
|
|
/* including commercial applications, and to alter it and redistribute it */
|
|
|
|
/* freely, subject to the following restrictions: */
|
|
|
|
/* */
|
|
|
|
/* 1. The origin of this software must not be misrepresented; you must not */
|
|
|
|
/* claim that you wrote the original software. If you use this software */
|
|
|
|
/* in a product, an acknowledgment in the product documentation would be */
|
|
|
|
/* appreciated but is not required. */
|
|
|
|
/* 2. Altered source versions must be plainly marked as such, and must not */
|
|
|
|
/* be misrepresented as being the original software. */
|
|
|
|
/* 3. This notice may not be removed or altered from any source */
|
|
|
|
/* distribution. */
|
|
|
|
/* */
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
2003-06-04 12:40:14 +00:00
|
|
|
/* ld65 */
|
|
|
|
#include "config.h"
|
2000-05-28 13:40:48 +00:00
|
|
|
#include "dbgsyms.h"
|
|
|
|
#include "exports.h"
|
2003-06-04 12:40:14 +00:00
|
|
|
#include "global.h"
|
|
|
|
#include "error.h"
|
2011-08-07 11:33:28 +00:00
|
|
|
#include "library.h"
|
2000-05-28 13:40:48 +00:00
|
|
|
#include "mapfile.h"
|
2003-06-04 12:40:14 +00:00
|
|
|
#include "objdata.h"
|
|
|
|
#include "segments.h"
|
|
|
|
#include "spool.h"
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2013-05-09 11:56:54 +00:00
|
|
|
/* Code */
|
2000-05-28 13:40:48 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-01-23 11:19:26 +00:00
|
|
|
void CreateMapFile (int ShortMap)
|
|
|
|
/* Create a map file. If ShortMap is true, only the segment lists are
|
2014-06-30 09:10:35 +00:00
|
|
|
** generated, not the import/export lists.
|
|
|
|
*/
|
2000-05-28 13:40:48 +00:00
|
|
|
{
|
|
|
|
unsigned I;
|
|
|
|
|
|
|
|
/* Open the map file */
|
|
|
|
FILE* F = fopen (MapFileName, "w");
|
|
|
|
if (F == 0) {
|
2019-01-05 19:57:12 +00:00
|
|
|
Error ("Cannot create map file '%s': %s", MapFileName, strerror (errno));
|
2000-05-28 13:40:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Write a modules list */
|
|
|
|
fprintf (F, "Modules list:\n"
|
2013-05-09 11:56:54 +00:00
|
|
|
"-------------\n");
|
2003-06-05 16:50:01 +00:00
|
|
|
for (I = 0; I < CollCount (&ObjDataList); ++I) {
|
|
|
|
|
|
|
|
unsigned J;
|
|
|
|
|
|
|
|
/* Get the object file */
|
|
|
|
const ObjData* O = CollConstAt (&ObjDataList, I);
|
|
|
|
|
|
|
|
/* Output the data */
|
2011-08-07 11:33:28 +00:00
|
|
|
if (O->Lib) {
|
2003-06-05 16:50:01 +00:00
|
|
|
/* The file is from a library */
|
2011-08-07 11:33:28 +00:00
|
|
|
fprintf (F, "%s(%s):\n", GetLibFileName (O->Lib), GetObjFileName (O));
|
2003-06-05 16:50:01 +00:00
|
|
|
} else {
|
|
|
|
fprintf (F, "%s:\n", GetObjFileName (O));
|
|
|
|
}
|
2010-07-30 20:58:51 +00:00
|
|
|
for (J = 0; J < CollCount (&O->Sections); ++J) {
|
|
|
|
const Section* S = CollConstAt (&O->Sections, J);
|
2003-06-05 16:50:01 +00:00
|
|
|
/* Don't include zero sized sections if not explicitly
|
2014-06-30 09:10:35 +00:00
|
|
|
** requested
|
|
|
|
*/
|
2003-06-05 16:50:01 +00:00
|
|
|
if (VerboseMap || S->Size > 0) {
|
2011-12-28 16:28:19 +00:00
|
|
|
fprintf (F,
|
|
|
|
" %-17s Offs=%06lX Size=%06lX "
|
|
|
|
"Align=%05lX Fill=%04lX\n",
|
|
|
|
GetString (S->Seg->Name), S->Offs, S->Size,
|
|
|
|
S->Alignment, S->Fill);
|
2003-06-05 16:50:01 +00:00
|
|
|
}
|
|
|
|
}
|
2000-05-28 13:40:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Write the segment list */
|
|
|
|
fprintf (F, "\n\n"
|
2013-05-09 11:56:54 +00:00
|
|
|
"Segment list:\n"
|
|
|
|
"-------------\n");
|
2000-05-28 13:40:48 +00:00
|
|
|
PrintSegmentMap (F);
|
|
|
|
|
2005-01-23 11:19:26 +00:00
|
|
|
/* The remainder is not written for short map files */
|
|
|
|
if (!ShortMap) {
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2014-03-20 01:01:21 +00:00
|
|
|
/* Write the exports list by name */
|
2005-01-23 11:19:26 +00:00
|
|
|
fprintf (F, "\n\n"
|
2014-03-20 01:01:21 +00:00
|
|
|
"Exports list by name:\n"
|
|
|
|
"---------------------\n");
|
|
|
|
PrintExportMapByName (F);
|
|
|
|
|
|
|
|
/* Write the exports list by value */
|
|
|
|
fprintf (F, "\n\n"
|
2014-03-20 01:22:43 +00:00
|
|
|
"Exports list by value:\n"
|
|
|
|
"----------------------\n");
|
2014-03-20 01:01:21 +00:00
|
|
|
PrintExportMapByValue (F);
|
2005-01-23 11:19:26 +00:00
|
|
|
|
|
|
|
/* Write the imports list */
|
|
|
|
fprintf (F, "\n\n"
|
|
|
|
"Imports list:\n"
|
|
|
|
"-------------\n");
|
|
|
|
PrintImportMap (F);
|
|
|
|
}
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
/* Close the file */
|
|
|
|
if (fclose (F) != 0) {
|
2019-01-05 19:57:12 +00:00
|
|
|
Error ("Error closing map file '%s': %s", MapFileName, strerror (errno));
|
2000-05-28 13:40:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void CreateLabelFile (void)
|
|
|
|
/* Create a label file */
|
|
|
|
{
|
2001-05-29 07:39:46 +00:00
|
|
|
/* Open the label file */
|
2000-05-28 13:40:48 +00:00
|
|
|
FILE* F = fopen (LabelFileName, "w");
|
|
|
|
if (F == 0) {
|
2019-01-05 19:57:12 +00:00
|
|
|
Error ("Cannot create label file '%s': %s", LabelFileName, strerror (errno));
|
2000-05-28 13:40:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Print the labels for the export symbols */
|
|
|
|
PrintExportLabels (F);
|
|
|
|
|
2011-08-29 20:30:57 +00:00
|
|
|
/* Output the labels */
|
|
|
|
PrintDbgSymLabels (F);
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
/* Close the file */
|
|
|
|
if (fclose (F) != 0) {
|
2019-01-05 19:57:12 +00:00
|
|
|
Error ("Error closing label file '%s': %s", LabelFileName, strerror (errno));
|
2000-05-28 13:40:48 +00:00
|
|
|
}
|
|
|
|
}
|