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 53fef80656
commit 063fbc872d
8 changed files with 33 additions and 8 deletions

View File

@ -1277,7 +1277,6 @@ tools/test_apps/build_system/embed_test/main/test_main.c
tools/test_apps/build_system/ldalign_test/main/test_main.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/test_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/main.cpp

View File

@ -59,7 +59,7 @@ class InputSectionDesc:
Outputs an input section description as described in
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
the emitted input section description.
"""
@ -83,9 +83,10 @@ class InputSectionDesc:
self.sort = sort
def __str__(self):
sections_string = '( )'
sections_string = ''
if self.sections:
sections_string = '( )'
exclusion_strings = []
for exc in sorted(self.exclusions):

View File

@ -1,9 +1,8 @@
#!/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
#
import os
import sys
import unittest
@ -122,14 +121,14 @@ class InputSectionDescTest(unittest.TestCase):
def test_empty_sections(self):
# Test empty sections
expected = '*libfreertos.a:croutine.*( )'
expected = '*libfreertos.a:croutine.*'
desc = InputSectionDesc(Entity('libfreertos.a', 'croutine'), [])
self.assertEqual(expected, str(desc))
def test_keep(self):
# Test KEEP
expected = 'KEEP(*libfreertos.a:croutine.*( ))'
expected = 'KEEP(*libfreertos.a:croutine.*)'
desc = InputSectionDesc(Entity('libfreertos.a', 'croutine'), [], keep=True)
self.assertEqual(expected, str(desc))

View File

@ -66,3 +66,5 @@ if not args.no_rtc:
check_location('func3', '.flash.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 "."
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

@ -7,3 +7,4 @@ entries:
text->iram0_text KEEP() ALIGN(9) ALIGN(12, post) SURROUND(sym1)
if SOC_RTC_MEM_SUPPORTED = y:
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 func3(void);
extern void func4(void);
extern const int const_array[];
void app_main(void)
{
func2();
func3();
func4();
if (esp_ptr_in_dram(const_array)) {
printf("const_array placed in dram\n");
} else {
printf("const_array NOT placed in dram\n");
}
}