chore: import upstream snapshot with attribution
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
set(COMPONENTS main)
|
||||
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
project(test_init_array)
|
||||
@@ -0,0 +1,20 @@
|
||||
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C5 | ESP32-C6 | ESP32-C61 | ESP32-H2 | ESP32-H21 | ESP32-H4 | ESP32-P4 | ESP32-S2 | ESP32-S3 | ESP32-S31 | Linux |
|
||||
| ----------------- | ----- | -------- | -------- | -------- | -------- | --------- | -------- | --------- | -------- | -------- | -------- | -------- | --------- | ----- |
|
||||
|
||||
# Historical note
|
||||
|
||||
Initially, ESP-IDF used the `do_global_ctors()` function to run global constructors.
|
||||
This was done to accommodate Xtensa targets that emit `.ctors.*` sections, which are ordered in descending order.
|
||||
|
||||
For RISC-V, compilation used `.init_array.*` sections, which are designed to have ascending order.
|
||||
Priority constructors in `.init_array.*` sections were correctly processed in ascending order.
|
||||
However, non-priority `.init_array` section was processed in descending order (as it was done for Xtensa `.ctors`).
|
||||
|
||||
Starting with ESP-IDF v6.0, the implementation switched to the standard LibC behavior (`__libc_init_array()`),
|
||||
which processes both priority and non-priority constructors in ascending order.
|
||||
|
||||
To achieve this, a breaking changes were introduced:
|
||||
- Xtensa `.ctors.*` entries converted to `.init_array.*` format (ascending), to be passed to `__libc_init_array()`.
|
||||
- Processing order of non-priority `.init_array` and `.ctors` sections was changed from descending to ascending.
|
||||
|
||||
This test ensures that the initialization order is correct and consistent between ESP-IDF and Linux targets.
|
||||
@@ -0,0 +1,2 @@
|
||||
idf_component_register(SRCS "test_app_main.c"
|
||||
REQUIRES esp_system)
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
__attribute__((constructor))
|
||||
void foo(void)
|
||||
{
|
||||
printf("%s\n", __FUNCTION__);
|
||||
}
|
||||
|
||||
__attribute__((constructor(103)))
|
||||
void init_prio_103(void)
|
||||
{
|
||||
printf("%s\n", __FUNCTION__);
|
||||
}
|
||||
|
||||
__attribute__((constructor(101)))
|
||||
void init_prio_101(void)
|
||||
{
|
||||
printf("%s\n", __FUNCTION__);
|
||||
}
|
||||
|
||||
__attribute__((constructor(102)))
|
||||
void init_prio_102(void)
|
||||
{
|
||||
printf("%s\n", __FUNCTION__);
|
||||
}
|
||||
|
||||
__attribute__((constructor))
|
||||
void bar(void)
|
||||
{
|
||||
printf("%s\n", __FUNCTION__);
|
||||
}
|
||||
|
||||
void preinit_func(void)
|
||||
{
|
||||
printf("%s\n", __FUNCTION__);
|
||||
}
|
||||
|
||||
__attribute__((section(".preinit_array"), used))
|
||||
uintptr_t test_preinit = (uintptr_t) preinit_func;
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
printf("app_main running\n");
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
# SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: CC0-1.0
|
||||
import pytest
|
||||
from pytest_embedded import Dut
|
||||
from pytest_embedded_idf.utils import idf_parametrize
|
||||
|
||||
|
||||
@pytest.mark.generic
|
||||
@idf_parametrize('target', ['supported_targets', 'preview_targets', 'linux'], indirect=['target'])
|
||||
def test_init_array(dut: Dut) -> None:
|
||||
dut.expect_exact('preinit_func')
|
||||
dut.expect_exact('init_prio_101')
|
||||
dut.expect_exact('init_prio_102')
|
||||
dut.expect_exact('init_prio_103')
|
||||
dut.expect_exact('foo')
|
||||
dut.expect_exact('bar')
|
||||
dut.expect_exact('app_main running')
|
||||
Reference in New Issue
Block a user