Fix included linker scripts with no newline at EOF (#2011)

This commit is contained in:
Rangi
2026-07-06 14:01:40 -04:00
committed by GitHub
parent 0adbb92e50
commit be3fc61859
5 changed files with 19 additions and 16 deletions
+11 -16
View File
@@ -24,8 +24,9 @@ struct LexerStackEntry {
std::filebuf file;
std::string path;
uint32_t lineNo;
bool atEof;
explicit LexerStackEntry(std::string &&path_) : file(), path(path_), lineNo(1) {}
explicit LexerStackEntry(std::string &&path_) : file(), path(path_), lineNo(1), atEof(false) {}
};
static std::vector<LexerStackEntry> lexerStack;
@@ -65,24 +66,18 @@ void lexer_IncLineNo() {
yy::parser::symbol_type yylex(); // Forward declaration for `yywrap`
static yy::parser::symbol_type yywrap() {
static bool atEof = false;
if (lexerStack.size() != 1) {
if (!atEof) {
// Inject a newline at EOF to simplify parsing.
atEof = true;
return yy::parser::make_newline();
}
lexerStack.pop_back();
// Increment the line number *after* an INCLUDE has finished.
++lexerStack.back().lineNo;
return yylex();
}
if (!atEof) {
if (LexerStackEntry &context = lexerStack.back(); !context.atEof) {
// Inject a newline at EOF to simplify parsing.
atEof = true;
context.atEof = true;
return yy::parser::make_newline();
}
return yy::parser::make_YYEOF();
if (lexerStack.size() == 1) {
return yy::parser::make_YYEOF();
}
lexerStack.pop_back();
// Increment the line number *after* an INCLUDE has finished.
++lexerStack.back().lineNo;
return yylex();
}
static std::string readKeyword(int initial) {
@@ -0,0 +1,2 @@
section "test", rom0[1337]
label:: dw label
@@ -0,0 +1 @@
rom0 ; no newline after this
@@ -0,0 +1,2 @@
include "linkerscript-no-newline-eof.inc"
"test" ; no newline after this
@@ -0,0 +1,3 @@
error: The linker script assigns section "test" to address $0000, but it was already at $0539
at linkerscript-no-newline-eof.link(2)
Linking failed with 1 error