-
Notifications
You must be signed in to change notification settings - Fork 1.5k
net: Support no-lto option for the network build. #17878
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
anchao
left a comment
There was a problem hiding this 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>
071350e to
dc00e83
Compare
I've removed some inaccurate descriptions. Could you please review them again? |
anchao
left a comment
There was a problem hiding this 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.
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. |
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_LTOto control Link Time Optimization (LTO) specifically for the network subsystem. When enabled, it appends-fno-ltoto the compilation flags for network files innet/Makefileandnet/CMakeLists.txt.This change is introduced to address the following scenarios:
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.
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.
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
menuconfig->Networking Support->Support no-lto option for the network Makefile.CONFIG_NET_NO_LTO=y, the-fno-ltoflag is added to the CFLAGS for network sources.n(disabled), preserving existing behavior.Testing
CONFIG_NET_NO_LTO=y.make --dry-runthat-fno-ltoappears in the compilation commands for files undernet/.CONFIG_NET_NO_LTO=n.-fno-ltois absent.tools/checkpatch.sh.