-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
scanf() not functional with newlib out of the box #25599
Comments
I suspect this is an issue with |
NOTE: This problem is not specific to I set an initial value for |
So what is happening is that the newlib Try something like:
|
@pfalcon (and other console subsystem authors if any) I see that Was that a deliberate decision or an oversight by the backend driver authors? |
As for the @andrewboie Maybe we should consider increasing the default |
Removing This could potentially lead to an enhancement in which the p.s. If, for some reason, we must not install the |
See also #25479 for more fun. |
To answer this question, we would first need to answer following question: "Is it reasonable to expect scanf() to work out of the box in the default Zephyr configuration?" Whoever thinks yes, please raise your hands. I for example think "no", because in the default Zephyr configuration, it should produce "hello world" app in 512 code bytes max (already violated) and be able to run full BLE stack on chips with 128K ROM/16K RAM. And if it's unclear where I lead to, supporting scanf() out of the box means incur significant overheads, almost certainly to be paid by all users, even those not using stuff like scanf() (and that's 99.9+%). Actually, I don't think that anybody so far wanted to use scanf() on Zephyr at all, far less out of the box. So, no surprise it doesn't work out of the box. Summing up, there're 2 questions to address:
I personally would like to see POSIX subsys to be more integrated into Zephyr core (== more of stuff work out of the box), but that doesn't include scanf(), etc. And I'm not ready to lead on the transformation. FYI @cfriedt. What's clear that if doesn't work (OOB or at all), we shouldn't make users confused about that, and instead should fail fast. E.g. #25479 is a step in that direction: it's reasonable to call write() on a socket, but who'd know one needs to enable CONFIG_POSIX_API for that? Well, now users will know. (zephyrproject-rtos/sdk-ng#221 (comment) is even better solution, with the next SDK release, users may get a link error unless they did so (to be tested to work like that, testing help welcome)). cc @nashif, @andrewboie, @galak |
I can't really think of any sane usage of As for |
From my perspective, Maybe there should be a There may be a very niche use case where someone does not want to use "standard" io in the console sense. In that case, I would say that Normally, user code really shouldn't be calling any |
That's exactly what crossed my mind yesterday when looking through those Kconfig options. |
Note that the initiator of zephyr/drivers/console/uart_console.c Lines 583 to 587 in 2716cbc
This is not specific to newlib or any libc for that matter. I believe the original intention was to make this a libc type-independent stdin/stdout hook installation interface (which, for now, only newlib is using). Also note that there is In general, I think the console subsystem as whole needs major refactoring. |
I agree with @stephanosio that the way we handle console hooks needs to be rewritten, it's some very very old stuff from the Wind River days that pre-dates anyone's involvement who's currently on the project. Some attention here would be gratefully received for anyone who has time/inclination. I haven't looked at what it would take to fix this particular issue, but @pfalcon's question "How much (with what priority) we want to support scanf() and the like at all?" is relevant in that
the C library printf() and scanf() use tons of stack space. Not many tests use them, it might be better to just increase stack size of those particular tests, but I don't have a strong opinion about it. Is it just x86 that this falls over? |
@andrewboie I haven't done a comprehensive testing, but I didn't see any such failures on the ARM platforms while testing this. I do recall seeing the x86 QEMU seldom crashing due to similar stack size related issues, so I thought it would be nice to address this at some point. But given where this discussion is going, I think it is better to wait for now. |
I see regular regressions in stack usages, i.e. it constantly growing, and various sample around crash. I regularly submit patches to bump stack sizes, but follow a policy of doing minimal bumps (say, by 64 bytes), so we continue to catch regressions. On first few occasions I cc: @nashif and @andrewboie on these cases, but never get a response, so I assume nobody cares about stack growth (and thus constant slip in minimum requirements for Zephyr, it's clear that we're by now far from "Zephyr can run in 8K", no matter what those 8K refer to, RAM or ROM). I personally would find bumping default stack size from 1K to 2K unacceptable. But yes, that's pretty much what more and more sample require now. (And we talk about stack size, we don't even talk about 64-bit archs, which of course require 2x times more stack. If I was to do it right, I'd add option to automatically 2x stack sizes on such platforms. (Well, who knows, maybe it's already there.)) |
It's possible to conduct this discussion without using unnecessary hyperbole like this. Consider for a moment that both me and @nashif get hundreds, if not over a thousand github emails every day. If something you see is broken, file a bug on it. That includes minimum stack sizes. Be data-driven and constructive. |
@stephanosio Is this a deterministic failure or something that fails intermittently. |
@andrewboie The failures are deterministic; they occur mostly when I am adding random code for testing and/or playing with the configurations, which is to be expected (it seems x86 is either on the verge of stack overflow with the default configs, or just particularly stack hungry; though I haven't done an in depth analysis on this). If I keep seeing related failures in the future, I will file an issue/PR for it |
Thank you for your help. |
This issue has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this issue will automatically be closed in 14 days. Note, that you can always re-open a closed issue at any time. |
Describe the bug
I'm new to Zephyr and did a small test application.
I'm able to build the application but when I try to run the application I'm not able to enter an integer and I receive an error.
I receive the same error when I just add two floats without using scanf.
main.c
prj.conf looks like:
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Enter an Integer:
result: 3
scanned value: "entered integer"
Impact
annoyance, showstopper
Screenshots or console output
Booting from ROM..Optimal CONFIG_X86_MMU_PAGE_POOL_PAGES 7
*** Booting Zephyr OS build v2.3.0-rc1-82-gc8a30ecacc50 ***
Enter an Integer:
result: 3
scanned value: 583
FAILED: zephyr/CMakeFiles/run
cd /home/user/zephyrproject/zephyr/project/test/build && /home/user/Zephyr/zephyr-sdk-0.11.2/sysroots/x86_64-pokysdk-linux/usr/bin/qemu-system-i386 -m 9 -cpu qemu32,+nx,+pae -device isa-debug-exit,iobase=0xf4,iosize=0x04 -no-reboot -nographic -net none -pidfile qemu.pid -chardev stdio,id=con,mux=on -serial chardev:con -mon chardev=con,mode=readline -kernel /home/user/zephyrproject/zephyr/project/test/build/zephyr/zephyr.elf
ninja: build stopped: subcommand failed.
FATAL ERROR: command exited with status 1: /usr/bin/cmake --build /home/user/zephyrproject/zephyr/project/test/build --target run.
Environment (please complete the following information):
Additional context
Note that the samples hello world and synchonization worked just fine. And just adding 2 integer works as well. Not sure if I made a mistake somewhere or if Qemu hast problems with scanf and float.
The text was updated successfully, but these errors were encountered: