@@ -25,6 +25,16 @@ BUILD_LIBC_TOP_HALF ?= yes
25
25
BUILD_LIBSETJMP ?= yes
26
26
# The directory where we will store intermediate artifacts.
27
27
OBJDIR ?= build/$(TARGET_TRIPLE )
28
+
29
+ # LTO; no, full, or thin
30
+ # Note: thin LTO here is just for experimentation. It has known issues:
31
+ # - https://github.com/llvm/llvm-project/issues/91700
32
+ # - https://github.com/llvm/llvm-project/issues/91711
33
+ LTO ?= no
34
+ ifneq ($(LTO ) ,no)
35
+ CLANG_VERSION ?= $(shell ${CC} -dumpversion)
36
+ override OBJDIR := $(OBJDIR ) /llvm-lto/$(CLANG_VERSION )
37
+ endif
28
38
# The directory where we store files and tools for generating WASIp2 bindings
29
39
BINDING_WORK_DIR ?= build/bindings
30
40
# URL from which to retrieve the WIT files used to generate the WASIp2 bindings
@@ -396,6 +406,18 @@ ASMFLAGS += -matomics
396
406
CFLAGS += -I$(LIBC_BOTTOM_HALF_CLOUDLIBC_SRC )
397
407
endif
398
408
409
+ ifneq ($(LTO ) ,no)
410
+ ifeq ($(LTO ) ,full)
411
+ CFLAGS += -flto=full
412
+ else
413
+ ifeq ($(LTO ) ,thin)
414
+ CFLAGS += -flto=thin
415
+ else
416
+ $(error unknown LTO value : $(LTO ) )
417
+ endif
418
+ endif
419
+ endif
420
+
399
421
ifeq ($(WASI_SNAPSHOT ) , p2)
400
422
CFLAGS += -D__wasilibc_use_wasip2
401
423
endif
@@ -456,6 +478,9 @@ LIBC_BOTTOM_HALF_CRT_OBJS = $(call objs,$(LIBC_BOTTOM_HALF_CRT_SOURCES))
456
478
# These variables describe the locations of various files and
457
479
# directories in the generated sysroot tree.
458
480
SYSROOT_LIB := $(SYSROOT ) /lib/$(TARGET_TRIPLE )
481
+ ifneq ($(LTO ) ,no)
482
+ override SYSROOT_LIB := $(SYSROOT_LIB ) /llvm-lto/$(CLANG_VERSION )
483
+ endif
459
484
SYSROOT_INC = $(SYSROOT ) /include/$(TARGET_TRIPLE )
460
485
SYSROOT_SHARE = $(SYSROOT ) /share/$(TARGET_TRIPLE )
461
486
@@ -794,12 +819,14 @@ finish: startup_files libc dummy_libs
794
819
# The build succeeded! The generated sysroot is in $(SYSROOT).
795
820
#
796
821
822
+ ifeq ($(LTO ) ,no)
797
823
# The check for defined and undefined symbols expects there to be a heap
798
824
# alloctor (providing malloc, calloc, free, etc). Skip this step if the build
799
825
# is done without a malloc implementation.
800
826
ifneq ($(MALLOC_IMPL ) ,none)
801
827
finish : check-symbols
802
828
endif
829
+ endif
803
830
804
831
DEFINED_SYMBOLS = $(SYSROOT_SHARE ) /defined-symbols.txt
805
832
UNDEFINED_SYMBOLS = $(SYSROOT_SHARE ) /undefined-symbols.txt
0 commit comments