From 7e47ef281eccd7d1391bcdcf92affd7493c0dbd3 Mon Sep 17 00:00:00 2001 From: Stephanos Ioannidis Date: Sun, 6 Jun 2021 02:12:14 +0900 Subject: [PATCH] linker: cpp: Fix C++ exception handling info section linking The `.eh_frame_hdr` and `.eh_frame` ROM sections, which contain read- only C++ exception handling information, are currently specified in `cplusplus-ram.ld`, and this can cause the linker output location counter to take a ROM region address while in the RAM region. This commit relocates these sections to `cplusplus-rom.ld` in order to prevent the linker output location counter from getting corrupted. For more details, refer to the issue #35972. Signed-off-by: Stephanos Ioannidis --- include/linker/cplusplus-ram.ld | 11 ----------- include/linker/cplusplus-rom.ld | 16 +++++++++++++++- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/include/linker/cplusplus-ram.ld b/include/linker/cplusplus-ram.ld index 7a98e12997c..eacb3bfb8a6 100644 --- a/include/linker/cplusplus-ram.ld +++ b/include/linker/cplusplus-ram.ld @@ -11,17 +11,6 @@ } GROUP_DATA_LINK_IN(RAMABLE_REGION, ROMABLE_REGION) #if defined (CONFIG_EXCEPTIONS) - SECTION_PROLOGUE(.eh_frame_hdr,,) - { - *(.eh_frame_hdr) - } - - SECTION_PROLOGUE(.eh_frame,,) - { - KEEP (*(SORT_NONE(EXCLUDE_FILE (*crtend.o) .eh_frame))) - KEEP (*(SORT_NONE(.eh_frame))) - } GROUP_LINK_IN(ROMABLE_REGION) - SECTION_PROLOGUE(.tm_clone_table,,) { KEEP (*(SORT_NONE(EXCLUDE_FILE (*crtend.o) .tm_clone_table))) diff --git a/include/linker/cplusplus-rom.ld b/include/linker/cplusplus-rom.ld index d4b730a591c..a8a0bb07c78 100644 --- a/include/linker/cplusplus-rom.ld +++ b/include/linker/cplusplus-rom.ld @@ -9,4 +9,18 @@ { *(.gcc_except_table .gcc_except_table.*) } GROUP_ROM_LINK_IN(RAMABLE_REGION, ROMABLE_REGION) -#endif + +#if defined (CONFIG_EXCEPTIONS) + SECTION_PROLOGUE(.eh_frame_hdr,,) + { + *(.eh_frame_hdr) + } GROUP_ROM_LINK_IN(RAMABLE_REGION, ROMABLE_REGION) + + SECTION_PROLOGUE(.eh_frame,,) + { + KEEP (*(SORT_NONE(EXCLUDE_FILE (*crtend.o) .eh_frame))) + KEEP (*(SORT_NONE(.eh_frame))) + } GROUP_ROM_LINK_IN(RAMABLE_REGION, ROMABLE_REGION) +#endif /* CONFIG_EXCEPTIONS */ + +#endif /* CONFIG_CPLUSPLUS */