Open Redrield opened 6 years ago
Playing around more I found that it was just me not knowing how GEP works. Equivalent code using stuff from librustc_trans segfaults as well.
This is still a bug though... segfaults are not allowed to happen in safe rust. So maybe inkwell is missing some sanity checks?
Unfortunately, I've only scratched the surface of what LLVM has to offer but I've learned it will segfault for ANYTHING, which is why most methods do not return status codes I suppose. While I agree that Inkwell should indeed provide a completely safe wrapper around LLVM, it has to be known that this will be very hard, or maybe impossible in some cases.
Yep, I agree with @6A's assessment. There are some things due to LLVM's nature that will just be too difficult to wrap and should either remain unsafe or safe with a documentation note (ie if it's just a rare edge case). I will reopen the ticket so we can at least triage and research what are our reasonable options to deal with this issue
Thank you @nicokoch for bringing it up!
In the meantime, we could start writing down somewhere all those "gotchas". I'll start: building instructions in a builder when no block has been created in that function will most likely result in a segfault.
@6A if you can get a concrete example of this segfault, feel free to open a separate issue. I think that's the best way to track them. Maybe I will start using a "gotcha" or "LLVM gotcha" label to these type of bug issues
Revisited this today and I'm not sure what can be done here... Maybe if we can encode pointer lengths into the type system, it could be smart enough to validate indexes that are OOB using something like the typenum
crate or const generics might help. Going to push this until 0.2.0
since there's not much we can do about it at the moment.
Does anyone have an example of safely constructing a global string with inkwell? I'm still unsure what the 'safe' way to do it is (and some of these examples no longer compile due to changes in the AddressSpace struct/enum, so I'm unsure what I'm doing wrong and if I'm making things worse as I 'fix' things)
In an attempt to get around #32, I've been trying to get a program working that can call printf with a string array. Looking at working IR, I see that to convert from an array to a pointer, an inbounds GEP instruction is used. This is the code I came up with to replicate that.
At the line where
value
is bound, the program exits with a SIGSEGVEnvironment
Operating system: Arch Linux Kernel version: 4.15.3-1-ARCH LLVM version: 5.0.1-2 Inkwell version: 0.1.0#eafca272 rustc -vV output: