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

cmake: c++ exceptions linking support #35647

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 9 additions & 0 deletions cmake/linker/ld/target.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ find_program(CMAKE_LINKER ${CROSS_COMPILE}ld PATHS ${TOOLCHAIN_HOME} NO

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.
Copy link
Contributor

Choose a reason for hiding this comment

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

FWIW: trying to do this on the command line is fragile. Really this needs to happen in a linker script. Also I wouldn't be surprised if the rules are platform-dependent.

Copy link
Collaborator

Choose a reason for hiding this comment

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

For GCC this has normally be done via a spec file. @andyross Have you seen anywhere that this is done via linker script?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

how will you tell the linker which objects (crtbegin.o and crtend.o) to link in a linker file ?
Not to mention that the position of those objects on the linker invocation is important.

This is why this is to be considered a toolchain (linker) setting.

set(CMAKE_CXX_LINK_EXECUTABLE
"<CMAKE_CXX_COMPILER> <FLAGS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> ${LIBGCC_DIR}/crtbegin.o <OBJECTS> -o <TARGET> <LINK_LIBRARIES> ${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
Expand Down
1 change: 0 additions & 1 deletion include/arch/riscv/common/linker.ld
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ SECTIONS
*(.text)
*(".text.*")
*(.gnu.linkonce.t.*)
*(.eh_frame)
#include <linker/kobject-text.ld>
} GROUP_LINK_IN(ROMABLE_REGION)

Expand Down
2 changes: 0 additions & 2 deletions include/arch/x86/ia32/linker.ld
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,6 @@ SECTIONS
*(.text)
*(".text.*")
*(.gnu.linkonce.t.*)
*(.eh_frame_hdr)
*(.eh_frame)
*(.init)
*(.fini)
*(.eini)
Expand Down
22 changes: 21 additions & 1 deletion include/linker/cplusplus-ram.ld
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
5 changes: 5 additions & 0 deletions soc/xtensa/sample_controller/linker.ld
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,11 @@ SECTIONS

#include <linker/common-ram.ld>

.tm_clone_table :
{
*(.tm_clone_table)
} >sram0_seg :sram0_phdr

.bss (NOLOAD) : ALIGN(8)
{
. = ALIGN (8);
Expand Down
2 changes: 1 addition & 1 deletion tests/subsys/cpp/libcxx/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ CONFIG_CPLUSPLUS=y
CONFIG_LIB_CPLUSPLUS=y
CONFIG_STD_CPP17=y
CONFIG_ZTEST=y
CONFIG_ZTEST_STACKSIZE=2048
CONFIG_ZTEST_STACKSIZE=4096
4 changes: 2 additions & 2 deletions tests/subsys/cpp/libcxx/testcase.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ tests:
tags: cpp
cpp.libcxx.exceptions:
# FIXME: change when issue is resolved #32448
platform_allow: mps2_an385
platform_allow: mps2_an385 qemu_arc_em qemu_arc_hs qemu_cortex_m0 qemu_cortex_m3 qemu_cortex_r5 qemu_riscv32 qemu_x86 qemu_xtensa
toolchain_exclude: xcc
min_flash: 54
tags: cpp
timeout: 5
timeout: 30
extra_configs:
- CONFIG_EXCEPTIONS=y