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

Enable libstdc++ v2 #146

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[submodule "crosstool-NG"]
path = crosstool-NG
url = https://github.com/jcmvbkbc/crosstool-NG
branch = lx106-g++
branch = xtensa-1.22.x
[submodule "lx106-hal"]
path = lx106-hal
url = https://github.com/tommie/lx106-hal
Expand All @@ -12,3 +12,14 @@
path = esp-open-lwip
url = https://github.com/pfalcon/esp-open-lwip
branch = sdk-1.5.0
[submodule "esp_newlib_port"]
path = esp_newlib_port
url = https://github.com/Sermus/esp_newlib_port.git
branch = lx106
[submodule "esp_stdcpp_port"]
path = esp_stdcpp_port
url = https://github.com/Sermus/esp_stdcpp_port.git
branch = lx106
[submodule "examples/esp8266_sgi_stl_tests"]
path = examples/esp8266_sgi_stl_tests
url = https://github.com/Sermus/esp8266_sgi_stl_tests.git
40 changes: 36 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ TOOLCHAIN = $(TOP)/xtensa-lx106-elf
# for supported versions.
VENDOR_SDK = 1.5.2

.PHONY: crosstool-NG toolchain libhal libcirom sdk
.PHONY: crosstool-NG toolchain libhal libcirom libstdc++irom libnewlibport libstdc++port sdk



Expand Down Expand Up @@ -65,7 +65,7 @@ VENDOR_SDK_DIR_0.9.2 = esp_iot_sdk_v0.9.2



