diff --git a/net/CMakeLists.txt b/net/CMakeLists.txt index 0183728c9ca..be79499d740 100644 --- a/net/CMakeLists.txt +++ b/net/CMakeLists.txt @@ -27,4 +27,8 @@ if(CONFIG_NET) target_sources(net PRIVATE net_initialize.c) target_include_directories(net PRIVATE ${CMAKE_CURRENT_LIST_DIR}) + + if(CONFIG_NET_NO_LTO) + add_compile_options(-fno-lto) + endif() endif() diff --git a/net/Kconfig b/net/Kconfig index 285078eab13..b561b3f8fcc 100644 --- a/net/Kconfig +++ b/net/Kconfig @@ -457,4 +457,19 @@ endmenu # Network Topologies source "net/route/Kconfig" +config NET_NO_LTO + bool "Support no-lto option for the network Makefile" + default n + ---help--- + This option disables Link Time Optimization (LTO) specifically for the + network subsystem. + + LTO can sometimes introduce build issues, excessive compilation time, + or difficult-to-debug runtime behaviors in complex network stacks + depending on the compiler version and architecture. + + Enable this option if you encounter LTO-related issues in the network + stack or need to debug network code without the aggressive optimizations + introduced by LTO, while keeping LTO enabled for the rest of the system. + endif # NET diff --git a/net/Makefile b/net/Makefile index 5263eb1e62f..a7258f50ba6 100644 --- a/net/Makefile +++ b/net/Makefile @@ -70,6 +70,10 @@ COBJS = $(CSRCS:.c=$(OBJEXT)) SRCS = $(ASRCS) $(CSRCS) OBJS = $(AOBJS) $(COBJS) +ifeq ($(CONFIG_NET_NO_LTO),y) +CFLAGS += -fno-lto +endif + BIN = libnet$(LIBEXT) all: $(BIN)