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

Update toolchains to C++17 #1825

Merged
merged 35 commits into from
Dec 10, 2019
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
5f65074
Fix strncpy issue in esptool2
mikee47 Nov 4, 2019
1f28c3f
Fix malloc_count function signatures
mikee47 Nov 21, 2019
62a4ed2
user_init() shouldn't be weak; if applications wish to override it th…
mikee47 Nov 23, 2019
a6a43d9
Add GCC_VERSION build variable
mikee47 Dec 1, 2019
5f4e70e
Move C/C++ library-related code into `libc` Component
mikee47 Dec 1, 2019
de100cb
Add newlib libraries for use with new toolchain
mikee47 Dec 1, 2019
4354e5c
Update heap Component
mikee47 Nov 22, 2019
12dcbf8
Core PROGMEM definitions provided by newlib in sys/pgmspace.h
mikee47 Dec 1, 2019
7752e97
Fix use of incompatible aliases in `gdb_hooks.cpp`
mikee47 Dec 1, 2019
ba3c23d
Fix conflicting attribute names
mikee47 Dec 1, 2019
bfe93f2
Define `asm` for stdc compatibility (it's a GNU extension)
mikee47 Dec 1, 2019
f1362d3
Fix xtensa system definitions required by gdbstub
mikee47 Dec 1, 2019
5ed8362
Select C++17 if supported by toolchain
mikee47 Dec 1, 2019
2e5cc29
Update travis/appveyor scripts
mikee47 Nov 29, 2019
4c14af4
Update linker script
mikee47 Dec 2, 2019
cb6a8c3
Update documentation.
mikee47 Dec 2, 2019
9ad72a1
Allow C++ standard to be overridden. Update documentation, including …
mikee47 Dec 2, 2019
e604e32
Reverse global initialisation order and add test case to HostTests to…
mikee47 Dec 2, 2019
7e997cd
Select unpatched GDB when using new toolchain
mikee47 Dec 3, 2019
54c40cc
Fix IRAM usage
mikee47 Dec 3, 2019
28b93e6
Put PSTR into mergeable section and simplify section filtering
mikee47 Dec 2, 2019
633610b
Update getting-start and toolchain docs. and use SmingTools repo. for…
mikee47 Dec 3, 2019
03394f4
Fix warning with `dist-clean` (missing AWK definition in docs. makefile)
mikee47 Dec 5, 2019
a60c1ac
Remove MFORCE32 and PROGMEM_L32, not required
mikee47 Dec 5, 2019
b39c123
Host emulator docs, note on gcc-9 multilib
mikee47 Dec 6, 2019
ebb970c
EQT toolchain updated to 3.0.0-gnu4 pre-release
mikee47 Dec 7, 2019
53a6872
Add tests to confirm strings end up in flash
mikee47 Dec 8, 2019
ae6129c
Add tests to confirm ROM versions of standard functions are linked
mikee47 Dec 8, 2019
7a69ed7
Move additional libgcc functions into flash, saves c. 800 bytes of IRAM
mikee47 Dec 8, 2019
703f8ab
Use `umoddi3` and `udivdi3` from ROM.
mikee47 Dec 8, 2019
e7081d0
EQT toolchain updated to 3.0.0-gnu5 pre-release
mikee47 Dec 8, 2019
664c745
Fix missing `calloc` when building with ENABLE_CUSTOM_HEAP=1
mikee47 Dec 10, 2019
33dfc6a
UMM Malloc fixes
mikee47 Dec 10, 2019
d781c6a
Widen irom0 section filter to move floating point routines for libmic…
mikee47 Dec 10, 2019
ad6ae3a
Run Travis CI build stages in parallel
mikee47 Dec 10, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion .appveyor/build.cmd
Expand Up @@ -2,7 +2,8 @@ REM Windows build script

set SMING_HOME=%APPVEYOR_BUILD_FOLDER%\Sming

if "%SMING_ARCH%" == "Esp8266" set ESP_HOME=c:\Espressif
if "%build_compiler%" == "udk" set ESP_HOME=%UDK_ROOT%
if "%build_compiler%" == "eqt" set ESP_HOME=%EQT_ROOT%

cd %SMING_HOME%
gcc -v
Expand Down
7 changes: 7 additions & 0 deletions .appveyor/install.cmd
Expand Up @@ -8,8 +8,15 @@ goto :%SMING_ARCH%

:Esp8266

REM Old toolchain
choco install esp8266-udk --source https://www.myget.org/F/sming/ -y --no-progress

REM New toolchain
mkdir %EQT_ROOT%
set TOOLCHAIN=x86_64-w64-mingw32.xtensa-lx106-elf-dd9f9a2.1569802152.zip
curl -LO https://github.com/earlephilhower/esp-quick-toolchain/releases/download/3.0.0-gnu2/%TOOLCHAIN%
7z -o%EQT_ROOT% x %TOOLCHAIN%

goto :EOF


Expand Down
17 changes: 15 additions & 2 deletions .travis.yml
Expand Up @@ -23,10 +23,23 @@ jobs:
- graphviz-dev
- xmlstarlet
- jq
env: SMING_ARCH=Host
env:
- SMING_ARCH=Host

- stage: build
os: linux
env: SMING_ARCH=Esp8266 SDK_VERSION=3.0.1
env:
- SMING_ARCH=Esp8266
- SDK_VERSION=3.0.1
- ESP_HOME=$TRAVIS_BUILD_DIR/opt/esp-alt-sdk

- stage: build c++17
Copy link
Contributor

@slaff slaff Dec 10, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mikee47 Can you try to use build as a stage name also here? It would be better to have the different builds running in parallel and not wait for build to finish in order for build c++17 to start. I am not sure if travis will merge them under one stage and run them in parallel but it is worth trying.

os: linux
env:
- SMING_ARCH=Esp8266
- SDK_VERSION=3.0.1
- ESP_HOME=$TRAVIS_BUILD_DIR/opt/esp-quick-toolchain

git:
submodules: false
addons:
Expand Down
1 change: 0 additions & 1 deletion .travis/build.sh
Expand Up @@ -27,7 +27,6 @@ fi

# Setup ARCH SDK paths
if [ "$SMING_ARCH" == "Esp8266" ]; then
export ESP_HOME=$TRAVIS_BUILD_DIR/opt/esp-alt-sdk
export PATH=$PATH:$ESP_HOME/xtensa-lx106-elf/bin:$ESP_HOME/utils/
slaff marked this conversation as resolved.
Show resolved Hide resolved
fi

Expand Down
14 changes: 10 additions & 4 deletions .travis/install.sh
Expand Up @@ -9,11 +9,17 @@ if [ "$TRAVIS_BUILD_STAGE_NAME" == "Test" ]; then
fi

if [ "$SMING_ARCH" == "Esp8266" ]; then
mkdir -p $TRAVIS_BUILD_DIR/opt/esp-alt-sdk

if [ "$TRAVIS_OS_NAME" == "linux" ]; then
wget --no-verbose https://github.com/nodemcu/nodemcu-firmware/raw/2d958750b56fc60297f564b4ec303e47928b5927/tools/esp-open-sdk.tar.xz
tar -Jxvf esp-open-sdk.tar.xz; ln -s $(pwd)/esp-open-sdk/xtensa-lx106-elf $TRAVIS_BUILD_DIR/opt/esp-alt-sdk/.
# Old toolchain
mkdir -p $TRAVIS_BUILD_DIR/opt/esp-alt-sdk
wget --no-verbose https://github.com/nodemcu/nodemcu-firmware/raw/2d958750b56fc60297f564b4ec303e47928b5927/tools/esp-open-sdk.tar.xz
tar -Jxvf esp-open-sdk.tar.xz; ln -s $(pwd)/esp-open-sdk/xtensa-lx106-elf $TRAVIS_BUILD_DIR/opt/esp-alt-sdk/.

# New toolchain
TOOLCHAIN=x86_64-linux-gnu.xtensa-lx106-elf-dd9f9a2.1569802152.tar.gz
wget --no-verbose https://github.com/earlephilhower/esp-quick-toolchain/releases/download/3.0.0-gnu2/$TOOLCHAIN
mkdir -p opt/esp-quick-toolchain
tar -zxf $TOOLCHAIN -C opt/esp-quick-toolchain --totals
fi

fi # Esp8266
24 changes: 17 additions & 7 deletions Sming/Arch/Esp8266/Compiler/ld/common.ld
Expand Up @@ -138,8 +138,13 @@ SECTIONS
{
_irom0_text_start = ABSOLUTE(.);

*libsmartconfig.a:(.literal .text .literal.* .text.*)
*libc.a:(.literal .text .literal.* .text.*)
*libm.a:(.literal .text .literal.* .text.*)
*libgcc.a:_umoddi3.o(.literal .text)
*libgcc.a:_udivdi3.o(.literal .text)
*libstdc++.a:(.literal .text .literal.* .text.*)

*libsmartconfig.a:(.literal .text .literal.* .text.*)
*libat.a:(.literal.* .text.*)
*libcrypto.a:(.literal.* .text.*)
*libespnow.a:(.literal.* .text.*)
Expand All @@ -156,27 +161,32 @@ SECTIONS

*libmbedtls.a:(.literal.* .text.*)

*libm.a:(.literal .text .literal.* .text.*)
/* C++ vtables */
*(.rodata._ZTV*)

*(.rodata._ZTV*) /* C++ vtables */
*(.irom0.literal .irom.literal .irom.text.literal .irom0.text .irom0.text.* .irom.text .irom.debug.*)
*(.irom0.literal .irom.literal .irom.text.literal .irom0.text .irom0.text.* .irom.text .irom.text.* .irom.debug.*)

/* Generated libraries */
*liblwip2.a:(.literal .text .literal.* .text.*)
*/clib-*.a:*(.literal .text .literal.* .text.* .stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.* .irom.debug.*)

/* Constant strings in flash (PSTRs) */
*(.irom0.pstr.*)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't actually necessary since __fstr__ below catches it, but doesn't hurt.


/* __FUNCTION__ locals */
*(.rodata._ZZ*__FUNCTION__)
*(.rodata._ZZ*__PRETTY_FUNCTION__)
*(.rodata._ZZ*__func__)
*(.rodata.__func__*)

/* debug_e() string pointers */
*(.rodata._ZZ*log_string)

/* const references, mainly in templated code */
*(.rodata._ZN*)
/* Inline flash strings _F() */
*(.rodata._ZZ*flash_str)

*(.rodata._ZZN*)
/* Inline flash strings PSTR() */
*(.rodata._ZZ*__c)

mikee47 marked this conversation as resolved.
Show resolved Hide resolved
_irom0_text_end = ABSOLUTE(.);
_flash_code_end = ABSOLUTE(.);
Expand Down
2 changes: 1 addition & 1 deletion Sming/Arch/Esp8266/Components/esp-open-lwip/component.mk
Expand Up @@ -76,5 +76,5 @@ INCDIR := \
$(SDK_BASE)/include \
$(SMING_HOME)/System/include \
$(ARCH_SYS)/include \
$(ARCH_COMPONENTS)/esp8266/include \
$(ARCH_COMPONENTS)/libc/include \
$(SMING_HOME)/Wiring
6 changes: 6 additions & 0 deletions Sming/Arch/Esp8266/Components/esp8266/ESP8266_NONOS_SDK.patch
@@ -0,0 +1,6 @@
diff --git a/lib/libc.a b/lib/libc.orig.a
rename from lib/libc.a
rename to lib/libc.orig.a
diff --git a/lib/libgcc.a b/lib/libgcc.orig.a
rename from lib/libgcc.a
rename to lib/libgcc.orig.a
39 changes: 12 additions & 27 deletions Sming/Arch/Esp8266/Components/esp8266/esp_cplusplus.cpp
@@ -1,3 +1,13 @@
/****
* Sming Framework Project - Open Source framework for high efficiency native ESP8266 development.
* Created 2015 by Skurydin Alexey
* http://github.com/SmingHub/Sming
* All files of the Sming Core are provided under the LGPL v3 license.
*
* esp_cplusplus.cpp
*
****/

#include <esp_systemapi.h>
#include "include/esp_cplusplus.h"
#include <stdlib.h>
Expand All @@ -11,34 +21,9 @@ extern void (*__init_array_end)();
void cpp_core_initialize()
{
void (**p)(void);
for (p = &__init_array_start; p != &__init_array_end; ++p)
for (p = &__init_array_start; p != &__init_array_end; ++p) {
slaff marked this conversation as resolved.
Show resolved Hide resolved
(*p)();
}

////////////////////////////////////////////////////////////////////////

void *operator new(size_t size)
{
//debugf("new: %d (%d)", size, system_get_free_heap_size());
return malloc(size);
}

void *operator new[](size_t size)
{
//debugf("new[]: %d (%d)", size, system_get_free_heap_size());
return malloc(size);
}

void operator delete(void * ptr)
{
if (ptr != NULL)
free(ptr);
}

void operator delete[](void * ptr)
{
if (ptr != NULL)
free(ptr);
}
}

extern "C" void __cxa_pure_virtual(void)
Expand Down
2 changes: 1 addition & 1 deletion Sming/Arch/Esp8266/Components/esp8266/startup.cpp
Expand Up @@ -17,7 +17,7 @@

extern void init();

extern "C" void WEAK_ATTR user_init(void)
extern "C" void user_init(void)
{
// Initialise hardware timers
hw_timer_init();
Expand Down
22 changes: 14 additions & 8 deletions Sming/Arch/Esp8266/Components/gdbstub/appcode/gdb_hooks.cpp
Expand Up @@ -226,18 +226,24 @@ void ATTR_GDBINIT gdb_init(void)
#endif
}

static unsigned IRAM_ATTR __gdb_no_op(void)
void WEAK_ATTR gdb_enable(bool state)
{
return 0;
}

#define NOOP __attribute__((weak, alias("__gdb_no_op")))
GdbState WEAK_ATTR gdb_present(void)
{
return eGDB_NotPresent;
}

void gdb_enable(bool state) NOOP;
GdbState gdb_present(void) NOOP;
void gdb_on_attach(bool attached) NOOP;
void gdb_detach(void) NOOP;
};
void WEAK_ATTR gdb_on_attach(bool attached)
{
}

void WEAK_ATTR gdb_detach(void)
{
}

} // extern "C"