all: esptool libcirom standalone sdk sdk_patch $(TOOLCHAIN)/xtensa-lx106-elf/sysroot/usr/lib/libhal.a $(TOOLCHAIN)/bin/xtensa-lx106-elf-gcc lwip
all: esptool libcirom libstdc++irom libnewlibport libstdc++port standalone sdk sdk_patch $(TOOLCHAIN)/xtensa-lx106-elf/sysroot/usr/lib/libhal.a $(TOOLCHAIN)/bin/xtensa-lx106-elf-gcc lwip
@echo
@echo "Xtensa toolchain is built, to use it:"
@echo
Expand All @@ -90,13 +90,19 @@ ifeq ($(STANDALONE),y)
@cp -Rf sdk/lib/* $(TOOLCHAIN)/xtensa-lx106-elf/sysroot/usr/lib/
@echo "Installing vendor SDK linker scripts into toolchain sysroot"
@sed -e 's/\r//' sdk/ld/eagle.app.v6.ld | sed -e s@../ld/@@ >$(TOOLCHAIN)/xtensa-lx106-elf/sysroot/usr/lib/eagle.app.v6.ld
@sed -e 's/\r//' sdk/ld/eagle.app.v6.irom.ld | sed -e s@../ld/@@ >$(TOOLCHAIN)/xtensa-lx106-elf/sysroot/usr/lib/eagle.app.v6.irom.ld
@sed -e 's/\r//' sdk/ld/eagle.app.v6.new.2048.ld | sed -e s@../ld/@@ >$(TOOLCHAIN)/xtensa-lx106-elf/sysroot/usr/lib/eagle.app.v6.new.2048.ld
@sed -e 's/\r//' sdk/ld/eagle.app.v6.new.2048.irom.ld | sed -e s@../ld/@@ >$(TOOLCHAIN)/xtensa-lx106-elf/sysroot/usr/lib/eagle.app.v6.new.2048.irom.ld
@sed -e 's/\r//' sdk/ld/eagle.rom.addr.v6.ld >$(TOOLCHAIN)/xtensa-lx106-elf/sysroot/usr/lib/eagle.rom.addr.v6.ld
@echo "Installing port lib headers into toolchain sysroot"
@cp -Rf esp_stdcpp_port/cpp_routines.h $(TOOLCHAIN)/xtensa-lx106-elf/sysroot/usr/include/cpp_routines.h
endif

clean: clean-sdk
make -C crosstool-NG clean MAKELEVEL=0
make -C esp_newlib_port clean MAKELEVEL=0
-rm -rf crosstool-NG/.build/src
-rm -f crosstool-NG/local-patches/gcc/4.8.2/1000-*
-rm -f crosstool-NG/local-patches/gcc/4.8.5/1000-*
-rm -rf $(TOOLCHAIN)


Expand All @@ -107,7 +113,7 @@ esptool: toolchain
toolchain: $(TOOLCHAIN)/bin/xtensa-lx106-elf-gcc

$(TOOLCHAIN)/bin/xtensa-lx106-elf-gcc: crosstool-NG/ct-ng
cp -f 1000-mforce-l32.patch crosstool-NG/local-patches/gcc/4.8.2/
cp -f 1000-mforce-l32.patch crosstool-NG/local-patches/gcc/4.8.5/
make -C crosstool-NG -f ../Makefile _toolchain

_toolchain:
Expand Down Expand Up @@ -143,6 +149,13 @@ $(TOOLCHAIN)/xtensa-lx106-elf/sysroot/lib/libcirom.a: $(TOOLCHAIN)/xtensa-lx106-
$(TOOLCHAIN)/bin/xtensa-lx106-elf-objcopy --rename-section .text=.irom0.text \
--rename-section .literal=.irom0.literal $(<) $(@);

libstdc++irom: $(TOOLCHAIN)/xtensa-lx106-elf/sysroot/lib/libstdc++irom.a

$(TOOLCHAIN)/xtensa-lx106-elf/sysroot/lib/libstdc++irom.a: $(TOOLCHAIN)/xtensa-lx106-elf/sysroot/lib/libstdc++.a $(TOOLCHAIN)/bin/xtensa-lx106-elf-gcc
@echo "Creating irom version of libstdc++..."
$(TOOLCHAIN)/bin/xtensa-lx106-elf-objcopy --rename-section .text=.irom0.text \
Copy link
Contributor

Choose a reason for hiding this comment

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

Since it has pretty much been established that this objcopy doesn't do anything useful, might it not be more efficient to just use cp instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tend to agree, but there is one argument against this approach. I tried to keep backward compatibility meaning the patch mustn't break solutions which worked before. If we change libstdc++irom just to a copy we either keep inconsistency between the way how libcirom is built and the way how libstdc++irom is built or we may break those solutions which used libcirom assuming that the functions inside are packed into .irom0.text.
So i'd rather keep it the way it's done now to keep backward compatibility and unified way of building *irom libs.

--rename-section .literal=.irom0.literal $(<) $(@);

libhal: $(TOOLCHAIN)/xtensa-lx106-elf/sysroot/usr/lib/libhal.a

$(TOOLCHAIN)/xtensa-lx106-elf/sysroot/usr/lib/libhal.a: $(TOOLCHAIN)/bin/xtensa-lx106-elf-gcc
Expand All @@ -154,7 +167,23 @@ _libhal:
PATH=$(TOOLCHAIN)/bin:$(PATH) make
PATH=$(TOOLCHAIN)/bin:$(PATH) make install

libnewlibport: $(TOOLCHAIN)/xtensa-lx106-elf/sysroot/usr/lib/libnewlibport.a

$(TOOLCHAIN)/xtensa-lx106-elf/sysroot/usr/lib/libnewlibport.a: $(TOOLCHAIN)/bin/xtensa-lx106-elf-gcc sdk sdk_patch toolchain standalone
make -C esp_newlib_port -f ../Makefile _libnewlibport
cp -f esp_newlib_port/libnewlibport.a $(TOOLCHAIN)/xtensa-lx106-elf/sysroot/usr/lib/libnewlibport.a

_libnewlibport:
PATH=$(TOOLCHAIN)/bin:$(PATH) make

libstdc++port: $(TOOLCHAIN)/xtensa-lx106-elf/sysroot/usr/lib/libstdc++port.a

$(TOOLCHAIN)/xtensa-lx106-elf/sysroot/usr/lib/libstdc++port.a: $(TOOLCHAIN)/bin/xtensa-lx106-elf-gcc sdk sdk_patch toolchain standalone
make -C esp_stdcpp_port -f ../Makefile _libstdc++port
cp -f esp_stdcpp_port/libstdc++port.a $(TOOLCHAIN)/xtensa-lx106-elf/sysroot/usr/lib/libstdc++port.a

_libstdc++port:
PATH=$(TOOLCHAIN)/bin:$(PATH) make

sdk: $(VENDOR_SDK_DIR)/.dir
ln -snf $(VENDOR_SDK_DIR) sdk
Expand All @@ -169,6 +198,9 @@ sdk_patch: $(VENDOR_SDK_DIR)/.dir .sdk_patch_$(VENDOR_SDK)
.sdk_patch_1.5.2:
echo -e "#undef ESP_SDK_VERSION\n#define ESP_SDK_VERSION 010502" >>$(VENDOR_SDK_DIR)/include/esp_sdk_ver.h
$(PATCH) -d $(VENDOR_SDK_DIR) -p1 < c_types-c99.patch
cp -f $(VENDOR_SDK_DIR)/ld/eagle.app.v6.ld $(VENDOR_SDK_DIR)/ld/eagle.app.v6.irom.ld
cp -f $(VENDOR_SDK_DIR)/ld/eagle.app.v6.new.2048.ld $(VENDOR_SDK_DIR)/ld/eagle.app.v6.new.2048.irom.ld
$(PATCH) -d $(VENDOR_SDK_DIR) -p1 < ld-script-irom.patch
cd $(VENDOR_SDK_DIR)/lib; mkdir -p tmp; cd tmp; $(TOOLCHAIN)/bin/xtensa-lx106-elf-ar x ../libcrypto.a; cd ..; $(TOOLCHAIN)/bin/xtensa-lx106-elf-ar rs libwpa.a tmp/*.o
@touch $@

Expand Down
2 changes: 1 addition & 1 deletion crosstool-NG
Submodule crosstool-NG updated 1032 files
1 change: 1 addition & 0 deletions esp_newlib_port
Submodule esp_newlib_port added at f34f68
1 change: 1 addition & 0 deletions esp_stdcpp_port
Submodule esp_stdcpp_port added at 77e48e
1 change: 1 addition & 0 deletions examples/esp8266_sgi_stl_tests
Submodule esp8266_sgi_stl_tests added at f5464c
116 changes: 116 additions & 0 deletions ld-script-irom.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
--- esp_iot_sdk_v1.5.2/ld/eagle.app.v6.irom.ld.orig 2016-04-01 09:11:42.171496836 +0300
+++ esp_iot_sdk_v1.5.2/ld/eagle.app.v6.irom.ld 2016-04-07 09:52:31.502596929 +0300
@@ -102,11 +102,14 @@
*(.gnu.linkonce.e.*)
*(.gnu.version_r)
*(.eh_frame)
+ . = (. + 3) & ~ 3;
/* C++ constructor and destructor tables, properly ordered: */
+ __init_array_start = ABSOLUTE(.);
KEEP (*crtbegin.o(.ctors))
KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors))
KEEP (*(SORT(.ctors.*)))
KEEP (*(.ctors))
+ __init_array_end = ABSOLUTE(.);
KEEP (*crtbegin.o(.dtors))
KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors))
KEEP (*(SORT(.dtors.*)))
@@ -151,6 +154,15 @@
} >dram0_0_seg :dram0_0_bss_phdr
/* __stack = 0x3ffc8000; */

