diff --git a/components/esp_system/ld/esp32/sections.ld.in b/components/esp_system/ld/esp32/sections.ld.in index 303f9e317a1..9a676ab3dbb 100644 --- a/components/esp_system/ld/esp32/sections.ld.in +++ b/components/esp_system/ld/esp32/sections.ld.in @@ -352,8 +352,13 @@ SECTIONS KEEP (*(.preinit_array)) __preinit_array_end = ABSOLUTE(.); ALIGNED_SYMBOL(4, __init_array_start) +#if CONFIG_IDF_TOOLCHAIN_CLANG + KEEP (*(SORT_BY_INIT_PRIORITY(EXCLUDE_FILE (*crtend.* *crtbegin.*) .init_array.*))) + KEEP (*(EXCLUDE_FILE (*crtend.* *crtbegin.*) .init_array)) +#else KEEP (*(SORT_BY_INIT_PRIORITY(EXCLUDE_FILE (*crtend.* *crtbegin.*) .ctors.*))) KEEP (*(EXCLUDE_FILE (*crtend.* *crtbegin.*) .ctors)) +#endif __init_array_end = ABSOLUTE(.); __bothinit_array_end = ABSOLUTE(.); diff --git a/components/esp_system/ld/esp32s2/sections.ld.in b/components/esp_system/ld/esp32s2/sections.ld.in index a8553095528..91230ee1dd8 100644 --- a/components/esp_system/ld/esp32s2/sections.ld.in +++ b/components/esp_system/ld/esp32s2/sections.ld.in @@ -356,8 +356,13 @@ SECTIONS KEEP (*(.preinit_array)) __preinit_array_end = ABSOLUTE(.); ALIGNED_SYMBOL(4, __init_array_start) +#if CONFIG_IDF_TOOLCHAIN_CLANG + KEEP (*(SORT_BY_INIT_PRIORITY(EXCLUDE_FILE (*crtend.* *crtbegin.*) .init_array.*))) + KEEP (*(EXCLUDE_FILE (*crtend.* *crtbegin.*) .init_array)) +#else KEEP (*(SORT_BY_INIT_PRIORITY(EXCLUDE_FILE (*crtend.* *crtbegin.*) .ctors.*))) KEEP (*(EXCLUDE_FILE (*crtend.* *crtbegin.*) .ctors)) +#endif __init_array_end = ABSOLUTE(.); __bothinit_array_end = ABSOLUTE(.); diff --git a/components/esp_system/ld/esp32s3/sections.ld.in b/components/esp_system/ld/esp32s3/sections.ld.in index da3e457f046..88033ee2aac 100644 --- a/components/esp_system/ld/esp32s3/sections.ld.in +++ b/components/esp_system/ld/esp32s3/sections.ld.in @@ -365,8 +365,13 @@ SECTIONS KEEP (*(.preinit_array)) __preinit_array_end = ABSOLUTE(.); ALIGNED_SYMBOL(4, __init_array_start) +#if CONFIG_IDF_TOOLCHAIN_CLANG + KEEP (*(SORT_BY_INIT_PRIORITY(EXCLUDE_FILE (*crtend.* *crtbegin.*) .init_array.*))) + KEEP (*(EXCLUDE_FILE (*crtend.* *crtbegin.*) .init_array)) +#else KEEP (*(SORT_BY_INIT_PRIORITY(EXCLUDE_FILE (*crtend.* *crtbegin.*) .ctors.*))) KEEP (*(EXCLUDE_FILE (*crtend.* *crtbegin.*) .ctors)) +#endif __init_array_end = ABSOLUTE(.); __bothinit_array_end = ABSOLUTE(.);