From d414eacc860c171a8c021c7525522d2c9e5183fa Mon Sep 17 00:00:00 2001 From: Frantisek Hrbata Date: Tue, 8 Oct 2024 16:51:48 +0200 Subject: [PATCH] fix(ldgen): enable default name SORT in linker fragment Currently, the `SORT` flag mandates the inclusion of at least the `sort_by_first` argument in the grammar, despite the documentation[1] indicating that `SORT` can be utilized without any arguments, defaulting to sorting input sections by name. Fix this by modifying the grammar to allow a default `SORT` and update a test accordingly. [1] https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-guides/ linker-script-generation.html Signed-off-by: Frantisek Hrbata --- tools/ldgen/ldgen/fragments.py | 43 ++++++++++++++++++++++-------- tools/ldgen/test/test_fragments.py | 4 ++- 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/tools/ldgen/ldgen/fragments.py b/tools/ldgen/ldgen/fragments.py index 0acd81f605d8..80cc167e207a 100644 --- a/tools/ldgen/ldgen/fragments.py +++ b/tools/ldgen/ldgen/fragments.py @@ -1,13 +1,34 @@ # -# SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD +# SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD # SPDX-License-Identifier: Apache-2.0 # - -from typing import Any, Dict, List, Optional, Set, Tuple, Union - -from pyparsing import (Combine, Forward, Group, IndentedBlock, Keyword, LineEnd, Literal, OneOrMore, Opt, - ParseFatalException, SkipTo, Suppress, Word, ZeroOrMore, alphanums, alphas, delimited_list, - nums, rest_of_line) +from typing import Any +from typing import Dict +from typing import List +from typing import Optional +from typing import Set +from typing import Tuple +from typing import Union + +from pyparsing import alphanums +from pyparsing import alphas +from pyparsing import Combine +from pyparsing import delimited_list +from pyparsing import Forward +from pyparsing import Group +from pyparsing import IndentedBlock +from pyparsing import Keyword +from pyparsing import LineEnd +from pyparsing import Literal +from pyparsing import nums +from pyparsing import OneOrMore +from pyparsing import Opt +from pyparsing import ParseFatalException +from pyparsing import rest_of_line +from pyparsing import SkipTo +from pyparsing import Suppress +from pyparsing import Word +from pyparsing import ZeroOrMore class Empty: @@ -227,11 +248,11 @@ class Sort(EntryFlag): _keywords = Keyword('name') | Keyword('alignment') | Keyword('init_priority') SORT = (Keyword('SORT').suppress() + Suppress('(') - + _keywords.set_results_name('first') - + Opt(Suppress(',') + _keywords.set_results_name('second')) + + Opt(_keywords.set_results_name('first') + + Opt(Suppress(',') + _keywords.set_results_name('second'))) + Suppress(')')) - def __init__(self, first: str, second: Optional[str] = None): + def __init__(self, first: Optional[str] = None, second: Optional[str] = None): self.first = first self.second = second @@ -244,7 +265,7 @@ def __eq__(self, other): @staticmethod def parse(toks): - return Sort(toks.first, toks.second or None) + return Sort(toks.first or None, toks.second or None) class Flag: diff --git a/tools/ldgen/test/test_fragments.py b/tools/ldgen/test/test_fragments.py index 9cc3899e989c..c7e72892eef4 100755 --- a/tools/ldgen/test/test_fragments.py +++ b/tools/ldgen/test/test_fragments.py @@ -705,6 +705,7 @@ def test_sort_flag(self): archive: libmain.a entries: obj1 (default); + text->flash_text SORT(), text->flash_text SORT(name), rodata->flash_rodata SORT(alignment), data->dram0_data SORT(init_priority), @@ -717,7 +718,8 @@ def test_sort_flag(self): fragment_file = parse_fragment_file(test_fragment, self.sdkconfig) fragment = fragment_file.fragments[0] - expected = [Flag('text', 'flash_text', [Sort('name')]), + expected = [Flag('text', 'flash_text', [Sort()]), + Flag('text', 'flash_text', [Sort('name')]), Flag('rodata', 'flash_rodata', [Sort('alignment')]), Flag('data', 'dram0_data', [Sort('init_priority')]), Flag('bss', 'dram0_bss', [Sort('name', 'alignment')]),