From 47b2e0e91278bbbd4b1e7cfbce9cf76de16090da Mon Sep 17 00:00:00 2001 From: ISSOtm Date: Wed, 14 Aug 2024 02:58:01 +0200 Subject: [PATCH] Trap bad `__at()` values too Those set the section type earlier than the linker script, so a check needs to be performed there too --- src/link/sdas_obj.cpp | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/link/sdas_obj.cpp b/src/link/sdas_obj.cpp index 9f5a5e7e..28677ed3 100644 --- a/src/link/sdas_obj.cpp +++ b/src/link/sdas_obj.cpp @@ -828,7 +828,37 @@ void sdobj_ReadFile(FileStackNode const &where, FILE *file, std::vector std::unique_ptr
§ion = entry.section; // RAM sections can have a size, but don't get any data (they shouldn't have any) - if (entry.writeIndex != section->size && entry.writeIndex != 0) + if (section->type != SECTTYPE_INVALID) { + auto const &typeInfo = sectionTypeInfo[section->type]; + // Otherwise, how would the type already be known at this point? + assume(section->isAddressFixed); + + if (!sect_HasData(section->type)) { + if (!section->data.empty()) { + fatal( + &where, + lineNo, + "\"%s\" is implicitly defined as a %s section (being at address $%04" PRIx16 + "), but it has data! (Was a bad `__at()` value used?)", + section->name.c_str(), + typeInfo.name.c_str(), + section->org + ); + } + } else if (section->size != 0 && section->data.empty()) { + fatal( + &where, + lineNo, + "\"%s\" is implicitly defined as a %s section (being at address $%04" PRIx16 + "), but it doesn't have any data! (Was a bad `__at()` value used?)", + section->name.c_str(), + typeInfo.name.c_str(), + section->org + ); + } + } + + if (entry.writeIndex != 0 && entry.writeIndex != section->size) { fatal( &where, lineNo, @@ -837,6 +867,7 @@ void sdobj_ReadFile(FileStackNode const &where, FILE *file, std::vector entry.writeIndex, section->size ); + } if (section->modifier == SECTION_FRAGMENT) { // Add the fragment's offset to all of its symbols