ldgen: use uppercase keywords for flags

This commit is contained in:
Renz Bagaporo
2021-02-16 13:44:18 +08:00
parent 7af3d65868
commit 10c5226095
8 changed files with 66 additions and 66 deletions

View File

@@ -9,7 +9,7 @@ entries:
data -> dram0_data data -> dram0_data
# For the following fragments, order matters for # For the following fragments, order matters for
# 'align(4, post) surround(sym)', which generates: # 'ALIGN(4, post) SURROUND(sym)', which generates:
# #
# _sym_start # _sym_start
# ... # ...
@@ -20,8 +20,8 @@ entries:
archive: libbt.a archive: libbt.a
entries: entries:
* (bt_start_end); * (bt_start_end);
bss_common -> dram0_bss align(4, post) surround(bt_bss), bss_common -> dram0_bss ALIGN(4, post) SURROUND(bt_bss),
data -> dram0_data align(4, post) surround(bt_data) data -> dram0_data ALIGN(4, post) SURROUND(bt_data)
if ESP_ALLOW_BSS_SEG_EXTERNAL_MEMORY = y: if ESP_ALLOW_BSS_SEG_EXTERNAL_MEMORY = y:
* (extram_bss) * (extram_bss)
@@ -29,12 +29,12 @@ entries:
archive: libbtdm_app.a archive: libbtdm_app.a
entries: entries:
* (bt_start_end); * (bt_start_end);
bss_common -> dram0_bss align(4, post) surround(btdm_bss), bss_common -> dram0_bss ALIGN(4, post) SURROUND(btdm_bss),
data -> dram0_data align(4, post) surround(btdm_data) data -> dram0_data ALIGN(4, post) SURROUND(btdm_data)
[mapping:nimble] [mapping:nimble]
archive: libnimble.a archive: libnimble.a
entries: entries:
* (bt_start_end); * (bt_start_end);
bss_common -> dram0_bss align(4, post) surround(nimble_bss), bss_common -> dram0_bss ALIGN(4, post) SURROUND(nimble_bss),
data -> dram0_data align(4, post) surround(nimble_data) data -> dram0_data ALIGN(4, post) SURROUND(nimble_data)

View File

@@ -27,12 +27,12 @@ entries:
archive: * archive: *
entries: entries:
* (coredump_default); * (coredump_default);
rtc_fast_coredump -> rtc_force_fast surround(coredump_rtc_fast), rtc_fast_coredump -> rtc_force_fast SURROUND(coredump_rtc_fast),
rtc_coredump -> rtc_data surround(coredump_rtc), rtc_coredump -> rtc_data SURROUND(coredump_rtc),
dram_coredump -> dram0_data surround(coredump_dram) dram_coredump -> dram0_data SURROUND(coredump_dram)
if IDF_TARGET_ESP32S2 = n: if IDF_TARGET_ESP32S2 = n:
* (coredump_default); * (coredump_default);
iram_coredump -> iram0_data surround(coredump_iram) iram_coredump -> iram0_data SURROUND(coredump_iram)
[mapping:espcoredump] [mapping:espcoredump]
archive: libespcoredump.a archive: libespcoredump.a

View File

