Emit warnings for wasted bytes when aligning

This commit is contained in:
Colin Leroy-Mira
2025-10-19 11:14:45 +02:00
parent 84bcd53c45
commit 28442e60b8
4 changed files with 10 additions and 4 deletions

View File

@@ -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 calculated in advance by the assembler. You are therefore required to
specify a matching alignment for the segment in the linker config. The 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 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: Example:

View File

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

View File

@@ -2035,8 +2035,8 @@ unsigned CfgProcess (void)
if (M->FillLevel == 0 && NewAddr > Addr) { if (M->FillLevel == 0 && NewAddr > Addr) {
PWarning (GetSourcePos (S->LI), PWarning (GetSourcePos (S->LI),
"The first segment in memory area `%s' " "The first segment in memory area `%s' "
"needs fill bytes for alignment.", "needs %lu fill bytes for alignment.",
GetString (M->Name)); GetString (M->Name), NewAddr - Addr);
} }
/* Use the aligned address */ /* Use the aligned address */

View File

@@ -236,6 +236,9 @@ Section* ReadSection (FILE* F, ObjData* O)
GetString (Name), Alignment, GetObjFileName (O)); GetString (Name), Alignment, GetObjFileName (O));
} }
S->Alignment = Alignment; 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 . */ /* Start reading fragments from the file and insert them into the section . */