-
Notifications
You must be signed in to change notification settings - Fork 236
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
GEP is actually unsafe #33
Comments
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. |
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 |
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:
The text was updated successfully, but these errors were encountered: