From 28442e60b84c7eacfd02079e1857b042f06c0150 Mon Sep 17 00:00:00 2001 From: Colin Leroy-Mira Date: Sun, 19 Oct 2025 11:14:45 +0200 Subject: [PATCH 1/2] Emit warnings for wasted bytes when aligning --- doc/ca65.sgml | 3 ++- src/ca65/segment.c | 4 +++- src/ld65/config.c | 4 ++-- src/ld65/segments.c | 3 +++ 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/doc/ca65.sgml b/doc/ca65.sgml index 40231920c..af5e73d13 100644 --- a/doc/ca65.sgml +++ b/doc/ca65.sgml @@ -2372,7 +2372,8 @@ Here's a list of all control commands and a description, what they do: calculated in advance by the assembler. You are therefore required to specify a matching alignment for the segment in the linker config. The linker will output a warning if the alignment of the segment is less than - what is necessary to have a correct alignment in the object file. + what is necessary to have a correct alignment in the object file. It will + also emit a warning to inform about the number of bytes wasted for alignment. Example: diff --git a/src/ca65/segment.c b/src/ca65/segment.c index adc5cec98..76126d23d 100644 --- a/src/ca65/segment.c +++ b/src/ca65/segment.c @@ -313,7 +313,9 @@ void SegAlign (unsigned long Alignment, int FillVal) /* Calculate the number of fill bytes */ Count = AlignCount (ActiveSeg->PC, Alignment); - + if (Count != 0) { + Warning(0, "Wasting %lu bytes for alignment", Count); + } } diff --git a/src/ld65/config.c b/src/ld65/config.c index bc2a26578..9536d5c26 100644 --- a/src/ld65/config.c +++ b/src/ld65/config.c @@ -2035,8 +2035,8 @@ unsigned CfgProcess (void) if (M->FillLevel == 0 && NewAddr > Addr) { PWarning (GetSourcePos (S->LI), "The first segment in memory area `%s' " - "needs fill bytes for alignment.", - GetString (M->Name)); + "needs %lu fill bytes for alignment.", + GetString (M->Name), NewAddr - Addr); } /* Use the aligned address */ diff --git a/src/ld65/segments.c b/src/ld65/segments.c index 1391d30f1..aeff972d2 100644 --- a/src/ld65/segments.c +++ b/src/ld65/segments.c @@ -236,6 +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)); + } } /* Start reading fragments from the file and insert them into the section . */ From 2220c6ec8dd4dc5ba497e8e783e15f4b305737eb Mon Sep 17 00:00:00 2001 From: Colin Leroy-Mira Date: Sun, 26 Oct 2025 16:06:08 +0100 Subject: [PATCH 2/2] Add --warn-align-waste option to ca65, ld65, cl65 --- doc/ca65.sgml | 8 ++++++++ doc/cl65.sgml | 2 ++ doc/ld65.sgml | 9 +++++++++ src/ca65/global.c | 1 + src/ca65/global.h | 1 + src/ca65/main.c | 11 +++++++++++ src/ca65/segment.c | 2 +- src/cl65/main.c | 16 ++++++++++++++-- src/ld65/global.c | 1 + src/ld65/global.h | 1 + src/ld65/main.c | 14 +++++++++++++- src/ld65/segments.c | 5 +++-- 12 files changed, 65 insertions(+), 6 deletions(-) diff --git a/doc/ca65.sgml b/doc/ca65.sgml index af5e73d13..4e42d0c05 100644 --- a/doc/ca65.sgml +++ b/doc/ca65.sgml @@ -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 --------------------------------------------------------------------------- @@ -407,6 +408,13 @@ Here is a description of all the command line options: something lower. +