Page 1 of 1

newlib vs glibc

Posted: Sat May 05, 2018 9:18 am
by michprev
Hi,
I noticed that memset function is being resolved even when I do not link against libraries in newlib component (https://github.com/espressif/esp-idf/tr ... nts/newlib). Even with "-nostdlib" option it is linking against libs located in toolchain (xtensa-esp32-elf/xtensa-esp32-elf/lib/esp32-psram/).

Which libraries should we use and why?

Re: newlib vs glibc

Posted: Sat May 05, 2018 11:54 am
by ESP_igrr
The library in the toolchain is also newlib, not glibc. It's linking memset probably because of memset = 0x400xxxxx in the ROM LD script.

Re: newlib vs glibc

Posted: Sat May 05, 2018 12:26 pm
by michprev
Which version should we use then / what is the difference? libc.a in toolchain takes 5.0 MB, in ESP-IDF 5.7 MB (both SPIRAM compatible versions)

memset is provided in esp32.rom.spiram_incompatible_fns.ld script but I am not using this script.

With "-nostdlib -mlongcalls -mfix-esp32-psram-cache-issue -g -Og -ggdb -Wall -Werror -Wl,--cref,-Map,bootloader.map -lc" memset is linked against toolchain libc.

With "-nostdlib -mlongcalls -mfix-esp32-psram-cache-issue -g -Og -ggdb -Wall -Werror -Wl,--cref,-Map,bootloader.map -L idf/components/newlib/lib -lc" memset is linked against ESP-IDF libc.

Re: newlib vs glibc

Posted: Sun May 06, 2018 2:45 pm
by ESP_igrr
michprev wrote:Which version should we use then / what is the difference? libc.a in toolchain takes 5.0 MB, in ESP-IDF 5.7 MB (both SPIRAM compatible versions)
There were a few changes done to the newlib version included into ESP-IDF, which were not propagated to newlib packaged with the toolchain.

For the most part, changes have to do with adding some functions which were not included, and removing some other functions which were included. You can see the list on this page:
https://github.com/espressif/esp-idf/co ... newlib/lib

We're doing some cleanup to the way we build GCC and newlib, this will introduce cleaner and more consistent results. All newlib and GCC patches will be published in Github repositories, and crosstool-NG will be configured to pull newlib and GCC from these repositories. IDF will have an option of building newlib from source.
michprev wrote: memset is provided in esp32.rom.spiram_incompatible_fns.ld script but I am not using this script.

With "-nostdlib -mlongcalls -mfix-esp32-psram-cache-issue -g -Og -ggdb -Wall -Werror -Wl,--cref,-Map,bootloader.map -lc" memset is linked against toolchain libc.
This makes sense. "-nostdlib" tells the linker to empty the implict list of linked libraries, but "-lc" later tells it to link against libc.a, which it finds, since no other paths are provided, in the toolchain directory.
michprev wrote: With "-nostdlib -mlongcalls -mfix-esp32-psram-cache-issue -g -Og -ggdb -Wall -Werror -Wl,--cref,-Map,bootloader.map -L idf/components/newlib/lib -lc" memset is linked against ESP-IDF libc.
This makes sense in the same way as above, except now you supply a new search path for libraries, so libc.a gets found there.

Re: newlib vs glibc

Posted: Sun May 06, 2018 2:52 pm
by michprev
Perfect! Thank you very much.