Skip to content
Closed
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
20 changes: 14 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@

cmake_minimum_required(VERSION 3.15)

project(libhal-exceptions LANGUAGES CXX)
set(CMAKE_COLOR_DIAGNOSTICS ON)

project(hal-exceptions LANGUAGES CXX)

message("Runtime: '${RUNTIME}', selected")

if("${RUNTIME}" STREQUAL "ARM_CORTEX_GCC")
set(SOURCE_LIST src/builtin/gcc/impl.cpp)
set(SOURCE_LIST src/builtin/gcc/override.cpp)
elseif("${RUNTIME}" STREQUAL "ARM_CORTEX_LLVM")
set(SOURCE_LIST src/builtin/llvm/override.cpp)
elseif("${RUNTIME}" STREQUAL "ARM_CORTEX_ESTELL")
set(SOURCE_LIST
src/arm_cortex/estell/exception.cpp
Expand All @@ -29,7 +34,7 @@ message(FATAL "Invalid Exception RUNTIME: '${RUNTIME}' provided!")
endif()

libhal_make_library(
LIBRARY_NAME libhal-exceptions
LIBRARY_NAME hal-exceptions

SOURCES
${SOURCE_LIST}
Expand All @@ -39,13 +44,16 @@ libhal_make_library(

LINK_LIBRARIES
libhal::util

COMPILE_FLAGS
-Wno-error,-Wgnu-label-as-value
)

target_compile_options(libhal-exceptions PRIVATE -save-temps=obj)
target_compile_options(hal-exceptions PRIVATE -save-temps=obj)

if(NOT ${CMAKE_CROSSCOMPILING})
libhal_unit_test(
LIBRARY_NAME libhal-exceptions
LIBRARY_NAME hal-exceptions

SOURCES
tests/main.test.cpp
Expand All @@ -58,4 +66,4 @@ libhal_unit_test(
LINK_LIBRARIES
libhal::util
)
endif()
endif()
67 changes: 37 additions & 30 deletions conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
from conan.tools.cmake import CMake, cmake_layout
from conan.tools.files import copy
from conan.tools.build import check_min_cppstd
import os
from conan.errors import ConanException
from pathlib import Path

required_conan_version = ">=2.0.14"

Expand Down Expand Up @@ -62,12 +63,15 @@ def _is_arm_cortex(self):

@property
def _runtime_select(self):
if self._is_arm_cortex and self.options.runtime == "builtin":
return "ARM_CORTEX_GCC"
elif self._is_arm_cortex and self.options.runtime == "estell":
if self.options.runtime == "builtin":
if self.settings.compiler == "gcc":
return "ARM_CORTEX_GCC"
if self.settings.compiler == "clang":
return "ARM_CORTEX_LLVM"
elif self.options.runtime == "estell":
return "ARM_CORTEX_ESTELL"
else:
return "ARM_CORTEX_GCC"
raise ConanException(
f"Invalid runtime ({self.options.runtime}) & compiler ({self.settings.compiler}) selected")

def validate(self):
if self.settings.get_safe("compiler.cppstd"):
Expand All @@ -77,7 +81,7 @@ def layout(self):
cmake_layout(self)

def build_requirements(self):
self.tool_requires("cmake/3.27.1")
self.tool_requires("cmake/[>=3.38.0 <5.0.0]")
self.tool_requires("libhal-cmake-util/[^4.0.3]")
self.test_requires("boost-ext-ut/2.1.0")

Expand All @@ -93,57 +97,58 @@ def build(self):
def package(self):
copy(self,
"LICENSE",
dst=os.path.join(self.package_folder, "licenses"),
dst=Path(self.package_folder) / "licenses",
src=self.source_folder)
copy(self,
"*.h",
dst=os.path.join(self.package_folder, "include"),
src=os.path.join(self.source_folder, "include"))
dst=Path(self.package_folder) / "include",
src=Path(self.source_folder) / "include")
copy(self,
"*.hpp",
dst=os.path.join(self.package_folder, "include"),
src=os.path.join(self.source_folder, "include"))
dst=Path(self.package_folder) / "include",
src=Path(self.source_folder) / "include")
copy(self,
"*.ld",
dst=os.path.join(self.package_folder, "linker_scripts"),
src=os.path.join(self.source_folder, "linker_scripts"))
dst=Path(self.package_folder) / "linker_scripts",
src=Path(self.source_folder) / "linker_scripts")

cmake = CMake(self)
cmake.install()

def package_info(self):
self.cpp_info.libs = ["libhal-exceptions"]
self.cpp_info.libs = ["hal-exceptions"]
self.cpp_info.set_property("cmake_target_name", "libhal::exceptions")
lib_path = os.path.join(self.package_folder,
'lib', 'liblibhal-exceptions.a')
using_wrap = False
self.cpp_info.defines = []

