Conversation
benpicco
left a comment
There was a problem hiding this comment.
Travis spotted two instances where tabs were used instead of spaces 😉
I tested this with examples/filesystem on weact-f411ce (so CDC ACM is used for stdio) and it works quite well.
Thank you for the contribution and creating picolibc 😃
4279290 to
76aae2b
Compare
Fixed! Would it be reasonable to add an 'EditorConfig' file to the source tree? |
Sounds like a good idea, I didn't know about that standard. |
benpicco
left a comment
There was a problem hiding this comment.
CI is happy now and the new code looks good, does pretty much what the newlibc code did for the most part.
With this and LTO we can get RIOT smaller than ever :)
| LINKFLAGS += -Wl,--defsym=__heap_end=_eheap | ||
| LINKFLAGS += -Wl,--defsym=__heap_start=_sheap |
There was a problem hiding this comment.
This will only work for one continuous region of memory.
Can we simply implement _sbrk_r ourself like we did for newlib to allow for multiple non-continuous memory regions?
(tests/malloc still works with this, but only the first memory region is used)
There was a problem hiding this comment.
Yes, you can. I've modified the smaller malloc implementation so that it should work with dis-continuous sbrk regions, but I have not tested that. The larger malloc implementation, and both versions in newlib have bugs in this area...
With this and LTO we can get RIOT smaller than ever :)
Would be fun to LTO the whole C library and see what that managed to do.
sys/Makefile.include
Outdated
| endif | ||
| endif | ||
|
|
||
| ifeq (,$(filter printf_float,$(USEMODULE))) |
There was a problem hiding this comment.
Both blocks could be factorized in a single one I think:
| ifeq (,$(filter printf_float,$(USEMODULE))) | |
| ifeq (,$(filter printf_float scanf_float,$(USEMODULE))) |
Since the CFLAGS is the same for both printf and scanf.
There was a problem hiding this comment.
This code wasn't working because there was code in makefiles/libc/picolibc.mk that was overriding it. I've removed the code from sys/Makefile.include and fixed the code in makefiles/libc/picolibc.mk to check USEMODULE instead of using a separate configuration variable.
|
Did you try on RISC-V ? Last time I tried #12305 on the sifive hifive1b it was not working. I can give this one another try tomorrow. |
picolibc: Use thread_getpid for getpid() in picolibc_syscalls_default
Instead of directly accessing the sched_active_pid variable (which
isn't defined in this context), use the existing wrapper function
to get that value.
Signed-off-by: Keith Packard <keithp@keithp.com>
---
v2:
Squash a couple of fixes in
* fixup! picolibc: Use thread_getpid for getpid() in
picolibc_syscalls_default
* squashme: Add `times` to picolibc syscalls
* Add __noreturn__ attribute to _exit
* Add VFS syscall wrappers. This provides the POSIX api used
by picolibc stdio
76aae2b to
faac559
Compare
Oops, somehow I missed a chunk of the riscv-v linker script. I've fixed that, run 'hello-world' on my hifive1-revb and pushed an updated PR. I've also added a call to stdio_init from cpu/fe310/cpu.c in the PICOLIBC case so that the uart gets initialized. I've tested 'hello-world' again and it still works (the previous test had hacked up hello-world to call stdio_init manually). |
Support for picolibc as alternative libc implementation is added with this commit. For now only cortex-m CPU's are supported. Enable via PICOLIBC=1 --- v2: squash fixes in v3: Remove picolibc integer printf/scanf stuff from sys/Makefile.include, it gets set in makefiles/libc/picolibc.mk fixup for dependency
Picolibc makes atexit state per-thread instead of global, so we can't register destructors with atexit in a non-thread context as we won't have any TLS space initialized. Signed-off-by: Keith Packard <keithp@keithp.com>
729714d to
64b04c3
Compare
I confirm this is now working, with 3.6kB less ROM used (from 8.6kB without picolibc to 5kB). |
|
Looks like CI is complaining about the commit message |
Disable the newlib-nano stubs code when picolibc is in use Signed-off-by: Keith Packard <keithp@keithp.com> --- v2: Squash fixes in v3: call stdio_init in _PICOLIBC_ mode to initialize uart v3: Remove call to stdio_init from nanostubs_init, always call from cpu_init.
Allocate and initialize a thread-local block for each thread at the top of the stack. Set the tls base when switching to a new thread. Add tdata/tbss linker instructions to cortex_m and risc-v scripts. Signed-off-by: Keith Packard <keithp@keithp.com> --- v2: Squash fixes v3: Replace tabs with spaces v4: Add tbss to fe310 linker script
--- v2: Squash fixes in
In most places, picolibc and newlib are the same, so use the existing newlib code when compiling with picolibc. Signed-off-by: Keith Packard <keithp@keithp.com>
This makes RIOT use the integer-only printf/scanf code by default and includes a new make parameter to select the full floating point version. This saves about 6kB of text space when building hello-world for the microbit board. Signed-off-by: Keith Packard <keithp@keithp.com> ---- v2: Use USEMODULE=printf_float instead of separate parameter
Add buffering so that USB back-ends get some batching for stdout Signed-off-by: Keith Packard <keithp@keithp.com> ---- v2: Replace tabs with spaces.
64b04c3 to
fda68c4
Compare
Oops. Adding [v2] went over the limit. Fixed now. |
|
And Murdock is happy - thanks a lot! |
|
Thanks @keith-packard! |
|
Hm sorry for the sloppy testing, when I now compile an application that uses This worked yesterday, but on a different machine. When I check out an old version of the |
picolibc doesn't provide or require this API for stdin/stdout/stderr, so I didn't leave it in the merge request. If you add the VFS layer, you'll get it, and it will rely on VFS operations. stdin/stdout/stderr will not be connected through that by default though; they'll still be connected to the console. Does the VFS layer reserve FDs 0-2 to avoid stepping on the usual FDs for stdin/stdout/stderr? If so, changing the VFS implementation for picolibc to redirect those through the console would make things work like newlib? |
No and it doesn't seem to consider fds to be anything other than indices to open files. |
I didn't test anything that used fmt. I think it would be reasonable to consider deprecating this code in favor of just using printf though; picolibc's printf is reasonably small, even if you want 'exact' floating point conversions ('exact' means you can print and then re-scan a string and get the same bits back).
If the underlying system offers a POSIX api, then using it directly will avoid linking in a bunch of stdio code, which saves space and is probably more efficient. For picolibc and avrlibc (which share stdio origins btw), the obvious fix seems like a good idea.
So the newlib POSIX apis may be conflicting with the VFS code? Would probably be good to sort that all out. |
This is the same code as on my pr/libc/picolibc-initial branch referenced in PR #12305 but with the patches squashed together to look a little cleaner.