From 324f041b24ed0ac69fe1c21df690fae4bb42ec7c Mon Sep 17 00:00:00 2001 From: David Gauchard Date: Mon, 26 Mar 2018 13:56:08 +0200 Subject: [PATCH 1/3] ldscripts: makefile to select where c++ vtables should be placed --- tools/sdk/ld/Makefile | 19 ++ tools/sdk/ld/eagle.app.v6.common.ld | 33 ++-- tools/sdk/ld/eagle.app.v6.common.ld.h | 187 ++++++++++++++++++ tools/sdk/ld/eagle.app.v6.common.ld.vtables.h | 65 ++++++ 4 files changed, 291 insertions(+), 13 deletions(-) create mode 100644 tools/sdk/ld/Makefile create mode 100644 tools/sdk/ld/eagle.app.v6.common.ld.h create mode 100644 tools/sdk/ld/eagle.app.v6.common.ld.vtables.h diff --git a/tools/sdk/ld/Makefile b/tools/sdk/ld/Makefile new file mode 100644 index 0000000000..52022fad1e --- /dev/null +++ b/tools/sdk/ld/Makefile @@ -0,0 +1,19 @@ + +CPP = ../../../tools/xtensa-lx106-elf/bin/xtensa-lx106-elf-cpp +COMMON = eagle.app.v6.common.ld +WARN = "\/\* warning: AUTOGENERATED from $(COMMON)\*.h \*\/" + +.PHONY: vtables-dram vtables-iram + +all: + @echo "available rules:" + @echo " iram: move c++ vtables to iram (= default in git master repository)" + @echo " heap: move c++ vtables to heap" + +heap: + @(echo "$(WARN)"; $(CPP) -E -DVTABLES_IN_DRAM $(COMMON).h | grep -v '^#') > $(COMMON) + @echo "c++ vtables moved to heap" + +iram: + @(echo "$(WARN)"; $(CPP) -E -DVTABLES_IN_IRAM $(COMMON).h | grep -v '^#') > $(COMMON) + @echo "c++ vtables moved to iram" diff --git a/tools/sdk/ld/eagle.app.v6.common.ld b/tools/sdk/ld/eagle.app.v6.common.ld index cbc1ebf871..f7b4bf046b 100644 --- a/tools/sdk/ld/eagle.app.v6.common.ld +++ b/tools/sdk/ld/eagle.app.v6.common.ld @@ -1,5 +1,6 @@ -/* This linker script generated from xt-genldscripts.tpp for LSP . */ -/* Linker Script for ld -N */ +/* warning: AUTOGENERATED from eagle.app.v6.common.ld*.h */ + + PHDRS { @@ -11,7 +12,7 @@ PHDRS } -/* Default entry point: */ + ENTRY(call_user_start) EXTERN(_DebugExceptionVector) EXTERN(_DoubleExceptionVector) @@ -20,7 +21,7 @@ EXTERN(_NMIExceptionVector) EXTERN(_UserExceptionVector) EXTERN(core_version) PROVIDE(_memmap_vecbase_reset = 0x40000000); -/* Various memory-map dependent cache attribute settings: */ + _memmap_cacheattr_wb_base = 0x00000110; _memmap_cacheattr_wt_base = 0x00000110; _memmap_cacheattr_bp_base = 0x00000220; @@ -84,12 +85,15 @@ SECTIONS _data_end = ABSOLUTE(.); } >dram0_0_seg :dram0_0_phdr + + + + .irom0.text : ALIGN(4) { _irom0_text_start = ABSOLUTE(.); *(.ver_number) - *.c.o( EXCLUDE_FILE (umm_malloc.c.o) .literal*, \ - EXCLUDE_FILE (umm_malloc.c.o) .text*) + *.c.o( EXCLUDE_FILE (umm_malloc.c.o) .literal*, EXCLUDE_FILE (umm_malloc.c.o) .text* ) *.cpp.o(.literal*, .text*) *libc.a:(.literal .text .literal.* .text.*) *libm.a:(.literal .text .literal.* .text.*) @@ -154,7 +158,9 @@ SECTIONS *(.literal .text .literal.* .text.* .stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*) *.cpp.o(.iram.text) *.c.o(.iram.text) - *(.rodata._ZTV*) /* C++ vtables */ + + *(.rodata._ZTV*) + *(.fini.literal) *(.fini) *(.gnu.version) @@ -162,6 +168,7 @@ SECTIONS _etext = .; } >iram1_0_seg :iram1_0_phdr + .rodata : ALIGN(4) { _rodata_start = ABSOLUTE(.); @@ -177,7 +184,7 @@ SECTIONS *(.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)) @@ -188,7 +195,7 @@ SECTIONS KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors)) KEEP (*(SORT(.dtors.*))) KEEP (*(.dtors)) - /* C++ exception handlers table: */ + __XT_EXCEPTION_DESCS__ = ABSOLUTE(.); *(.xt_except_desc) *(.gnu.linkonce.h.*) @@ -196,7 +203,7 @@ SECTIONS *(.xt_except_desc_end) *(.dynamic) *(.gnu.version_d) - . = ALIGN(4); /* this table MUST be 4-byte aligned */ + . = ALIGN(4); _bss_table_start = ABSOLUTE(.); LONG(_bss_start) LONG(_bss_end) @@ -224,9 +231,9 @@ SECTIONS . = ALIGN (8); _bss_end = ABSOLUTE(.); _heap_start = ABSOLUTE(.); -/* _stack_sentry = ALIGN(0x8); */ + } >dram0_0_seg :dram0_0_bss_phdr -/* __stack = 0x3ffc8000; */ + .lit4 : ALIGN(4) { @@ -240,5 +247,5 @@ SECTIONS } -/* get ROM code address */ + INCLUDE "../ld/eagle.rom.addr.v6.ld" diff --git a/tools/sdk/ld/eagle.app.v6.common.ld.h b/tools/sdk/ld/eagle.app.v6.common.ld.h new file mode 100644 index 0000000000..bbc2004236 --- /dev/null +++ b/tools/sdk/ld/eagle.app.v6.common.ld.h @@ -0,0 +1,187 @@ +/* This linker script generated from xt-genldscripts.tpp for LSP . */ +/* Linker Script for ld -N */ + +PHDRS +{ + dport0_0_phdr PT_LOAD; + dram0_0_phdr PT_LOAD; + dram0_0_bss_phdr PT_LOAD; + iram1_0_phdr PT_LOAD; + irom0_0_phdr PT_LOAD; +} + + +/* Default entry point: */ +ENTRY(call_user_start) +EXTERN(_DebugExceptionVector) +EXTERN(_DoubleExceptionVector) +EXTERN(_KernelExceptionVector) +EXTERN(_NMIExceptionVector) +EXTERN(_UserExceptionVector) +EXTERN(core_version) +PROVIDE(_memmap_vecbase_reset = 0x40000000); +/* Various memory-map dependent cache attribute settings: */ +_memmap_cacheattr_wb_base = 0x00000110; +_memmap_cacheattr_wt_base = 0x00000110; +_memmap_cacheattr_bp_base = 0x00000220; +_memmap_cacheattr_unused_mask = 0xFFFFF00F; +_memmap_cacheattr_wb_trapnull = 0x2222211F; +_memmap_cacheattr_wba_trapnull = 0x2222211F; +_memmap_cacheattr_wbna_trapnull = 0x2222211F; +_memmap_cacheattr_wt_trapnull = 0x2222211F; +_memmap_cacheattr_bp_trapnull = 0x2222222F; +_memmap_cacheattr_wb_strict = 0xFFFFF11F; +_memmap_cacheattr_wt_strict = 0xFFFFF11F; +_memmap_cacheattr_bp_strict = 0xFFFFF22F; +_memmap_cacheattr_wb_allvalid = 0x22222112; +_memmap_cacheattr_wt_allvalid = 0x22222112; +_memmap_cacheattr_bp_allvalid = 0x22222222; +PROVIDE(_memmap_cacheattr_reset = _memmap_cacheattr_wb_trapnull); + +SECTIONS +{ + + .dport0.rodata : ALIGN(4) + { + _dport0_rodata_start = ABSOLUTE(.); + *(.dport0.rodata) + *(.dport.rodata) + _dport0_rodata_end = ABSOLUTE(.); + } >dport0_0_seg :dport0_0_phdr + + .dport0.literal : ALIGN(4) + { + _dport0_literal_start = ABSOLUTE(.); + *(.dport0.literal) + *(.dport.literal) + _dport0_literal_end = ABSOLUTE(.); + } >dport0_0_seg :dport0_0_phdr + + .dport0.data : ALIGN(4) + { + _dport0_data_start = ABSOLUTE(.); + *(.dport0.data) + *(.dport.data) + _dport0_data_end = ABSOLUTE(.); + } >dport0_0_seg :dport0_0_phdr + + .data : ALIGN(4) + { + _data_start = ABSOLUTE(.); + *(.data) + *(.data.*) + *(.gnu.linkonce.d.*) + *(.data1) + *(.sdata) + *(.sdata.*) + *(.gnu.linkonce.s.*) + *(.sdata2) + *(.sdata2.*) + *(.gnu.linkonce.s2.*) + *(.jcr) + . = ALIGN(4); + _Pri_3_HandlerAddress = ABSOLUTE(.); + _data_end = ABSOLUTE(.); + } >dram0_0_seg :dram0_0_phdr + +#ifdef VTABLES_IN_DRAM +#include "eagle.app.v6.common.ld.vtables.h" +#endif + + .irom0.text : ALIGN(4) + { + _irom0_text_start = ABSOLUTE(.); + *(.ver_number) + *.c.o( EXCLUDE_FILE (umm_malloc.c.o) .literal*, EXCLUDE_FILE (umm_malloc.c.o) .text* ) + *.cpp.o(.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) + *libsmartconfig.a:(.literal .text .literal.* .text.*) + *libstdc++.a:(.literal .text .literal.* .text.*) + *liblwip_gcc.a:(.literal .text .literal.* .text.*) + *liblwip_src.a:(.literal .text .literal.* .text.*) + *liblwip2.a:(.literal .text .literal.* .text.*) + *liblwip2_1460.a:(.literal .text .literal.* .text.*) + *libaxtls.a:(.literal .text .literal.* .text.*) + *libat.a:(.literal.* .text.*) + *libcrypto.a:(.literal.* .text.*) + *libespnow.a:(.literal.* .text.*) + *libjson.a:(.literal.* .text.*) + *liblwip.a:(.literal.* .text.*) + *libmesh.a:(.literal.* .text.*) + *libnet80211.a:(.literal.* .text.*) + *libsmartconfig.a:(.literal.* .text.*) + *libssl.a:(.literal.* .text.*) + *libupgrade.a:(.literal.* .text.*) + *libwpa.a:(.literal.* .text.*) + *libwpa2.a:(.literal.* .text.*) + *libwps.a:(.literal.* .text.*) + *(.irom0.literal .irom.literal .irom.text.literal .irom0.text .irom.text .irom.text.*) + _irom0_text_end = ABSOLUTE(.); + _flash_code_end = ABSOLUTE(.); + } >irom0_0_seg :irom0_0_phdr + + .text : ALIGN(4) + { + _stext = .; + _text_start = ABSOLUTE(.); + *(.UserEnter.text) + . = ALIGN(16); + *(.DebugExceptionVector.text) + . = ALIGN(16); + *(.NMIExceptionVector.text) + . = ALIGN(16); + *(.KernelExceptionVector.text) + LONG(0) + LONG(0) + LONG(0) + LONG(0) + . = ALIGN(16); + *(.UserExceptionVector.text) + LONG(0) + LONG(0) + LONG(0) + LONG(0) + . = ALIGN(16); + *(.DoubleExceptionVector.text) + LONG(0) + LONG(0) + LONG(0) + LONG(0) + . = ALIGN (16); + *(.entry.text) + *(.init.literal) + *(.init) + *(.literal .text .literal.* .text.* .stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*) + *.cpp.o(.iram.text) + *.c.o(.iram.text) +#ifdef VTABLES_IN_IRAM + *(.rodata._ZTV*) /* C++ vtables */ +#endif + *(.fini.literal) + *(.fini) + *(.gnu.version) + _text_end = ABSOLUTE(.); + _etext = .; + } >iram1_0_seg :iram1_0_phdr + +#ifdef VTABLES_IN_IRAM +#include "eagle.app.v6.common.ld.vtables.h" +#endif + + .lit4 : ALIGN(4) + { + _lit4_start = ABSOLUTE(.); + *(*.lit4) + *(.lit4.*) + *(.gnu.linkonce.lit4.*) + _lit4_end = ABSOLUTE(.); + } >iram1_0_seg :iram1_0_phdr + + +} + +/* get ROM code address */ +INCLUDE "../ld/eagle.rom.addr.v6.ld" diff --git a/tools/sdk/ld/eagle.app.v6.common.ld.vtables.h b/tools/sdk/ld/eagle.app.v6.common.ld.vtables.h new file mode 100644 index 0000000000..6649e08a25 --- /dev/null +++ b/tools/sdk/ld/eagle.app.v6.common.ld.vtables.h @@ -0,0 +1,65 @@ + .rodata : ALIGN(4) + { + _rodata_start = ABSOLUTE(.); + *(.sdk.version) + *(.rodata) + *(.rodata.*) + *(.gnu.linkonce.r.*) + *(.rodata1) + __XT_EXCEPTION_TABLE__ = ABSOLUTE(.); + *(.xt_except_table) + *(.gcc_except_table) + *(.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.*))) + KEEP (*(.dtors)) + /* C++ exception handlers table: */ + __XT_EXCEPTION_DESCS__ = ABSOLUTE(.); + *(.xt_except_desc) + *(.gnu.linkonce.h.*) + __XT_EXCEPTION_DESCS_END__ = ABSOLUTE(.); + *(.xt_except_desc_end) + *(.dynamic) + *(.gnu.version_d) + . = ALIGN(4); /* this table MUST be 4-byte aligned */ + _bss_table_start = ABSOLUTE(.); + LONG(_bss_start) + LONG(_bss_end) + _bss_table_end = ABSOLUTE(.); + _rodata_end = ABSOLUTE(.); + } >dram0_0_seg :dram0_0_phdr + + .bss ALIGN(8) (NOLOAD) : ALIGN(4) + { + . = ALIGN (8); + _bss_start = ABSOLUTE(.); + *(.dynsbss) + *(.sbss) + *(.sbss.*) + *(.gnu.linkonce.sb.*) + *(.scommon) + *(.sbss2) + *(.sbss2.*) + *(.gnu.linkonce.sb2.*) + *(.dynbss) + *(.bss) + *(.bss.*) + *(.gnu.linkonce.b.*) + *(COMMON) + . = ALIGN (8); + _bss_end = ABSOLUTE(.); + _heap_start = ABSOLUTE(.); +/* _stack_sentry = ALIGN(0x8); */ + } >dram0_0_seg :dram0_0_bss_phdr +/* __stack = 0x3ffc8000; */ From 1210abc1fd1f40f4e93cb65475b782bd644dc01d Mon Sep 17 00:00:00 2001 From: David Gauchard Date: Mon, 26 Mar 2018 13:58:32 +0200 Subject: [PATCH 2/3] ldscripts makefile: remove unneeded .PHONY --- tools/sdk/ld/Makefile | 2 -- 1 file changed, 2 deletions(-) diff --git a/tools/sdk/ld/Makefile b/tools/sdk/ld/Makefile index 52022fad1e..73d79a1eaa 100644 --- a/tools/sdk/ld/Makefile +++ b/tools/sdk/ld/Makefile @@ -3,8 +3,6 @@ CPP = ../../../tools/xtensa-lx106-elf/bin/xtensa-lx106-elf-cpp COMMON = eagle.app.v6.common.ld WARN = "\/\* warning: AUTOGENERATED from $(COMMON)\*.h \*\/" -.PHONY: vtables-dram vtables-iram - all: @echo "available rules:" @echo " iram: move c++ vtables to iram (= default in git master repository)" From e674f2a024232d56269c6feea188b885e6132048 Mon Sep 17 00:00:00 2001 From: david gauchard Date: Mon, 26 Mar 2018 22:51:32 +0200 Subject: [PATCH 3/3] ldscripts/cpp: add -CC option to preserve comments --- tools/sdk/ld/Makefile | 4 ++-- tools/sdk/ld/eagle.app.v6.common.ld | 21 +++++++++++---------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/tools/sdk/ld/Makefile b/tools/sdk/ld/Makefile index 73d79a1eaa..44225371ff 100644 --- a/tools/sdk/ld/Makefile +++ b/tools/sdk/ld/Makefile @@ -9,9 +9,9 @@ all: @echo " heap: move c++ vtables to heap" heap: - @(echo "$(WARN)"; $(CPP) -E -DVTABLES_IN_DRAM $(COMMON).h | grep -v '^#') > $(COMMON) + @(echo "$(WARN)"; $(CPP) -CC -E -DVTABLES_IN_DRAM $(COMMON).h | grep -v '^#') > $(COMMON) @echo "c++ vtables moved to heap" iram: - @(echo "$(WARN)"; $(CPP) -E -DVTABLES_IN_IRAM $(COMMON).h | grep -v '^#') > $(COMMON) + @(echo "$(WARN)"; $(CPP) -CC -E -DVTABLES_IN_IRAM $(COMMON).h | grep -v '^#') > $(COMMON) @echo "c++ vtables moved to iram" diff --git a/tools/sdk/ld/eagle.app.v6.common.ld b/tools/sdk/ld/eagle.app.v6.common.ld index f7b4bf046b..0fb87f4119 100644 --- a/tools/sdk/ld/eagle.app.v6.common.ld +++ b/tools/sdk/ld/eagle.app.v6.common.ld @@ -1,6 +1,6 @@ /* warning: AUTOGENERATED from eagle.app.v6.common.ld*.h */ - - +/* This linker script generated from xt-genldscripts.tpp for LSP . */ +/* Linker Script for ld -N */ PHDRS { @@ -12,7 +12,7 @@ PHDRS } - +/* Default entry point: */ ENTRY(call_user_start) EXTERN(_DebugExceptionVector) EXTERN(_DoubleExceptionVector) @@ -21,7 +21,7 @@ EXTERN(_NMIExceptionVector) EXTERN(_UserExceptionVector) EXTERN(core_version) PROVIDE(_memmap_vecbase_reset = 0x40000000); - +/* Various memory-map dependent cache attribute settings: */ _memmap_cacheattr_wb_base = 0x00000110; _memmap_cacheattr_wt_base = 0x00000110; _memmap_cacheattr_bp_base = 0x00000220; @@ -159,7 +159,7 @@ SECTIONS *.cpp.o(.iram.text) *.c.o(.iram.text) - *(.rodata._ZTV*) + *(.rodata._ZTV*) /* C++ vtables */ *(.fini.literal) *(.fini) @@ -184,7 +184,7 @@ SECTIONS *(.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)) @@ -195,7 +195,7 @@ SECTIONS KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors)) KEEP (*(SORT(.dtors.*))) KEEP (*(.dtors)) - + /* C++ exception handlers table: */ __XT_EXCEPTION_DESCS__ = ABSOLUTE(.); *(.xt_except_desc) *(.gnu.linkonce.h.*) @@ -203,7 +203,7 @@ SECTIONS *(.xt_except_desc_end) *(.dynamic) *(.gnu.version_d) - . = ALIGN(4); + . = ALIGN(4); /* this table MUST be 4-byte aligned */ _bss_table_start = ABSOLUTE(.); LONG(_bss_start) LONG(_bss_end) @@ -231,8 +231,9 @@ SECTIONS . = ALIGN (8); _bss_end = ABSOLUTE(.); _heap_start = ABSOLUTE(.); - +/* _stack_sentry = ALIGN(0x8); */ } >dram0_0_seg :dram0_0_bss_phdr +/* __stack = 0x3ffc8000; */ .lit4 : ALIGN(4) @@ -247,5 +248,5 @@ SECTIONS } - +/* get ROM code address */ INCLUDE "../ld/eagle.rom.addr.v6.ld"