Skip to content

Commit a319aa9

Browse files
committed
Merge branch 'feature/change-orphan-handling-behavior-to-error' into 'master'
feat(build): change orphan-handling behavior to error Closes IDF-9792 and DOC-11408 See merge request espressif/esp-idf!39566
2 parents a4037e2 + be87c12 commit a319aa9

File tree

7 files changed

+65
-3
lines changed

7 files changed

+65
-3
lines changed

Kconfig

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,14 +647,19 @@ mainmenu "Espressif IoT Development Framework Configuration"
647647

648648
choice COMPILER_ORPHAN_SECTIONS
649649
prompt "Orphan sections handling"
650-
default COMPILER_ORPHAN_SECTIONS_WARNING
650+
default COMPILER_ORPHAN_SECTIONS_ERROR
651651
depends on !IDF_TARGET_LINUX
652652
help
653653
If the linker finds orphan sections, it attempts to place orphan sections after sections of the same
654654
attribute such as code vs data, loadable vs non-loadable, etc.
655655
That means that orphan sections could placed between sections defined in IDF linker scripts.
656656
This could lead to corruption of the binary image. Configure the linker action here.
657657

658+
config COMPILER_ORPHAN_SECTIONS_ERROR
659+
bool "Fail if orphan sections found"
660+
help
661+
Fails the link step with an error if orphan sections are detected.
662+
658663
config COMPILER_ORPHAN_SECTIONS_WARNING
659664
bool "Place with warning"
660665
help
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Build System
2+
============
3+
4+
:link_to_translation:`zh_CN:[中文]`
5+
6+
Linker Orphan-Handling Behavior Changed to Error
7+
------------------------------------------------
8+
9+
Starting with ESP-IDF v6.0, the build system no longer allows orphan sections in the final ELF file. The linker will now produce an error if any orphan sections are encountered during linking.
10+
11+
.. note::
12+
13+
An *orphan section* is a section that is not explicitly placed into any output section by the linker script and is not discarded during linking.
14+
15+
How to Resolve Orphan Section Errors
16+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
17+
18+
If you encounter an orphan section error during linking, you can resolve it using one of the following methods:
19+
20+
1. Remove the code or data that causes the orphan section, if it's unused or unnecessary.
21+
2. Explicitly place the orphan section using a :ref:`linker fragment file <ldgen-linker-fragment-files>`.
22+
3. Suppress errors by setting :ref:`CONFIG_COMPILER_ORPHAN_SECTIONS` to ``warning`` or ``place``.
23+
24+
.. warning::
25+
26+
The option 3 is **not recommended**, as orphan sections may indicate misconfigured memory mapping or unintentional behavior in your application.

docs/en/migration-guides/release-6.x/6.0/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Migration from 5.5 to 6.0
66
.. toctree::
77
:maxdepth: 1
88

9+
build-system
910
peripherals
1011
security
1112
tools
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
迁移构建系统至 ESP-IDF v6.0
2+
===================================
3+
4+
:link_to_translation:`en:[English]`
5+
6+
链接器孤立段处理行为变更为报错
7+
-------------------------------
8+
9+
从 ESP-IDF v6.0 开始,构建系统不再允许最终 ELF 文件中存在孤立段。如果链接过程中发现任何孤立段,链接器将报错。
10+
11+
.. note::
12+
13+
*孤立段* 是指未被链接脚本显式放置到任何输出段,且在链接过程中未被丢弃的段。
14+
15+
如何解决孤立段错误
16+
~~~~~~~~~~~~~~~~~~~~
17+
18+
如果在链接时遇到孤立段错误,可通过以下任一方式解决:
19+
20+
1. 移除导致孤立段的代码或数据(若未使用或不必要)。
21+
2. 使用 :ref:`链接器片段文件 <ldgen-linker-fragment-files>` 显式放置孤立段。
22+
3. 通过设置 :ref:`CONFIG_COMPILER_ORPHAN_SECTIONS` 为 ``warning`` 或 ``place`` 来抑制错误。
23+
24+
.. warning::
25+
26+
方案3 **不推荐使用**,因为孤立段可能意味着内存映射配置存在问题,或应用程序中存在非预期行为。

docs/zh_CN/migration-guides/release-6.x/6.0/index.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
.. toctree::
77
:maxdepth: 1
88

9-
security
9+
build-system
1010
peripherals
11+
security
1112
tools

tools/cmake/project.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,9 @@ macro(project project_name)
879879
if(CONFIG_COMPILER_ORPHAN_SECTIONS_WARNING)
880880
# Print warnings if orphan sections are found
881881
target_link_options(${project_elf} PRIVATE "-Wl,--orphan-handling=warn")
882+
elseif(CONFIG_COMPILER_ORPHAN_SECTIONS_ERROR)
883+
# Throw error if orphan sections are found
884+
target_link_options(${project_elf} PRIVATE "-Wl,--orphan-handling=error")
882885
endif()
883886
unset(idf_target)
884887
endif()

tools/idf_py_actions/hints.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@
434434

435435
-
436436
re: "unplaced orphan section"
437-
hint: "Avoid creating custom sections. Please refer to the 'Linker Script Generation' article in the IDF documentation to address this. Or set option CONFIG_COMPILER_ORPHAN_SECTIONS_PLACE (not recommended)."
437+
hint: "An orphan section was detected during linking stage. For more information run 'idf.py docs -sp migration-guides/release-6.x/build-system.html#linker-orphan-handling-behavior-changed-to-error'."
438438

439439
-
440440
re: "the current mclk multiple cannot perform integer division"

0 commit comments

Comments
 (0)