From 17bc7263606c6ec3ba20a67f5d57d8040090cbd5 Mon Sep 17 00:00:00 2001 From: Norbert Manthey Date: Tue, 10 Jul 2018 13:23:10 +0200 Subject: [PATCH 1/2] ls_parse: Allow handling unknown blocks The Xen linker script has a block "PHDRS" that results in a failure of the ls_parse.py script. As there is nothing to be done in that script for that block, this commit adds an empty handler for this block name. In case more blocks should be added, only the regular expression to match the blocks has to be modified. --- scripts/ls_parse.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/scripts/ls_parse.py b/scripts/ls_parse.py index 5cbaee68319..16b39897d4e 100755 --- a/scripts/ls_parse.py +++ b/scripts/ls_parse.py @@ -81,6 +81,7 @@ def get_linker_script_data(script): text = re.sub(r"/\*.*?\*/", " ", text) close_brace = re.compile(r"\s}(\s*>\s*\w+)?") + uwnknown_cmd = re.compile(r"\sPHDRS\s*{") # only this pattern for now, more might follow! memory_cmd = re.compile(r"\sMEMORY\s*{") sections_cmd = re.compile(r"\sSECTIONS\s*{") assign_current = re.compile(r"\s(?P\w+)\s*=\s*\.\s*;") @@ -102,6 +103,7 @@ def get_linker_script_data(script): # with the info gleaned from the matched string. jump_table = { close_brace : close_brace_fun, + uwnknown_cmd : unknown_cmd_fun, memory_cmd : memory_cmd_fun, sections_cmd : sections_cmd_fun, assign_current : assign_current_fun, @@ -146,6 +148,7 @@ def get_linker_script_data(script): state["MEM"] = False state["SEC"] = False state["DEF"] = False + state["UNKNOWN"] = False i = 0 while i < len(text): @@ -274,6 +277,9 @@ def close_brace_fun(state, _, buf): elif state["MEM"]: info("Closing memory command") state["MEM"] = False + elif state["UNKNOWN"]: + info("Closing unknown command") + state["UNKNOWN"] = False else: error("Not in block\n%s", buf) exit(1) @@ -306,6 +312,9 @@ def memory_cmd_fun(state, _, buf): asrt(not state["MEM"], "encountered MEMORY twice", buf) state["MEM"] = True +def unknown_cmd_fun(state, _, buf): + asrt(not state["MEM"], "encountered UNKNOWN twice", buf) + state["UNKNOWN"] = True def match_up_expr_assigns(state): blocks = set([data["origin"] for data in state["expr-assigns"]]) From d5ea30600f84aab1c48ceb331c905d78df1530fb Mon Sep 17 00:00:00 2001 From: Norbert Manthey Date: Tue, 10 Jul 2018 13:24:00 +0200 Subject: [PATCH 2/2] ls_parse: improve debugging by printing a trace In case parsing a linker script fails, generate a trace, so that debugging is possible. This way, unknown blocks in linker scripts can be spotted more easily. --- scripts/ls_parse.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/ls_parse.py b/scripts/ls_parse.py index 16b39897d4e..f56e0092a9c 100755 --- a/scripts/ls_parse.py +++ b/scripts/ls_parse.py @@ -15,6 +15,7 @@ import subprocess import sys import textwrap +import traceback def epilog(): @@ -282,6 +283,7 @@ def close_brace_fun(state, _, buf): state["UNKNOWN"] = False else: error("Not in block\n%s", buf) + traceback.print_stack() exit(1)