newlib vs glibc

michprev
Posts: 92
Joined: Fri Aug 04, 2017 8:57 pm

newlib vs glibc

Postby michprev » Sat May 05, 2018 9:18 am

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?

ESP_igrr
Posts: 2071
Joined: Tue Dec 01, 2015 8:37 am

Re: newlib vs glibc

Postby ESP_igrr » Sat May 05, 2018 11:54 am

The library in the toolchain is also newlib, not glibc. It's linking memset probably because of memset = 0x400xxxxx in the ROM LD script.

michprev
Posts: 92
Joined: Fri Aug 04, 2017 8:57 pm

Re: newlib vs glibc

Postby michprev » Sat May 05, 2018 12:26 pm

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.

ESP_igrr
Posts: 2071
Joined: Tue Dec 01, 2015 8:37 am

Re: newlib vs glibc

Postby ESP_igrr » Sun May 06, 2018 2:45 pm

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.

michprev
Posts: 92
Joined: Fri Aug 04, 2017 8:57 pm

Re: newlib vs glibc

Postby michprev » Sun May 06, 2018 2:52 pm

Perfect! Thank you very much.

Who is online

Users browsing this forum: No registered users and 92 guests