summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Fischer <matt.fischer@garmin.com>2013-04-15 09:53:29 -0500
committerMatt Fischer <matt.fischer@garmin.com>2013-05-13 10:50:17 -0500
commiteac65dc9b8cc18fa4c65c0485878a11c470357b6 (patch)
tree9e9df0cd13876251b7240c2209fceb73631258d8
parentac6c0a6535975f1dc2da6e4e2766614baac2a14a (diff)
downloadlibunwind-eac65dc9b8cc18fa4c65c0485878a11c470357b6.tar.gz
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
-rw-r--r--configure.ac19
-rw-r--r--include/dwarf.h14
-rw-r--r--include/libunwind_i.h17
-rw-r--r--src/Makefile.am10
-rw-r--r--src/arm/Gis_signal_frame.c3
-rw-r--r--src/dwarf/Gfind_proc_info-lsb.c3
-rw-r--r--src/dwarf/Gfind_unwind_table.c1
-rw-r--r--src/elfxx.h1
-rw-r--r--src/os-qnx.c101
9 files changed, 159 insertions, 10 deletions
diff --git a/configure.ac b/configure.ac
index 425991c8..8e7a12a3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -37,7 +37,7 @@ dnl Checks for header files.
AC_HEADER_STDC
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 \
- 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.
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_HPUX, expr x$target_os : xhpux >/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])
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
CFLAGS="${CFLAGS} -fexceptions -Wall -Wsign-compare"
- LIBCRTS="-lgcc"
fi
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
AC_MSG_CHECKING([if linker supports -static-libcxa])
save_LDFLAGS="$LDFLAGS"
@@ -294,6 +298,16 @@ if test x$intel_compiler = xyes; then
AC_MSG_RESULT([$have_static_libcxa])
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_LINK_IFELSE(
[AC_LANG_PROGRAM([[]], [[__builtin___clear_cache(0, 0)]])],
@@ -351,6 +365,7 @@ AC_SUBST(target_os)
AC_SUBST(arch)
AC_SUBST(ARCH)
AC_SUBST(LDFLAGS_STATIC_LIBCXA)
+AC_SUBST(LDFLAGS_NOSTARTFILES)
AC_SUBST(LIBCRTS)
AC_SUBST(PKG_MAJOR)
AC_SUBST(PKG_MINOR)
diff --git a/include/dwarf.h b/include/dwarf.h
index 1885b9b1..7800567a 100644
--- a/include/dwarf.h
+++ b/include/dwarf.h
@@ -32,9 +32,21 @@ struct dwarf_cursor; /* forward-declaration */
struct elf_dyn_info;
#include "dwarf-config.h"
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
#ifndef UNW_REMOTE_ONLY
-#include <link.h>
+ #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>
/* DWARF expression opcodes. */
diff --git a/include/libunwind_i.h b/include/libunwind_i.h
index 966a3e36..f412e6ac 100644
--- a/include/libunwind_i.h
+++ b/include/libunwind_i.h
@@ -56,7 +56,14 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#include <string.h>
#include <unistd.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)
# include <endian.h>
@@ -67,6 +74,14 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
# define __BIG_ENDIAN 4321
# if defined(__hpux)
# 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
# error Host has unknown byte-order.
# endif
diff --git a/src/Makefile.am b/src/Makefile.am
index 9ad00204..8c0c098e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -4,7 +4,7 @@ COREDUMP_SO_VERSION=0:0:0
#
# 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_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_qnx = os-qnx.c
+
libunwind_dwarf_common_la_SOURCES = dwarf/global.c
libunwind_dwarf_local_la_SOURCES = \
@@ -450,6 +452,11 @@ if OS_FREEBSD
libunwind_coredump_la_SOURCES += coredump/_UCD_access_reg_freebsd.c
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
lib_LTLIBRARIES += libunwind-aarch64.la
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_linux) \
$(libunwind_la_SOURCES_os_hpux) \
+ $(libunwind_la_SOURCES_os_qnx) \
$(libunwind_la_SOURCES_common) \
$(libunwind_la_SOURCES_local) \
$(libunwind_la_SOURCES_generic) \
diff --git a/src/arm/Gis_signal_frame.c b/src/arm/Gis_signal_frame.c
index e2e8cd67..e8efe7f4 100644
--- a/src/arm/Gis_signal_frame.c
+++ b/src/arm/Gis_signal_frame.c
@@ -77,6 +77,9 @@ unw_is_signal_frame (unw_cursor_t *cursor)
return 2;
return 0;
+#elif defined(__QNX__)
+ /* Not supported yet */
+ return 0;
#else
printf ("%s: implement me\n", __FUNCTION__);
return -UNW_ENOINFO;
diff --git a/src/dwarf/Gfind_proc_info-lsb.c b/src/dwarf/Gfind_proc_info-lsb.c
index 975c9692..f75bda28 100644
--- a/src/dwarf/Gfind_proc_info-lsb.c
+++ b/src/dwarf/Gfind_proc_info-lsb.c
@@ -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
(http://www.linuxbase.org/spec/). */
-#ifndef UNW_REMOTE_ONLY
-#include <link.h>
-#endif /* !UNW_REMOTE_ONLY */
#include <stddef.h>
#include <stdio.h>
#include <limits.h>
diff --git a/src/dwarf/Gfind_unwind_table.c b/src/dwarf/Gfind_unwind_table.c
index 961226a5..eb01ae90 100644
--- a/src/dwarf/Gfind_unwind_table.c
+++ b/src/dwarf/Gfind_unwind_table.c
@@ -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
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
-#include <elf.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
diff --git a/src/elfxx.h b/src/elfxx.h
index dea0463f..558a2354 100644
--- a/src/elfxx.h
+++ b/src/elfxx.h
@@ -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
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
-#include <elf.h>
#include <fcntl.h>
#include <unistd.h>
diff --git a/src/os-qnx.c b/src/os-qnx.c
new file mode 100644
index 00000000..d01f920b
--- /dev/null
+++ b/src/os-qnx.c
@@ -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;
+}