diff options
author | Adeel Mujahid <3840695+am11@users.noreply.github.com> | 2022-06-29 02:43:45 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-28 19:43:45 -0400 |
commit | cfcf3d193a4425f58ed9556ec54b6d7ab0557330 (patch) | |
tree | 04da0e1e3fe3dc3fbdb55f53b0fabbf01e033d82 | |
parent | 9c7245b97d515c9bdb9f8b63dc1d4e35e2fafa56 (diff) | |
download | libunwind-cfcf3d193a4425f58ed9556ec54b6d7ab0557330.tar.gz |
Add remote unwinding support for macOS (#365)
* Add remote unwinding support for macOS
* Fix broken Win build by bumping minimum language requirement to C11
* Update license headers
* Rename remote_unwind to remote
* Revert Gparser.c
-rw-r--r-- | CMakeLists.txt | 9 | ||||
-rw-r--r-- | include/remote/elf.h (renamed from include/win/elf.h) | 9 | ||||
-rw-r--r-- | include/remote/endian.h (renamed from include/win/endian.h) | 10 | ||||
-rw-r--r-- | include/remote/freebsd-elf32.h (renamed from include/win/freebsd-elf32.h) | 0 | ||||
-rw-r--r-- | include/remote/freebsd-elf64.h (renamed from include/win/freebsd-elf64.h) | 0 | ||||
-rw-r--r-- | include/remote/freebsd-elf_common.h (renamed from include/win/freebsd-elf_common.h) | 4 | ||||
-rw-r--r-- | include/remote/mac/ucontext.h | 47 | ||||
-rw-r--r-- | include/remote/win/fakestdalign.h.in (renamed from include/win/fakestdalign.h.in) | 2 | ||||
-rw-r--r-- | include/remote/win/fakestdatomic.h.in (renamed from include/win/fakestdatomic.h.in) | 2 | ||||
-rw-r--r-- | include/remote/win/pthread.h (renamed from include/win/pthread.h) | 0 | ||||
-rw-r--r-- | include/remote/win/signal.h (renamed from include/win/signal.h) | 0 | ||||
-rw-r--r-- | include/remote/win/sys/mman.h (renamed from include/win/sys/mman.h) | 0 | ||||
-rw-r--r-- | include/remote/win/sys/stat.h (renamed from include/win/sys/stat.h) | 0 | ||||
-rw-r--r-- | include/remote/win/sys/syscall.h (renamed from include/win/sys/syscall.h) | 0 | ||||
-rw-r--r-- | include/remote/win/sys/types.h (renamed from include/win/sys/types.h) | 0 | ||||
-rw-r--r-- | include/remote/win/sys/ucontext.h (renamed from include/win/sys/ucontext.h) | 0 | ||||
-rw-r--r-- | include/remote/win/ucontext.h (renamed from include/win/ucontext.h) | 0 | ||||
-rw-r--r-- | include/remote/win/unistd.h (renamed from include/win/unistd.h) | 0 | ||||
-rw-r--r-- | src/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/remote/mac/missing-functions.c | 76 | ||||
-rw-r--r-- | src/remote/win/missing-functions.c (renamed from src/win/pal-single-threaded.c) | 9 |
21 files changed, 146 insertions, 24 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index dc12eb7e..245a41bf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,6 +2,8 @@ project(libunwind) cmake_minimum_required(VERSION 3.16.1) +set(CMAKE_C_STANDARD 11) + set(PKG_MAJOR "1") set(PKG_MINOR "6") set(PKG_EXTRA "-rc1") @@ -50,7 +52,8 @@ if ("${CMAKE_GENERATOR}" MATCHES "^Visual Studio.*$") add_compile_options(/permissive-) # files for cross os compilation - include_directories(include/win) + include_directories(include/remote) + include_directories(include/remote/win) # Warnings in release builds add_compile_options(-wd4068) # ignore unknown pragma warnings (gcc pragmas) @@ -75,14 +78,14 @@ if ("${CMAKE_GENERATOR}" MATCHES "^Visual Studio.*$") # Fake it until support is added check_include_files(stdalign.h HAVE_STDALIGN_H) if (NOT HAVE_STDALIGN_H) - configure_file(include/win/fakestdalign.h.in ${CMAKE_CURRENT_BINARY_DIR}/include/stdalign.h) + configure_file(include/remote/win/fakestdalign.h.in ${CMAKE_CURRENT_BINARY_DIR}/include/stdalign.h) endif (NOT HAVE_STDALIGN_H) # MSVC compiler is currently missing C11 stdatomic.h header # Fake it until support is added check_include_files(stdatomic.h HAVE_STDATOMIC_H) if (NOT HAVE_STDATOMIC_H) - configure_file(include/win/fakestdatomic.h.in ${CMAKE_CURRENT_BINARY_DIR}/include/stdatomic.h) + configure_file(include/remote/win/fakestdatomic.h.in ${CMAKE_CURRENT_BINARY_DIR}/include/stdatomic.h) endif (NOT HAVE_STDATOMIC_H) # MSVC compiler is currently missing C11 _Thread_local diff --git a/include/win/elf.h b/include/remote/elf.h index 5089ff6b..79193ab4 100644 --- a/include/win/elf.h +++ b/include/remote/elf.h @@ -1,11 +1,8 @@ // This is an incomplete & imprecice implementation // It defers to the open source freebsd-elf implementations. -// Since this is only intended for VC++ compilers -// use #pragma once instead of guard macros -#pragma once - -#ifdef _MSC_VER // Only for cross compilation to windows +#ifndef ELF_H +#define ELF_H #include <inttypes.h> @@ -13,4 +10,4 @@ #include "freebsd-elf32.h" #include "freebsd-elf64.h" -#endif // _MSC_VER +#endif // ELF_H diff --git a/include/win/endian.h b/include/remote/endian.h index 56fb68a7..6aa6466d 100644 --- a/include/win/endian.h +++ b/include/remote/endian.h @@ -1,16 +1,12 @@ // This is an incomplete & imprecice implementation of the // standard file by the same name - -// Since this is only intended for VC++ compilers -// use #pragma once instead of guard macros -#pragma once - -#ifdef _MSC_VER // Only for cross compilation to windows +#ifndef ENDIAN_H +#define ENDIAN_H #define __LITTLE_ENDIAN 1234 #define __BIG_ENDIAN 4321 #define __BYTE_ORDER __LITTLE_ENDIAN -#endif // _MSC_VER +#endif // ENDIAN_H diff --git a/include/win/freebsd-elf32.h b/include/remote/freebsd-elf32.h index b4c0d942..b4c0d942 100644 --- a/include/win/freebsd-elf32.h +++ b/include/remote/freebsd-elf32.h diff --git a/include/win/freebsd-elf64.h b/include/remote/freebsd-elf64.h index 0991fe35..0991fe35 100644 --- a/include/win/freebsd-elf64.h +++ b/include/remote/freebsd-elf64.h diff --git a/include/win/freebsd-elf_common.h b/include/remote/freebsd-elf_common.h index 7aef2d49..cc780208 100644 --- a/include/win/freebsd-elf_common.h +++ b/include/remote/freebsd-elf_common.h @@ -195,12 +195,12 @@ typedef struct { #define SHT_STRTAB 3 /* string table section */ #define SHT_RELA 4 /* relocation section with addends */ #define SHT_HASH 5 /* symbol hash table section */ -#define SHT_DYNAMIC 6 /* dynamic section */ +#define SHT_DYNAMIC 6 /* dynamic section */ #define SHT_NOTE 7 /* note section */ #define SHT_NOBITS 8 /* no space section */ #define SHT_REL 9 /* relocation section - no addends */ #define SHT_SHLIB 10 /* reserved - purpose unknown */ -#define SHT_DYNSYM 11 /* dynamic symbol table section */ +#define SHT_DYNSYM 11 /* dynamic symbol table section */ #define SHT_INIT_ARRAY 14 /* Initialization function pointers. */ #define SHT_FINI_ARRAY 15 /* Termination function pointers. */ #define SHT_PREINIT_ARRAY 16 /* Pre-initialization function ptrs. */ diff --git a/include/remote/mac/ucontext.h b/include/remote/mac/ucontext.h new file mode 100644 index 00000000..bb09f9cc --- /dev/null +++ b/include/remote/mac/ucontext.h @@ -0,0 +1,47 @@ +/* Copyright (C) 2022 Hewlett-Packard Co. + Contributed by David Mosberger-Tang <davidm@hpl.hp.com>. + +This file is part of libunwind. + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ + +#define UC_MCONTEXT_GREGS_R8 0x28 +#define UC_MCONTEXT_GREGS_R9 0x30 +#define UC_MCONTEXT_GREGS_R10 0x38 +#define UC_MCONTEXT_GREGS_R11 0x40 +#define UC_MCONTEXT_GREGS_R12 0x48 +#define UC_MCONTEXT_GREGS_R13 0x50 +#define UC_MCONTEXT_GREGS_R14 0x58 +#define UC_MCONTEXT_GREGS_R15 0x60 +#define UC_MCONTEXT_GREGS_RDI 0x68 +#define UC_MCONTEXT_GREGS_RSI 0x70 +#define UC_MCONTEXT_GREGS_RBP 0x78 +#define UC_MCONTEXT_GREGS_RBX 0x80 +#define UC_MCONTEXT_GREGS_RDX 0x88 +#define UC_MCONTEXT_GREGS_RAX 0x90 +#define UC_MCONTEXT_GREGS_RCX 0x98 +#define UC_MCONTEXT_GREGS_RSP 0xa0 +#define UC_MCONTEXT_GREGS_RIP 0xa8 +#define UC_MCONTEXT_FPREGS_PTR 0x1a8 +#define UC_MCONTEXT_FPREGS_MEM 0xe0 +#define UC_SIGMASK 0x128 +#define FPREGS_OFFSET_MXCSR 0x18 + +#include <sys/ucontext.h> diff --git a/include/win/fakestdalign.h.in b/include/remote/win/fakestdalign.h.in index 6eb292c9..3baf6268 100644 --- a/include/win/fakestdalign.h.in +++ b/include/remote/win/fakestdalign.h.in @@ -4,6 +4,6 @@ #ifndef FAKE_STD_ALIGN_H #define FAKE_STD_ALIGN_H -#define alignas(x) +#define alignas(x) #endif // FAKE_STD_ALIGN_H diff --git a/include/win/fakestdatomic.h.in b/include/remote/win/fakestdatomic.h.in index 48cde832..799770e8 100644 --- a/include/win/fakestdatomic.h.in +++ b/include/remote/win/fakestdatomic.h.in @@ -15,7 +15,7 @@ typedef uint8_t atomic_flag; #define atomic_compare_and_exchange_strong(x, y, z) return ((*(x) == *(y)) ? ((*(x) = z), true) : ((*(y) = *(x)),false)) -#define atomic_fetch_add(x, y) *(x) += (y), (*(x) - (y)) +#define atomic_fetch_add(x, y) *(x) += (y), (*(x) - (y)) static inline void atomic_flag_clear(volatile atomic_flag* flag) { diff --git a/include/win/pthread.h b/include/remote/win/pthread.h index 8a0b0a18..8a0b0a18 100644 --- a/include/win/pthread.h +++ b/include/remote/win/pthread.h diff --git a/include/win/signal.h b/include/remote/win/signal.h index 48e8e3f9..48e8e3f9 100644 --- a/include/win/signal.h +++ b/include/remote/win/signal.h diff --git a/include/win/sys/mman.h b/include/remote/win/sys/mman.h index 0a3f6f93..0a3f6f93 100644 --- a/include/win/sys/mman.h +++ b/include/remote/win/sys/mman.h diff --git a/include/win/sys/stat.h b/include/remote/win/sys/stat.h index a5b54dea..a5b54dea 100644 --- a/include/win/sys/stat.h +++ b/include/remote/win/sys/stat.h diff --git a/include/win/sys/syscall.h b/include/remote/win/sys/syscall.h index d655d1a8..d655d1a8 100644 --- a/include/win/sys/syscall.h +++ b/include/remote/win/sys/syscall.h diff --git a/include/win/sys/types.h b/include/remote/win/sys/types.h index 7b131f6e..7b131f6e 100644 --- a/include/win/sys/types.h +++ b/include/remote/win/sys/types.h diff --git a/include/win/sys/ucontext.h b/include/remote/win/sys/ucontext.h index c37c3aba..c37c3aba 100644 --- a/include/win/sys/ucontext.h +++ b/include/remote/win/sys/ucontext.h diff --git a/include/win/ucontext.h b/include/remote/win/ucontext.h index fb5aaf73..fb5aaf73 100644 --- a/include/win/ucontext.h +++ b/include/remote/win/ucontext.h diff --git a/include/win/unistd.h b/include/remote/win/unistd.h index d4ff2278..d4ff2278 100644 --- a/include/win/unistd.h +++ b/include/remote/win/unistd.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 82ef68a9..7b7d1446 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -351,7 +351,7 @@ endif() add_library(libunwind OBJECT - win/pal-single-threaded.c + remote/win/missing-functions.c # ${libunwind_la_SOURCES} Local... ${libunwind_remote_la_SOURCES} # Commented out above for LOCAL + REMOTE runtime build diff --git a/src/remote/mac/missing-functions.c b/src/remote/mac/missing-functions.c new file mode 100644 index 00000000..f0a7b3f5 --- /dev/null +++ b/src/remote/mac/missing-functions.c @@ -0,0 +1,76 @@ +/* Copyright (C) 2022 Hewlett-Packard Co. + Contributed by David Mosberger-Tang <davidm@hpl.hp.com>. + +This file is part of libunwind. + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ + +// This is minimal implementation functions files required to cross compile +// libunwind on MacOS for UNW_REMOTE_ONLY application. + +#include <pthread.h> +#include <signal.h> +#include <stdlib.h> +#include <stdatomic.h> +#include "libunwind_i.h" +#include "compiler.h" + +unw_addr_space_t UNW_OBJ(local_addr_space); + +unw_accessors_t * +unw_get_accessors (unw_addr_space_t as) +{ + if (!atomic_load(&tdep_init_done)) + tdep_init (); + return &as->acc; +} + +unw_accessors_t * +unw_get_accessors_int (unw_addr_space_t as) +{ + return unw_get_accessors(as); +} + +#if defined(TARGET_AMD64) && !defined(HOST_AMD64) +#define X86_64_SCF_NONE 0 +#endif + +#if defined(TARGET_ARM64) && !defined(HOST_ARM64) +#define AARCH64_SCF_NONE 0 +#endif + +int +unw_is_signal_frame (unw_cursor_t *cursor) +{ + struct cursor *c = (struct cursor *) cursor; +#ifdef TARGET_AMD64 + return c->sigcontext_format != X86_64_SCF_NONE; +#elif defined(TARGET_ARM64) + return c->sigcontext_format != AARCH64_SCF_NONE; +#else + #error Unexpected target +#endif +} + +int +UNW_OBJ(handle_signal_frame) (unw_cursor_t *cursor) +{ + return -UNW_EBADFRAME; +} diff --git a/src/win/pal-single-threaded.c b/src/remote/win/missing-functions.c index acaa4659..8bd362a1 100644 --- a/src/win/pal-single-threaded.c +++ b/src/remote/win/missing-functions.c @@ -1,7 +1,8 @@ -/* libunwind - a platform-independent unwind library - Copyright (c) 2003-2005 Hewlett-Packard Development Company, L.P. - Contributed by David Mosberger-Tang <davidm@hpl.hp.com> +/* Copyright (C) 2022 Hewlett-Packard Co. + Contributed by David Mosberger-Tang <davidm@hpl.hp.com>. + This file is part of libunwind. + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including @@ -9,8 +10,10 @@ without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |