Skip to content

Commit 65a3d38

Browse files
invertegoLukeUsher
authored andcommitted
build: enable clang ThinLTO
With ThinLTO and an incremental LTO cache, incremental link time (with LTO, of course) goes down from tens of seconds to less than a second. For whatever reason, ThinLTO needs libco's co_swap_function to have external linkage. Who am I to argue?
1 parent aa9c641 commit 65a3d38

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

libco/aarch64.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ static void (*co_swap)(cothread_t, cothread_t) = 0;
1919
#else
2020
section(text)
2121
#endif
22-
static const uint32_t co_swap_function[1024] = {
22+
const uint32_t co_swap_function[1024] = {
2323
0x910003f0, /* mov x16,sp */
2424
0xa9007830, /* stp x16,x30,[x1] */
2525
0xa9407810, /* ldp x16,x30,[x0] */

libco/amd64.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ static void (*co_swap)(cothread_t, cothread_t) = 0;
2020
#endif
2121
#ifdef _WIN32
2222
/* ABI: Win64 */
23-
static const unsigned char co_swap_function[4096] = {
23+
const unsigned char co_swap_function[4096] = {
2424
0x48, 0x89, 0x22, /* mov [rdx],rsp */
2525
0x48, 0x8b, 0x21, /* mov rsp,[rcx] */
2626
0x58, /* pop rax */
@@ -87,7 +87,7 @@ static void (*co_swap)(cothread_t, cothread_t) = 0;
8787
}
8888
#else
8989
/* ABI: SystemV */
90-
static const unsigned char co_swap_function[4096] = {
90+
const unsigned char co_swap_function[4096] = {
9191
0x48, 0x89, 0x26, /* mov [rsi],rsp */
9292
0x48, 0x8b, 0x27, /* mov rsp,[rdi] */
9393
0x58, /* pop rax */

libco/x86.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ static void (fastcall *co_swap)(cothread_t, cothread_t) = 0;
2727
section(text)
2828
#endif
2929
/* ABI: fastcall */
30-
static const unsigned char co_swap_function[4096] = {
30+
const unsigned char co_swap_function[4096] = {
3131
0x89, 0x22, /* mov [edx],esp */
3232
0x8b, 0x21, /* mov esp,[ecx] */
3333
0x58, /* pop eax */

nall/GNUmakefile

+13-3
Original file line numberDiff line numberDiff line change
@@ -200,14 +200,24 @@ endif
200200
# link-time optimization
201201
ifeq ($(lto),true)
202202
ifeq ($(cl),true)
203-
flags += $(if $(findstring clang,$(compiler)),-flto,-GL)
204-
options += -ltcg:incremental -ltcgout:$(object.path)/$(name).iobj
203+
ifneq ($(findstring clang,$(compiler)),clang)
204+
flags += -GL
205+
options += -ltcg:incremental -ltcgout:$(object.path)/$(name).iobj
206+
else
207+
flags += -flto=thin
208+
options += -lldltocache:$(object.path)/lto
209+
endif
205210
else
206211
ifneq ($(findstring clang++,$(compiler)),clang++)
207212
flags += -flto=auto -fno-fat-lto-objects
208213
else
209-
flags += -flto
214+
flags += -flto=thin
210215
options += -flto=thin
216+
ifneq ($(platform),macos)
217+
options += -Wl,--thinlto-cache-dir=$(object.path)/lto
218+
else
219+
options += -Wl,-cache_path_lto,$(object.path)/lto
220+
endif
211221
endif
212222
endif
213223
endif

0 commit comments

Comments
 (0)