-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Fixes #26449 #26749
Fixes #26449 #26749
Conversation
This allows to compile libcore on architectures that lack floating point support or to use libcore in kernel code without worrying about saving and restoring the floating point register state inside the kernel.
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @huonw (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. The way Github handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
cc @rust-lang/libs, how do we want to handle this? |
0_o computers are crazy This feels like an RFC is needed, unless it lands behind a -Z flag. Also seems like more of a tools (compiler interface) issue assuming you accept that this is at all a desirable thing to do. |
I would argue the change falls under: But if you decide that it needs an RFC I can write one. Let me know. |
Just to add to @gz's comment - This should only have an affect when libcore is being compiled manually, not when it's being used by general users. This means that it shouldn't need a -Z flag |
I feel like this isn't quite the way we'd want to approach this. We generally have a fairly bad track record for sprinkling |
For solving it in the compiler: compiling libcore without SSE registers works on the nightly before #26025 happened -- so there may indeed be some LLVM changes that caused this strict requirement. |
@alexcrichton The ideal solution would be to get --soft-float working once more, but it appears that LLVM was what broke this. Either that, or have a way to tell LLVM to not use SSE etc for anything except explicit floating-point operations. What sort of compiler-provided solution would work for disabling floating point support, without causing compile errors? |
@gz is this just a bug that needs to be fixed in upstream LLVM then? @thepowersgang what is
I don't understand how floating point support is connected to the SSE errors that have been reported in #26449, so I fear that this may be going a bit far down the rabbit hole. |
@alexcrichton Sorry, it's From what I have been told, the x86_64 ELF ABI requires that floating-point arguments be passed in SSE registers, which is why floating point support requires SSE to be enabled. I assume that until recently |
Perhaps the solution is then to dig around in LLVM rather than adding a compile mode to libcore? |
☔ The latest upstream changes (presumably #26981) made this pull request unmergeable. Please resolve the merge conflicts. |
@alexcrichton should we close this? |
Yeah I think that we may want to end up tackling this a different way, perhaps only stabilizing a large portion of the functionality in the standard library instead of libcore, or perhaps allowing libcore to be recompiled in an easier fashion. |
@alexcrichton, would you reconsider patching libcore to allow disabling float support? This is adding a lot of manual steps to thepowersgang's barebones kernel build, requiring getting, patching (usually merging by hand), and rebuilding a modified libcore w/ every Rust update. It seems to me that float support in libcore is a good idea in the general case. Given the correct initialization, it can be done in a freestanding environment, so it makes sense to include it. But, at the same time, there are use cases that don't want to do that initialization. Given it would require breaking the ABI (specifically, the calling convention) in LLVM and, that by all normal standards, SSE support is guaranteed on amd64, I doubt we'll see a fix from LLVM. (Nonetheless, I've posted to their development list to get their thoughts on it.)
In the method Test case (
(With and without
cc @gankro |
I'm uh... Not really sure why I was pinged on this. I agree that llvm is a jerk who makes our lives hard? |
@gankro, sorry. I assumed you were the libs guy, I guess. :P Not familiar enough with the project who would be best to contact. |
Unfortunately I don't think I understand the problem space here enough to be able to say one way or another what the best way forward is. I have personally built kernels in Rust in the past and they've all run just fine, I've never run into these kinds of floating point problems, so I don't know what this is precisely targeting. Regardless, though, I'm not a huge fan of sprinkling around |
@alexcrichton While you can definitely build a kernel that makes use of SSE registers, it is usually not desirable to do so, as you want to minimize the number of registers saved on context switches as much as possible. Especially with wide registers (such as SSE) because they may have higher access latencies than general purpose register. Also note that just disabling SSE in the build and not using float/double is not good enough since llvm usually tries to make good use of those registers to optimize other stuff in libcore. There was a point in time where LLVM was able to compile libcore without SSE and floating point support. There is currently an open bug for LLVM that seems to target the same issue (for C++), so it may be better to wait and see how this gets resolved: https://llvm.org/bugs/show_bug.cgi?id=23203 |
@gz, I think the fact that both gcc and llvm have the same "SSE return while SSE disabled" error suggests that the change that caused this was a bug fix rather than a removal of functionality. It used to result in a miscompilation, including SSE when SSE is disabled, which (as of the bug fix) they catch and throw an error. If I get some time this weekend I'll try building libcore <1.2 with SSE disabled and check the disassembly for SSE instructions. (This was the point of the GGC/LLVM section in my last post, but I forgot to get around to making it explicit. Sorry if you already got it and I'm just being overly verbose now.) |
@Tyler-Hardin I see. In case it helps with your research, the nightly before #26025 was the last version known to work. (See also #26449) |
@gz Well, this was unexpected (for me, at least), but it did actually have working soft floats on amd64. I've modified an old version of @thepowersgang's barebones to do some floating point math, disassembled it, and verified that is had call to So, the above would make it sound like an LLVM regression. But, I used |
Allows for compilation of libcore without floating point support.