Skip to content

Commit 3e4c14c

Browse files
authored
Merge pull request #253 from sysprog21/enable-lto
Enable link-time optimization by default
2 parents 6e88bb6 + 30ac674 commit 3e4c14c

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

Makefile

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,28 @@ CFLAGS += -D DEFAULT_STACK_ADDR=0xFFFFE000
1616
# Set the default args starting address
1717
CFLAGS += -D DEFAULT_ARGS_ADDR=0xFFFFF000
1818

19+
# Enable link-time optimization (LTO)
20+
ENABLE_LTO ?= 1
21+
ifeq ($(call has, LTO), 1)
22+
ifeq ("$(CC_IS_CLANG)$(CC_IS_GCC)",)
23+
$(warning LTO is only supported in clang and gcc.)
24+
override ENABLE_LTO := 0
25+
endif
26+
endif
27+
$(call set-feature, LTO)
28+
ifeq ($(call has, LTO), 1)
29+
ifeq ("$(CC_IS_GCC)", "1")
30+
CFLAGS += -flto
31+
endif
32+
ifeq ("$(CC_IS_CLANG)", "1")
33+
CFLAGS += -flto=thin -fsplit-lto-unit
34+
LDFLAGS += -flto=thin
35+
endif
36+
endif
37+
38+
# Disable Intel's Control-flow Enforcement Technology (CET)
39+
CFLAGS += $(CFLAGS_NO_CET)
40+
1941
OBJS_EXT :=
2042

2143
# Control and Status Register (CSR)
@@ -90,7 +112,7 @@ endif
90112

91113
# For tail-call elimination, we need a specific set of build flags applied.
92114
# FIXME: On macOS + Apple Silicon, -fno-stack-protector might have a negative impact.
93-
$(OUT)/emulate.o: CFLAGS += $(CFLAGS_NO_CET) -foptimize-sibling-calls -fomit-frame-pointer -fno-stack-check -fno-stack-protector
115+
$(OUT)/emulate.o: CFLAGS += -foptimize-sibling-calls -fomit-frame-pointer -fno-stack-check -fno-stack-protector
94116

95117
# Clear the .DEFAULT_GOAL special variable, so that the following turns
96118
# to the first target after .DEFAULT_GOAL is not set.

0 commit comments

Comments
 (0)