1
0
Fork 0
mirror of https://github.com/tobast/libunwind-eh_elf.git synced 2024-11-25 08:37:38 +01:00

Add basic support for the QNX operating system

This change adds some special cases to allow libunwind to compile
for QNX.

* QNX's copy of <elf.h> and <link.h> reside in sys/ instead.  To deal
  with this, an AC_CHECK_HEADERS() was added to check for the files
  in both locations.
* Similarly, QNX does not have <endian.h>.  In cases where the file is
  not found, logic was added to refer to QNX-specific macros to determine
  endianness.
* The QCC compiler, which is a wrapper around GCC, cannot handle some
  standard GCC options.  Therefore, logic was added to check for QCC,
  and when it is found, to suppress the use of -lgcc, and to express the
  option -nostartfiles as -Wc,-nostartfiles instead, which is correctly
  passed on to the underlying GCC.
* Finally, the support file os-qnx.c was added, patterned after the existing
  os-*.c files.  Only local image lookup is currently supported (see the
  comments for more information), but this is sufficient for QNX, since
  ptrace is not supported there anyway, and that is the only case where the
  function is required to do remote image lookup.

Change-Id: Ie7934f94a7317bdde59335f2acd4c3a97c0384c1
This commit is contained in:
Matt Fischer 2013-04-15 09:53:29 -05:00
parent ac6c0a6535
commit eac65dc9b8
9 changed files with 160 additions and 11 deletions

View file

