From f9077cb073ebdd51d91c6caa49570ddf64413150 Mon Sep 17 00:00:00 2001 From: You Wei Date: Mon, 11 Sep 2023 21:24:05 +0800 Subject: [PATCH 1/2] fix(ldgen): check target conflict for entries with section alias --- components/bt/linker.lf | 9 +++++---- tools/ldgen/generation.py | 2 +- tools/ldgen/test/test_generation.py | 25 +++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/components/bt/linker.lf b/components/bt/linker.lf index 17b581b1930..e112695fb73 100644 --- a/components/bt/linker.lf +++ b/components/bt/linker.lf @@ -24,12 +24,13 @@ entries: [mapping:bt] archive: libbt.a entries: - * (bt_start_end); - bt_bss -> dram0_bss ALIGN(4) ALIGN(4, post) SURROUND(bt_bss), - bt_common -> dram0_bss ALIGN(4) ALIGN(4, post) SURROUND(bt_common), - data -> dram0_data ALIGN(4) ALIGN(4, post) SURROUND(bt_data) if ESP_ALLOW_BSS_SEG_EXTERNAL_MEMORY = y: * (extram_bss) + else: + * (bt_start_end); + bt_bss -> dram0_bss ALIGN(4) ALIGN(4, post) SURROUND(bt_bss), + bt_common -> dram0_bss ALIGN(4) ALIGN(4, post) SURROUND(bt_common), + data -> dram0_data ALIGN(4) ALIGN(4, post) SURROUND(bt_data) [mapping:btdm] archive: libbtdm_app.a diff --git a/tools/ldgen/generation.py b/tools/ldgen/generation.py index f082f714a92..0b19a1eec12 100644 --- a/tools/ldgen/generation.py +++ b/tools/ldgen/generation.py @@ -477,7 +477,7 @@ def get_section_strs(section): sections_str = get_section_strs(section) - key = (entity, section.name) + key = (entity, sections_str) try: existing = entity_mappings[key] diff --git a/tools/ldgen/test/test_generation.py b/tools/ldgen/test/test_generation.py index 28aac1c9748..89f821ce9e0 100755 --- a/tools/ldgen/test/test_generation.py +++ b/tools/ldgen/test/test_generation.py @@ -801,6 +801,31 @@ def test_same_entity_conflicting_scheme(self, alt=None): with self.assertRaises(GenerationException): self.generation.generate(self.entities) + def test_same_entity_conflicting_section(self): + # Test same entity being mapped by scheme conflicting with another. + # + # custom_rtc = .text -> rtc_text + # noflash = .text -> iram0_text, .rodata -> dram0_data + # + # This operation should fail. + mapping = u""" +[sections:custom_text] +entries: + .text+ + .literal+ + +[scheme:custom_rtc] +entries: + custom_text -> rtc_text + +[mapping:test] +archive: libfreertos.a +entries: + croutine (noflash) #1 + croutine (custom_rtc) #2 +""" + self.test_same_entity_conflicting_scheme(mapping) + def test_complex_mapping_case(self, alt=None): # Test a complex case where an object is mapped using # one scheme, but a specific symbol in that object is mapped From ea2f6455a0d0ccf55ea9f29ebae0b3416e1b05cd Mon Sep 17 00:00:00 2001 From: You Wei Date: Tue, 12 Sep 2023 11:20:12 +0800 Subject: [PATCH 2/2] fix(ldgen): duplicate entries in the generated .ld file --- tools/ldgen/test/test_generation.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/tools/ldgen/test/test_generation.py b/tools/ldgen/test/test_generation.py index 89f821ce9e0..3c5952ca1d4 100755 --- a/tools/ldgen/test/test_generation.py +++ b/tools/ldgen/test/test_generation.py @@ -79,7 +79,10 @@ def setUp(self): self.entities.add_sections_info(objdump) with open('data/linker_script.ld') as linker_script: - self.linker_script = LinkerScript(linker_script) + self.linker_script_expect = LinkerScript(linker_script) + + with open('data/linker_script.ld') as linker_script: + self.linker_script_actual = LinkerScript(linker_script) @staticmethod def create_fragment_file(contents, name='test_fragment.lf'): @@ -93,11 +96,11 @@ def add_fragments(self, text): self.generation.add_fragments_from_file(fragment_file) def write(self, expected, actual): - self.linker_script.fill(expected) - self.linker_script.write(open('expected.ld', 'w')) + self.linker_script_expect.fill(expected) + self.linker_script_expect.write(open('expected.ld', 'w')) - self.linker_script.fill(actual) - self.linker_script.write(open('actual.ld', 'w')) + self.linker_script_actual.fill(actual) + self.linker_script_actual.write(open('actual.ld', 'w')) def generate_default_rules(self): rules = collections.defaultdict(list)