mirror of
https://github.com/espressif/esp-idf
synced 2025-03-10 09:39:10 -04:00
ldgen: fix sections info parsing
Fixes an issure where the first part of an object file name is not included, due to matching the rule for a section entry previously. Reduce depedency on matching literal strings in sections which might change depending on toolchain (ex. matching 'elf32-xtensa-le') Make sure parsing rule succeeds for the entirety of the sections info string by adding 'parseAll=True'. Add test for sections info parsing.
This commit is contained in:
parent
32206d3a7d
commit
ef6c8e351b
@ -21,7 +21,7 @@ import fnmatch
|
|||||||
|
|
||||||
from fragments import Sections, Scheme, Mapping, Fragment
|
from fragments import Sections, Scheme, Mapping, Fragment
|
||||||
from pyparsing import Suppress, White, ParseException, Literal, Group, ZeroOrMore
|
from pyparsing import Suppress, White, ParseException, Literal, Group, ZeroOrMore
|
||||||
from pyparsing import Word, OneOrMore, nums, alphanums, alphas, Optional, restOfLine
|
from pyparsing import Word, OneOrMore, nums, alphas, restOfLine, SkipTo
|
||||||
from ldgen_common import LdGenFailure
|
from ldgen_common import LdGenFailure
|
||||||
|
|
||||||
|
|
||||||
@ -608,7 +608,7 @@ class SectionsInfo(dict):
|
|||||||
results = None
|
results = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
results = parser.parseString(first_line)
|
results = parser.parseString(first_line, parseAll=True)
|
||||||
except ParseException as p:
|
except ParseException as p:
|
||||||
raise ParseException("Parsing sections info for library " + sections_info_dump.name + " failed. " + p.msg)
|
raise ParseException("Parsing sections info for library " + sections_info_dump.name + " failed. " + p.msg)
|
||||||
|
|
||||||
@ -616,27 +616,26 @@ class SectionsInfo(dict):
|
|||||||
self.sections[archive] = SectionsInfo.__info(sections_info_dump.name, sections_info_dump.read())
|
self.sections[archive] = SectionsInfo.__info(sections_info_dump.name, sections_info_dump.read())
|
||||||
|
|
||||||
def _get_infos_from_file(self, info):
|
def _get_infos_from_file(self, info):
|
||||||
# Object file line: '{object}: file format elf32-xtensa-le'
|
# {object}: file format elf32-xtensa-le
|
||||||
obj = Fragment.ENTITY.setResultsName("object") + Literal(":").suppress() + \
|
object_line = SkipTo(":").setResultsName("object") + Suppress(restOfLine)
|
||||||
(Literal("file format elf32-") + (Literal("xtensa-le") | Literal("littleriscv"))).suppress()
|
|
||||||
|
|
||||||
# Sections table
|
# Sections:
|
||||||
header = Suppress(Literal("Sections:") + Literal("Idx") + Literal("Name") + Literal("Size") + Literal("VMA") +
|
# Idx Name ...
|
||||||
Literal("LMA") + Literal("File off") + Literal("Algn"))
|
section_start = Suppress(Literal("Sections:"))
|
||||||
entry = Word(nums).suppress() + Fragment.ENTITY + Suppress(OneOrMore(Word(alphanums, exact=8)) +
|
section_header = Suppress(OneOrMore(Word(alphas)))
|
||||||
Word(nums + "*") + ZeroOrMore(Word(alphas.upper()) +
|
|
||||||
Optional(Literal(","))))
|
|
||||||
|
|
||||||
# Content is object file line + sections table
|
# 00 {section} 0000000 ...
|
||||||
content = Group(obj + header + Group(ZeroOrMore(entry)).setResultsName("sections"))
|
# CONTENTS, ALLOC, ....
|
||||||
|
section_entry = Suppress(Word(nums)) + SkipTo(' ') + Suppress(restOfLine) + \
|
||||||
|
Suppress(ZeroOrMore(Word(alphas) + Literal(",")) + Word(alphas))
|
||||||
|
|
||||||
|
content = Group(object_line + section_start + section_header + Group(OneOrMore(section_entry)).setResultsName("sections"))
|
||||||
parser = Group(ZeroOrMore(content)).setResultsName("contents")
|
parser = Group(ZeroOrMore(content)).setResultsName("contents")
|
||||||
|
|
||||||
sections_info_text = info.content
|
|
||||||
results = None
|
results = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
results = parser.parseString(sections_info_text)
|
results = parser.parseString(info.content, parseAll=True)
|
||||||
except ParseException as p:
|
except ParseException as p:
|
||||||
raise ParseException("Unable to parse section info file " + info.filename + ". " + p.msg)
|
raise ParseException("Unable to parse section info file " + info.filename + ". " + p.msg)
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
In archive /home/user/ãóç+ěščřžýáíé/build/esp-idf/freertos/libfreertos.a:
|
In archive /home/user/build/esp-idf/freertos/libfreertos.a:
|
||||||
|
|
||||||
FreeRTOS-openocd.c.obj: file format elf32-xtensa-le
|
FreeRTOS-openocd.c.obj: file format elf32-xtensa-le
|
||||||
|
|
||||||
|
19
tools/ldgen/test/data/sections_parse.info
Normal file
19
tools/ldgen/test/data/sections_parse.info
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
In archive /home/user/ãóç+ěščřžýáíé/build/esp-idf/freertos/libsections_parse.a:
|
||||||
|
|
||||||
|
croutine.c.obj: file format elf32-littleriscv
|
||||||
|
|
||||||
|
Sections:
|
||||||
|
Idx Name Size VMA LMA File off Algn
|
||||||
|
0 .text 00000000 00000000 00000000 00000034 2**0
|
||||||
|
CONTENTS, ALLOC, LOAD, READONLY, CODE
|
||||||
|
1 .data 00000000 00000000 00000000 00000034 2**0
|
||||||
|
CONTENTS, ALLOC, LOAD, DATA
|
||||||
|
2 .bss 00000000 00000000 00000000 00000034 2**0
|
||||||
|
ALLOC
|
||||||
|
|
||||||
|
FreeRTOS-openocd.c.obj: file format elf32-xtensa-le // 'F' should not get included in match for 'CONTENTS, ALLOC, LOAD ...' prior
|
||||||
|
|
||||||
|
Sections:
|
||||||
|
Idx Name Size VMA LMA File off Algn
|
||||||
|
0 .literal.prvCheckPendingReadyList 00000018 00000000 00000000 00000034 2**2
|
||||||
|
CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE
|
@ -1422,6 +1422,19 @@ entries:
|
|||||||
self.assertListEqual(actual["flash_text"], expected["flash_text"])
|
self.assertListEqual(actual["flash_text"], expected["flash_text"])
|
||||||
self.assertListEqual(actual["iram0_text"], expected["iram0_text"])
|
self.assertListEqual(actual["iram0_text"], expected["iram0_text"])
|
||||||
|
|
||||||
|
def test_sections_info_parsing(self):
|
||||||
|
|
||||||
|
self.sections_info = SectionsInfo()
|
||||||
|
|
||||||
|
with open("data/sections_parse.info") as sections_info_file_obj:
|
||||||
|
self.sections_info.add_sections_info(sections_info_file_obj)
|
||||||
|
|
||||||
|
sections = self.sections_info.get_obj_sections("libsections_parse.a", "croutine")
|
||||||
|
self.assertEqual(set(sections), set([".text", ".data", ".bss"]))
|
||||||
|
|
||||||
|
sections = self.sections_info.get_obj_sections("libsections_parse.a", "FreeRTOS-openocd")
|
||||||
|
self.assertEqual(set(sections), set([".literal.prvCheckPendingReadyList"]))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user