Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit implements LTO for rust leveraging LLVM's passes. What this means is: * When compiling an rlib, in addition to insdering foo.o into the archive, also insert foo.bc (the LLVM bytecode) of the optimized module. * When the compiler detects the -Z lto option, it will attempt to perform LTO on a staticlib or binary output. The compiler will emit an error if a dylib or rlib output is being generated. * The actual act of performing LTO is as follows: 1. Force all upstream libraries to have an rlib version available. 2. Load the bytecode of each upstream library from the rlib. 3. Link all this bytecode into the current LLVM module (just using llvm apis) 4. Run an internalization pass which internalizes all symbols except those found reachable for the local crate of compilation. 5. Run the LLVM LTO pass manager over this entire module 6a. If assembling an archive, then add all upstream rlibs into the output archive. This ignores all of the object/bitcode/metadata files rust generated and placed inside the rlibs. 6b. If linking a binary, create copies of all upstream rlibs, remove the rust-generated object-file, and then link everything as usual. As I have explained in #10741, this process is excruciatingly slow, so this is *not* turned on by default, and it is also why I have decided to hide it behind a -Z flag for now. The good news is that the binary sizes are about as small as they can be as a result of LTO, so it's definitely working. Closes #10741 Closes #10740
- Loading branch information
fce4a17
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
saw approval from pcwalton
at alexcrichton@fce4a17
fce4a17
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
merging alexcrichton/rust/lto = fce4a17 into auto
fce4a17
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alexcrichton/rust/lto = fce4a17 merged ok, testing candidate = 29ca435
fce4a17
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all tests pass:
success: http://buildbot.rust-lang.org/builders/auto-mac-32-opt/builds/2872
success: http://buildbot.rust-lang.org/builders/auto-mac-32-nopt-c/builds/717
success: http://buildbot.rust-lang.org/builders/auto-mac-32-nopt-t/builds/717
success: http://buildbot.rust-lang.org/builders/auto-mac-64-opt/builds/2876
success: http://buildbot.rust-lang.org/builders/auto-mac-64-nopt-c/builds/1982
success: http://buildbot.rust-lang.org/builders/auto-mac-64-nopt-t/builds/1981
success: http://buildbot.rust-lang.org/builders/auto-linux-32-opt/builds/2888
success: http://buildbot.rust-lang.org/builders/auto-linux-32-nopt-c/builds/1980
success: http://buildbot.rust-lang.org/builders/auto-linux-32-nopt-t/builds/1981
success: http://buildbot.rust-lang.org/builders/auto-linux-64-opt/builds/2890
success: http://buildbot.rust-lang.org/builders/auto-linux-64-nopt-c/builds/1980
success: http://buildbot.rust-lang.org/builders/auto-linux-64-nopt-t/builds/1980
success: http://buildbot.rust-lang.org/builders/auto-linux-64-x-android/builds/2056
success: http://buildbot.rust-lang.org/builders/auto-win-32-opt/builds/2877
success: http://buildbot.rust-lang.org/builders/auto-win-32-nopt-c/builds/1981
success: http://buildbot.rust-lang.org/builders/auto-win-32-nopt-t/builds/1983
success: http://buildbot.rust-lang.org/builders/auto-bsd-64-opt/builds/2652
fce4a17
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fast-forwarding master to auto = 29ca435