Skip to content

Add real ThinLTO mode #3489

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: dev
Choose a base branch
from
Draft

Add real ThinLTO mode #3489

wants to merge 3 commits into from

Conversation

aykevl
Copy link
Member

@aykevl aykevl commented Feb 26, 2023

We use ThinLTO for linking, but we use it in a way that doesn't give most of its benefits: we merge all the bitcode files into a single LLVM module and run some optimizations on it before linking. Therefore, this works more like a traditional "full" LTO link rather than a true thin link.

This PR adds a new experimental -lto=thin option to do a true ThinLTO link. The main benefit is that linking will be a lot faster especially for large programs consisting of many packages.

At the moment, it only works for programs that don't do interface type asserts and don't call interface methods. It also probably won't work on WebAssembly and baremetal systems. But it's part of a larger goal towards a truly incremental build system: #2870
Once interface type asserts and method calls are converted to a vtable-like implementation, most programs should just work on linux/darwin/windows.

@aykevl aykevl force-pushed the builder-real-thinlto branch 2 times, most recently from c3a5e87 to 0a531e2 Compare February 26, 2023 22:17

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
Create it in a separate LLVM module that is then linked. This refactor
is useful for the -lto=thin build mode.

I checked the binary size difference and while the machine code of most
binaries did change, there was no change in binary size (except for one
smoke test with -opt=1, which doesn't really count).
I found that with `-lto=thin` and by setting the llvm.ident metadata,
source level debugging finally works on MacOS!
The downside is of course that it requires `-lto=thin`, which is barely
supported.
We use ThinLTO for linking, but we use it in a way that doesn't give
most of its benefits: we merge all the bitcode files into a single LLVM
module and run some optimizations on it before linking. Therefore, this
works more like a traditional "full" LTO link rather than a true thin
link.

This commit adds a new experimental -lto=thin option to do a true
ThinLTO link. The main benefit is that linking will be a lot faster,
especially for large programs consisting of many packages.

At the moment, it only works for programs that don't do interface type
asserts and don't call interface methods. It also probably won't work on
WebAssembly and baremetal systems. But it's part of a larger goal
towards a truly incremental build system:
#2870
Once interface type asserts and method calls are converted to a
vtable-like implementation, most programs should just work on
linux/darwin/windows.
@aykevl aykevl force-pushed the builder-real-thinlto branch from 0a531e2 to 2de0635 Compare February 26, 2023 22:49
@aykevl
Copy link
Member Author

aykevl commented Feb 26, 2023

@dgryski this also includes a small patch that finally enables source-level debugging on MacOS:

Screenshot 2023-02-26 at 23 58 52

(This only works with -lto=thin, so it's not very useful yet).

@deadprogram
Copy link
Member

Seems like some actual build problems on this @aykevl please take a look.

@aykevl
Copy link
Member Author

aykevl commented Feb 28, 2023

@deadprogram yeah I saw it. Frustratingly, I can't reproduce the MacOS issue locally. To fix both issues (Windows and MacOS), I think I need to do the interface refactor first.

@aykevl aykevl marked this pull request as draft April 27, 2023 00:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants