-
-
Notifications
You must be signed in to change notification settings - Fork 267
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
Ship with LTO default libs on Linux & macOS #2640
Conversation
Tested it now; it's principally working, but the C and asm parts of druntime/Phobos are missing in the bitcode libs. We don't have these object files explicitly, CMake takes care of compiling them, so that's blocking this LTO-libs-for-free scheme. |
Working now. A Phobos-hello-world can be linked against the normal libs as well as with both thin & full LTO against the ThinLTO bitcode libs (incl. C/ASM parts in machine code): void main()
{
import std.stdio;
writefln("Hello world, %d bits", cast(int) size_t.sizeof * 8);
}
|
ce67728
to
7036593
Compare
I'd prefer an |
.circleci/config.yml
Outdated
@@ -258,7 +270,7 @@ jobs: | |||
- LLVM_VERSION: 5.0.1 | |||
- HOST_LDC_VERSION: 1.6.0 | |||
- BOOTSTRAP_CMAKE_FLAGS: "-DCMAKE_CXX_FLAGS='-stdlib=libc++' -DCMAKE_EXE_LINKER_FLAGS=-lc++" | |||
- EXTRA_CMAKE_FLAGS: "-DMULTILIB=ON -DCMAKE_CXX_FLAGS='-stdlib=libc++' -DCMAKE_EXE_LINKER_FLAGS=-lc++" | |||
- EXTRA_CMAKE_FLAGS: "-DMULTILIB=ON -DBUILD_BC_LIBS=ON -DD_FLAGS='-w;-flto=thin' -DCMAKE_CXX_FLAGS='-stdlib=libc++' -DCMAKE_EXE_LINKER_FLAGS=-lc++" |
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.
Adding -flto
to D_FLAGS
also builds the normal libs with that option, right? But then how do the tests pass: how does linking succeed without specifying the LLVMgold plugin on the linker line for normal tests without LTO ?
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.
Adding -flto to D_FLAGS also builds the normal libs with that option, right?
In combination with BUILD_BC_LIBS=ON
, this yields a command line ldc2 -c -output-o -output-bc -flto=thin ...
; producing both the normal object file in machine code and the LTO bitcode file (-flto=thin
only affecting the module summaries in the bitcode files in this case). After this PR's first commit that is.
how does linking succeed without specifying the LLVMgold plugin
We use LDC to firstly compile the modules, one object (and bitcode file for BUILD_BC_LIBS) per druntime/Phobos module (and D_FLAGS
only affect compilation). We then archive them to static libs via separate LDC invokations - normal libs containing machine code only, and bitcode/LTO libs containing bitcode for the D parts and machine code for the C/ASM parts. The shared libs are obviously only generated for the normal machine-code objects.
So specifying -flto=...
for linking is only required when choosing the bitcode/LTO libs explicitly via -defaultlib=...
, which is only tested by the CircleCI integration test so far (Linux only; linker crashing on OSX for both thin and full LTO tests).
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.
This scheme allows the user to choose LTO for his code only via -flto=...
and LTO incl. default libs via -flto=... -defaultlib=...
.
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.
producing both the normal object file in machine code and the LTO bitcode file
OK got it.
This is pretty neat.
Me too. |
@JohanEngelen: Do you have any clues as to why both trivial LTO tests fail on Circle OSX ( |
Btw the CircleCI package sizes are increased by about 10%. |
I've seen the Need to find time to look at it closely again... |
Feasible by using LDC for archiving (via 'D' linker language), opening up the door for including C/ASM parts by source file (and another compilation of the few of them), as used for the normal druntime/Phobos libs. As LDC doesn't support .bc files as pure archiving/linking input directly (they are injected into the first compiled module/object, but if there is none, they are ignored), the .bc files need to be renamed to .bc.o files before creating the static libs. While at it, get rid of redundancies by extending set_common_library_properties().
LTO with debug libs probably isn't very useful.
Oh wow, the CircleCI macOS LTO integration tests now work with LLVM 6. :) |
There was an XCode update recently, perhaps related? |
I don't think so, we're using the XCode 9.0 CircleCI image. |
This allows additional bitcode libs to be generated simultaneously with the normal druntime/Phobos libs (i.e., single compilation) by including something like
-DBUILD_LTO_LIBS=ON -DD_FLAGS="-w;-flto=thin"
in the CMake command line (additional D_FLAGS entry here to include the ThinLTO module summaries in the bitcode files; not needed for FullLTO).This then allows linking against the LTO default libs via
ldc2 -flto=<thin|full> ... -defaultlib=phobos2-ldc-lto,druntime-ldc-lto
; unfortunately, I couldn't test this yet, as my LLVM 6 Linux build has a 0-byte LLVMgold.so...