diff --git a/tools/test_apps/system/eh_frame/CMakeLists.txt b/tools/test_apps/system/eh_frame/CMakeLists.txt new file mode 100644 index 0000000000..51e1dc8ca5 --- /dev/null +++ b/tools/test_apps/system/eh_frame/CMakeLists.txt @@ -0,0 +1,6 @@ +# The following lines of boilerplate have to be in your project's CMakeLists +# in this exact order for cmake to work correctly +cmake_minimum_required(VERSION 3.16) + +include($ENV{IDF_PATH}/tools/cmake/project.cmake) +project(eh_frame) diff --git a/tools/test_apps/system/eh_frame/README.md b/tools/test_apps/system/eh_frame/README.md new file mode 100644 index 0000000000..c274fdc56a --- /dev/null +++ b/tools/test_apps/system/eh_frame/README.md @@ -0,0 +1,16 @@ +| Supported Targets | ESP32-C3 | ESP32-H2 | ESP32-C2 | +| ----------------- | -------- | -------- | -------- | + +# Building and running + +The main goal of this test is to check whether the compiler/linker generates non-empty sections `.eh_frame` and `.eh_frame_hdr`. + +Thus, as soon as this example compiles we can considered it passed. However, it will also print the addresses of both sections on the UART. + +In order to build and run the example, use the following commands: + +``` +idf.py set-target +idf.py build +idf.py flash monitor +``` diff --git a/tools/test_apps/system/eh_frame/main/CMakeLists.txt b/tools/test_apps/system/eh_frame/main/CMakeLists.txt new file mode 100644 index 0000000000..09f0d02fdf --- /dev/null +++ b/tools/test_apps/system/eh_frame/main/CMakeLists.txt @@ -0,0 +1,3 @@ +idf_component_register(SRCS "eh_frame_main.c" + INCLUDE_DIRS "." + REQUIRES esp_system) diff --git a/tools/test_apps/system/eh_frame/main/eh_frame_main.c b/tools/test_apps/system/eh_frame/main/eh_frame_main.c new file mode 100644 index 0000000000..8abf55144e --- /dev/null +++ b/tools/test_apps/system/eh_frame/main/eh_frame_main.c @@ -0,0 +1,40 @@ +/* + * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Unlicense OR CC0-1.0 + */ +#include +#include +#include +#include + +/** + * @brief Symbols defined by the linker. + * Retrieve the addresses of both .eh_frame_hdr and .eh_frame sections. + */ +extern char __eh_frame_hdr; +extern char __eh_frame_hdr_end; +extern char __eh_frame; +extern char __eh_frame_end; + +/** + * @brief Pointers to both .eh_frame_hdr and .eh_frame sections. + */ +#define EH_FRAME_HDR_ADDR ((void*) (&__eh_frame_hdr)) +#define EH_FRAME_HDR_END_ADDR ((void*) (&__eh_frame_hdr_end)) +#define EH_FRAME_ADDR ((void*) (&__eh_frame)) +#define EH_FRAME_END_ADDR ((void*) (&__eh_frame_end)) + + +void app_main(void) +{ + /* As soon as this test compiles, it can be considered passed. The linker should + * test that the eh_frame and eh_frame_hdr sections are not empty but let's make + * sure again that they are not empty. */ + assert((EH_FRAME_END_ADDR > EH_FRAME_ADDR) && ".eh_frame section must not be empty"); + assert((EH_FRAME_HDR_END_ADDR > EH_FRAME_HDR_ADDR) && ".eh_frame_hdr section must not be empty"); + + /* Use the symbols just to make sure they won't be optimized away */ + printf(".eh_frame start: %p, end: %p\n", EH_FRAME_ADDR, EH_FRAME_END_ADDR); + printf(".eh_frame_hdr start: %p, end: %p\n", EH_FRAME_HDR_ADDR, EH_FRAME_HDR_END_ADDR); +} diff --git a/tools/test_apps/system/eh_frame/sdkconfig.defaults b/tools/test_apps/system/eh_frame/sdkconfig.defaults new file mode 100644 index 0000000000..dae200b3ef --- /dev/null +++ b/tools/test_apps/system/eh_frame/sdkconfig.defaults @@ -0,0 +1,2 @@ +# Enable eh_frame sections generation +CONFIG_ESP_SYSTEM_USE_EH_FRAME=y