[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Minios-devel] [UNIKRAFT/GCC PATCH v2 3/5] Port libbacktrace library



This port also adds the generated config.h and backtrace-supported.h headers.
Another option would have been to generate them during the build

Signed-off-by: Charalampos Mainas <Charalampos.Mainas@xxxxxxxxx>
Signed-off-by: Costin Lupu <costin.lupu@xxxxxxxxx>
---
 Config.uk                                  |  14 ++
 Makefile.uk                                |  33 ++++
 libbacktrace/exportsyms.uk                 |   6 +
 libbacktrace/include/backtrace-supported.h |  66 +++++++
 libbacktrace/include/backtrace.h           | 200 +++++++++++++++++++++
 libbacktrace/include/config/config.h       | 135 ++++++++++++++
 6 files changed, 454 insertions(+)
 create mode 100644 libbacktrace/exportsyms.uk
 create mode 100644 libbacktrace/include/backtrace-supported.h
 create mode 100644 libbacktrace/include/backtrace.h
 create mode 100644 libbacktrace/include/config/config.h

diff --git a/Config.uk b/Config.uk
index fa4da07..ea411b0 100644
--- a/Config.uk
+++ b/Config.uk
@@ -6,4 +6,18 @@ menuconfig LIBGCC
        select LIBUKALLOC
 
 if LIBGCC
+
+config LIBBACKTRACE
+       bool "libbacktrace library"
+       default n
+       select LIBNEWLIBC
+       select LIBCOMPILER_RT
+       select LIBUNWIND
+       select LIBCXX
+       select LIBCXXABI
+       select LIBUKMMAP
+       select UKSYSINFO
+if LIBBACKTRACE
+endif
+
 endif
diff --git a/Makefile.uk b/Makefile.uk
index 2a572dd..2e763f9 100644
--- a/Makefile.uk
+++ b/Makefile.uk
@@ -40,6 +40,7 @@
 # Library registration
 
################################################################################
 $(eval $(call addlib_s,libgcc,$(CONFIG_LIBGCC)))
+$(eval $(call addlib_s,libbacktrace,$(CONFIG_LIBBACKTRACE)))
 
 
################################################################################
 # Original sources
@@ -53,9 +54,41 @@ $(eval $(call fetch,libgcc,$(LIBGCC_URL)))
 # Helpers
 
################################################################################
 LIBGCC_EXTRACTED = $(LIBGCC_ORIGIN)/gcc-$(LIBGCC_VERSION)
+LIBBACKTRACE_EXTRACTED = $(LIBGCC_EXTRACTED)/libbacktrace
 
 
################################################################################
 # Library includes
 
################################################################################
 CINCLUDES-$(CONFIG_LIBGCC)   += -I$(LIBGCC_BASE)/include
 CXXINCLUDES-$(CONFIG_LIBGCC) += -I$(LIBGCC_BASE)/include
