Skip to content

Commit d27bc03

Browse files
authored
Add LTO support for most compilers and do some VCC fixes (#14013)
* Added LTO in nim.cfg, added /link in extccomp.nim and other fixes * Fix line endings * Fix line endings, for real this time. Almost certainly. Like, 95% certain. * Removed /MD from extccom.nim VCC comiler
1 parent 6cfe2e0 commit d27bc03

File tree

2 files changed

+37
-6
lines changed

2 files changed

+37
-6
lines changed

compiler/extccomp.nim

+4-3
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,12 @@ compiler vcc:
157157
optSize: " /O1 ",
158158
compilerExe: "cl",
159159
cppCompiler: "cl",
160-
compileTmpl: "/c$vccplatform $options $include /Fo$objfile $file",
161-
buildGui: " /link /SUBSYSTEM:WINDOWS ",
160+
compileTmpl: "/c$vccplatform $options $include /nologo /Fo$objfile $file",
161+
buildGui: " /SUBSYSTEM:WINDOWS user32.lib ",
162162
buildDll: " /LD",
163163
buildLib: "lib /OUT:$libfile $objfiles",
164164
linkerExe: "cl",
165-
linkTmpl: "$builddll$vccplatform /Fe$exefile $objfiles $buildgui $options",
165+
linkTmpl: "$builddll$vccplatform /Fe$exefile $objfiles $buildgui /link /nologo $options",
166166
includeCmd: " /I",
167167
linkDirCmd: " /LIBPATH:",
168168
linkLibCmd: " $1.lib",
@@ -180,6 +180,7 @@ compiler clangcl:
180180
result.compilerExe = "clang-cl"
181181
result.cppCompiler = "clang-cl"
182182
result.linkerExe = "clang-cl"
183+
result.linkTmpl = "-fuse-ld=lld " & result.linkTmpl
183184

184185
# Intel C/C++ Compiler
185186
compiler icl:

config/nim.cfg

+33-3
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,7 @@ vcc.linkerexe = "vccexe.exe"
271271
vcc.cpp.linkerexe = "vccexe.exe"
272272

273273
vcc.options.always = "/nologo"
274-
vcc.cpp.options.always = "/EHsc"
275-
vcc.options.linker = "/nologo /F33554432" # set the stack size to 32 MiB
276-
vcc.cpp.options.linker = "/nologo /F33554432"
274+
vcc.cpp.options.always = "/nologo /EHsc"
277275
vcc.options.debug = "/Zi /FS /Od"
278276
vcc.cpp.options.debug = "/Zi /FS /Od"
279277
vcc.options.speed = "/O2"
@@ -317,3 +315,35 @@ tcc.options.always = "-w"
317315
--define:nimOldCaseObjects
318316
--define:nimOldShiftRight
319317
@end
318+
319+
@if lto or lto_incremental:
320+
@if lto_incremental:
321+
vcc.options.always%= "${vcc.options.always} /GL /Gw /Gy"
322+
vcc.cpp.options.always%= "${vcc.cpp.options.always} /GL /Gw /Gy"
323+
vcc.options.linker %= "${vcc.options.linker} /LTCG:incremental"
324+
vcc.cpp.options.linker %= "${vcc.cpp.options.linker} /LTCG:incremental"
325+
@else:
326+
vcc.options.always%= "${vcc.options.always} /GL"
327+
vcc.cpp.options.always%= "${vcc.cpp.options.always} /GL"
328+
vcc.options.linker %= "${vcc.options.linker} /LTCG"
329+
vcc.cpp.options.linker %= "${vcc.cpp.options.linker} /LTCG"
330+
@end
331+
clang_cl.options.always%= "${clang_cl.options.always} -flto"
332+
clang_cl.cpp.options.always%= "${clang.cpp.options.always} -flto"
333+
clang.options.always%= "${clang.options.always} -flto"
334+
clang.cpp.options.always%= "${clang.cpp.options.always} -flto"
335+
icl.options.always %= "${icl.options.always} /Qipo"
336+
icl.cpp.options.always %= "${icl.cpp.options.always} /Qipo"
337+
gcc.options.always %= "${gcc.options.always} -flto"
338+
gcc.cpp.options.always %= "${gcc.cpp.options.always} -flto"
339+
clang.options.linker %= "${clang.options.linker} -fuse-ld=lld -flto"
340+
clang.cpp.options.linker %= "${clang.cpp.options.linker} -fuse-ld=lld -flto"
341+
gcc.options.linker %= "${gcc.options.linker} -flto"
342+
gcc.cpp.options.linker %= "${gcc.cpp.options.linker} -flto"
343+
@end
344+
@if strip:
345+
gcc.options.linker %= "${gcc.options.linker} -s"
346+
gcc.cpp.options.linker %= "${gcc.cpp.options.linker} -s"
347+
clang.options.linker %= "${clang.options.linker} -s"
348+
clang.cpp.options.linker %= "${clang.cpp.options.linker} -s"
349+
@end

0 commit comments

Comments
 (0)