Skip to content

runtime: fix compile failure from use of _Unwind_Backtrace() on FreeBSD 13.0 #61693

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions stdlib/public/runtime/Errors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,22 @@
#include <mutex>
#endif

#if defined(__ELF__)
# if defined(__FreeBSD__) && !defined(_GNU_SOURCE)
// In order to access _Unwind_Backtrace() from (the non-LLVM, non-GCC)
// <unwind.h> in FreeBSD, define _GNU_SOURCE around the include. Do this
// before including other headers which may in turn include <unwind.h>, which
// has a header guard.
# define _GNU_SOURCE
# define _SHOULD_UNDEFINE_GNU_SOURCE
# endif
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How terrible would it be to define _GNU_SOURCE when building just this source file for FreeBSD? That would impact any other headers included, but should be generally acceptable I imagine. That could then sink this into the build system as:

set_source_files_properties(Errors.cpp PROPERTIES
  COMPILE_DEFINITIONS $<$<PLATFORM_ID:FreeBSD>:_GNU_SOURCE>)

# include <unwind.h>
# ifdef _SHOULD_UNDEFINE_GNU_SOURCE
# undef _GNU_SOURCE
# undef _SHOULD_UNDEFINE_GNU_SOURCE
# endif
#endif

#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>
Expand Down Expand Up @@ -56,10 +72,6 @@
#include <android/log.h>
#endif

#if defined(__ELF__)
#include <unwind.h>
#endif

#include <inttypes.h>

#ifdef SWIFT_HAVE_CRASHREPORTERCLIENT
Expand Down