Skip to content

Commit

Permalink
libstdc++: Define <stacktrace> header for C++23
Browse files Browse the repository at this point in the history
Add the <stacktrace> header and a new libstdc++_libbacktrace.a library
that provides the implementation. For now, the new library is only built
if --enable-libstdcxx-backtrace=yes is used. As with the Filesystem TS,
the new library is only provided as a static archive.

libstdc++-v3/ChangeLog:

	* acinclude.m4 (GLIBCXX_ENABLE_BACKTRACE): New macro.
	* configure.ac: Use GLIBCXX_ENABLE_BACKTRACE.
	* include/Makefile.am: Add new header.
	* include/Makefile.in: Regenerate.
	* include/std/stacktrace: New header.
	* include/std/version (__cpp_lib_stacktrace): Define.
	* Makefile.in: Regenerate.
	* config.h.in: Regenerate.
	* configure: Regenerate.
	* doc/Makefile.in: Regenerate.
	* libsupc++/Makefile.in: Regenerate.
	* po/Makefile.in: Regenerate.
	* python/Makefile.in: Regenerate.
	* src/Makefile.am: Regenerate.
	* src/Makefile.in: Regenerate.
	* src/c++11/Makefile.in: Regenerate.
	* src/c++17/Makefile.in: Regenerate.
	* src/c++20/Makefile.in: Regenerate.
	* src/c++98/Makefile.in: Regenerate.
	* src/filesystem/Makefile.in: Regenerate.
	* testsuite/Makefile.in: Regenerate.
	* src/libbacktrace/Makefile.am: New file.
	* src/libbacktrace/Makefile.in: New file.
	* src/libbacktrace/backtrace-rename.h: New file.
	* src/libbacktrace/backtrace-supported.h.in: New file.
	* src/libbacktrace/config.h.in: New file.
	* testsuite/lib/libstdc++.exp (check_effective_target_stacktrace):
	New proc.
	* testsuite/20_util/stacktrace/entry.cc: New test.
	* testsuite/20_util/stacktrace/synopsis.cc: New test.
	* testsuite/20_util/stacktrace/version.cc: New test.
  • Loading branch information
