Skip to content

Commit

Permalink
Port libunwind changes
Browse files Browse the repository at this point in the history
  • Loading branch information
miscco committed Sep 8, 2022
1 parent 4fe8bd0 commit 377a956
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 15 deletions.
6 changes: 5 additions & 1 deletion libunwind/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,11 @@ if (LIBUNWIND_USES_ARM_EHABI AND NOT CXX_SUPPORTS_FUNWIND_TABLES_FLAG)
endif()

add_cxx_compile_flags_if_supported(-fno-exceptions)
add_cxx_compile_flags_if_supported(-fno-rtti)
if (CMAKE_C_COMPILER_ID STREQUAL "PGI")
add_cxx_compile_flags_if_supported(--no_rtti)
else()
add_cxx_compile_flags_if_supported(-fno-rtti)
endif()

# Ensure that we don't depend on C++ standard library.
if (CXX_SUPPORTS_NOSTDINCXX_FLAG)
Expand Down
2 changes: 2 additions & 0 deletions libunwind/src/AddressSpace.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,9 @@ inline bool LocalAddressSpace::findUnwindSections(pint_t targetAddr,
return static_cast<bool>(found);
#endif

#ifndef __PGIC__
return false;
#endif
}

inline bool LocalAddressSpace::findOtherFDE(pint_t targetAddr, pint_t &fde) {
Expand Down
13 changes: 12 additions & 1 deletion libunwind/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,14 @@ set(LIBUNWIND_C_SOURCES
UnwindLevel1-gcc-ext.c
Unwind-sjlj.c
)
set(C99_FLAG "-std=c99")
if (CMAKE_CXX_COMPILER_ID STREQUAL PGI)
set(C99_FLAG "-c99")
endif()

set_source_files_properties(${LIBUNWIND_C_SOURCES}
PROPERTIES
COMPILE_FLAGS "-std=c99")
COMPILE_FLAGS ${C99_FLAG})

