Skip to content

Commit

Permalink
Update toolchains to C++17 (#1825)
Browse files Browse the repository at this point in the history
Updates framework to build using GCC 9.2.0 toolchain for C++17.

Toolchains are at https://github.com/earlephilhower/esp-quick-toolchain/releases.

See `docs/source/arch/esp8266/getting-started/eqt.rst` for installation details.

(Also at https://smingdev.readthedocs.io/en/dev-esp-quick-toolchain/arch/esp8266/getting-started/eqt.html)

Extract the toolchain to a suitable location, e.g. `opt/esp-quick-toolchain` or `C:\tools\esp-quick-toolchain`, and set `ESP_HOME` accordingly.

The main change for the new toolchain is that the core PROGMEM handling stuff is included in `sys/pgmspace.h`. See esp8266/Arduino#5376 for more details.

Also includes de-duplication for NUL-terminated PSTR definitions.
  • Loading branch information
mikee47 authored and slaff committed Dec 10, 2019
1 parent d1a1efa commit 3a99771
Show file tree
Hide file tree
Showing 73 changed files with 1,587 additions and 901 deletions.
3 changes: 2 additions & 1 deletion .appveyor/build.cmd
Original file line number Diff line number Diff line change
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
13 changes: 11 additions & 2 deletions .appveyor/install.cmd
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
REM Windows install script

rmdir /s /q c:\MinGW
curl -LO https://github.com/SmingHub/SmingTools/releases/download/1.0/MinGW.7z
curl -LO %SMINGTOOLS%/MinGW.7z
7z -oC:\ x MinGW.7z

goto :%SMING_ARCH%

:Esp8266

choco install esp8266-udk --source https://www.myget.org/F/sming/ -y --no-progress
REM Old toolchain
set TOOLCHAIN=esp-udk-win32.7z
curl -LO %SMINGTOOLS%/%TOOLCHAIN%
7z -o%UDK_ROOT% x %TOOLCHAIN%

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

goto :EOF

Expand Down
24 changes: 18 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
language: cpp
os: linux
env:
global:
- SDK_BUILD=258
- SMINGTOOLS=https://github.com/SmingHub/SmingTools/releases/download/1.0
- secure: D/cPk+sL2MNHLtfuU/rMiVN63+CTFpo9Chqa39LEH5VloGqC5f7RyIi2Maa3C/U2JQfM01HlsNR7E5bB0W8DQYbtzBDTqbZ4C7ppZRU5jCQ+L51ERKJ0EAV3KkaravQCRbWt3tlgOp6Xk6xaRMBaHEGrdbFjHYgEMPVteUQNr0A=
- secure: pc8Yqwmn6AM+iBjLNNnknmOoi+AxoyvcVy128b2WXSdj6Q4bOIXgj4WUg8I52i1fgyh0Rxg19WUB6qSVyykCXVdSRajIU1MsKZI+0q44Q83wnwVeYm7nPWxDqS3FKMajucZCg4p0BTE4T6tpnm7zZNHduHnggua/NpP2h7B/Sqs=
- secure: TX0IxYV3tTocCaJcgIA2xzJyHIzbxo7sAkLLYL+OITgWPD1VDUrEqEe7konQA5NIDJJ0VjoHxpdfti2LHG1fw45vrEMfBIOmZG6nW2gxD8ZS2G8KlYIxFB93oNNB6qJRHps1uIANk2hM+Ju6Pnqfc+lLh8oabs974ziAxoYuAJQ=
jobs:
include:
- stage: test
os: linux
dist: xenial
addons:
apt:
packages:
Expand All @@ -23,10 +22,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
name: C++11
env:
- SMING_ARCH=Esp8266
- SDK_VERSION=3.0.1
- ESP_HOME=$TRAVIS_BUILD_DIR/opt/esp-alt-sdk

- stage: build
name: C++17
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
Original file line number Diff line number Diff line change
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/
fi

Expand Down
16 changes: 12 additions & 4 deletions .travis/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,19 @@ 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
TOOLCHAIN=esp-open-sdk-linux-x86_64.tar.gz
wget --no-verbose $SMINGTOOLS/$TOOLCHAIN
tar -zxf $TOOLCHAIN
mkdir -p $TRAVIS_BUILD_DIR/opt/esp-alt-sdk
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-a5c9861.1575819473.tar.gz
wget --no-verbose https://github.com/earlephilhower/esp-quick-toolchain/releases/download/3.0.0-gnu5/$TOOLCHAIN
mkdir -p opt/esp-quick-toolchain
tar -zxf $TOOLCHAIN -C opt/esp-quick-toolchain --totals
fi

fi # Esp8266
30 changes: 20 additions & 10 deletions Sming/Arch/Esp8266/Compiler/ld/common.ld
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,15 @@ SECTIONS
{
_irom0_text_start = ABSOLUTE(.);

*libsmartconfig.a:(.literal .text .literal.* .text.*)
*libc.a:(.literal .text .literal.* .text.*)
*libm.a:(.literal .text .literal.* .text.*)
*gcc.a:_divsf3.o(.literal .text)
*gcc.a:_fixsfsi.o(.literal .text)
*gcc.a:_cmpdf2.o(.literal .text)
*gcc.a:_cmpsf2.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 +163,30 @@ 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.*)

/* __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, including those within templated code */
*(*__pstr__*)
*(*__fstr__*)

*(.rodata._ZZN*)
/* Templated code */
*(.rodata._ZN8NanoTimeL9unitTicksE)

_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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
50 changes: 18 additions & 32 deletions Sming/Arch/Esp8266/Components/esp8266/esp_cplusplus.cpp
Original file line number Diff line number Diff line change
@@ -1,44 +1,30 @@
/****
* 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>

extern void (*__init_array_start)();
extern void (*__init_array_end)();

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

// Just do it! :)
void cpp_core_initialize()
{
void (**p)(void);
for (p = &__init_array_start; p != &__init_array_end; ++p)
(*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);
/*
* Must be initialised in reverse order
* see https://github.com/esp8266/Arduino/pull/2074
*/
auto p = &__init_array_end;
while(p != &__init_array_start) {
(*--p)();
}
}

extern "C" void __cxa_pure_virtual(void)
Expand Down
2 changes: 1 addition & 1 deletion Sming/Arch/Esp8266/Components/esp8266/startup.cpp
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
10 changes: 9 additions & 1 deletion Sming/Arch/Esp8266/Components/gdbstub/component.mk
Original file line number Diff line number Diff line change
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 Expand Up @@ -35,3 +38,8 @@ CONFIG_VARS += GDB_UART_SWAP
ifeq ($(GDB_UART_SWAP),1)
APP_CFLAGS += -DGDB_UART_SWAP=1
endif

#
ifeq ($(USE_NEWLIB),1)
APP_CFLAGS += -DGDBSTUB_GDB_PATCHED=0
endif
16 changes: 16 additions & 0 deletions Sming/Arch/Esp8266/Components/gdbstub/gdbstub-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,22 @@

#pragma once

#define XCHAL_CP0_SA_SIZE 0
#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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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

# remove mem_manager.o module from libmain of SDK
define HEAP_LIBMAIN_COMMANDS
@echo Enabling custom heap implementation
Expand Down

0 comments on commit 3a99771

Please sign in to comment.