@@ -283,11 +283,11 @@ class Mapping(Fragment):
@staticmethod @staticmethod
def get_grammar(): def get_grammar():
# surround(symbol) # SURROUND(symbol)
# #
# __symbol_start, __symbol_end is generated before and after # __symbol_start, __symbol_end is generated before and after
# the corresponding input section description, respectively. # the corresponding input section description, respectively.
grammar = (Keyword('surround').suppress() + grammar = (Keyword('SURROUND').suppress() +
Suppress('(') + Suppress('(') +
Fragment.IDENTIFIER.setResultsName('symbol') + Fragment.IDENTIFIER.setResultsName('symbol') +
Suppress(')')) Suppress(')'))
@@ -308,8 +308,8 @@ class Mapping(Fragment):
@staticmethod @staticmethod
def get_grammar(): def get_grammar():
# align(alignment, [, pre, post]) # ALIGN(alignment, [, pre, post])
grammar = (Keyword('align').suppress() + grammar = (Keyword('ALIGN').suppress() +
Suppress('(') + Suppress('(') +
Word(nums).setResultsName('alignment') + Word(nums).setResultsName('alignment') +
Mapping.Flag.PRE_POST + Mapping.Flag.PRE_POST +
@@ -343,7 +343,7 @@ class Mapping(Fragment):
@staticmethod @staticmethod
def get_grammar(): def get_grammar():
grammar = Keyword('keep').setParseAction(Mapping.Keep) grammar = Keyword('KEEP').setParseAction(Mapping.Keep)
return grammar return grammar
def __eq__(self, other): def __eq__(self, other):
@@ -361,9 +361,9 @@ class Mapping(Fragment):
@staticmethod @staticmethod
def get_grammar(): def get_grammar():
# sort(sort_by_first [, sort_by_second]) # SORT(sort_by_first [, sort_by_second])
keywords = Keyword('name') | Keyword('alignment') | Keyword('init_priority') keywords = Keyword('name') | Keyword('alignment') | Keyword('init_priority')
grammar = (Keyword('sort').suppress() + Suppress('(') + grammar = (Keyword('SORT').suppress() + Suppress('(') +
keywords.setResultsName('first') + keywords.setResultsName('first') +
Optional(Suppress(',') + keywords.setResultsName('second')) + Suppress(')')) Optional(Suppress(',') + keywords.setResultsName('second')) + Suppress(')'))
@@ -428,7 +428,7 @@ class Mapping(Fragment):
# obj (scheme) # obj (scheme)
# * (scheme) # * (scheme)
# Flags can be specified for section->target in the scheme specified, ex: # Flags can be specified for section->target in the scheme specified, ex:
# obj (scheme); section->target surround(symbol), section2->target2 align(4) # obj (scheme); section->target SURROUND(symbol), section2->target2 ALIGN(4)
obj = Fragment.ENTITY.setResultsName('object') obj = Fragment.ENTITY.setResultsName('object')
symbol = Suppress(':') + Fragment.IDENTIFIER.setResultsName('symbol') symbol = Suppress(':') + Fragment.IDENTIFIER.setResultsName('symbol')
scheme = Suppress('(') + Fragment.IDENTIFIER.setResultsName('scheme') + Suppress(')') scheme = Suppress('(') + Fragment.IDENTIFIER.setResultsName('scheme') + Suppress(')')

View File

@@ -155,14 +155,14 @@ class EntityNode():
keep = True keep = True
elif isinstance(flag, Mapping.Sort): elif isinstance(flag, Mapping.Sort):
sort = (flag.first, flag.second) sort = (flag.first, flag.second)
else: # surround or align else: # SURROUND or ALIGN
surround_type.append(flag) surround_type.append(flag)
for flag in surround_type: for flag in surround_type:
if flag.pre: if flag.pre:
if isinstance(flag, Mapping.Surround): if isinstance(flag, Mapping.Surround):
commands[placement.target].append(SymbolAtAddress('_%s_start' % flag.symbol)) commands[placement.target].append(SymbolAtAddress('_%s_start' % flag.symbol))
else: # align else: # ALIGN
commands[placement.target].append(AlignAtAddress(flag.alignment)) commands[placement.target].append(AlignAtAddress(flag.alignment))
# This is for expanded object node and symbol node placements without checking for # This is for expanded object node and symbol node placements without checking for
@@ -185,7 +185,7 @@ class EntityNode():
if flag.post: if flag.post:
if isinstance(flag, Mapping.Surround): if isinstance(flag, Mapping.Surround):
commands[placement.target].append(SymbolAtAddress('_%s_end' % flag.symbol)) commands[placement.target].append(SymbolAtAddress('_%s_end' % flag.symbol))
else: # align else: # ALIGN
commands[placement.target].append(AlignAtAddress(flag.alignment)) commands[placement.target].append(AlignAtAddress(flag.alignment))
return commands return commands

View File

@@ -818,8 +818,8 @@ entries:
archive: libmain.a archive: libmain.a
entries: entries:
obj1 (default); obj1 (default);
text->flash_text keep, text->flash_text KEEP,
rodata->flash_rodata keep keep rodata->flash_rodata KEEP KEEP
""") """)
fragment_file = FragmentFile(test_fragment, self.sdkconfig) fragment_file = FragmentFile(test_fragment, self.sdkconfig)
@@ -838,11 +838,11 @@ entries:
archive: libmain.a archive: libmain.a
entries: entries:
obj1 (default); obj1 (default);
text->flash_text align(8), text->flash_text ALIGN(8),
rodata->flash_rodata align(8, pre), rodata->flash_rodata ALIGN(8, pre),
data->dram0_data align(8, pre, post), data->dram0_data ALIGN(8, pre, post),
bss->dram0_bss align(8, post), bss->dram0_bss ALIGN(8, post),
common->dram0_bss align(8, pre, post) align(8) common->dram0_bss ALIGN(8, pre, post) ALIGN(8)
""") """)
fragment_file = FragmentFile(test_fragment, self.sdkconfig) fragment_file = FragmentFile(test_fragment, self.sdkconfig)
@@ -863,7 +863,7 @@ entries:
archive: libmain.a archive: libmain.a
entries: entries:
obj1 (noflash) obj1 (noflash)
text->iram0_text align(8, post, pre) text->iram0_text ALIGN(8, post, pre)
""") """)
with self.assertRaises(ParseFatalException): with self.assertRaises(ParseFatalException):
@@ -876,13 +876,13 @@ entries:
archive: libmain.a archive: libmain.a
entries: entries:
obj1 (default); obj1 (default);
text->flash_text sort(name), text->flash_text SORT(name),
rodata->flash_rodata sort(alignment), rodata->flash_rodata SORT(alignment),
data->dram0_data sort(init_priority), data->dram0_data SORT(init_priority),
bss->dram0_bss sort(name, alignment), bss->dram0_bss SORT(name, alignment),
common->dram0_bss sort(alignment, name), common->dram0_bss SORT(alignment, name),
iram->iram0_text sort(name, name), iram->iram0_text SORT(name, name),
dram->dram0_data sort(alignment, alignment) dram->dram0_data SORT(alignment, alignment)
""") """)
fragment_file = FragmentFile(test_fragment, self.sdkconfig) fragment_file = FragmentFile(test_fragment, self.sdkconfig)
@@ -903,7 +903,7 @@ entries:
archive: libmain.a archive: libmain.a
entries: entries:
obj1 (default) obj1 (default)
text->iram0_text sort(name) sort(alignment) text->iram0_text SORT(name) SORT(alignment)
""") """)
def test_surround_flag(self): def test_surround_flag(self):
@@ -913,7 +913,7 @@ entries:
archive: libmain.a archive: libmain.a
entries: entries:
obj1 (default); obj1 (default);
text->flash_text surround(sym1) text->flash_text SURROUND(sym1)
""") """)
fragment_file = FragmentFile(test_fragment, self.sdkconfig) fragment_file = FragmentFile(test_fragment, self.sdkconfig)
@@ -930,8 +930,8 @@ entries:
archive: libmain.a archive: libmain.a
entries: entries:
obj1 (default); obj1 (default);
text->flash_text align(4) keep surround(sym1) align(8) sort(name), text->flash_text ALIGN(4) KEEP SURROUND(sym1) ALIGN(8) SORT(name),
rodata->flash_rodata keep align(4) keep surround(sym1) align(8) align(4) sort(name) rodata->flash_rodata KEEP ALIGN(4) KEEP SURROUND(sym1) ALIGN(8) ALIGN(4) SORT(name)
""") """)
fragment_file = FragmentFile(test_fragment, self.sdkconfig) fragment_file = FragmentFile(test_fragment, self.sdkconfig)
fragment = fragment_file.fragments[0] fragment = fragment_file.fragments[0]
@@ -960,8 +960,8 @@ entries:
archive: libmain.a archive: libmain.a
entries: entries:
obj1 (default); obj1 (default);
text->flash_text align(4) keep surround(sym1) sort(name), text->flash_text ALIGN(4) KEEP SURROUND(sym1) SORT(name),
text->flash_text align(4) keep surround(sym1) sort(name) text->flash_text ALIGN(4) KEEP SURROUND(sym1) SORT(name)
""") """)
fragment_file = FragmentFile(test_fragment, self.sdkconfig) fragment_file = FragmentFile(test_fragment, self.sdkconfig)
fragment = fragment_file.fragments[0] fragment = fragment_file.fragments[0]
@@ -987,9 +987,9 @@ entries:
archive: libmain.a archive: libmain.a
entries: entries:
obj1 (default); obj1 (default);
text->flash_text align(4) keep surround(sym1) sort(name) text->flash_text ALIGN(4) KEEP SURROUND(sym1) SORT(name)
obj1 (default); obj1 (default);
text->flash_text align(4) keep surround(sym1) sort(name) text->flash_text ALIGN(4) KEEP SURROUND(sym1) SORT(name)
""") """)
fragment_file = FragmentFile(test_fragment, self.sdkconfig) fragment_file = FragmentFile(test_fragment, self.sdkconfig)
fragment = fragment_file.fragments[0] fragment = fragment_file.fragments[0]

