diff --git a/tools/test_apps/build_system/ldgen_test/check_placements.py b/tools/test_apps/build_system/ldgen_test/check_placements.py index c465f7bf0e..5f515df9a7 100644 --- a/tools/test_apps/build_system/ldgen_test/check_placements.py +++ b/tools/test_apps/build_system/ldgen_test/check_placements.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -# SPDX-FileCopyrightText: 2020-2024 Espressif Systems (Shanghai) CO LTD +# SPDX-FileCopyrightText: 2020-2025 Espressif Systems (Shanghai) CO LTD # SPDX-License-Identifier: Apache-2.0 # # Check placements in this test app for main @@ -8,13 +8,13 @@ import argparse import subprocess -from pyparsing import alphanums -from pyparsing import hexnums from pyparsing import LineEnd from pyparsing import LineStart from pyparsing import Literal from pyparsing import Optional from pyparsing import Word +from pyparsing import alphanums +from pyparsing import hexnums argparser = argparse.ArgumentParser() @@ -29,13 +29,16 @@ contents = subprocess.check_output([args.objdump, '-t', args.elf]).decode() def check_location(symbol, expected): - pattern = (LineStart() + Word(hexnums).setResultsName('address') - + Optional(Word(alphanums, exact=1)) - + Optional(Word(alphanums,exact=1)) - + Word(alphanums + '._*').setResultsName('actual') - + Word(hexnums) - + Literal(symbol) - + LineEnd()) + pattern = ( + LineStart() + + Word(hexnums).setResultsName('address') + + Optional(Word(alphanums, exact=1)) + + Optional(Word(alphanums, exact=1)) + + Word(alphanums + '._*').setResultsName('actual') + + Word(hexnums) + + Literal(symbol) + + LineEnd() + ) try: results = pattern.searchString(contents)[0] @@ -43,7 +46,9 @@ def check_location(symbol, expected): raise Exception("check placement fail: '%s' was not found" % (symbol)) if results.actual != expected: - raise Exception("check placement fail: '%s' was placed in '%s', not in '%s'" % (symbol, results.actual, expected)) + raise Exception( + "check placement fail: '%s' was placed in '%s', not in '%s'" % (symbol, results.actual, expected) + ) print("check placement pass: '%s' was successfully placed in '%s'" % (symbol, results.actual)) return int(results.address, 16) @@ -82,3 +87,5 @@ check_location('func3', '.flash.text') check_location('func4', '.iram0.text') check_location('const_array', '.dram0.data') + +check_location('prebuilt_func', '.iram0.text') diff --git a/tools/test_apps/build_system/ldgen_test/components/prebuilt/CMakeLists.txt b/tools/test_apps/build_system/ldgen_test/components/prebuilt/CMakeLists.txt new file mode 100644 index 0000000000..50f01feab5 --- /dev/null +++ b/tools/test_apps/build_system/ldgen_test/components/prebuilt/CMakeLists.txt @@ -0,0 +1,14 @@ +idf_component_register() + +include(ExternalProject) +externalproject_add(subproject + SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/subproject + CMAKE_ARGS -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} + BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/subproject" + INSTALL_COMMAND "" + BUILD_BYPRODUCTS "${CMAKE_CURRENT_BINARY_DIR}/subproject/libprebuilt.a" +) + +add_prebuilt_library(prebuilt "${CMAKE_CURRENT_BINARY_DIR}/subproject/libprebuilt.a") + +target_link_libraries(${COMPONENT_LIB} INTERFACE prebuilt) diff --git a/tools/test_apps/build_system/ldgen_test/components/prebuilt/subproject/CMakeLists.txt b/tools/test_apps/build_system/ldgen_test/components/prebuilt/subproject/CMakeLists.txt new file mode 100644 index 0000000000..24e1b2255b --- /dev/null +++ b/tools/test_apps/build_system/ldgen_test/components/prebuilt/subproject/CMakeLists.txt @@ -0,0 +1,5 @@ +cmake_minimum_required(VERSION 3.12) + +project(prebuilt) +add_library(prebuilt STATIC prebuilt.c) +target_compile_options(prebuilt PRIVATE "-ffunction-sections" "-fdata-sections") diff --git a/tools/test_apps/build_system/ldgen_test/components/prebuilt/subproject/prebuilt.c b/tools/test_apps/build_system/ldgen_test/components/prebuilt/subproject/prebuilt.c new file mode 100644 index 0000000000..becc2ec615 --- /dev/null +++ b/tools/test_apps/build_system/ldgen_test/components/prebuilt/subproject/prebuilt.c @@ -0,0 +1,9 @@ +/* + * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Unlicense OR CC0-1.0 + */ +int prebuilt_func(void) +{ + return 42; +} diff --git a/tools/test_apps/build_system/ldgen_test/main/CMakeLists.txt b/tools/test_apps/build_system/ldgen_test/main/CMakeLists.txt index 6f10a09e80..47d89879fc 100644 --- a/tools/test_apps/build_system/ldgen_test/main/CMakeLists.txt +++ b/tools/test_apps/build_system/ldgen_test/main/CMakeLists.txt @@ -1,3 +1,4 @@ idf_component_register(SRCS "src1.c" "src2.c" "test_main.c" "consts.c" INCLUDE_DIRS "." + PRIV_REQUIRES prebuilt LDFRAGMENTS "linker.lf") diff --git a/tools/test_apps/build_system/ldgen_test/main/linker.lf b/tools/test_apps/build_system/ldgen_test/main/linker.lf index e2b06fb614..eb0a753fd9 100644 --- a/tools/test_apps/build_system/ldgen_test/main/linker.lf +++ b/tools/test_apps/build_system/ldgen_test/main/linker.lf @@ -10,3 +10,8 @@ entries: if SOC_RTC_MEM_SUPPORTED = y: src1:func2 (rtc) consts : const_array (noflash) + +[mapping:prebuilt] +archive: libprebuilt.a +entries: + prebuilt:prebuilt_func (noflash) diff --git a/tools/test_apps/build_system/ldgen_test/main/test_main.c b/tools/test_apps/build_system/ldgen_test/main/test_main.c index d01bec546e..775935f5a0 100644 --- a/tools/test_apps/build_system/ldgen_test/main/test_main.c +++ b/tools/test_apps/build_system/ldgen_test/main/test_main.c @@ -11,12 +11,14 @@ extern void func3(void); extern void func4(void); extern const int const_array[]; +extern int prebuilt_func(void); void app_main(void) { func2(); func3(); func4(); + prebuilt_func(); if (esp_ptr_in_dram(const_array)) { printf("const_array placed in dram\n"); } else {