Add --warn-align-waste option to ca65, ld65, cl65

This commit is contained in:
Colin Leroy-Mira
2025-10-26 16:06:08 +01:00
parent 28442e60b8
commit 2220c6ec8d
12 changed files with 65 additions and 6 deletions

View File

@@ -133,6 +133,7 @@ Long options:
--target sys Set the target system
--verbose Increase verbosity
--version Print the assembler version
--warn-align-waste Print bytes "wasted" for alignment
--warnings-as-errors Treat warnings as errors
---------------------------------------------------------------------------
</verb></tscreen>
@@ -407,6 +408,13 @@ Here is a description of all the command line options:
something lower.
<label id="option--warn-align-waste">
<tag><tt>--warn-align-waste</tt></tag>
Warnings will be generated when alignment requirements cause emission of
fill bytes.
<label id="option--warnings-as-errors">
<tag><tt>--warnings-as-errors</tt></tag>

View File

@@ -119,6 +119,8 @@ Long options:
--target sys Set the target system
--version Print the version number
--verbose Verbose mode
--warn-align-waste Print bytes "wasted" for alignment
--warnings-as-errors Treat warnings as errors
--zeropage-label name Define and export a ZEROPAGE segment label
--zeropage-name seg Set the name of the ZEROPAGE segment
---------------------------------------------------------------------------

View File

@@ -92,6 +92,8 @@ Long options:
--start-group Start a library group
--target sys Set the target system
--version Print the linker version
--warn-align-waste Print bytes "wasted" for alignment
--warnings-as-errors Treat warnings as errors
---------------------------------------------------------------------------
</verb></tscreen>
@@ -349,6 +351,13 @@ Here is a description of all of the command-line options:
directories given by environment variables, and in a built-in default directory.
<label id="option--warn-align-waste">
<tag><tt>--warn-align-waste</tt></tag>
Warnings will be generated when alignment requirements cause emission of
fill bytes.
<label id="option--warnings-as-errors">
<tag><tt>--warnings-as-errors</tt></tag>

View File

@@ -68,6 +68,7 @@ unsigned char LargeAlignment = 0; /* Don't warn about large alignments */
unsigned char RelaxChecks = 0; /* Relax a few assembler checks */
unsigned char StringEscapes = 0; /* Allow C-style escapes in strings */
unsigned char LongJsrJmpRts = 0; /* Allow JSR/JMP/RTS as alias for JSL/JML/RTL */
unsigned char WarnAlignWaste = 0; /* Warn about "wasted" bytes when aligning */
unsigned char WarningsAsErrors = 0; /* Error if any warnings */
unsigned char SegList = 0; /* Show segments in listing */
unsigned char ExpandMacros = 0; /* Expand macros in listing */

View File

@@ -70,6 +70,7 @@ extern unsigned char LargeAlignment; /* Don't warn about large alignments
extern unsigned char RelaxChecks; /* Relax a few assembler checks */
extern unsigned char StringEscapes; /* Allow C-style escapes in strings */
extern unsigned char LongJsrJmpRts; /* Allow JSR/JMP/RTS as alias for JSL/JML/RTL */
extern unsigned char WarnAlignWaste; /* Warn about "wasted" bytes when aligning */
extern unsigned char WarningsAsErrors; /* Error if any warnings */
extern unsigned char SegList; /* Show segments in listing */
extern unsigned char ExpandMacros; /* Expand macros in listing */

View File

@@ -138,6 +138,7 @@ static void Usage (void)
" --target sys\t\t\tSet the target system\n"
" --verbose\t\t\tIncrease verbosity\n"
" --version\t\t\tPrint the assembler version\n"
" --warn-align-waste\t\tPrint bytes \"wasted\" for alignment\n"
" --warnings-as-errors\t\tTreat warnings as errors\n",
ProgName);
}
@@ -753,6 +754,15 @@ static void OptSeglist (const char* Opt attribute ((unused)),
static void OptWarnAlignWaste (const char* Opt attribute ((unused)),
const char* Arg attribute ((unused)))
/* Warn about bytes "wasted" for alignment */
{
WarnAlignWaste = 1;
}
static void OptWarningsAsErrors (const char* Opt attribute ((unused)),
const char* Arg attribute ((unused)))
/* Generate an error if any warnings occur */
@@ -1091,6 +1101,7 @@ int main (int argc, char* argv [])
{ "--target", 1, OptTarget },
{ "--verbose", 0, OptVerbose },
{ "--version", 0, OptVersion },
{ "--warn-align-waste", 0, OptWarnAlignWaste },
{ "--warnings-as-errors", 0, OptWarningsAsErrors },
};

View File

