diff --git a/src/ld65/config.c b/src/ld65/config.c index 3722b5cbe..5a14c7861 100644 --- a/src/ld65/config.c +++ b/src/ld65/config.c @@ -1709,10 +1709,20 @@ static void ProcessSegments (void) ** in any of the object file, check that there's no initialized data ** in the segment. */ - if ((S->Flags & SF_BSS) != 0 && S->Seg != 0 && !IsBSSType (S->Seg)) { - PWarning (GetSourcePos (S->LI), - "Segment `%s' with type `bss' contains initialized data", - GetString (S->Name)); + if ((S->Flags & SF_BSS) != 0 && S->Seg != 0) { + Section* Sec = GetNonBSSSection (S->Seg); + if (Sec) { + const FilePos* Pos = GetSourcePos (S->LI); + if (Sec->Obj) { + AddPNote (Pos, "Initialized data comes at least partially " + "from `%s'", GetString (Sec->Obj->Name)); + } else { + AddPNote (Pos, "Initialized data is at least partially " + "linker generated"); + } + PWarning (Pos, "Segment `%s' with type `bss' contains " + "initialized data", GetString (S->Name)); + } } /* If this segment does exist in any of the object files, insert the diff --git a/src/ld65/segments.c b/src/ld65/segments.c index 47005d29f..b2518c62a 100644 --- a/src/ld65/segments.c +++ b/src/ld65/segments.c @@ -306,9 +306,11 @@ Segment* SegFind (unsigned Name) -int IsBSSType (Segment* S) -/* Check if the given segment is a BSS style segment, that is, it does not -** contain non-zero data. +Section* GetNonBSSSection (Segment* S) +/* Used when checking a BSS style segment for initialized data. Will walk over +** all sections in S and check if any of them contains initialized data. If so, +** the first section containing initialized data is returned. Otherwise the +** function returns NULL. */ { /* Loop over all sections */ @@ -326,18 +328,20 @@ int IsBSSType (Segment* S) unsigned long Count = F->Size; while (Count--) { if (*Data++ != 0) { - return 0; + return Sec; } } } else if (F->Type == FRAG_EXPR || F->Type == FRAG_SEXPR) { if (GetExprVal (F->Expr) != 0) { - return 0; + return Sec; } } F = F->Next; } } - return 1; + + /* No uninitialized data found */ + return 0; } diff --git a/src/ld65/segments.h b/src/ld65/segments.h index dc1e61d7d..19f2b6504 100644 --- a/src/ld65/segments.h +++ b/src/ld65/segments.h @@ -131,9 +131,11 @@ Section* ReadSection (FILE* F, struct ObjData* O); Segment* SegFind (unsigned Name); /* Return the given segment or NULL if not found. */ -int IsBSSType (Segment* S); -/* Check if the given segment is a BSS style segment, that is, it does not -** contain non-zero data. +Section* GetNonBSSSection (Segment* S); +/* Used when checking a BSS style segment for initialized data. Will walk over +** all sections in S and check if any of them contains initialized data. If so, +** the first section containing initialized data is returned. Otherwise the +** function returns NULL. */ void SegDump (void);