jwakely committed Jan 17, 2022
1 parent 5a3dc58 commit 3acb929
Show file tree
Hide file tree
Showing 30 changed files with 2,605 additions and 14 deletions.
7 changes: 7 additions & 0 deletions libstdc++-v3/Makefile.in
Expand Up @@ -185,6 +185,7 @@ ABI_TWEAKS_SRCDIR = @ABI_TWEAKS_SRCDIR@
ACLOCAL = @ACLOCAL@
ALLOCATOR_H = @ALLOCATOR_H@
ALLOCATOR_NAME = @ALLOCATOR_NAME@
ALLOC_FILE = @ALLOC_FILE@
AMTAR = @AMTAR@
AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
AR = @AR@
Expand All @@ -196,6 +197,10 @@ AUTOCONF = @AUTOCONF@
AUTOHEADER = @AUTOHEADER@
AUTOMAKE = @AUTOMAKE@
AWK = @AWK@
BACKTRACE_CPPFLAGS = @BACKTRACE_CPPFLAGS@
BACKTRACE_SUPPORTED = @BACKTRACE_SUPPORTED@
BACKTRACE_SUPPORTS_THREADS = @BACKTRACE_SUPPORTS_THREADS@
BACKTRACE_USES_MALLOC = @BACKTRACE_USES_MALLOC@
BASIC_FILE_CC = @BASIC_FILE_CC@
BASIC_FILE_H = @BASIC_FILE_H@
CC = @CC@
Expand Down Expand Up @@ -240,6 +245,7 @@ EXEEXT = @EXEEXT@
EXTRA_CFLAGS = @EXTRA_CFLAGS@
EXTRA_CXX_FLAGS = @EXTRA_CXX_FLAGS@
FGREP = @FGREP@
FORMAT_FILE = @FORMAT_FILE@
FREESTANDING_FLAGS = @FREESTANDING_FLAGS@
GLIBCXX_INCLUDES = @GLIBCXX_INCLUDES@
GLIBCXX_LIBS = @GLIBCXX_LIBS@
Expand Down Expand Up @@ -295,6 +301,7 @@ SYMVER_FILE = @SYMVER_FILE@
TOPLEVEL_INCLUDES = @TOPLEVEL_INCLUDES@
USE_NLS = @USE_NLS@
VERSION = @VERSION@
VIEW_FILE = @VIEW_FILE@
VTV_CXXFLAGS = @VTV_CXXFLAGS@
VTV_CXXLINKFLAGS = @VTV_CXXLINKFLAGS@
VTV_PCH_CXXFLAGS = @VTV_PCH_CXXFLAGS@
Expand Down
138 changes: 137 additions & 1 deletion libstdc++-v3/acinclude.m4
Expand Up @@ -49,7 +49,7 @@ AC_DEFUN([GLIBCXX_CONFIGURE], [
# Keep these sync'd with the list in Makefile.am. The first provides an
# expandable list at autoconf time; the second provides an expandable list
# (i.e., shell variable) at configure time.
m4_define([glibcxx_SUBDIRS],[include libsupc++ src src/c++98 src/c++11 src/c++17 src/c++20 src/filesystem doc po testsuite python])
m4_define([glibcxx_SUBDIRS],[include libsupc++ src src/c++98 src/c++11 src/c++17 src/c++20 src/filesystem src/libbacktrace doc po testsuite python])
SUBDIRS='glibcxx_SUBDIRS'
# These need to be absolute paths, yet at the same time need to
Expand Down Expand Up @@ -4801,6 +4801,142 @@ AC_DEFUN([GLIBCXX_CHECK_ARC4RANDOM], [
AC_LANG_RESTORE
])

dnl
dnl Check to see whether to build libstdc++_libbacktrace.a
dnl
dnl --enable-libstdcxx-backtrace
dnl
AC_DEFUN([GLIBCXX_ENABLE_BACKTRACE], [
GLIBCXX_ENABLE(libstdcxx-backtrace,auto,,
[turns on libbacktrace support],
[permit yes|no|auto])
# Most of this is adapted from libsanitizer/configure.ac
BACKTRACE_CPPFLAGS=
# libbacktrace only needs atomics for int, which we've already tested
if test "$glibcxx_cv_atomic_int" = "yes"; then
BACKTRACE_CPPFLAGS="$BACKTRACE_CPPFLAGS -DHAVE_ATOMIC_FUNCTIONS=1"
fi
# Test for __sync support.
AC_CACHE_CHECK([__sync extensions],
[glibcxx_cv_sys_sync],
[GCC_TRY_COMPILE_OR_LINK(
[int i;],
[__sync_bool_compare_and_swap (&i, i, i);
__sync_lock_test_and_set (&i, 1);
__sync_lock_release (&i);],
[glibcxx_cv_sys_sync=yes],
[glibcxx_cv_sys_sync=no])
])
if test "$glibcxx_cv_sys_sync" = "yes"; then
BACKTRACE_CPPFLAGS="$BACKTRACE_CPPFLAGS -DHAVE_SYNC_FUNCTIONS=1"
fi
# Check for dl_iterate_phdr.
AC_CHECK_HEADERS(link.h)
if test "$ac_cv_header_link_h" = "no"; then
have_dl_iterate_phdr=no
else
# When built as a GCC target library, we can't do a link test.
AC_EGREP_HEADER([dl_iterate_phdr], [link.h], [have_dl_iterate_phdr=yes],
[have_dl_iterate_phdr=no])
fi
if test "$have_dl_iterate_phdr" = "yes"; then
BACKTRACE_CPPFLAGS="$BACKTRACE_CPPFLAGS -DHAVE_DL_ITERATE_PHDR=1"
fi
# Check for the fcntl function.
if test -n "${with_target_subdir}"; then
case "${host}" in
*-*-mingw*) have_fcntl=no ;;
*) have_fcntl=yes ;;
esac
else
AC_CHECK_FUNC(fcntl, [have_fcntl=yes], [have_fcntl=no])
fi
if test "$have_fcntl" = "yes"; then
BACKTRACE_CPPFLAGS="$BACKTRACE_CPPFLAGS -DHAVE_FCNTL=1"
fi
AC_CHECK_DECLS(strnlen)
# Check for getexecname function.
if test -n "${with_target_subdir}"; then
case "${host}" in
*-*-solaris2*) have_getexecname=yes ;;
*) have_getexecname=no ;;
esac
else
AC_CHECK_FUNC(getexecname, [have_getexecname=yes], [have_getexecname=no])
fi
if test "$have_getexecname" = "yes"; then
BACKTRACE_CPPFLAGS="$BACKTRACE_CPPFLAGS -DHAVE_GETEXECNAME=1"
fi
# The library needs to be able to read the executable itself. Compile
# a file to determine the executable format. The awk script
# filetype.awk prints out the file type.
AC_CACHE_CHECK([output filetype],
[glibcxx_cv_sys_filetype],
[filetype=
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM([int i;], [int j;])],
[filetype=`${AWK} -f $srcdir/../libbacktrace/filetype.awk conftest.$ac_objext`],
[AC_MSG_FAILURE([compiler failed])])
glibcxx_cv_sys_filetype=$filetype])
# Match the file type to decide what files to compile.
FORMAT_FILE=
case "$glibcxx_cv_sys_filetype" in
elf*) FORMAT_FILE="elf.lo" ;;
*) AC_MSG_WARN([could not determine output file type])
FORMAT_FILE="unknown.lo"
enable_libstdcxx_backtrace=no
;;
esac
AC_SUBST(FORMAT_FILE)
# ELF defines.
elfsize=
case "$glibcxx_cv_sys_filetype" in
elf32) elfsize=32 ;;
elf64) elfsize=64 ;;
esac
BACKTRACE_CPPFLAGS="$BACKTRACE_CPPFLAGS -DBACKTRACE_ELF_SIZE=$elfsize"
ALLOC_FILE=alloc.lo
AC_SUBST(ALLOC_FILE)
VIEW_FILE=read.lo
AC_SUBST(VIEW_FILE)
AC_MSG_CHECKING([whether to build libbacktrace support])
if test "$enable_libstdcxx_backtrace" == "auto"; then
enable_libstdcxx_backtrace=no
fi
if test "$enable_libstdcxx_backtrace" == "yes"; then
BACKTRACE_SUPPORTED=1
BACKTRACE_USES_MALLOC=1
if test "$ac_has_gthreads" = "yes"; then
BACKTRACE_SUPPORTS_THREADS=1
else
BACKTRACE_SUPPORTS_THREADS=0
fi
AC_SUBST(BACKTRACE_CPPFLAGS)
AC_SUBST(BACKTRACE_SUPPORTED)
AC_SUBST(BACKTRACE_USES_MALLOC)
AC_SUBST(BACKTRACE_SUPPORTS_THREADS)
AC_DEFINE(HAVE_STACKTRACE, 1, [Define if the <stacktrace> header is supported.])
else
BACKTRACE_SUPPORTED=0
BACKTRACE_USES_MALLOC=0
BACKTRACE_SUPPORTS_THREADS=0
fi
AC_MSG_RESULT($enable_libstdcxx_backtrace)
GLIBCXX_CONDITIONAL(ENABLE_BACKTRACE, [test "$enable_libstdcxx_backtrace" != no])
])