set(LIBUNWIND_ASM_SOURCES
UnwindRegistersRestore.S
Expand Down Expand Up @@ -139,6 +144,9 @@ set(CMAKE_CXX_IMPLICIT_LINK_LIBRARIES "")
add_library(unwind_shared_objects OBJECT EXCLUDE_FROM_ALL ${LIBUNWIND_SOURCES} ${LIBUNWIND_HEADERS})
if(CMAKE_C_COMPILER_ID STREQUAL MSVC)
target_compile_options(unwind_shared_objects PRIVATE /GR-)
# Check the CXX ID because CMake is perplexed about NVCXX as the C compiler.
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL PGI)
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL NVCXX)
else()
target_compile_options(unwind_shared_objects PRIVATE -fno-rtti)
endif()
Expand Down Expand Up @@ -176,6 +184,9 @@ endif()
add_library(unwind_static_objects OBJECT EXCLUDE_FROM_ALL ${LIBUNWIND_SOURCES} ${LIBUNWIND_HEADERS})
if(CMAKE_C_COMPILER_ID STREQUAL MSVC)
target_compile_options(unwind_static_objects PRIVATE /GR-)
# Check the CXX ID because CMake is perplexed about NVCXX as the C compiler.
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL PGI)
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL NVCXX)
else()
target_compile_options(unwind_static_objects PRIVATE -fno-rtti)
endif()
Expand Down
2 changes: 2 additions & 0 deletions libunwind/src/DwarfParser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,9 @@ bool CFI_Parser<A>::parseFDEInstructions(A &addressSpace,
break;

#else
#ifndef __PGIC__
(void)arch;
#endif
#endif

default:
Expand Down
14 changes: 3 additions & 11 deletions libunwind/src/UnwindCursor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,9 +424,9 @@ template <typename A> class UnwindSectionLsdaArray {

class _LIBUNWIND_HIDDEN AbstractUnwindCursor {
public:
// NOTE: provide a class specific placement deallocation function (S5.3.4 p20)
// This avoids an unnecessary dependency to libc++abi.
void operator delete(void *, size_t) {}
static void * operator new(size_t, void *p) { return p; }
static void operator delete(void *, size_t) {}
static void operator delete(void *, void *) {}

virtual ~AbstractUnwindCursor() {}
virtual bool validReg(int) { _LIBUNWIND_ABORT("validReg not implemented"); }
Expand Down Expand Up @@ -509,10 +509,6 @@ class UnwindCursor : public AbstractUnwindCursor {
DISPATCHER_CONTEXT *getDispatcherContext() { return &_dispContext; }
void setDispatcherContext(DISPATCHER_CONTEXT *disp) { _dispContext = *disp; }

// libunwind does not and should not depend on C++ library which means that we
// need our own defition of inline placement new.
static void *operator new(size_t, UnwindCursor<A, R> *p) { return p; }

private:

pint_t getLastPC() const { return _dispContext.ControlPc; }
Expand Down Expand Up @@ -945,10 +941,6 @@ class UnwindCursor : public AbstractUnwindCursor{
virtual void *get_registers() { return &_registers; }
#endif

// libunwind does not and should not depend on C++ library which means that we
// need our own defition of inline placement new.
static void *operator new(size_t, UnwindCursor<A, R> *p) { return p; }

private:

#if defined(_LIBUNWIND_ARM_EHABI)
Expand Down
2 changes: 2 additions & 0 deletions libunwind/src/UnwindLevel1.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,11 @@ unwind_phase2(unw_context_t *uc, unw_cursor_t *cursor, _Unwind_Exception *except
}
}

#ifndef __PGIC__
// Clean up phase did not resume at the frame that the search phase
// said it would...
return _URC_FATAL_PHASE2_ERROR;
#endif
}

static _Unwind_Reason_Code
Expand Down
4 changes: 4 additions & 0 deletions libunwind/src/assembly.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
#ifndef UNWIND_ASSEMBLY_H
#define UNWIND_ASSEMBLY_H

#if defined(__PGIC__) && defined(__linux__)
#define __ELF__
#endif

#if defined(__linux__) && defined(__CET__)
#include <cet.h>
#define _LIBUNWIND_CET_ENDBR _CET_ENDBR
Expand Down
9 changes: 9 additions & 0 deletions libunwind/src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@
#endif
#endif

#if defined(__PGIC__)
#undef _LIBUNWIND_HIDE_SYMBOLS
#define _LIBUNWIND_HIDE_SYMBOLS
#endif

#if defined(_LIBUNWIND_HIDE_SYMBOLS)
// The CMake file passes -fvisibility=hidden to control ELF/Mach-O visibility.
#define _LIBUNWIND_EXPORT
Expand All @@ -73,6 +78,10 @@
#define XSTR(a) STR(a)
#define SYMBOL_NAME(name) XSTR(__USER_LABEL_PREFIX__) #name

#if defined(__PGIC__) && defined(__linux__)
#define __ELF__
#endif

#if defined(__APPLE__)
#if defined(_LIBUNWIND_HIDE_SYMBOLS)
#define _LIBUNWIND_ALIAS_VISIBILITY(name) __asm__(".private_extern " name);
Expand Down
4 changes: 2 additions & 2 deletions libunwind/src/libunwind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ _LIBUNWIND_HIDDEN int __unw_init_local(unw_cursor_t *cursor,
#elif defined(__mips64)
# define REGISTER_KIND Registers_mips_newabi
#elif defined(__mips__)
# warning The MIPS architecture is not supported with this ABI and environment!
# error The MIPS architecture is not supported with this ABI and environment!
#elif defined(__sparc__) && defined(__arch64__)
#define REGISTER_KIND Registers_sparc64
#elif defined(__sparc__)
Expand All @@ -81,7 +81,7 @@ _LIBUNWIND_HIDDEN int __unw_init_local(unw_cursor_t *cursor,
# error Architecture not supported
#endif
// Use "placement new" to allocate UnwindCursor in the cursor buffer.
new (reinterpret_cast<UnwindCursor<LocalAddressSpace, REGISTER_KIND> *>(cursor))
new (static_cast<void *>(cursor))
UnwindCursor<LocalAddressSpace, REGISTER_KIND>(
context, LocalAddressSpace::sThisAddressSpace);
#undef REGISTER_KIND
Expand Down

0 comments on commit 377a956

Please sign in to comment.