Skip to content

Conversation

@13627105546
Copy link
Contributor

@13627105546 13627105546 commented Jan 14, 2026

Add CONFIG_NET_NO_LTO to allow compiling the network stack with -fno-lto. This is useful for avoiding LTO-related issues in the network layer.

Note: Please adhere to Contributing Guidelines.

Summary

This PR adds a new Kconfig option CONFIG_NET_NO_LTO to control Link Time Optimization (LTO) specifically for the network subsystem. When enabled, it appends -fno-lto to the compilation flags for network files in net/Makefile and net/CMakeLists.txt.

This change is introduced to address the following scenarios:

  1. Debugging Support: LTO can heavily inline functions and optimize away symbols, making the debugging of complex network protocol stacks difficult. Disabling LTO locally preserves the code structure for easier analysis.

  2. Compiler Compatibility: In certain build environments or with specific toolchain versions, enabling LTO globally may trigger internal compiler errors or produce incorrect code for the network stack state machines.

  3. Build Performance: Disabling LTO for the network subsystem can reduce the link time and memory usage during the build process on resource-constrained build machines.

This granular control allows users to keep LTO enabled for the rest of the system to maintain performance while disabling it for the network layer if needed for debugging or stability.

Impact

  • Impact on user: Users can now optionally disable LTO for the network stack via menuconfig -> Networking Support -> Support no-lto option for the network Makefile.
  • Build process: If CONFIG_NET_NO_LTO=y, the -fno-lto flag is added to the CFLAGS for network sources.
  • Compatibility: Backward compatible; default is n (disabled), preserving existing behavior.

Testing

  • Verification:
    1. Configured with CONFIG_NET_NO_LTO=y.
    2. Verified via make --dry-run that -fno-lto appears in the compilation commands for files under net/.
    3. Configured with CONFIG_NET_NO_LTO=n.
    4. Verified that -fno-lto is absent.
    5. Passed tools/checkpatch.sh.

@github-actions github-actions bot added Area: Networking Effects networking subsystem Size: S The size of the change in this PR is small labels Jan 14, 2026
Copy link
Contributor

@anchao anchao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a rather odd requirement:

symbol visibility problems

Symbol visibility should be resolved via the interfaces provided by syscalls. If certain sockets are not supposed to be subject to LTO, we only need to mark these symbols with special attributes.

stack overflow due to aggressive inlining

Stack overflow caused by excessive inlining should be addressed by determining whether stack adjustments are needed based on compilation options and compiler types. Otherwise, the issue may still occur even with LTO disabled when using compilers with strong optimization capabilities.

Add CONFIG_NET_NO_LTO to allow compiling the network stack with -fno-lto.
This is useful for avoiding LTO-related issues in the network layer.

Signed-off-by: daichuan <daichuan@xiaomi.com>
@13627105546
Copy link
Contributor Author

This is a rather odd requirement:

symbol visibility problems

Symbol visibility should be resolved via the interfaces provided by syscalls. If certain sockets are not supposed to be subject to LTO, we only need to mark these symbols with special attributes.

stack overflow due to aggressive inlining

Stack overflow caused by excessive inlining should be addressed by determining whether stack adjustments are needed based on compilation options and compiler types. Otherwise, the issue may still occur even with LTO disabled when using compilers with strong optimization capabilities.

I've removed some inaccurate descriptions. Could you please review them again?

Copy link
Contributor

@anchao anchao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the purpose of this modification is to facilitate debugging, then I have no objections. Alternatively, could we add a DEBUG flag to this config? Anyway, this is not a big deal.

@xiaoxiang781216
Copy link
Contributor

If the purpose of this modification is to facilitate debugging, then I have no objections. Alternatively, could we add a DEBUG flag to this config? Anyway, this is not a big deal.

not only for debugging, the network stack code may need move into TCM to get the best performance on some platform. but the code layout arrangement is impossible with lto.

@xiaoxiang781216 xiaoxiang781216 merged commit d19ee93 into apache:master Jan 20, 2026
40 checks passed
@anchao
Copy link
Contributor

anchao commented Jan 20, 2026

If the purpose of this modification is to facilitate debugging, then I have no objections. Alternatively, could we add a DEBUG flag to this config? Anyway, this is not a big deal.

not only for debugging, the network stack code may need move into TCM to get the best performance on some platform. but the code layout arrangement is impossible with lto.

So why not use .a to specified in the linker script? If LTO is disabled, wouldn’t LTO (O3) and LD optimizations be mutually exclusive in some performance-critical scenarios?

@xiaoxiang781216
Copy link
Contributor

If the purpose of this modification is to facilitate debugging, then I have no objections. Alternatively, could we add a DEBUG flag to this config? Anyway, this is not a big deal.

not only for debugging, the network stack code may need move into TCM to get the best performance on some platform. but the code layout arrangement is impossible with lto.

So why not use .a to specified in the linker script? If LTO is disabled, wouldn’t LTO (O3) and LD optimizations be mutually exclusive in some performance-critical scenarios?

.a doesn't work too, it's the limitation of LTO implementation.

@anchao
Copy link
Contributor

anchao commented Jan 20, 2026

If the purpose of this modification is to facilitate debugging, then I have no objections. Alternatively, could we add a DEBUG flag to this config? Anyway, this is not a big deal.

not only for debugging, the network stack code may need move into TCM to get the best performance on some platform. but the code layout arrangement is impossible with lto.

So why not use .a to specified in the linker script? If LTO is disabled, wouldn’t LTO (O3) and LD optimizations be mutually exclusive in some performance-critical scenarios?

.a doesn't work too, it's the limitation of LTO implementation.

Actually, we use .a static libraries for LTO, with full support from the linker script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: Networking Effects networking subsystem Size: S The size of the change in this PR is small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants