Skip to content

Commit

Permalink
Merge branch 'fix/ldgen_sort_v5.0' into 'release/v5.0'
Browse files Browse the repository at this point in the history
fix(ldgen): enable default name SORT in linker fragment (v5.0)

See merge request espressif/esp-idf!34077
  • Loading branch information
dobairoland committed Oct 16, 2024
2 parents e7bff6c + b56d53d commit e5617c2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 13 deletions.
43 changes: 32 additions & 11 deletions tools/ldgen/ldgen/fragments.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -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

Expand All @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions tools/ldgen/test/test_fragments.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Apache-2.0
#

import os
import sys
import tempfile
Expand Down Expand Up @@ -706,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),
Expand All @@ -718,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')]),
Expand Down

0 comments on commit e5617c2

Please sign in to comment.