feat(esp_system): switch to standard __libc_init_array initialization

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.* priority 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.

Also, this change introduces .preinit_array for linking. This may be
needed for some C++ or sanitizer features.

Related to https://github.com/espressif/esp-idf/issues/15529
This commit is contained in:
Alexey Lapshin
2023-05-08 18:11:32 +08:00
committed by BOT
parent 819970f439
commit 019dc93ae0
25 changed files with 228 additions and 199 deletions

View File

@@ -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')