+ .irom0.text : ALIGN(4)
+ {
+ _irom0_text_start = ABSOLUTE(.);
+ *(.irom0.literal .irom.literal .irom.text.literal .irom0.text .irom.text)
+ *libm.a:(.literal .text .literal.* .text.*)
+ *irom.a:(.literal .text .literal.* .text.*)
+ _irom0_text_end = ABSOLUTE(.);
+ } >irom0_0_seg :irom0_0_phdr
+
.text : ALIGN(4)
{
_stext = .;
@@ -182,7 +194,7 @@
*(.entry.text)
*(.init.literal)
*(.init)
- *(.literal .text .literal.* .text.* .stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*)
+ *(.literal .text .stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*)
*(.fini.literal)
*(.fini)
*(.gnu.version)
@@ -198,14 +210,8 @@
*(.gnu.linkonce.lit4.*)
_lit4_end = ABSOLUTE(.);
} >iram1_0_seg :iram1_0_phdr
-
- .irom0.text : ALIGN(4)
- {
- _irom0_text_start = ABSOLUTE(.);
- *(.irom0.literal .irom.literal .irom.text.literal .irom0.text .irom.text)
- _irom0_text_end = ABSOLUTE(.);
- } >irom0_0_seg :irom0_0_phdr
}

/* get ROM code address */
INCLUDE "../ld/eagle.rom.addr.v6.ld"
+
--- esp_iot_sdk_v1.5.2/ld/eagle.app.v6.new.2048.irom.ld.orig 2016-04-01 09:11:42.175496836 +0300
+++ esp_iot_sdk_v1.5.2/ld/eagle.app.v6.new.2048.irom.ld 2016-04-07 09:53:01.086596929 +0300
@@ -102,11 +102,14 @@
*(.gnu.linkonce.e.*)
*(.gnu.version_r)
*(.eh_frame)
+ . = (. + 3) & ~ 3;
/* C++ constructor and destructor tables, properly ordered: */
+ __init_array_start = ABSOLUTE(.);
KEEP (*crtbegin.o(.ctors))
KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors))
KEEP (*(SORT(.ctors.*)))
KEEP (*(.ctors))
+ __init_array_end = ABSOLUTE(.);
KEEP (*crtbegin.o(.dtors))
KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors))
KEEP (*(SORT(.dtors.*)))
@@ -151,6 +154,15 @@
} >dram0_0_seg :dram0_0_bss_phdr
/* __stack = 0x3ffc8000; */

