From f7f697c2677be5fe456effeb6f27138f62c1bc42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Ni=C3=B1o=20D=C3=ADaz?= Date: Fri, 14 Apr 2017 17:07:01 +0100 Subject: [PATCH] Fix parsing of first line of included linkerscripts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When including a linkerscript from a parent one, the lexer didn't include a newline character because the INCLUDE command was handled before reaching the newline. This behaviour is needed to parse the last line of a linkerscript correctly (it doesn't have a newline character). However, this meant that when the included file was being parsed, the first line was considered a continuation of the last line of the parent script (the INCLUDE command), which means that the first line of an included linkerscript could only contain a comment (or nothing at all). This patch adds a newline character to the buffer used by the lexer so that the parser will receive a newline and it will handle the first line of the included file as expected. Signed-off-by: Antonio Niño Díaz --- src/link/lexer.l | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/link/lexer.l b/src/link/lexer.l index 1461b618..424b477c 100644 --- a/src/link/lexer.l +++ b/src/link/lexer.l @@ -15,7 +15,6 @@ */ %option noinput -%option nounput %option yylineno %{ @@ -131,7 +130,22 @@ void script_IncludeFile(const char * path) include_path[include_stack_ptr][sizeof(include_path[0])-1] = '\0'; yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE)); - yylineno = 0; + yylineno = 1; + + /* + * The INCLUDE keyword is handled before reaching a newline token, it's + * handled right after parsing the string with the file name that has to + * be included. It isn't actually needed to include a newline after the + * path, the last line of the linkerscript doesn't need to have a + * newline character but it can have a command. + * + * This means that, when opening a new file, we must tell the parser + * that what it is going to start at a new line or it will think that + * the first line of the included script is the continuation of the + * INCLUDE line of the parent script. If this is not done, the first + * line of an included linkerscript can only be a comment (or empty). + */ + unput('\n'); } int script_IncludeDepthGet(void)