+
+CINCLUDES-$(CONFIG_LIBBACKTRACE)   += -I$(LIBGCC_BASE)/libbacktrace/include
+CXXINCLUDES-$(CONFIG_LIBBACKTRACE) += -I$(LIBGCC_BASE)/libbacktrace/include
+
+################################################################################
+# libbacktrace code
+################################################################################
+LIBBACKTRACE_CINCLUDES-y = -I$(LIBGCC_BASE)/libbacktrace/include \
+       -I$(LIBGCC_EXTRACTED)/include -I$(LIBBACKTRACE_EXTRACTED) \
+       -I$(LIBGCC_BASE)/libbacktrace/include/config
+
+LIBBACKTRACE_CFLAGS-y += -DHAVE_CONFIG_H -DHAVE_STDINT_H\
+       -funwind-tables \
+       -W -Wall -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes \
+       -Wold-style-definition -Wmissing-format-attribute -Wcast-qual
+
+LIBBACKTRACE_SRCS-y += $(LIBBACKTRACE_EXTRACTED)/atomic.c
+LIBBACKTRACE_SRCS-y += $(LIBBACKTRACE_EXTRACTED)/dwarf.c
+LIBBACKTRACE_SRCS-y += $(LIBBACKTRACE_EXTRACTED)/fileline.c
+LIBBACKTRACE_SRCS-y += $(LIBBACKTRACE_EXTRACTED)/posix.c
+LIBBACKTRACE_SRCS-y += $(LIBBACKTRACE_EXTRACTED)/print.c
+LIBBACKTRACE_SRCS-y += $(LIBBACKTRACE_EXTRACTED)/sort.c
+LIBBACKTRACE_SRCS-y += $(LIBBACKTRACE_EXTRACTED)/state.c
+LIBBACKTRACE_SRCS-y += $(LIBBACKTRACE_EXTRACTED)/backtrace.c
+LIBBACKTRACE_SRCS-y += $(LIBBACKTRACE_EXTRACTED)/simple.c
+LIBBACKTRACE_SRCS-y += $(LIBBACKTRACE_EXTRACTED)/elf.c
+LIBBACKTRACE_SRCS-y += $(LIBBACKTRACE_EXTRACTED)/mmapio.c
+LIBBACKTRACE_SRCS-y += $(LIBBACKTRACE_EXTRACTED)/mmap.c
+
+LIBBACKTRACE_EXPORTS = $(LIBGCC_BASE)/libbacktrace/exportsyms.uk
+
diff --git a/libbacktrace/exportsyms.uk b/libbacktrace/exportsyms.uk
new file mode 100644
index 0000000..96f3e86
--- /dev/null
+++ b/libbacktrace/exportsyms.uk
@@ -0,0 +1,6 @@
+backtrace_create_state
+backtrace_full
+backtrace_pcinfo
+backtrace_print
+backtrace_simple
+backtrace_syminfo
diff --git a/libbacktrace/include/backtrace-supported.h 
b/libbacktrace/include/backtrace-supported.h
new file mode 100644
index 0000000..c03a98d
--- /dev/null
+++ b/libbacktrace/include/backtrace-supported.h
@@ -0,0 +1,66 @@
+/* backtrace-supported.h.in -- Whether stack backtrace is supported.
+   Copyright (C) 2012-2017 Free Software Foundation, Inc.
+   Written by Ian Lance Taylor, Google.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+    (1) Redistributions of source code must retain the above copyright
+    notice, this list of conditions and the following disclaimer.
+
+    (2) Redistributions in binary form must reproduce the above copyright
+    notice, this list of conditions and the following disclaimer in
+    the documentation and/or other materials provided with the
+    distribution.
+
+    (3) The name of the author may not be used to
+    endorse or promote products derived from this software without
+    specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.  */
+
+/* The file backtrace-supported.h.in is used by configure to generate
+   the file backtrace-supported.h.  The file backtrace-supported.h may
+   be #include'd to see whether the backtrace library will be able to
+   get a backtrace and produce symbolic information.  */
+
+
+/* BACKTRACE_SUPPORTED will be #define'd as 1 if the backtrace library
+   should work, 0 if it will not.  Libraries may #include this to make
+   other arrangements.  */
+
+#define BACKTRACE_SUPPORTED 1
+
+/* BACKTRACE_USES_MALLOC will be #define'd as 1 if the backtrace
+   library will call malloc as it works, 0 if it will call mmap
+   instead.  This may be used to determine whether it is safe to call
+   the backtrace functions from a signal handler.  In general this
+   only applies to calls like backtrace and backtrace_pcinfo.  It does
+   not apply to backtrace_simple, which never calls malloc.  It does
+   not apply to backtrace_print, which always calls fprintf and
+   therefore malloc.  */
+
+#define BACKTRACE_USES_MALLOC 0
+
+/* BACKTRACE_SUPPORTS_THREADS will be #define'd as 1 if the backtrace
+   library is configured with threading support, 0 if not.  If this is
+   0, the threaded parameter to backtrace_create_state must be passed
+   as 0.  */
+
+#define BACKTRACE_SUPPORTS_THREADS 1
+
+/* BACKTRACE_SUPPORTS_DATA will be #defined'd as 1 if the backtrace_syminfo
+   will work for variables.  It will always work for functions.  */
+
+#define BACKTRACE_SUPPORTS_DATA 1
diff --git a/libbacktrace/include/backtrace.h b/libbacktrace/include/backtrace.h
new file mode 100644
index 0000000..e239b34
--- /dev/null
+++ b/libbacktrace/include/backtrace.h
@@ -0,0 +1,200 @@
+/* backtrace.h -- Public header file for stack backtrace library.
+   Copyright (C) 2012-2017 Free Software Foundation, Inc.
+   Written by Ian Lance Taylor, Google.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+    (1) Redistributions of source code must retain the above copyright
+    notice, this list of conditions and the following disclaimer.
+
+    (2) Redistributions in binary form must reproduce the above copyright
+    notice, this list of conditions and the following disclaimer in
+    the documentation and/or other materials provided with the
+    distribution.
+
+    (3) The name of the author may not be used to
+    endorse or promote products derived from this software without
+    specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.  */
+
+#ifndef BACKTRACE_H
+#define BACKTRACE_H
+
+#include <stddef.h>
+#include <stdio.h>
+
+/* We want to get a definition for uintptr_t, but we still care about
+   systems that don't have <stdint.h>.  */
+#if defined(__GLIBC__) && __GLIBC__ >= 2
+
+#include <stdint.h>
+
+#elif defined(HAVE_STDINT_H)
+
+#include <stdint.h>
+
+#else
+
+/* Systems that don't have <stdint.h> must provide gstdint.h, e.g.,
+   from GCC_HEADER_STDINT in configure.ac.  */
+//#include "gstdint.h"
+
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* The backtrace state.  This struct is intentionally not defined in
+   the public interface.  */
+
+struct backtrace_state;
+
+/* The type of the error callback argument to backtrace functions.
+   This function, if not NULL, will be called for certain error cases.
+   The DATA argument is passed to the function that calls this one.
+   The MSG argument is an error message.  The ERRNUM argument, if
+   greater than 0, holds an errno value.  The MSG buffer may become
+   invalid after this function returns.
+
+   As a special case, the ERRNUM argument will be passed as -1 if no
+   debug info can be found for the executable, but the function
+   requires debug info (e.g., backtrace_full, backtrace_pcinfo).  The
+   MSG in this case will be something along the lines of "no debug
+   info".  Similarly, ERRNUM will be passed as -1 if there is no
+   symbol table, but the function requires a symbol table (e.g.,
+   backtrace_syminfo).  This may be used as a signal that some other
+   approach should be tried.  */
+
+typedef void (*backtrace_error_callback) (void *data, const char *msg,
+                                         int errnum);
+
+/* Create state information for the backtrace routines.  This must be
+   called before any of the other routines, and its return value must
+   be passed to all of the other routines.  FILENAME is the path name
+   of the executable file; if it is NULL the library will try
+   system-specific path names.  If not NULL, FILENAME must point to a
+   permanent buffer.  If THREADED is non-zero the state may be
+   accessed by multiple threads simultaneously, and the library will
+   use appropriate atomic operations.  If THREADED is zero the state
+   may only be accessed by one thread at a time.  This returns a state
+   pointer on success, NULL on error.  If an error occurs, this will
+   call the ERROR_CALLBACK routine.  */
+
+extern struct backtrace_state *backtrace_create_state (
+    const char *filename, int threaded,
+    backtrace_error_callback error_callback, void *data);
+
+/* The type of the callback argument to the backtrace_full function.
+   DATA is the argument passed to backtrace_full.  PC is the program
+   counter.  FILENAME is the name of the file containing PC, or NULL
+   if not available.  LINENO is the line number in FILENAME containing
+   PC, or 0 if not available.  FUNCTION is the name of the function
+   containing PC, or NULL if not available.  This should return 0 to
+   continuing tracing.  The FILENAME and FUNCTION buffers may become
+   invalid after this function returns.  */
+
+typedef int (*backtrace_full_callback) (void *data, uintptr_t pc,
+                                       const char *filename, int lineno,
+                                       const char *function);
+
+/* Get a full stack backtrace.  SKIP is the number of frames to skip;
+   passing 0 will start the trace with the function calling
+   backtrace_full.  DATA is passed to the callback routine.  If any
+   call to CALLBACK returns a non-zero value, the stack backtrace
+   stops, and backtrace returns that value; this may be used to limit
+   the number of stack frames desired.  If all calls to CALLBACK
+   return 0, backtrace returns 0.  The backtrace_full function will
+   make at least one call to either CALLBACK or ERROR_CALLBACK.  This
+   function requires debug info for the executable.  */
+
+extern int backtrace_full (struct backtrace_state *state, int skip,
+                          backtrace_full_callback callback,
+                          backtrace_error_callback error_callback,
+                          void *data);
+
+/* The type of the callback argument to the backtrace_simple function.
+   DATA is the argument passed to simple_backtrace.  PC is the program
+   counter.  This should return 0 to continue tracing.  */
+
+typedef int (*backtrace_simple_callback) (void *data, uintptr_t pc);
+
+/* Get a simple backtrace.  SKIP is the number of frames to skip, as
+   in backtrace.  DATA is passed to the callback routine.  If any call
+   to CALLBACK returns a non-zero value, the stack backtrace stops,
+   and backtrace_simple returns that value.  Otherwise
+   backtrace_simple returns 0.  The backtrace_simple function will
+   make at least one call to either CALLBACK or ERROR_CALLBACK.  This
+   function does not require any debug info for the executable.  */
+
+extern int backtrace_simple (struct backtrace_state *state, int skip,
+                            backtrace_simple_callback callback,
+                            backtrace_error_callback error_callback,
+                            void *data);
+
+/* Print the current backtrace in a user readable format to a FILE.
+   SKIP is the number of frames to skip, as in backtrace_full.  Any
+   error messages are printed to stderr.  This function requires debug
+   info for the executable.  */
+
+extern void backtrace_print (struct backtrace_state *state, int skip, FILE *);
+
+/* Given PC, a program counter in the current program, call the
+   callback function with filename, line number, and function name
+   information.  This will normally call the callback function exactly
+   once.  However, if the PC happens to describe an inlined call, and
+   the debugging information contains the necessary information, then
+   this may call the callback function multiple times.  This will make
+   at least one call to either CALLBACK or ERROR_CALLBACK.  This
+   returns the first non-zero value returned by CALLBACK, or 0.  */
+
+extern int backtrace_pcinfo (struct backtrace_state *state, uintptr_t pc,
+                            backtrace_full_callback callback,
+                            backtrace_error_callback error_callback,
+                            void *data);
+
+/* The type of the callback argument to backtrace_syminfo.  DATA and
+   PC are the arguments passed to backtrace_syminfo.  SYMNAME is the
+   name of the symbol for the corresponding code.  SYMVAL is the
+   value and SYMSIZE is the size of the symbol.  SYMNAME will be NULL
+   if no error occurred but the symbol could not be found.  */
+
+typedef void (*backtrace_syminfo_callback) (void *data, uintptr_t pc,
+                                           const char *symname,
+                                           uintptr_t symval,
+                                           uintptr_t symsize);
+
+/* Given ADDR, an address or program counter in the current program,
+   call the callback information with the symbol name and value
+   describing the function or variable in which ADDR may be found.
+   This will call either CALLBACK or ERROR_CALLBACK exactly once.
+   This returns 1 on success, 0 on failure.  This function requires
+   the symbol table but does not require the debug info.  Note that if
+   the symbol table is present but ADDR could not be found in the
+   table, CALLBACK will be called with a NULL SYMNAME argument.
+   Returns 1 on success, 0 on error.  */
+
+extern int backtrace_syminfo (struct backtrace_state *state, uintptr_t addr,
+                             backtrace_syminfo_callback callback,
+                             backtrace_error_callback error_callback,
+                             void *data);
+
+#ifdef __cplusplus
+} /* End extern "C".  */
+#endif
+
+#endif
+
diff --git a/libbacktrace/include/config/config.h 
b/libbacktrace/include/config/config.h
new file mode 100644
index 0000000..5086f4d
--- /dev/null
+++ b/libbacktrace/include/config/config.h
@@ -0,0 +1,135 @@
+/* config.h.  Generated from config.h.in by configure.  */
+/* config.h.in.  Generated from configure.ac by autoheader.  */
+
+/* ELF size: 32 or 64 */
+#define BACKTRACE_ELF_SIZE 64
+
+/* Define to 1 if you have the __atomic functions */
+#define HAVE_ATOMIC_FUNCTIONS 1
+
+/* Define to 1 if you have the declaration of `strnlen', and to 0 if you
+   don't. */
+#define HAVE_DECL_STRNLEN 1
+
+/* Define to 1 if you have the <dlfcn.h> header file. */
+#define HAVE_DLFCN_H 1
+
+/* Define if dl_iterate_phdr is available. */
+#define HAVE_DL_ITERATE_PHDR 1
+
+/* Define to 1 if you have the fcntl function */
+#define HAVE_FCNTL 1
+
+/* Define if getexecname is available. */
+/* #undef HAVE_GETEXECNAME */
+
+/* Define if _Unwind_GetIPInfo is available. */
+#define HAVE_GETIPINFO 1
+
+/* Define to 1 if you have the <inttypes.h> header file. */
+#define HAVE_INTTYPES_H 1
+
+/* Define to 1 if you have the <link.h> header file. */
+#define HAVE_LINK_H 1
+
+/* Define to 1 if you have the <memory.h> header file. */
+#define HAVE_MEMORY_H 1
+
+/* Define to 1 if you have the <stdint.h> header file. */
+#define HAVE_STDINT_H 1
+
+/* Define to 1 if you have the <stdlib.h> header file. */
+#define HAVE_STDLIB_H 1
+
+/* Define to 1 if you have the <strings.h> header file. */
+#define HAVE_STRINGS_H 1
+
+/* Define to 1 if you have the <string.h> header file. */
+#define HAVE_STRING_H 1
+
+/* Define to 1 if you have the __sync functions */
+#define HAVE_SYNC_FUNCTIONS 1
+
+/* Define to 1 if you have the <sys/mman.h> header file. */
+#define HAVE_SYS_MMAN_H 1
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
+#define HAVE_SYS_STAT_H 1
+
+/* Define to 1 if you have the <sys/types.h> header file. */
+#define HAVE_SYS_TYPES_H 1
+
+/* Define to 1 if you have the <unistd.h> header file. */
+#define HAVE_UNISTD_H 1
+
+/* Define to the sub-directory in which libtool stores uninstalled libraries.
+   */
+#define LT_OBJDIR ".libs/"
+
+/* Define to the address where bug reports for this package should be sent. */
+#define PACKAGE_BUGREPORT ""
+
+/* Define to the full name of this package. */
+#define PACKAGE_NAME "package-unused"
+
+/* Define to the full name and version of this package. */
+#define PACKAGE_STRING "package-unused version-unused"
+
+/* Define to the one symbol short name of this package. */
+#define PACKAGE_TARNAME "libbacktrace"
+
+/* Define to the home page for this package. */
+#define PACKAGE_URL ""
+
+/* Define to the version of this package. */
+#define PACKAGE_VERSION "version-unused"
+
+/* The size of `char', as computed by sizeof. */
+/* #undef SIZEOF_CHAR */
+
+/* The size of `int', as computed by sizeof. */
+/* #undef SIZEOF_INT */
+
+/* The size of `long', as computed by sizeof. */
+/* #undef SIZEOF_LONG */
+
+/* The size of `short', as computed by sizeof. */
+/* #undef SIZEOF_SHORT */
+
+/* The size of `void *', as computed by sizeof. */
+/* #undef SIZEOF_VOID_P */
+
+/* Define to 1 if you have the ANSI C header files. */
+#define STDC_HEADERS 1
+
+/* Enable extensions on AIX 3, Interix.  */
+#ifndef _ALL_SOURCE
+# define _ALL_SOURCE 1
+#endif
+/* Enable GNU extensions on systems that have them.  */
+#ifndef _GNU_SOURCE
+# define _GNU_SOURCE 1
+#endif
+/* Enable threading extensions on Solaris.  */
+#ifndef _POSIX_PTHREAD_SEMANTICS
+# define _POSIX_PTHREAD_SEMANTICS 1
+#endif
+/* Enable extensions on HP NonStop.  */
+#ifndef _TANDEM_SOURCE
+# define _TANDEM_SOURCE 1
+#endif
+/* Enable general extensions on Solaris.  */
+#ifndef __EXTENSIONS__
+# define __EXTENSIONS__ 1
+#endif
+
+
+/* Define to 1 if on MINIX. */
+/* #undef _MINIX */
+
+/* Define to 2 if the system does not provide POSIX.1 features except with
+   this defined. */
+/* #undef _POSIX_1_SOURCE */
+
+/* Define to 1 if you need to in order for `stat' and other things to work. */
+/* #undef _POSIX_SOURCE */
-- 
2.17.1


_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.