+ .irom0.text : ALIGN(4)
+ {
+ _irom0_text_start = ABSOLUTE(.);
+ *(.irom0.literal .irom.literal .irom.text.literal .irom0.text .irom.text)
+ *libm.a:(.literal .text .literal.* .text.*)
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about taking the *libm.a line out and instead making a copy of libm.a to libmirom.a in the Makefile? Would give the user more flexibility.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed. But i'd build libmirom the same way as other *irom libs are done now (see my previous comment).

+ *irom.a:(.literal .text .literal.* .text.*)
+ _irom0_text_end = ABSOLUTE(.);
+ } >irom0_0_seg :irom0_0_phdr
+
.text : ALIGN(4)
{
_stext = .;
@@ -182,7 +194,7 @@
*(.entry.text)
*(.init.literal)
*(.init)
- *(.literal .text .literal.* .text.* .stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*)
+ *(.literal .text .stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*)
Copy link
Contributor

Choose a reason for hiding this comment

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

Where did *(.literal.* .text.*) wind up? I'm not seeing it in .text or in .irom0.text

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for pointing me to this. This is definitely my fault.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Funny enough. I tested micropython with this. Since these sections are not in .text they end up in .lit. So actually their location in RAM is changed, but because they are still in RAM the linker script creates working binaries.

*(.fini.literal)
*(.fini)
*(.gnu.version)
@@ -198,14 +210,8 @@
*(.gnu.linkonce.lit4.*)
_lit4_end = ABSOLUTE(.);
} >iram1_0_seg :iram1_0_phdr
-
- .irom0.text : ALIGN(4)
- {
- _irom0_text_start = ABSOLUTE(.);
- *(.irom0.literal .irom.literal .irom.text.literal .irom0.text .irom.text)
- _irom0_text_end = ABSOLUTE(.);
- } >irom0_0_seg :irom0_0_phdr
}

/* get ROM code address */
INCLUDE "../ld/eagle.rom.addr.v6.ld"
+