-
Notifications
You must be signed in to change notification settings - Fork 46
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
Make failed with clang built kernel 6.4.0 #67
Comments
The intent was to help avoid stack overflows in cases where some of our call stacks may go many layers deep. (I believe the kernel stack sizes have increased since we introduced the check, but they’re still not huge and having such a sanity check isn’t the worst thing.) There’s no magic number that’s going to make the code right or wrong; the 400 byte limit is pretty arbitrary, but helped us catch some of the biggest offenders. Any cases of functions with large local allocations get reviewed to see if static or heap storage would work well. I wasn’t aware of the difference in how clang evaluates the frame size for the warning. Thank you for that analysis. We do builds against clang in our automated testing but most of our development uses gcc. Hmm... actually it looks like our only clang builds use kernel snapshots, our latest working snapshot is from a week ago. Also, we’re using the clang compiler distributed with Fedora 37, so if that’s out of date, a newer one might do its stack allocations or its frame size calculations differently. Yes, I think it would make sense to consider different limits based on the compiler, in light of their different calculations. I haven’t checked but I think it should be easy to do in the makefile. However, it may also make sense to re-examine the function(s) where the warning has come up, too. Where were you getting this warning? |
Sorry for the late reply. I'll post the log when this problem occurrs on AArch64(I don't have a x86 evironment to try on).
I guess the stack space in these places is mainly occupied by struct split_config.
Another question of confusion is that I found the clang version of Fedora 37 is 15.0.7(the same version as I'm using). Looks like I need to find out what's the difference between the version I'm using and the version on fedora 37 that causes the stack size to be larger at compile time. |
As for the difference between how gcc and llvm stack sizes are calculated, I wrote a small example to analyze (On AArch64, with clang15&gcc12).
In the preceding code, the stack frame size calculated by gcc is 688 (struct) + 8 (char*) + 8 (16-byte alignment) = 704. The size of clang calculation is 8 (stack pointer) + 16 (fixed 16 word offset) + 688 + 100 (alloca space) + 8 + 4 (return value) + 8 (16-byte alignment) = 832. The range of clang calculation is more comprehensive. So the result is larger and closer to the actual stack size used. |
Yes, split_config looks like the worst culprit there, though if clang is expanding the compute_volume_index_save_bytes005 calls inline, its automatic storage will contribute as well. Packing those structures better could help, but I think raising the limit in the clang case is pretty reasonable. Maybe by a small fixed amount to account for fixed differences in the calculations? I don’t think alloca would be used in our code anywhere so that can be ignored... |
Make failed when installing with DKMS in a clang built kernel 6.4.0 environment. A "warning: stack frame size (420) exceeds limit (400) in 'func' [-Wframe-larger-than][-Werror] " occorred.
The root cause is clang spent more than 400bytes of stack frame, which triggered
-Werror, -Wframe-larger-than=400
and failed. I checked both source code and found that gcc will only calculates the size of temporary variables in the code as the stack frame size. In contrast, clang calculates more objects such as stack pointer offsets, stack space allocated by alloc() func. So clang gets larger and more accurate results.I don't understand the reason behind this 400bytes restriction, but since clang outputs a larger stack frame with the same code, is it reasonable to make a separate stack frame size limite for clang built kernel?
The text was updated successfully, but these errors were encountered: