diff options
| author | Jesse Meyer <jesse.r.meyer@me.com> | 2026-02-01 09:04:53 -0500 |
|---|---|---|
| committer | Jesse Meyer <jesse.r.meyer@me.com> | 2026-02-03 20:16:20 -0500 |
| commit | 43ad4a1d9f18a89822e1b9f554adef1a228136db (patch) | |
| tree | ca7a569d1e5adc6fa3f1d7eb6c1a5fe36b175715 /src/build_settings.cpp | |
| parent | f7901cffc9f4983259586241d5b336cdb6377b9c (diff) | |
Add ThinLTO support via -lto:thin and -lto:thin-files flags
- Add -lto:thin and -lto:thin-files CLI flags with validation
- Emit LLVM bitcode (.bc) instead of object files when LTO is enabled
- Pass -flto=thin and -flto-jobs to clang/lld linkers
- Guard linkage corrections to skip declarations without definitions
(required for LTO where declarations appear across modules)
- Allow module-per-file with LTO even at higher optimization levels
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Diffstat (limited to 'src/build_settings.cpp')
| -rw-r--r-- | src/build_settings.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/build_settings.cpp b/src/build_settings.cpp index 6b8fefa59..e0017baea 100644 --- a/src/build_settings.cpp +++ b/src/build_settings.cpp @@ -420,6 +420,12 @@ struct BuildCacheData { }; +enum LTOKind : i32 { + LTO_None, + LTO_Thin, + LTO_Thin_Files, +}; + enum LinkerChoice : i32 { Linker_Invalid = -1, Linker_Default = 0, @@ -560,6 +566,7 @@ struct BuildContext { bool use_single_module; bool use_separate_modules; + LTOKind lto_kind; bool module_per_file; bool cached; BuildCacheData build_cache_data; @@ -2030,6 +2037,29 @@ gb_internal void init_build_context(TargetMetrics *cross_target, Subtarget subta bc->use_separate_modules = false; } + if (bc->lto_kind == LTO_Thin || bc->lto_kind == LTO_Thin_Files) { +#if LLVM_VERSION_MAJOR < 17 + gb_printf_err("-lto:thin requires LLVM 17 or later\n"); + gb_exit(1); +#endif + if (bc->build_mode == BuildMode_Assembly || bc->build_mode == BuildMode_LLVM_IR) { + gb_printf_err("-lto:thin is incompatible with -build-mode:asm and -build-mode:llvm-ir\n"); + gb_exit(1); + } +#if defined(GB_SYSTEM_WINDOWS) + if (bc->linker_choice != Linker_lld) { + gb_printf_err("-lto:thin on Windows requires -linker:lld\n"); + gb_exit(1); + } +#endif + if (bc->use_single_module) { + gb_printf_err("Warning: -lto:thin overrides -use-single-module; separate modules will be used\n"); + } + bc->use_separate_modules = true; + if (bc->lto_kind == LTO_Thin_Files) { + bc->module_per_file = true; + } + } bc->ODIN_VALGRIND_SUPPORT = false; if (build_context.metrics.os != TargetOs_windows) { |