diff --git a/stdlib/public/runtime/Errors.cpp b/stdlib/public/runtime/Errors.cpp index c3d5b0ff5f81c..e027ec6e72dbe 100644 --- a/stdlib/public/runtime/Errors.cpp +++ b/stdlib/public/runtime/Errors.cpp @@ -22,6 +22,22 @@ #include #endif +#if defined(__ELF__) +# if defined(__FreeBSD__) && !defined(_GNU_SOURCE) +// In order to access _Unwind_Backtrace() from (the non-LLVM, non-GCC) +// in FreeBSD, define _GNU_SOURCE around the include. Do this +// before including other headers which may in turn include , which +// has a header guard. +# define _GNU_SOURCE +# define _SHOULD_UNDEFINE_GNU_SOURCE +# endif +# include +# ifdef _SHOULD_UNDEFINE_GNU_SOURCE +# undef _GNU_SOURCE +# undef _SHOULD_UNDEFINE_GNU_SOURCE +# endif +#endif + #include #include #include @@ -56,10 +72,6 @@ #include #endif -#if defined(__ELF__) -#include -#endif - #include #ifdef SWIFT_HAVE_CRASHREPORTERCLIENT