[ox] Fix FreeBSD build

This commit is contained in:
Gary Talent 2023-08-08 23:57:09 -05:00
parent ea266da691
commit e5a7d8c0a9
5 changed files with 20 additions and 4 deletions

View File

@ -1,3 +1,6 @@
set(OX_FREEBSD ${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD")
set(OX_LINUX ${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
if(OX_USE_STDLIB)
add_subdirectory(oc)
endif()

View File

@ -16,7 +16,7 @@ if(NOT MSVC)
endif()
if(NOT OX_BARE_METAL)
if(NOT APPLE AND NOT MSVC)
if(NOT APPLE AND NOT MSVC AND NOT ${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD")
target_link_libraries(
OxFS PUBLIC
stdc++fs

View File

@ -20,6 +20,7 @@ target_link_libraries(
OxLogConn PUBLIC
OxStd
OxMetalClaw
$<$<BOOL:OX_FREEBSD>:pthread>
)
install(

View File

@ -44,7 +44,7 @@ add_library(
if(NOT MSVC)
target_compile_options(OxStd PRIVATE -Wsign-conversion)
target_compile_options(OxStd PRIVATE -Wconversion)
if(UNIX AND NOT APPLE)
if(${OX_LINUX})
target_compile_options(OxStd PUBLIC -export-dynamic)
#target_link_options(OxStd PUBLIC -W1,-E)
endif()
@ -74,6 +74,7 @@ endif()
target_link_libraries(
OxStd PUBLIC
$<$<CXX_COMPILER_ID:GNU>:gcc>
$<$<BOOL:${OX_FREEBSD}>:execinfo>
OxTraceHook
)

View File

@ -18,6 +18,7 @@
#endif
#endif
#include "defines.hpp"
#include "string.hpp"
#include "trace.hpp"
#include "vector.hpp"
@ -32,7 +33,12 @@ static auto symbolicate([[maybe_unused]]void **frames,
using StrT = BasicString<100>;
Vector<StrT, 30> out;
#if __has_include(<cxxabi.h>) && __has_include(<execinfo.h>)
const auto mangledSymbols = backtrace_symbols(frames, static_cast<int>(frameCnt));
#ifdef OX_OS_FreeBSD
using FrameCnt_t = unsigned;
#else
using FrameCnt_t = signed;
#endif
const auto mangledSymbols = backtrace_symbols(frames, static_cast<FrameCnt_t>(frameCnt));
for (auto i = 0u; i < frameCnt; ++i) {
Dl_info info;
if (dladdr(frames[i], &info) && info.dli_sname) {
@ -55,7 +61,12 @@ void printStackTrace([[maybe_unused]]unsigned shave) noexcept {
#if defined(OX_USE_STDLIB) && __has_include(<unistd.h>) && __has_include(<execinfo.h>)
constexpr auto FrameCnt = 100;
Vector<void*, FrameCnt> frames(FrameCnt);
frames.resize(static_cast<std::size_t>(backtrace(frames.data(), static_cast<int>(frames.size()))));
#ifdef OX_OS_FreeBSD
using FrameCnt_t = unsigned;
#else
using FrameCnt_t = signed;
#endif
frames.resize(static_cast<std::size_t>(backtrace(frames.data(), static_cast<FrameCnt_t>(frames.size()))));
if (frames.size() - shave > 2) {
const auto symbolicatedStacktrace = symbolicate(frames.data() + shave, frames.size() - shave, "\t");
oxErr("Stacktrace:\n");