@ -37,7 +37,7 @@ dnl Checks for header files.
AC_HEADER_STDC AC_HEADER_STDC
AC_CHECK_HEADERS(asm/ptrace_offsets.h endian.h sys/endian.h execinfo.h \ AC_CHECK_HEADERS(asm/ptrace_offsets.h endian.h sys/endian.h execinfo.h \
ia64intrin.h sys/uc_access.h unistd.h signal.h sys/types.h \ ia64intrin.h sys/uc_access.h unistd.h signal.h sys/types.h \
sys/procfs.h sys/ptrace.h byteswap.h) sys/procfs.h sys/ptrace.h byteswap.h elf.h sys/elf.h link.h sys/link.h)
dnl Checks for typedefs, structures, and compiler characteristics. dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST AC_C_CONST
@ -152,6 +152,7 @@ AM_CONDITIONAL(ARCH_SH, test x$target_arch = xsh)
AM_CONDITIONAL(OS_LINUX, expr x$target_os : xlinux >/dev/null) AM_CONDITIONAL(OS_LINUX, expr x$target_os : xlinux >/dev/null)
AM_CONDITIONAL(OS_HPUX, expr x$target_os : xhpux >/dev/null) AM_CONDITIONAL(OS_HPUX, expr x$target_os : xhpux >/dev/null)
AM_CONDITIONAL(OS_FREEBSD, expr x$target_os : xfreebsd >/dev/null) AM_CONDITIONAL(OS_FREEBSD, expr x$target_os : xfreebsd >/dev/null)
AM_CONDITIONAL(OS_QNX, expr x$target_os : xnto-qnx >/dev/null)
AC_MSG_CHECKING([for ELF helper width]) AC_MSG_CHECKING([for ELF helper width])
case "${target_arch}" in case "${target_arch}" in
@ -278,10 +279,13 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[#ifndef __INTEL_COMPILER
if test x$GCC = xyes -a x$intel_compiler != xyes; then if test x$GCC = xyes -a x$intel_compiler != xyes; then
CFLAGS="${CFLAGS} -fexceptions -Wall -Wsign-compare" CFLAGS="${CFLAGS} -fexceptions -Wall -Wsign-compare"
LIBCRTS="-lgcc"
fi fi
AC_MSG_RESULT([$intel_compiler]) AC_MSG_RESULT([$intel_compiler])
AC_MSG_CHECKING([for QCC compiler])
AS_CASE([$CC], [qcc*|QCC*], [qcc_compiler=yes], [qcc_compiler=no])
AC_MSG_RESULT([$qcc_compiler])
if test x$intel_compiler = xyes; then if test x$intel_compiler = xyes; then
AC_MSG_CHECKING([if linker supports -static-libcxa]) AC_MSG_CHECKING([if linker supports -static-libcxa])
save_LDFLAGS="$LDFLAGS" save_LDFLAGS="$LDFLAGS"
@ -294,6 +298,16 @@ if test x$intel_compiler = xyes; then
AC_MSG_RESULT([$have_static_libcxa]) AC_MSG_RESULT([$have_static_libcxa])
fi fi
if test x$qcc_compiler = xyes; then
LDFLAGS_NOSTARTFILES="-XCClinker -Wc,-nostartfiles"
else
LDFLAGS_NOSTARTFILES="-XCClinker -nostartfiles"
fi
if test x$GCC = xyes -a x$intel_compiler != xyes -a x$qcc_compiler != xyes; then
LIBCRTS="-lgcc"
fi
AC_MSG_CHECKING([for __builtin___clear_cache]) AC_MSG_CHECKING([for __builtin___clear_cache])
AC_LINK_IFELSE( AC_LINK_IFELSE(
[AC_LANG_PROGRAM([[]], [[__builtin___clear_cache(0, 0)]])], [AC_LANG_PROGRAM([[]], [[__builtin___clear_cache(0, 0)]])],
@ -351,6 +365,7 @@ AC_SUBST(target_os)
AC_SUBST(arch) AC_SUBST(arch)
AC_SUBST(ARCH) AC_SUBST(ARCH)
AC_SUBST(LDFLAGS_STATIC_LIBCXA) AC_SUBST(LDFLAGS_STATIC_LIBCXA)
AC_SUBST(LDFLAGS_NOSTARTFILES)
AC_SUBST(LIBCRTS) AC_SUBST(LIBCRTS)
AC_SUBST(PKG_MAJOR) AC_SUBST(PKG_MAJOR)
AC_SUBST(PKG_MINOR) AC_SUBST(PKG_MINOR)

View file

@ -32,9 +32,21 @@ struct dwarf_cursor; /* forward-declaration */
struct elf_dyn_info; struct elf_dyn_info;
#include "dwarf-config.h" #include "dwarf-config.h"
#ifndef UNW_REMOTE_ONLY
#include <link.h> #ifdef HAVE_CONFIG_H
# include "config.h"
#endif #endif
#ifndef UNW_REMOTE_ONLY
#if defined(HAVE_LINK_H)
#include <link.h>
#elif defined(HAVE_SYS_LINK_H)
#include <sys/link.h>
#else
#error Could not find <link.h>
#endif
#endif
#include <pthread.h> #include <pthread.h>
/* DWARF expression opcodes. */ /* DWARF expression opcodes. */

View file

@ -56,7 +56,14 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <sys/mman.h> #include <sys/mman.h>
#include <elf.h>
#if defined(HAVE_ELF_H)
# include <elf.h>
#elif defined(HAVE_SYS_ELF_H)
# include <sys/elf.h>
#else
# error Could not locate <elf.h>
#endif
#if defined(HAVE_ENDIAN_H) #if defined(HAVE_ENDIAN_H)
# include <endian.h> # include <endian.h>
@ -67,6 +74,14 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
# define __BIG_ENDIAN 4321 # define __BIG_ENDIAN 4321
# if defined(__hpux) # if defined(__hpux)
# define __BYTE_ORDER __BIG_ENDIAN # define __BYTE_ORDER __BIG_ENDIAN
# elif defined(__QNX__)
# if defined(__BIGENDIAN__)
# define __BYTE_ORDER __BIG_ENDIAN
# elif defined(__LITTLEENDIAN__)
# define __BYTE_ORDER __LITTLE_ENDIAN
# else
# error Host has unknown byte-order.
# endif
# else # else
# error Host has unknown byte-order. # error Host has unknown byte-order.
# endif # endif

View file

@ -4,7 +4,7 @@ COREDUMP_SO_VERSION=0:0:0
# #
# Don't link with start-files since we don't use any constructors/destructors: # Don't link with start-files since we don't use any constructors/destructors:
# #
COMMON_SO_LDFLAGS = -XCClinker -nostartfiles COMMON_SO_LDFLAGS = $(LDFLAGS_NOSTARTFILES)
lib_LIBRARIES = lib_LIBRARIES =
lib_LTLIBRARIES = lib_LTLIBRARIES =
@ -149,6 +149,8 @@ libunwind_la_SOURCES_os_hpux = os-hpux.c
libunwind_la_SOURCES_os_freebsd = os-freebsd.c libunwind_la_SOURCES_os_freebsd = os-freebsd.c
libunwind_la_SOURCES_os_qnx = os-qnx.c
libunwind_dwarf_common_la_SOURCES = dwarf/global.c libunwind_dwarf_common_la_SOURCES = dwarf/global.c
libunwind_dwarf_local_la_SOURCES = \ libunwind_dwarf_local_la_SOURCES = \
@ -450,6 +452,11 @@ if OS_FREEBSD
libunwind_coredump_la_SOURCES += coredump/_UCD_access_reg_freebsd.c libunwind_coredump_la_SOURCES += coredump/_UCD_access_reg_freebsd.c
endif endif
if OS_QNX
libunwind_la_SOURCES_os = $(libunwind_la_SOURCES_os_qnx)
libunwind_la_SOURCES_os_local = $(libunwind_la_SOURCES_os_qnx_local)
endif
if ARCH_AARCH64 if ARCH_AARCH64
lib_LTLIBRARIES += libunwind-aarch64.la lib_LTLIBRARIES += libunwind-aarch64.la
libunwind_la_SOURCES = $(libunwind_la_SOURCES_aarch64) libunwind_la_SOURCES = $(libunwind_la_SOURCES_aarch64)
@ -622,6 +629,7 @@ EXTRA_DIST = $(libunwind_la_SOURCES_aarch64) \
$(libunwind_la_SOURCES_os_freebsd) \ $(libunwind_la_SOURCES_os_freebsd) \
$(libunwind_la_SOURCES_os_linux) \ $(libunwind_la_SOURCES_os_linux) \
$(libunwind_la_SOURCES_os_hpux) \ $(libunwind_la_SOURCES_os_hpux) \
$(libunwind_la_SOURCES_os_qnx) \
$(libunwind_la_SOURCES_common) \ $(libunwind_la_SOURCES_common) \
$(libunwind_la_SOURCES_local) \ $(libunwind_la_SOURCES_local) \
$(libunwind_la_SOURCES_generic) \ $(libunwind_la_SOURCES_generic) \

View file

@ -76,6 +76,9 @@ unw_is_signal_frame (unw_cursor_t *cursor)
|| w0 == THUMB_RT_SIGRETURN) || w0 == THUMB_RT_SIGRETURN)
return 2; return 2;
return 0;
#elif defined(__QNX__)
/* Not supported yet */
return 0; return 0;
#else #else
printf ("%s: implement me\n", __FUNCTION__); printf ("%s: implement me\n", __FUNCTION__);

View file

@ -26,9 +26,6 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/* Locate an FDE via the ELF data-structures defined by LSB v1.3 /* Locate an FDE via the ELF data-structures defined by LSB v1.3
(http://www.linuxbase.org/spec/). */ (http://www.linuxbase.org/spec/). */
#ifndef UNW_REMOTE_ONLY
#include <link.h>
#endif /* !UNW_REMOTE_ONLY */
#include <stddef.h> #include <stddef.h>
#include <stdio.h> #include <stdio.h>
#include <limits.h> #include <limits.h>

View file

@ -23,7 +23,6 @@ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#include <elf.h>
#include <fcntl.h> #include <fcntl.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>

View file

@ -24,7 +24,6 @@ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#include <elf.h>
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h> #include <unistd.h>

101
src/os-qnx.c Normal file
View file

@ -0,0 +1,101 @@
/* libunwind - a platform-independent unwind library
Copyright (C) 2013 Garmin International
Contributed by Matt Fischer <matt.fischer@garmin.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. */
#include <string.h>
#include "libunwind_i.h"
struct cb_info
{
unw_word_t ip;
unsigned long segbase;
unsigned long offset;
const char *path;
};
static int callback(const struct dl_phdr_info *info, size_t size, void *data)
{
int i;
struct cb_info *cbi = (struct cb_info*)data;
for(i=0; i<info->dlpi_phnum; i++) {
int segbase = info->dlpi_addr + info->dlpi_phdr[i].p_vaddr;
if(cbi->ip >= segbase && cbi->ip < segbase + info->dlpi_phdr[i].p_memsz)
{
cbi->path = info->dlpi_name;
cbi->offset = info->dlpi_phdr[i].p_offset;
cbi->segbase = segbase;
return 1;
}
}
return 0;
}
PROTECTED int
tdep_get_elf_image (struct elf_image *ei, pid_t pid, unw_word_t ip,
unsigned long *segbase, unsigned long *mapoff,
char *path, size_t pathlen)
{
struct cb_info cbi;
int ret = -1;
cbi.ip = ip;
cbi.segbase = 0;
cbi.offset = 0;
cbi.path = NULL;
/* QNX's support for accessing symbol maps is severely broken. There is a devctl() call that
can be made on a proc node (DCMD_PROC_MAPDEBUG) which returns information similar to Linux's
/proc/<pid>/maps node, however the filename that is returned by this call is not an absolute
path, and there is no foolproof way to map the filename back to the file that it came from.
Therefore, the normal approach for implementing this function, which works equally well for
both local and remote unwinding, will not work here. The only type of image lookup which
works reliably is locally, using dl_iterate_phdr(). However, the only time that this function
is required to look up a remote image is for ptrace support, which doesn't work on QNX anyway.
Local unwinding, which is the main case that makes use of this function, will work fine with
dl_iterate_phdr(). Therefore, in lieu of any better platform support for remote image lookup,
this function has just been implemented in terms of dl_iterate_phdr().
*/
if (pid != getpid())
{
/* Return an error if an attempt is made to perform remote image lookup */
return -1;
}
if (dl_iterate_phdr (callback, &cbi) != 0)
{
if (path)
{
strncpy (path, cbi.path, pathlen);
}
*mapoff = cbi.offset;
*segbase = cbi.segbase;
ret = elf_map_image (ei, cbi.path);
}
return ret;
}