fix(ldgen): fix linker script generation from a single-entry fragment file

This commit is contained in:
Omar Chebib 2024-08-23 15:21:58 +08:00
parent ac8f354458
commit a8bb279dff
8 changed files with 33 additions and 8 deletions

View File

@ -1157,7 +1157,6 @@ tools/templates/sample_component/main.c
tools/test_apps/build_system/embed_test/main/test_main.c tools/test_apps/build_system/embed_test/main/test_main.c
tools/test_apps/build_system/ldgen_test/main/src1.c tools/test_apps/build_system/ldgen_test/main/src1.c
tools/test_apps/build_system/ldgen_test/main/src2.c tools/test_apps/build_system/ldgen_test/main/src2.c
tools/test_apps/build_system/ldgen_test/main/test_main.c
tools/test_apps/peripherals/i2c_wifi/main/i2c_wifi_main.c tools/test_apps/peripherals/i2c_wifi/main/i2c_wifi_main.c
tools/test_apps/protocols/esp_netif/build_config/main/init_macro.h tools/test_apps/protocols/esp_netif/build_config/main/init_macro.h
tools/test_apps/protocols/esp_netif/build_config/main/main.cpp tools/test_apps/protocols/esp_netif/build_config/main/main.cpp

View File

@ -60,7 +60,7 @@ class InputSectionDesc:
Outputs an input section description as described in Outputs an input section description as described in
https://www.acrc.bris.ac.uk/acrc/RedHat/rhel-ld-en-4/sections.html#INPUT-SECTION. https://www.acrc.bris.ac.uk/acrc/RedHat/rhel-ld-en-4/sections.html#INPUT-SECTION.
These commands are emmited from mapping fragment entries, specifically attaching These commands are emitted from mapping fragment entries, specifically attaching
a scheme onto an entity. Mapping fragment flags KEEP, SORT will also affect a scheme onto an entity. Mapping fragment flags KEEP, SORT will also affect
the emitted input section description. the emitted input section description.
""" """
@ -85,9 +85,10 @@ class InputSectionDesc:
self.tied = tied self.tied = tied
def __str__(self): def __str__(self):
sections_string = '( )' sections_string = ''
if self.sections: if self.sections:
sections_string = '( )'
exclusion_strings = [] exclusion_strings = []
for exc in sorted(self.exclusions): for exc in sorted(self.exclusions):

View File

@ -1,9 +1,8 @@
#!/usr/bin/env python #!/usr/bin/env python
# #
# SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD # SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
# #
import os import os
import sys import sys
import unittest import unittest
@ -122,14 +121,14 @@ class InputSectionDescTest(unittest.TestCase):
def test_empty_sections(self): def test_empty_sections(self):
# Test empty sections # Test empty sections
expected = '*libfreertos.a:croutine.*( )' expected = '*libfreertos.a:croutine.*'
desc = InputSectionDesc(Entity('libfreertos.a', 'croutine'), []) desc = InputSectionDesc(Entity('libfreertos.a', 'croutine'), [])
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)
self.assertEqual(expected, str(desc)) self.assertEqual(expected, str(desc))

View File

@ -80,3 +80,5 @@ if not args.no_rtc:
check_location('func3', '.flash.text') check_location('func3', '.flash.text')
check_location('func4', '.iram0.text') check_location('func4', '.iram0.text')
check_location('const_array', '.dram0.data')

View File

@ -1,3 +1,3 @@
idf_component_register(SRCS "src1.c" "src2.c" "test_main.c" idf_component_register(SRCS "src1.c" "src2.c" "test_main.c" "consts.c"
INCLUDE_DIRS "." INCLUDE_DIRS "."
LDFRAGMENTS "linker.lf") LDFRAGMENTS "linker.lf")

View File

@ -0,0 +1,9 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: CC0-1.0
*/
const int const_array[] = {
10, 20, 30, 40, 50, 60, 70, 80
};

View File

@ -9,3 +9,4 @@ entries:
text->iram0_text KEEP() text->iram0_text KEEP()
if SOC_RTC_MEM_SUPPORTED = y: if SOC_RTC_MEM_SUPPORTED = y:
src1:func2 (rtc) src1:func2 (rtc)
consts : const_array (noflash)

View File

@ -1,11 +1,25 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: CC0-1.0
*/
#include <stdio.h>
#include "esp_memory_utils.h"
extern void func2(void); extern void func2(void);
extern void func3(void); extern void func3(void);
extern void func4(void); extern void func4(void);
extern const int const_array[];
void app_main(void) void app_main(void)
{ {
func2(); func2();
func3(); func3();
func4(); func4();
if (esp_ptr_in_dram(const_array)) {
printf("const_array placed in dram\n");
} else {
printf("const_array NOT placed in dram\n");
}
} }