-
Notifications
You must be signed in to change notification settings - Fork 13.3k
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
Use libc from newlib #1752
Use libc from newlib #1752
Conversation
Output to stdout is not properly redirected to Serial yet. |
Note: might make sense to switch to newlib 2.2.0 from @projectgus |
Any progress on this? Would be a huge help with getting some things working. I still seem to be missing _putc_r definitions. I tried including lib_a-putc.o and lib_a.putc_u.o but this caused a previously working code to crash. Still investigating why. |
@benjamind Last time i checked, this was working in my tests. I'm ready to merge once this change has received enough testing. |
I'm attempting to compile Cesanta v7 Javascript engine (https://www.cesanta.com/developer/v7) into a sketch with a bunch of other wifi code, I'm trying to work up the simplest test case now. |
There's a little example of trying to compile v7 with Arduino here Arduinov7.zip In order to get this to compile I had to add the lib_a-putc.o and lib_a-putc_u.o symbols back (they're commented out in the make_libcmin.sh above). This gave me _putc_r implementation, but I think the heap management might be off since its crashing in a umm_malloc call. Something related to the heap changes above? Is there another hook I need to make for _putc_r to function correctly? Only deviation in the v7 here from the official source on github is that I set the following defines in the v7.h. The CS_PLATFORM declares the esp8266_lwip build of v7, and I've disabled STDIO and LIBC usage, while giving it the minimum build profile. I also had to declare _exit since this also seemed to be undefined. #define CS_PLATFORM 3
#define CS_DISABLE_STDIO
#define V7_BUILD_PROFILE 1
#define NO_LIBC
void _exit(int status) {
printf("_exit(%d)\n", status);
abort();
} Here's the stack trace for the crash:
Here's the output from the ESP exception parser:
|
I don't think this crash is related to putc. Looks like a null pointer dereference. Looking at v7 code, I'm not sure this will work out of the box. For instance, cesanta uses a different linker script. |
Sure I can open another issue. The missing _putc_r definition should probably be addressed in this ticket
|
Size difference report for these changes:
Need to investigate where do 2-3k RAM consumption comes from. |
After trying this branch it seems that
|
@proppy which code triggers this issue? |
@igrr https://github.com/munificent/wren, I'll try to nail down where their codebase trigger the call. |
Ah, okay, that's pretty easy then. |
Thanks for digging! @igrr I could also open an issue on their end so that they make the |
IMO usage of wall-clock time (or "absolute" time, the one which gettimeofday returns) does make sense on a microcontroller. |
Excuse my ignorance, but does the ESP has the way to get epoch time without dedicated RTC hardware or talking to a NTP service?
Isn't that just == uptime "time since power on" (since the only "process" is the OS+its tasks)? I assumed RTOS was already tracking that. |
NTP is certainly an option on the ESP, and built-in time functions will actually return correct values if you initialize NTP by calling |
Forgot to post the updated size difference report. It's getting better.
Personally I think +8k flash and +0.5k ram is not a showstopper, since we are adding floating-point format support. Thoughts? |
Current coverage is 27.61%@@ master #1752 diff @@
==========================================
Files 20 20
Lines 3686 3686
Methods 337 337
Messages 0 0
Branches 678 678
==========================================
Hits 1018 1018
Misses 2490 2490
Partials 178 178
|
This change adds libcmin.a, which is created from newlib libc by selectively removing some of the object files (mostly related to heap management). The list of files is available in tools/sdk/lib/make_libcmin.sh. Files which are not needed are commented out. This change adds support for various functions which were missing, like sscanf, strftime, etc.
Built from https://github.com/igrr/newlib-xtensa using: ./configure --with-newlib --enable-multilib --disable-newlib-io-c99-formats --enable-newlib-supplied-syscalls --enable-target-optspace --program-transform-name="s&^&xtensa-lx106-elf-&" --disable-option-checking --with-target-subdir=xtensa-lx106-elf --target=xtensa-lx106-elf --enable-newlib-nano-formatted-io --enable-newlib-reent-small --prefix=path-to-arduino-core/tools/sdk/libc CROSS_CFLAGS="-DMALLOC_PROVIDED -DSIGNAL_PROVIDED -DABORT_PROVIDED" make make install
This pull request attempts to replace all the libc replacements we had in our project with... newlib libc.
We add libc_orig.a, which comes from OS X-built toolchain, and use it to generate libcmin.a.
New shell script (tools/sdk/lib/make_libcmin.sh) has a list of all objects from libcmin.a which should be added. The ones which are to be removed are commented out. This makes it quite easy to add/remove object files as we find cases when newlib implementations do not fit the bill.
All heap management functions are removed, and hooks are added so that newlib functions use global umm_malloc instead. There is no real reentrancy support anyway.
Benefits of this change include support for
sscanf
,strftime
, and other functions which were missing.Potentially we can make fopen/fclose functions hook into SPIFFS, so that plain C libraries can run on ESP8266 with access to file system.