# Macros from the top-level gcc directory.
m4_include([../config/gc++filt.m4])
Expand Down
10 changes: 10 additions & 0 deletions libstdc++-v3/config.h.in
Expand Up @@ -66,6 +66,10 @@
/* Define to 1 if you have the `cosl' function. */
#undef HAVE_COSL

/* Define to 1 if you have the declaration of `strnlen', and to 0 if you
don't. */
#undef HAVE_DECL_STRNLEN

/* Define to 1 if you have the <dirent.h> header file. */
#undef HAVE_DIRENT_H

Expand Down Expand Up @@ -213,6 +217,9 @@
/* Define if link is available in <unistd.h>. */
#undef HAVE_LINK

/* Define to 1 if you have the <link.h> header file. */
#undef HAVE_LINK_H

/* Define if futex syscall is available. */
#undef HAVE_LINUX_FUTEX

Expand Down Expand Up @@ -346,6 +353,9 @@
/* Define to 1 if you have the `sqrtl' function. */
#undef HAVE_SQRTL

/* Define if the <stacktrace> header is supported. */
#undef HAVE_STACKTRACE

/* Define to 1 if you have the <stdalign.h> header file. */
#undef HAVE_STDALIGN_H

Expand Down

0 comments on commit 3acb929

Please sign in to comment.