Skip to content

Commit

Permalink
Restore libunwind detection
Browse files Browse the repository at this point in the history
Restore libunwind detection when TSan is enabled at configure time. This
is based on the commit b694e84 by Seb Hinderer (@shindere), which was
undone by ocaml#9948, with significant changes:

- libunwind detection is only attempted when tsan is enabled
- if tsan is enabled, libunwind is requested and not optional
- libunwind_include_dirs and libunwind_link_dirs become
  libunwind_cppflags and libunwind_ldflags, respectively
  • Loading branch information
OlivierNicole authored and fabbing committed Jul 12, 2023
1 parent acb8924 commit 5b31b63
Show file tree
Hide file tree
Showing 5 changed files with 165 additions and 7 deletions.
3 changes: 0 additions & 3 deletions Makefile.config.in
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,6 @@ WITH_OCAMLTEST=@ocamltest@
ASM_CFI_SUPPORTED=@asm_cfi_supported@
WITH_FRAME_POINTERS=@frame_pointers@
HEADER_RESERVED_BITS=@reserved_header_bits@
LIBUNWIND_AVAILABLE=@libunwind_available@
LIBUNWIND_INCLUDE_FLAGS=@libunwind_include_flags@
LIBUNWIND_LINK_FLAGS=@libunwind_link_flags@
WITH_FPIC=@fpic@
TARGET=@target@
HOST=@host@
Expand Down
8 changes: 4 additions & 4 deletions aclocal.m4
Original file line number Diff line number Diff line change
Expand Up @@ -322,16 +322,16 @@ int main (int argc, char *argv[]){
])

AC_DEFUN([OCAML_CHECK_LIBUNWIND], [
SAVED_CFLAGS="$CFLAGS"
SAVED_CPPFLAGS="$CPPFLAGS"
SAVED_LDFLAGS="$LDFLAGS"
CFLAGS="$CFLAGS $libunwind_include_flags"
LDFLAGS="$LDFLAGS $libunwind_link_flags"
CPPFLAGS="$CPPFLAGS $libunwind_cppflags"
LDFLAGS="$LDFLAGS $libunwind_ldflags"
AC_CHECK_HEADER([libunwind.h],
[AC_DEFINE([HAS_LIBUNWIND])
libunwind_available=true],
[libunwind_available=false])
LDFLAGS="$SAVED_LDFLAGS"
CFLAGS="$SAVED_CFLAGS"
CPPFLAGS="$SAVED_CPPFLAGS"
])

AC_DEFUN([OCAML_TEST_FLEXLINK], [
Expand Down
101 changes: 101 additions & 0 deletions configure

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 58 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ oc_dll_ldflags=""
oc_exe_ldflags=""

tsan=false
# Passed to the linker by ocamlopt when tsan is enabled
oc_tsan_ldflags="-fsanitize=thread"

# The C# compiler and its flags
CSC=""
Expand Down Expand Up @@ -352,6 +354,15 @@ AC_ARG_ENABLE([tsan],
[],
[enable_tsan=no])

# Preprocessor and linker flags for libunwind (currently only used when TSan is
# enabled)

AC_ARG_VAR([LIBUNWIND_CPPFLAGS],
[cc flags for libunwind (e.g. -I<location of header files>)])

AC_ARG_VAR([LIBUNWIND_LDFLAGS],
[linker flags for libunwind (e.g. -L<location of static object files>])

AC_ARG_ENABLE([graph-lib], [],
[AS_IF([test "x$enableval" != 'xno'],
[AC_MSG_ERROR(m4_normalize([The graphics library is no longer distributed
Expand Down Expand Up @@ -1616,6 +1627,53 @@ $cc_basename on system $system"])]
)],
[tsan=false])

# libunwind detection when TSan is enabled
AC_MSG_CHECKING([whether libunwind is required])
AS_IF([! $tsan],
[libunwind_available=false
libunwind_cppflags=
libunwind_ldflags=
AC_MSG_RESULT([no])],
[AC_MSG_RESULT([yes])
AS_IF([test "$system" = "macosx"],
[AS_IF([test x"$LIBUNWIND_CPPFLAGS" != x -o \
x"$LIBUNWIND_LDFLAGS" != x],
[AC_MSG_WARN(m4_normalize([
On MacOSX, specifying paths for libunwind headers or libraries is
strongly discouraged. It is recommended to rely on the defaults
provided by the configure script
]))])])
AS_IF([test x"$LIBUNWIND_CPPFLAGS" != x],
[libunwind_cppflags="$LIBUNWIND_CPPFLAGS"],
[libunwind_cppflags=""])
AS_CASE(["$system"],
["macosx"], [libunwind_ldflags="-framework System"],
[libunwind_ldflags="-lunwind -lunwind-x86_64"])
AS_IF([test x"$LIBUNWIND_LDFLAGS" != x],
[libunwind_ldflags="$LIBUNWIND_LDFLAGS $libunwind_ldflags"])
native_cppflags="$native_cppflags $libunwind_cppflags"
oc_tsan_ldflags="$oc_tsan_ldflags $libunwind_ldflags"
OCAML_CHECK_LIBUNWIND
AS_IF([! $libunwind_available],
[AC_MSG_ERROR([libunwind was requested by tsan but can not be found])])
# We need unwinding information at runtime, but since we use
# -no_compact_unwind, we also need -keep_dwarf_unwind otherwise
# the OS X linker will chuck away the DWARF-like (.eh_frame)
# information. (Older versions of OS X don't provide this.)
AS_IF([$libunwind_available && test x"$system" = "xmacosx"],
[extra_flags="-Wl,-keep_dwarf_unwind"
mkexe="$mkexe $extra_flags"
mksharedlib="$mksharedlib $extra_flags"])
])

## Sockets

## TODO: check whether the different libraries are really useful
Expand Down
2 changes: 2 additions & 0 deletions runtime/caml/s.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,8 @@

#undef HUGE_PAGE_SIZE

#undef HAS_LIBUNWIND

#undef HAS_BROKEN_PRINTF

#undef HAS_STRERROR
Expand Down

0 comments on commit 5b31b63

Please sign in to comment.