View File

@@ -1397,8 +1397,8 @@ class FlagTest(GenerationTest):
# with flags. # with flags.
def test_flags_basics(self): def test_flags_basics(self):
# Test that input section commands additions are done (keep, sort). # Test that input section commands additions are done (KEEP, SORT).
# Test that order dependent commands are properly generated (align, surround) # Test that order dependent commands are properly generated (ALIGN, SURROUND)
# Normally, if an entry has the same mapping as parent, commands. # Normally, if an entry has the same mapping as parent, commands.
# are not emitted for them. However, if there are flags, they should be - # are not emitted for them. However, if there are flags, they should be -
# only for the scheme entries that have flags, though. # only for the scheme entries that have flags, though.
@@ -1428,11 +1428,11 @@ class FlagTest(GenerationTest):
archive: libfreertos.a archive: libfreertos.a
entries: entries:
croutine (noflash_text); croutine (noflash_text);
text->iram0_text align(4, pre, post) surround(sym1) #1 text->iram0_text ALIGN(4, pre, post) SURROUND(sym1) #1
timers (default); timers (default);
text->flash_text keep sort(name) #2 text->flash_text KEEP SORT(name) #2
timers (default); timers (default);
rodata->flash_rodata surround(sym2) align(4, pre, post) #3 rodata->flash_rodata SURROUND(sym2) ALIGN(4, pre, post) #3
""" """
self.add_fragments(mapping) self.add_fragments(mapping)
@@ -1489,7 +1489,7 @@ archive: *
entries: entries:
# 1 # 1
* (default); * (default);
text->flash_text surround(sym1) keep #2 text->flash_text SURROUND(sym1) KEEP #2
[mapping:test] [mapping:test]
archive: libfreertos.a archive: libfreertos.a
@@ -1509,7 +1509,7 @@ entries:
# Command for #2, pre A.1 # Command for #2, pre A.1
flash_text.insert(0, SymbolAtAddress('_sym1_start')) flash_text.insert(0, SymbolAtAddress('_sym1_start'))
# Command for #1 with keep B # Command for #1 with KEEP B
# and exclusion for #3 # and exclusion for #3
flash_text[1].keep = True flash_text[1].keep = True
flash_text[1].exclusions.add(CROUTINE) flash_text[1].exclusions.add(CROUTINE)
@@ -1551,7 +1551,7 @@ archive: libfreertos.a
entries: entries:
# 1 # 1
* (default); * (default);
text->flash_text surround(sym1) keep #2 text->flash_text SURROUND(sym1) KEEP #2
croutine:prvCheckPendingReadyList (noflash_text) #3 croutine:prvCheckPendingReadyList (noflash_text) #3
""" """
@@ -1567,7 +1567,7 @@ entries:
flash_text.append(SymbolAtAddress('_sym1_start')) flash_text.append(SymbolAtAddress('_sym1_start'))
flash_text[0].exclusions.add(FREERTOS) flash_text[0].exclusions.add(FREERTOS)
# Command for #1 with keep B # Command for #1 with KEEP B
# and exclusion for #3 # and exclusion for #3
flash_text.append(InputSectionDesc(FREERTOS, flash_text[0].sections, [CROUTINE], keep=True)) flash_text.append(InputSectionDesc(FREERTOS, flash_text[0].sections, [CROUTINE], keep=True))
@@ -1607,7 +1607,7 @@ archive: libfreertos.a
entries: entries:
# 1 # 1
croutine (default); croutine (default);
text->flash_text surround(sym1) keep #2 text->flash_text SURROUND(sym1) KEEP #2
croutine:prvCheckPendingReadyList (noflash_text) #3 croutine:prvCheckPendingReadyList (noflash_text) #3
""" """
@@ -1658,7 +1658,7 @@ archive: *
entries: entries:
# 1 # 1
* (default); * (default);
text->flash_text surround(sym1) keep #2 text->flash_text SURROUND(sym1) KEEP #2
[mapping:test] [mapping:test]
archive: libfreertos.a archive: libfreertos.a
@@ -1679,7 +1679,7 @@ entries:
# Command for #2, pre A.1 # Command for #2, pre A.1
flash_text.insert(0, SymbolAtAddress('_sym1_start')) flash_text.insert(0, SymbolAtAddress('_sym1_start'))
# Command for #1 with keep B # Command for #1 with KEEP B
# and exclusion for #3 # and exclusion for #3
flash_text[1].keep = True flash_text[1].keep = True
flash_text[1].exclusions.add(CROUTINE) flash_text[1].exclusions.add(CROUTINE)
@@ -1720,7 +1720,7 @@ archive: libfreertos.a
entries: entries:
# 1 # 1
* (default); * (default);
text->flash_text surround(sym1) keep text->flash_text SURROUND(sym1) KEEP
croutine (default) #2 croutine (default) #2
croutine:prvCheckPendingReadyList (noflash_text) #3 croutine:prvCheckPendingReadyList (noflash_text) #3
""" """
@@ -1737,7 +1737,7 @@ entries:
flash_text.append(SymbolAtAddress('_sym1_start')) flash_text.append(SymbolAtAddress('_sym1_start'))
flash_text[0].exclusions.add(FREERTOS) flash_text[0].exclusions.add(FREERTOS)
# Command for #1 with keep B # Command for #1 with KEEP B
# and exclusion for #3 # and exclusion for #3
flash_text.append(InputSectionDesc(FREERTOS, flash_text[0].sections, [CROUTINE], keep=True)) flash_text.append(InputSectionDesc(FREERTOS, flash_text[0].sections, [CROUTINE], keep=True))
@@ -1766,7 +1766,7 @@ entries:
archive: * archive: *
entries: entries:
* (default); * (default);
text->flash_text keep text->flash_text KEEP
""" """
self.add_fragments(mapping) self.add_fragments(mapping)
@@ -1787,13 +1787,13 @@ entries:
archive: * archive: *
entries: entries:
* (default); * (default);
text->flash_text keep text->flash_text KEEP
[mapping:default_add_flag_2] [mapping:default_add_flag_2]
archive: * archive: *
entries: entries:
* (default); * (default);
text->flash_text keep text->flash_text KEEP
""" """
self.add_fragments(mapping) self.add_fragments(mapping)
@@ -1814,13 +1814,13 @@ entries:
archive: * archive: *
entries: entries:
* (default); * (default);
text->flash_text align(2) text->flash_text ALIGN(2)
[mapping:default_add_flag_2] [mapping:default_add_flag_2]
archive: * archive: *
entries: entries:
* (default); * (default);
text->flash_text surround(sym1) text->flash_text SURROUND(sym1)
""" """
self.add_fragments(mapping) self.add_fragments(mapping)

View File

@@ -137,7 +137,7 @@ class InputSectionDescTest(unittest.TestCase):
self.assertEqual(expected, str(desc)) self.assertEqual(expected, str(desc))
def test_keep(self): def test_keep(self):
# Test keep # Test KEEP
expected = 'KEEP(*libfreertos.a:croutine.*( ))' expected = 'KEEP(*libfreertos.a:croutine.*( ))'
desc = InputSectionDesc(Entity('libfreertos.a', 'croutine'), [], keep=True) desc = InputSectionDesc(Entity('libfreertos.a', 'croutine'), [], keep=True)

View File

@@ -4,5 +4,5 @@ entries:
* (noflash) * (noflash)
src1 (default) src1 (default)
src1:func1 (noflash); src1:func1 (noflash);
text->iram0_text keep align(9) align(12, post) surround(sym1) text->iram0_text KEEP ALIGN(9) ALIGN(12, post) SURROUND(sym1)
src1:func2 (rtc) src1:func2 (rtc)