Fix off-by-one error with INCLUDEd linker script line numbers

This commit is contained in:
Rangi
2026-06-09 15:54:46 -04:00
committed by Rangi
parent f72a4d53e2
commit 6b2b6e6000
4 changed files with 9 additions and 7 deletions
+5 -4
View File
@@ -52,11 +52,10 @@ void lexer_IncludeFile(std::string &&path) {
scriptError(
"Failed to open included linker script \"%s\": %s", badPath.c_str(), strerror(errno)
);
// `.pop_back()` cannot invalidate an unpopped reference, so `prevContext`
// is still valid even if `.open()` failed.
++prevContext.lineNo;
}
// `.pop_back()` cannot invalidate an unpopped reference, so `prevContext`
// is still valid even if `.open()` failed.
++prevContext.lineNo;
}
void lexer_IncLineNo() {
@@ -74,6 +73,8 @@ static yy::parser::symbol_type yywrap() {
return yy::parser::make_newline();
}
lexerStack.pop_back();
// Increment the line number *after* an INCLUDE has finished.
++lexerStack.back().lineNo;
return yylex();
}
if (!atEof) {
+2 -1
View File
@@ -52,7 +52,8 @@ lines:
line:
INCLUDE string newline {
lexer_IncludeFile(std::move($2)); // Note: this additionally increments the line number!
// This does *not* increment the line number until the included content has finished parsing!
lexer_IncludeFile(std::move($2));
}
| directive newline {
lexer_IncLineNo();
+1 -1
View File
@@ -1,2 +1,2 @@
warning: Integer constant is too large [-Wlarge-constant]
at large-constant.inc(1) <- large-constant.link(3)
at large-constant.inc(1) <- large-constant.link(2)
+1 -1
View File
@@ -1,3 +1,3 @@
error: The linker script assigns section "test" to address $0000, but it was already at $002a
at linkerscript-include.inc(1) <- linkerscript-include.link(4)
at linkerscript-include.inc(1) <- linkerscript-include.link(3)
Linking failed with 1 error