if self.options.runtime == "estell":
using_wrap = True
# If the platform matches the linker script, just use that linker
# script
self.cpp_info.exelinkflags.extend([
"-fexceptions",
"-L" + os.path.join(self.package_folder, "linker_scripts"),
'-Wl,-Tarm-none-eabi-gcc-14.2_discard.ld',
"-L" + str(Path(self.package_folder) / "linker_scripts"),
# '-Wl,-Tarm-none-eabi-gcc-14.2_discard.ld',
"-Wl,--wrap=__cxa_throw",
"-Wl,--wrap=__cxa_rethrow",
"-Wl,--wrap=__cxa_end_catch",
"-Wl,--wrap=__cxa_begin_catch",
"-Wl,--wrap=__cxa_end_cleanup",
"-Wl,--wrap=_Unwind_Resume",
# "-Wl,--wrap=__gnu_unwind_pr_common",
# "-Wl,--wrap=__aeabi_unwind_cpp_pr0",
# "-Wl,--wrap=__aeabi_unwind_cpp_pr1",
# "-Wl,--wrap=__aeabi_unwind_cpp_pr2",
# "-Wl,--wrap=_sig_func",
# "-Wl,--wrap=__gxx_personality_v0",
# "-Wl,--wrap=__gcc_personality_v0",
# "-Wl,--wrap=deregister_tm_clones",
# "-Wl,--wrap=register_tm_clones",
])
self.cpp_info.defines.append("LIBHAL_ESTELL_EXCEPTIONS")

if self.settings.compiler == "clang":
using_wrap = True
# If the platform matches the linker script, just use that linker
# script
self.cpp_info.exelinkflags.extend([
"-fexceptions",
"-Wl,--wrap=__cxa_terminate_handler",
])

# Keep this for now, will update this for the runtime select
if self._is_arm_cortex:
if self._is_arm_cortex and self.settings.compiler == "gcc":
using_wrap = True
self.cpp_info.exelinkflags.extend([
"-Wl,--wrap=__cxa_allocate_exception",
Expand All @@ -152,9 +157,11 @@ def package_info(self):
])

if using_wrap:
package_folder = Path(self.package_folder)
lib_path = package_folder / 'lib' / 'libhal-exceptions.a'
self.cpp_info.exelinkflags.extend([
# Ensure that all symbols are added to the linker's symbol table
"-Wl,--whole-archive",
lib_path,
str(lib_path),
"-Wl,--no-whole-archive",
])
16 changes: 2 additions & 14 deletions demos/main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#include <span>

#include <libhal-exceptions/control.hpp>
#include <exception>

#include <resource_list.hpp>

Expand All @@ -13,17 +11,7 @@ void terminate_handler()

int main()
{
hal::set_terminate(terminate_handler);
std::set_terminate(terminate_handler);
initialize_platform();
application();
}

// NOLINTBEGIN(bugprone-reserved-identifier)
// NOLINTBEGIN(readability-identifier-naming)
namespace ke::__except_abi {
std::span<std::uint32_t> near_point_descriptor{};
std::span<std::uint32_t> normal_table{};
std::span<std::uint32_t> small_table{};
} // namespace ke::__except_abi
// NOLINTEND(readability-identifier-naming)
// NOLINTEND(bugprone-reserved-identifier)
1 change: 0 additions & 1 deletion demos/platforms/lpc4078.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

#include <libhal-arm-mcu/dwt_counter.hpp>
#include <libhal-arm-mcu/lpc40/clock.hpp>
#include <libhal-exceptions/control.hpp>

#include <resource_list.hpp>

Expand Down
1 change: 0 additions & 1 deletion demos/platforms/stm32f103c8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

#include <libhal-arm-mcu/dwt_counter.hpp>
#include <libhal-arm-mcu/stm32f1/clock.hpp>
#include <libhal-exceptions/control.hpp>

#include <resource_list.hpp>

Expand Down
53 changes: 0 additions & 53 deletions include/libhal-exceptions/control.hpp

This file was deleted.

8 changes: 8 additions & 0 deletions include/libhal-exceptions/module.cppm
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

module;

#include "new.hpp"

export module libhal_exceptions;

export ke::exception_allocation_tag;
19 changes: 19 additions & 0 deletions include/libhal-exceptions/new.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once

#include <cstddef>

#include <new>

namespace ke {
struct exception_allocation_tag
{};
} // namespace ke

void* operator new(std::size_t p_size,
std::align_val_t p_align,
ke::exception_allocation_tag);

void operator delete(void* p_ptr,
std::size_t p_size,
std::align_val_t p_align,
ke::exception_allocation_tag);
Loading
Loading