-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Support LLVM 3.9 #3439
Support LLVM 3.9 #3439
Conversation
end | ||
{% if LibLLVM::IS_35 || LibLLVM::IS_36 %} | ||
def add_target_data(target_data) | ||
puts "LLVMAddTargetData" |
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.
debug leftovers? btw, there's another one in module_pass_manager.cr
.
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.
Good catch. I just removed them.
b364a52
to
00dcbcc
Compare
Are the default data layouts of llvm <= 3.8 the same as the custom data layouts we used to have? I am not sure if they weren't used because we didn't know about them or if there were some issues with them. |
The custom data layout were added in 5666375 which states « "Set llvm module data layout. Apparently this helps llvm do more optimizations". We still set the data layout on the module, so LLVM should optimize out, but instead of harcoding them, we let LLVM create the best one for the target triple (not just the arch). I compiled Crystal in release mode and ran specs for each LLVM version on Linux64 and they passed. But I have some segfaults when running the compiler specs against LLVM 3.9 😢 |
The segfault always come down to the following backtrace (gdb).
If I copy paste the compiler samples from crashing specs, to run them directly with Some crashing specs I identified (there are more):
|
00dcbcc
to
e874df8
Compare
@ysbaddaden SWEET!! When you say "Breaking changes", do you mean compiling against LLVM < 3.9 will stop working? At least travis seems happy... did you maybe mean there are some breaking changes in LLVM that you needed to handle, but no breaking changes will happen in Crystal? I'm just a bit worried about that because we are still using LLVM 3.6 for the official releases, and merging this might prevent us from releasing until we upgrade our omnibus build to LLVM 3.9. |
@asterite don't worry, I merely listed the breaking changes introduced by LLVM 3.9 that were fixed. LLVM 3.5, 3.6 and 3.8 are still supported and working (it compiles and specs are passing). This PR only fixes compilation against 3.9, and can be merged already. Thought some other changes in LLVM 3.9 introduced bugs (see pull request description), so a Crystal binary against LLVM 3.9, despite working, isn't release-grade, yet. |
I pushed the fix for |
f844466
to
b69dcad
Compare
b69dcad
to
79661c9
Compare
I pushed a second fix for Now I can build
|
79661c9
to
67024f3
Compare
- LLVMGetTargetMachineDatawas replaced with LLVMCreateTargetDataLayout. - LLVMSetDataLayout was replaced by LLVMSetModuleDataLayout. This patch drops the custom data layouts. We now use the ones provided by LLVM that match the target triple.
67024f3
to
472530f
Compare
…e unit) In LLVM 3.9 DISubprogram references the DICompileUnit directly, we thus need to generate the DICompileUnit before we generate LLVM IR code for the rest of the module (not after), otherwise the DISubprogram ends up with no DICompileUnit and LLVM fails to compile. This patch also enables DWARF versions above v2 for platforms that do support these versions (i.e. everything but OS X and Android). It also defines the "Debug Info Version" that matches the LLVM release.
Some syntax sugar expansions didn't set the location for some generated `Crystal::Call` nodes, which is rejected by LLVM 3.9 when the parent definition has a `!dbg` location itself.
472530f
to
e573772
Compare
@ysbaddaden @asterite just a heads up that in Homebrew I've now upgraded the llvm formula to 3.9 and alongside that shipped crystal-lang with this PR applied as a patch. So a new release tag with this PR or equivalent merged would be much appreciated as soon as possible so that we can get rid of the patching and distribute an unaltered upstream release once again. |
@ilovezfs Thank you! But why can't Crystal still depend on the |
Dependencies on anything in homebrew/versions are not allowed in homebrew/core. |
This is harsh. Each new minor LLVM is tricky or plain hard to upgrade to. It would be fantastic to have a few LLVM releases in The patch proposed here is working but barely tested. The segfault in the compiler spec is worrisome (at best), and leads to the impossibility to hack the compiler with LLVM 3.9 for the time being... |
Can you not build crystal-lang with Xcode 8 alone? |
I'm getting this when compiling against LLVM 3.9 on Mac:
Nothing to worry about because I can still use an older LLVM, and it's probably something simple to fix because it worked for homebrew. @ysbaddaden Any idea? |
Ah, ignore the above, I had |
@asterite @ysbaddaden Homebrew/homebrew-core#6139 I've moved the patch into a stable-do block since it's no longer applicable to HEAD of master now that it's been merged here. |
This seems to fix an issue with unwind stopping to work well after using a JIT without disposing it. See #3439
@ysbaddaden I just pushed a fix to the crashing-specs problem. Could you test that it works for you too? :-) I'm not 100% sure about the fix but it works, though I'm 99% sure it has something to do with LLVM's MCJIT. At least in the past it brought us some issues, and that's one of the reasons why we don't use it for specs that use exceptions, so maybe there are still some bugs in it (on LLVM's side). |
@asterite works for me! thanks! Argh, I just got one more |
@ysbaddaden What is this error? Can we maybe skip debug info for calls that don't have a location, or is this required in LLVM 3.9? I found this error is raised for |
@ysbaddaden I'll commit a fix for this soon, seems that using a type's location fixes it. There are a couple more calls that the codegen generates without a Call node, |
@ysbaddaden Try now ;-) |
@asterite thanks, it passes! |
I saw @ysbaddaden's request for people to test. Tested head crystal with llvm 3.9 on crystal-pg specs and everything seems good. |
Thanks for testing. Overall is seems good. Maybe |
Breaking changes (introduced by LLVM 3.9):
LLVMCreateTargetDataLayout
).Also:
llvm-config
to use withmake LLVM_CONFIG=llvm-config-3.6
to select a specific LLVM version among the many that are installed.Errors:
#crashing compiler specs (not reproducible when run directly)
JIT messed with the unwind table. See 7517056.
--debug
fails withModule validation failed: subprogram definitions must have a compile unit
We used to generate the DICompileUnit after generating the IR code, but LLVM reverses the DICompileUnit and DISubprogram relationships. It now refers to the CU from the SP. We thus have to genrate the CU as soon as possible (i.e. immediately after instanciating the DIBuilder).
--debug
fail withinlinable function call in a function with debug info must have a !dbg location
closes #3237