Skip to content
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

Adding the -mgeneral-regs-only flag breaks variadic functions #383

Open
fdischner opened this issue Jul 11, 2023 · 0 comments
Open

Adding the -mgeneral-regs-only flag breaks variadic functions #383

fdischner opened this issue Jul 11, 2023 · 0 comments

Comments

@fdischner
Copy link
Contributor

This issue was observed with the printf function, but seems to affect all variadic functions. The printf() function is in lib/libc/stdio.c, which is currently compiled with -mgeneral-regs-only on x86 and arm64 targets. The _printf_engine() function, however, is in lib/libc/printf.c, which does use floating point and is compiled without the -mgeneral-regs-only flag.

The issue is that, when compiling with -mgeneral-regs-only, the compiler assumes the variadic arguments cannot be float or double and so does not emit the necessary assembly to move arguments from floating point registers into the va_list that is passed to vfprintf(). However, if another source is compiled without this flag and calls printf(), then the compiler will pass float/double arguments in floating point registers, because it's unaware that printf() was compiled without this support. Thus, everything compiles and links without warnings or errors, but printing floating point values does not work.

Note that things get even worse when compiling with clang. Clang will happily compile floating point code with -mgeneral-regs-only without any warnings, but will convert it to a soft-float ABI. This seems to be a bug in clang (see https://reviews.llvm.org/D38479 and llvm/llvm-project#30140), but there is no progress on a fix.

Would it maybe make sense to reverse the logic of when to apply -mgeneral-regs-only? So all sources would be compiled without the flag by default and then the flag would be applied only to those core kernel sources (and dependencies), which must not use floating point (and are known not to).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant