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

Cpp exception #34357

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,7 @@ if(CONFIG_USERSPACE)
)

set(APP_SMEM_UNALIGNED_LIB app_smem_unaligned_output_obj_renamed_lib)
add_executable( app_smem_unaligned_prebuilt misc/empty_file.c)
add_executable( app_smem_unaligned_prebuilt ${LIBGCC_DIR}/crtbeing.o misc/empty_file.c)
Copy link
Contributor

Choose a reason for hiding this comment

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

typo

toolchain_ld_link_elf(
TARGET_ELF app_smem_unaligned_prebuilt
OUTPUT_MAP ${PROJECT_BINARY_DIR}/app_smem_unaligned_prebuilt.map
Expand Down Expand Up @@ -1081,7 +1081,7 @@ set_property(TARGET
)

# FIXME: Is there any way to get rid of empty_file.c?
add_executable( ${ZEPHYR_PREBUILT_EXECUTABLE} misc/empty_file.c)
add_executable( ${ZEPHYR_PREBUILT_EXECUTABLE} ${LIBGCC_DIR}/crtbegin.o misc/empty_file.c)
toolchain_ld_link_elf(
TARGET_ELF ${ZEPHYR_PREBUILT_EXECUTABLE}
OUTPUT_MAP ${PROJECT_BINARY_DIR}/${ZEPHYR_PREBUILT_EXECUTABLE}.map
Expand Down Expand Up @@ -1133,7 +1133,7 @@ else()
${ZEPHYR_INCLUDE_DIRS}
)

add_executable( ${ZEPHYR_FINAL_EXECUTABLE} misc/empty_file.c ${GKSF})
add_executable( ${ZEPHYR_FINAL_EXECUTABLE} ${LIBGCC_DIR}/crtbegin.o misc/empty_file.c ${GKSF})
toolchain_ld_link_elf(
TARGET_ELF ${ZEPHYR_FINAL_EXECUTABLE}
OUTPUT_MAP ${PROJECT_BINARY_DIR}/${ZEPHYR_FINAL_EXECUTABLE}.map
Expand Down
8 changes: 7 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 Expand Up @@ -177,6 +176,13 @@ SECTIONS
_app_smem_size = _app_smem_end - _app_smem_start;
_app_smem_rom_start = LOADADDR(_APP_SMEM_SECTION_NAME);
#endif /* CONFIG_USERSPACE */
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_DATA_PROLOGUE(_BSS_SECTION_NAME,(NOLOAD),)
{
Expand Down
11 changes: 9 additions & 2 deletions include/arch/x86/ia32/linker.ld
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,6 @@ SECTIONS
*(.text)
*(".text.*")
*(.gnu.linkonce.t.*)
*(.eh_frame_hdr)
*(.eh_frame)
*(.init)
*(.fini)
*(.eini)
Expand Down Expand Up @@ -209,13 +207,22 @@ SECTIONS
_app_smem_rom_start = LOADADDR(_APP_SMEM_SECTION_NAME);
_app_smem_num_words = _app_smem_size >> 2;
#endif /* CONFIG_USERSPACE */
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(_BSS_SECTION_NAME, (NOLOAD),)
{
MMU_PAGE_ALIGN_PERM
#if !defined(CONFIG_USERSPACE)
_image_ram_start = .;
#endif


/*
* For performance, BSS section is forced to be both 4 byte aligned and
* a multiple of 4 bytes.
Expand Down
4 changes: 4 additions & 0 deletions lib/libc/newlib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,7 @@ if(CONFIG_NEWLIB_LIBC_NANO)
-specs=nano.specs
)
endif()

zephyr_link_libraries(
${LIBGCC_DIR}/crtend.o
)
2 changes: 1 addition & 1 deletion samples/hello_world/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ cmake_minimum_required(VERSION 3.13.1)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(hello_world)

target_sources(app PRIVATE src/main.c)
target_sources(app PRIVATE src/main.cpp)
7 changes: 7 additions & 0 deletions samples/hello_world/prj.conf
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
# nothing here
CONFIG_NEWLIB_LIBC=y
CONFIG_CPLUSPLUS=y
CONFIG_LIB_CPLUSPLUS=y
CONFIG_STD_CPP17=y
CONFIG_EXCEPTIONS=y
CONFIG_NEWLIB_LIBC_NANO=n
CONFIG_MAIN_STACK_SIZE=4096
13 changes: 0 additions & 13 deletions samples/hello_world/src/main.c

This file was deleted.

31 changes: 31 additions & 0 deletions samples/hello_world/src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (c) 2012-2014 Wind River Systems, Inc.
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr.h>
#include <sys/printk.h>

void main(void)
{
printk("Hello World! %s\n", CONFIG_BOARD);

try
{
printk("Throwing integer exception 20.\n");
throw 20;
}
catch (int e)
{
printk("An integer exception occurred and was handled.\n");
}
catch (bool e)
{
printk("A bool exception occurred and was handled.\n");
}
catch (void* e)
{
printk("A C++ void exception occurred and was handled.\n");
}
}