int WEAK_ATTR gdb_syscall(const GdbSyscallInfo& info)
{
Expand Down
5 changes: 4 additions & 1 deletion Sming/Arch/Esp8266/Components/gdbstub/component.mk
Expand Up @@ -3,7 +3,10 @@ COMPONENT_LIBNAME :=
COMPONENT_DEPENDS := esp8266

COMPONENT_APPCODE := appcode
COMPONENT_INCDIRS := . $(ARCH_COMPONENTS)/driver
COMPONENT_INCDIRS := \
. \
$(ARCH_COMPONENTS)/driver \
$(ESP_HOME)/xtensa-lx106-elf/include

ifeq ($(ENABLE_GDB), 1)
COMPONENT_APPCODE += .
Expand Down
16 changes: 16 additions & 0 deletions Sming/Arch/Esp8266/Components/gdbstub/gdbstub-internal.h
Expand Up @@ -12,6 +12,22 @@

#pragma once

#define XCHAL_CP0_SA_SIZE 0
mikee47 marked this conversation as resolved.
Show resolved Hide resolved
#define XCHAL_CP0_SA_ALIGN 1
#define XCHAL_CP1_SA_SIZE 0
#define XCHAL_CP1_SA_ALIGN 1
#define XCHAL_CP2_SA_SIZE 0
#define XCHAL_CP2_SA_ALIGN 1
#define XCHAL_CP3_SA_SIZE 0
#define XCHAL_CP3_SA_ALIGN 1
#define XCHAL_CP4_SA_SIZE 0
#define XCHAL_CP4_SA_ALIGN 1
#define XCHAL_CP5_SA_SIZE 0
#define XCHAL_CP5_SA_ALIGN 1
#define XCHAL_CP6_SA_SIZE 0
#define XCHAL_CP6_SA_ALIGN 1
#define XCHAL_CP7_SA_SIZE 0
#define XCHAL_CP7_SA_ALIGN 1
#include "xtensa/xtruntime-frames.h"
#include "gdbstub-cfg.h"

Expand Down
41 changes: 41 additions & 0 deletions Sming/Arch/Esp8266/Components/heap/alloc.cpp
@@ -0,0 +1,41 @@
/****
* Sming Framework Project - Open Source framework for high efficiency native ESP8266 development.
* Created 2015 by Skurydin Alexey
* http://github.com/SmingHub/Sming
* All files of the Sming Core are provided under the LGPL v3 license.
*
* alloc.cpp - C++ heap allocators
*
****/

#include <stdlib.h>

void* operator new(size_t size)
{
return malloc(size);
}

void* operator new[](size_t size)
{
return malloc(size);
}

void operator delete(void* ptr)
{
free(ptr);
}

void operator delete[](void* ptr)
{
free(ptr);
}

void operator delete(void* ptr, size_t sz)
{
free(ptr);
}

void operator delete[](void* ptr, size_t sz)
{
free(ptr);
}
5 changes: 3 additions & 2 deletions Sming/Arch/Esp8266/Components/heap/component.mk
@@ -1,5 +1,6 @@
COMPONENT_SRCDIRS :=
COMPONENT_INCDIRS :=
COMPONENT_SRCFILES := heap.c alloc.cpp

# => Custom heap
COMPONENT_VARS := ENABLE_CUSTOM_HEAP
Expand All @@ -9,13 +10,13 @@ COMPONENT_SUBMODULES := umm_malloc
COMPONENT_SRCFILES += custom_heap.c umm_malloc/src/umm_malloc.c
COMPONENT_INCDIRS += umm_malloc/src umm_malloc/includes/c-helper-macros

COMPONENT_DEPENDS := esp8266

COMPONENT_VARS += UMM_POISON_CHECK
ifeq ($(UMM_POISON_CHECK),1)
GLOBAL_CFLAGS += -DUMM_POISON_CHECK
endif

COMPONENT_CFLAGS += -Wno-array-bounds
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is that change needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you comment this out then try compiling with ENABLE_CUSTOM_HEAP=1:

s:/sandboxes/sming-dev/Sming/Arch/Esp8266/Components/heap/umm_malloc/src/umm_malloc.c: In function 'umm_init':
s:/sandboxes/sming-dev/Sming/Arch/Esp8266/Components/heap/umm_malloc/src/umm_malloc.c:73:32: error: array subscript 1 is outside array bounds of 'char[1]' [-Werror=array-bounds]
   73 | #define UMM_BLOCK(b)  (umm_heap[b])
      |                       ~~~~~~~~~^~~~
s:/sandboxes/sming-dev/Sming/Arch/Esp8266/Components/heap/umm_malloc/src/umm_malloc.c:75:24: note: in expansion of macro 'UMM_BLOCK'
   75 | #define UMM_NBLOCK(b) (UMM_BLOCK(b).header.used.next)
      |                        ^~~~~~~~~
s:/sandboxes/sming-dev/Sming/Arch/Esp8266/Components/heap/umm_malloc/src/umm_malloc.c:231:5: note: in expansion of macro 'UMM_NBLOCK'
  231 |     UMM_NBLOCK(block_1th) = block_last | UMM_FREELIST_MASK;
      |     ^~~~~~~~~~
In file included from s:/sandboxes/sming-dev/Sming/Arch/Esp8266/Components/heap/umm_malloc/src/umm_malloc.c:35:
s:/sandboxes/sming-dev/Sming/Arch/Esp8266/Components/heap/umm_malloc/src/umm_malloc_cfg.h:60:13: note: while referencing '_heap_start'
   60 | extern char _heap_start;
      |             ^~~~~~~~~~~
s:/sandboxes/sming-dev/Sming/Arch/Esp8266/Components/heap/umm_malloc/src/umm_malloc.c:73:32: error: array subscript 1 is outside array bounds of 'char[1]' [-Werror=array-bounds]
   73 | #define UMM_BLOCK(b)  (umm_heap[b])
      |                       ~~~~~~~~~^~~~
s:/sandboxes/sming-dev/Sming/Arch/Esp8266/Components/heap/umm_malloc/src/umm_malloc.c:77:24: note: in expansion of macro 'UMM_BLOCK'
   77 | #define UMM_NFREE(b)  (UMM_BLOCK(b).body.free.next)
      |                        ^~~~~~~~~
s:/sandboxes/sming-dev/Sming/Arch/Esp8266/Components/heap/umm_malloc/src/umm_malloc.c:232:5: note: in expansion of macro 'UMM_NFREE'
  232 |     UMM_NFREE(block_1th)  = 0;
      |     ^~~~~~~~~
In file included from s:/sandboxes/sming-dev/Sming/Arch/Esp8266/Components/heap/umm_malloc/src/umm_malloc.c:35:
s:/sandboxes/sming-dev/Sming/Arch/Esp8266/Components/heap/umm_malloc/src/umm_malloc_cfg.h:60:13: note: while referencing '_heap_start'
   60 | extern char _heap_start;
      |             ^~~~~~~~~~~
s:/sandboxes/sming-dev/Sming/Arch/Esp8266/Components/heap/umm_malloc/src/umm_malloc.c:73:32: error: array subscript 1 is outside array bounds of 'char[1]' [-Werror=array-bounds]
   73 | #define UMM_BLOCK(b)  (umm_heap[b])
      |                       ~~~~~~~~~^~~~
s:/sandboxes/sming-dev/Sming/Arch/Esp8266/Components/heap/umm_malloc/src/umm_malloc.c:76:24: note: in expansion of macro 'UMM_BLOCK'
   76 | #define UMM_PBLOCK(b) (UMM_BLOCK(b).header.used.prev)
      |                        ^~~~~~~~~
s:/sandboxes/sming-dev/Sming/Arch/Esp8266/Components/heap/umm_malloc/src/umm_malloc.c:233:5: note: in expansion of macro 'UMM_PBLOCK'
  233 |     UMM_PBLOCK(block_1th) = block_0th;
      |     ^~~~~~~~~~
In file included from s:/sandboxes/sming-dev/Sming/Arch/Esp8266/Components/heap/umm_malloc/src/umm_malloc.c:35:
s:/sandboxes/sming-dev/Sming/Arch/Esp8266/Components/heap/umm_malloc/src/umm_malloc_cfg.h:60:13: note: while referencing '_heap_start'
   60 | extern char _heap_start;
      |             ^~~~~~~~~~~
s:/sandboxes/sming-dev/Sming/Arch/Esp8266/Components/heap/umm_malloc/src/umm_malloc.c:73:32: error: array subscript 1 is outside array bounds of 'char[1]' [-Werror=array-bounds]
   73 | #define UMM_BLOCK(b)  (umm_heap[b])
      |                       ~~~~~~~~~^~~~
s:/sandboxes/sming-dev/Sming/Arch/Esp8266/Components/heap/umm_malloc/src/umm_malloc.c:78:24: note: in expansion of macro 'UMM_BLOCK'
   78 | #define UMM_PFREE(b)  (UMM_BLOCK(b).body.free.prev)
      |                        ^~~~~~~~~
s:/sandboxes/sming-dev/Sming/Arch/Esp8266/Components/heap/umm_malloc/src/umm_malloc.c:234:5: note: in expansion of macro 'UMM_PFREE'
  234 |     UMM_PFREE(block_1th)  = block_0th;
      |     ^~~~~~~~~
In file included from s:/sandboxes/sming-dev/Sming/Arch/Esp8266/Components/heap/umm_malloc/src/umm_malloc.c:35:
s:/sandboxes/sming-dev/Sming/Arch/Esp8266/Components/heap/umm_malloc/src/umm_malloc_cfg.h:60:13: note: while referencing '_heap_start'
   60 | extern char _heap_start;
      |             ^~~~~~~~~~~
cc1.exe: all warnings being treated as errors


# remove mem_manager.o module from libmain of SDK
define HEAP_LIBMAIN_COMMANDS
@echo Enabling custom heap implementation
Expand Down
19 changes: 19 additions & 0 deletions Sming/Arch/Esp8266/Components/heap/custom_heap.c
Expand Up @@ -27,6 +27,25 @@ void IRAM_ATTR vPortFree(void *ptr, const char* file, int line)
UMM_FUNC(free)(ptr);
}

#ifdef __NEWLIB__

void* IRAM_ATTR malloc(size_t size)
{
return UMM_FUNC(malloc)(size);
}

void* IRAM_ATTR realloc(void* ptr, size_t size)
{
return UMM_FUNC(realloc)(ptr, size);
}

void IRAM_ATTR free(void *ptr)
{
UMM_FUNC(free)(ptr);
}

#endif

void* IRAM_ATTR pvPortCalloc(size_t count, size_t size, const char* file, int line)
{
return UMM_FUNC(calloc)(count, size);
Expand Down
28 changes: 28 additions & 0 deletions Sming/Arch/Esp8266/Components/heap/heap.c
@@ -0,0 +1,28 @@
#include <stdlib.h>
#include <stddef.h>
#include <sys/reent.h>

void* _malloc_r(struct _reent* unused, size_t size)
{
(void) unused;
return malloc(size);
}

void _free_r(struct _reent* unused, void* ptr)
{
(void) unused;
free(ptr);
}

void* _realloc_r(struct _reent* unused, void* ptr, size_t size)
{
(void) unused;
return realloc(ptr, size);
}

void* _calloc_r(struct _reent* unused, size_t count, size_t size)
{
(void) unused;
return calloc(count, size);
}