Skip to content
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

libc-provided malloc and free need to be replaced by os_malloc and os_free #11

Closed
igrr opened this issue Mar 29, 2015 · 3 comments
Closed

Comments

@igrr
Copy link
Member

igrr commented Mar 29, 2015

References to malloc and other functions that use malloc (like sprintf) pull in _sbrk, which isn't available.
Need to tweak libc build so that it would use os_malloc and os_free instead.

@dmcinnes
Copy link

dmcinnes commented Apr 1, 2015

Running into the same issue here. Error output:

Arduino: 1.6.1 (Mac OS X), Board: "Generic ESP8266 board"

/Applications/Arduino-esp8266.app/Contents/Java/hardware/tools/esp8266/xtensa-lx106-elf/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/lib/libc.a(lib_a-mallocr.o):(.literal+0x1c): undefined reference to `_sbrk_r'
/Applications/Arduino-esp8266.app/Contents/Java/hardware/tools/esp8266/xtensa-lx106-elf/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/lib/libc.a(lib_a-mallocr.o): In function `malloc_extend_top':
mallocr.c:(.text+0x5e): undefined reference to `_sbrk_r'
mallocr.c:(.text+0x127): undefined reference to `_sbrk_r'
/Applications/Arduino-esp8266.app/Contents/Java/hardware/tools/esp8266/xtensa-lx106-elf/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/lib/libc.a(lib_a-freer.o): In function `_malloc_trim_r':
mallocr.c:(.text+0x366): undefined reference to `_sbrk_r'
mallocr.c:(.text+0x38f): undefined reference to `_sbrk_r'
/Applications/Arduino-esp8266.app/Contents/Java/hardware/tools/esp8266/xtensa-lx106-elf/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/lib/libc.a(lib_a-freer.o):mallocr.c:(.text+0x3a0): more undefined references to `_sbrk_r' follow
collect2: error: ld returned 1 exit status
Error compiling.

@igrr
Copy link
Member Author

igrr commented Apr 1, 2015

I did try disabling built-in malloc and free in ulibc at some point. But I guess I wasn't able to pass correct parameters via crosstool-NG because the resulting library still had malloc and free.
One hack that I just thought of is to use ar to remove malloc and free from libc.a, and then provide os_malloc and os_free as replacements in the linker script (perhaps they are already there).

@igrr igrr closed this as completed Apr 11, 2015
igrr pushed a commit that referenced this issue May 5, 2015
chadouming pushed a commit to chadouming/Arduino that referenced this issue Jun 27, 2015
igrr pushed a commit that referenced this issue Oct 29, 2015
igrr pushed a commit that referenced this issue Oct 29, 2015
@oystein-devicedrive
Copy link

Also make sure you use os_sprintf instead of sprintf.

ascillato pushed a commit to ascillato/Arduino that referenced this issue Nov 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants