diff --git a/cmake/linker/ld/target.cmake b/cmake/linker/ld/target.cmake index 8cd1c6c48ff..e31e0eb7c28 100644 --- a/cmake/linker/ld/target.cmake +++ b/cmake/linker/ld/target.cmake @@ -13,6 +13,15 @@ endif() set_ifndef(LINKERFLAGPREFIX -Wl) +if(CONFIG_EXCEPTIONS) + # When building with C++ Exceptions, it is important that crtbegin and crtend + # are linked at specific locations. + # The location is so important that we cannot let this be controlled by normal + # link libraries, instead we must control the link command specifically as + # part of toolchain. + set(CMAKE_CXX_LINK_EXECUTABLE + " ${LIBGCC_DIR}/crtbegin.o -o ${LIBGCC_DIR}/crtend.o") +endif() # Run $LINKER_SCRIPT file through the C preprocessor, producing ${linker_script_gen} # NOTE: ${linker_script_gen} will be produced at build-time; not at configure-time diff --git a/include/arch/riscv/common/linker.ld b/include/arch/riscv/common/linker.ld index f5db23cd278..106658b056f 100644 --- a/include/arch/riscv/common/linker.ld +++ b/include/arch/riscv/common/linker.ld @@ -130,7 +130,6 @@ SECTIONS *(.text) *(".text.*") *(.gnu.linkonce.t.*) - *(.eh_frame) #include } GROUP_LINK_IN(ROMABLE_REGION) diff --git a/include/arch/x86/ia32/linker.ld b/include/arch/x86/ia32/linker.ld index eafe1bc089c..cc8e7671295 100644 --- a/include/arch/x86/ia32/linker.ld +++ b/include/arch/x86/ia32/linker.ld @@ -316,8 +316,6 @@ SECTIONS *(.text) *(".text.*") *(.gnu.linkonce.t.*) - *(.eh_frame_hdr) - *(.eh_frame) *(.init) *(.fini) *(.eini) diff --git a/include/linker/cplusplus-ram.ld b/include/linker/cplusplus-ram.ld index fd696df5938..43d3ef1ce04 100644 --- a/include/linker/cplusplus-ram.ld +++ b/include/linker/cplusplus-ram.ld @@ -9,4 +9,24 @@ { *(.gcc_except_table .gcc_except_table.*) } GROUP_DATA_LINK_IN(RAMABLE_REGION, ROMABLE_REGION) -#endif + +#if defined (CONFIG_EXCEPTIONS) + SECTION_PROLOGUE(.eh_frame_hdr,,) + { + *(.eh_frame_hdr) + } + + SECTION_PROLOGUE(.eh_frame,,) + { + KEEP (*(EXCLUDE_FILE (*crtend.o) .eh_frame)) + KEEP (*(.eh_frame)) + } GROUP_LINK_IN(ROMABLE_REGION) + + SECTION_PROLOGUE(.tm_clone_table,,) + { + KEEP (*(EXCLUDE_FILE (*crtend.o) .tm_clone_table)) + KEEP (*(.tm_clone_table)) + } GROUP_DATA_LINK_IN(RAMABLE_REGION, ROMABLE_REGION) +#endif /* CONFIG_EXCEPTIONS */ + +#endif /* CONFIG_CPLUSPLUS */ diff --git a/soc/xtensa/sample_controller/linker.ld b/soc/xtensa/sample_controller/linker.ld index 215c2f7247e..76edfe3919a 100644 --- a/soc/xtensa/sample_controller/linker.ld +++ b/soc/xtensa/sample_controller/linker.ld @@ -534,6 +534,11 @@ SECTIONS #include + .tm_clone_table : + { + *(.tm_clone_table) + } >sram0_seg :sram0_phdr + .bss (NOLOAD) : ALIGN(8) { . = ALIGN (8);