@@ -313,7 +313,7 @@ void SegAlign (unsigned long Alignment, int FillVal)
/* Calculate the number of fill bytes */
Count = AlignCount (ActiveSeg->PC, Alignment);
if (Count != 0) {
if (WarnAlignWaste && Count != 0) {
Warning(0, "Wasting %lu bytes for alignment", Count);
}
}

View File

@@ -897,9 +897,10 @@ static void Usage (void)
" --target sys\t\t\tSet the target system\n"
" --version\t\t\tPrint the version number\n"
" --verbose\t\t\tVerbose mode\n"
" --warn-align-waste\t\tPrint bytes \"wasted\" for alignment\n"
" --warnings-as-errors\t\tTreat warnings as errors\n"
" --zeropage-label name\t\tDefine and export a ZEROPAGE segment label\n"
" --zeropage-name seg\t\tSet the name of the ZEROPAGE segment\n"
" --warnings-as-errors\t\tTreat warnings as errors\n",
" --zeropage-name seg\t\tSet the name of the ZEROPAGE segment\n",
ProgName);
}
@@ -1436,6 +1437,16 @@ static void OptZeropageName (const char* Opt attribute ((unused)), const char* A
static void OptWarnAlignWaste (const char* Opt attribute ((unused)),
const char* Arg attribute ((unused)))
/* Handle the --warn-align-waste option */
{
CmdAddArg (&CA65, "--warn-align-waste");
CmdAddArg (&LD65, "--warn-align-waste");
}
static void OptWarningsAsErrors (const char* Opt attribute ((unused)),
const char* Arg attribute ((unused)))
/* Handle the --warnings-as-errors option */
@@ -1506,6 +1517,7 @@ int main (int argc, char* argv [])
{ "--version", 0, OptVersion },
{ "--zeropage-label", 1, OptZeropageLabel },
{ "--zeropage-name", 1, OptZeropageName },
{ "--warn-align-waste", 0, OptWarnAlignWaste },
{ "--warnings-as-errors", 0, OptWarningsAsErrors },
};

View File

@@ -55,6 +55,7 @@ unsigned long StartAddr = 0x200; /* Start address */
unsigned char VerboseMap = 0; /* Verbose map file */
unsigned char AllowMultDef = 0; /* Allow multiple definitions */
unsigned char LargeAlignment = 0; /* Don't warn about large alignments */
unsigned char WarnAlignWaste = 0; /* Warn about "wasted" bytes when aligning */
unsigned char WarningsAsErrors = 0; /* Error if any warnings */
const char* MapFileName = 0; /* Name of the map file */

View File

@@ -55,6 +55,7 @@ extern unsigned long StartAddr; /* Start address */
extern unsigned char VerboseMap; /* Verbose map file */
extern unsigned char AllowMultDef; /* Allow multiple definitions */
extern unsigned char LargeAlignment; /* Don't warn about large alignments */
extern unsigned char WarnAlignWaste; /* Warn about "wasted" bytes when aligning */
extern unsigned char WarningsAsErrors; /* Error if any warnings */
extern const char* MapFileName; /* Name of the map file */

View File

@@ -179,7 +179,9 @@ static void Usage (void)
" --start-addr addr\t\tSet the default start address\n"
" --start-group\t\t\tStart a library group\n"
" --target sys\t\t\tSet the target system\n"
" --version\t\t\tPrint the linker version\n",
" --version\t\t\tPrint the linker version\n"
" --warn-align-waste\t\tPrint bytes \"wasted\" for alignment\n"
" --warnings-as-errors\t\tTreat warnings as errors\n",
ProgName);
}
@@ -608,6 +610,15 @@ static void OptVersion (const char* Opt attribute ((unused)),
static void OptWarnAlignWaste (const char* Opt attribute ((unused)),
const char* Arg attribute ((unused)))
/* Warn about bytes "wasted" for alignment */
{
WarnAlignWaste = 1;
}
static void OptWarningsAsErrors (const char* Opt attribute ((unused)),
const char* Arg attribute ((unused)))
/* Generate an error if any warnings occur */
@@ -691,6 +702,7 @@ static void ParseCommandLine (void)
{ "--start-group", 0, CmdlOptStartGroup },
{ "--target", 1, CmdlOptTarget },
{ "--version", 0, OptVersion },
{ "--warn-align-waste", 0, OptWarnAlignWaste },
{ "--warnings-as-errors", 0, OptWarningsAsErrors },
};

View File

@@ -236,8 +236,9 @@ Section* ReadSection (FILE* F, ObjData* O)
GetString (Name), Alignment, GetObjFileName (O));
}
S->Alignment = Alignment;
if (Sec->Fill != 0) {
Warning("Wasting %lu bytes for alignment from %s", Sec->Fill, GetObjFileName (O));
if (WarnAlignWaste && Sec->Fill != 0) {
Warning("%s: Wasting %lu bytes for `%s' alignment",
GetObjFileName (O), Sec->Fill, GetString (Name));
}
}