Skip to content

Commit 555c511

Browse files
Lapshin0cici
authored andcommitted
feat(build): change orphan-handling behavior to error
1 parent c10d3ac commit 555c511

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+
Build System
2+
============
3+
4+
:link_to_translation:`en:[English]`
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/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)