Commit Graph

118 Commits

Author SHA1 Message Date
Saleem Abdulrasool
e9ec50132f runtime: sprinkle some linker pragmas to autolink
This prepares the runtime to be closed with its dependencies when
performing static linking. The pragma ensures that the linker will
automatically pick up the dependent libraries avoiding the need to
explicitly add the dependencies.
2025-01-17 08:58:42 -08:00
Saleem Abdulrasool
9e413bd3d2 runtime: use _strdup on Windows
Windows prefers the `_strdup` extension over `strdup`. This avoids
unnecessary warnings when building the standard library.
2024-12-12 10:36:36 -08:00
Alastair Houghton
a72c167af5 [Runtime][Win32] Further tweaks to SymbolInfo.cpp and Errors.cpp.
Fix an unused variable warning in `Errors.cpp`.

Use brace initialization syntax in `SymbolInfo.cpp` rather than using
a constructor call.

rdar://130992923
2024-07-11 11:51:59 +01:00
Alastair Houghton
8ad89c08e2 [Runtime][Win32] Fix fatalError() backtraces.
We were calling `SymInitialize()` multiple times, which is wrong, which
was making the `SymbolInfo::lookup()` call fail.  Also, we weren't
fetching the module names, so we should do that too.

rdar://130992923
2024-07-09 18:50:20 +01:00
Saleem Abdulrasool
269565c9dd runtime: add an explicit cast for older C++ runtimes
The older C++ runtime seems to be unhappy with the implicit conversion
of the parameters:

~~~
FAILED: stdlib/public/runtime/CMakeFiles/swiftRuntime-linux-x86_64.dir/Errors.cpp.o
/home/build-user/build/buildbot_incremental_lsan/llvm-linux-x86_64/./bin/clang++ -DCMARK_STATIC_DEFINE -DGTEST_HAS_RTTI=0 -DLLVM_DISABLE_ABI_BREAKING_CHECKS_ENFORCING=1 -DOBJC_OLD_DISPATCH_PROTOTYPES=0 -DSWIFT_BUILD_SWIFT_SYNTAX -DSWIFT_INLINE_NAMESPACE=__runtime -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_LIBCPP_ENABLE_HARDENED_MODE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/build-user/build/buildbot_incremental_lsan/swift-linux-x86_64/stdlib/public/runtime -I/home/build-user/swift/stdlib/public/runtime -I/home/build-user/swift/stdlib/include -I/home/build-user/swift/stdlib/public/SwiftShims -I/home/build-user/build/buildbot_incremental_lsan/swift-linux-x86_64/include -I/home/build-user/swift/include -I/home/build-user/build/buildbot_incremental_lsan/llvm-linux-x86_64/include -I/home/build-user/llvm-project/clang/include -I/home/build-user/build/buildbot_incremental_lsan/llvm-linux-x86_64/tools/clang/include -I/home/build-user/cmark/src/include -I/home/build-user/build/buildbot_incremental_lsan/cmark-linux-x86_64/src -I/home/build-user/swift-corelibs-libdispatch/src/BlocksRuntime -I/home/build-user/swift-corelibs-libdispatch -gline-tables-only -fPIC -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fno-omit-frame-pointer -fsanitize=leak -fdiagnostics-color -ffunction-sections -fdata-sections -O2 -DNDEBUG -fvisibility=hidden -fvisibility-inlines-hidden -fno-exceptions -funwind-tables -fno-rtti -Werror=gnu -Werror=c++98-compat-extra-semi -UNDEBUG -Werror=switch -Wimplicit-fallthrough -Wunreachable-code -Woverloaded-virtual -Wno-nested-anon-types -fno-sanitize=all -Wall -Wformat-nonliteral -Werror=format-nonliteral -Wglobal-constructors -Werror=global-constructors -Wexit-time-destructors -Werror=exit-time-destructors -DSWIFT_RUNTIME_CLOBBER_FREED_OBJECTS=1 -DswiftCore_EXPORTS -I/home/build-user/swift/stdlib/include/llvm/Support -I/home/build-user/swift/include -DSWIFT_TARGET_LIBRARY_NAME=swiftRuntime -DSWIFT_RUNTIME -DSWIFT_LIB_SUBDIR="linux" -DSWIFT_ARCH="x86_64" -target x86_64-unknown-linux-gnu -fno-omit-frame-pointer -O0 -g -mcx16 -DSWIFT_ENABLE_RUNTIME_FUNCTION_COUNTERS -march=core2 -DSWIFT_OBJC_INTEROP=0 -DSWIFT_LIBRARY_EVOLUTION=1 -DSWIFT_STDLIB_SUPPORT_BACK_DEPLOYMENT -DSWIFT_ENABLE_REFLECTION -DSWIFT_STDLIB_HAS_DLADDR -DSWIFT_STDLIB_HAS_DLSYM=1 -DSWIFT_STDLIB_HAS_FILESYSTEM -DSWIFT_STDLIB_HAS_DARWIN_LIBMALLOC=1 -DSWIFT_STDLIB_HAS_STDIN -DSWIFT_STDLIB_HAS_ENVIRON -DSWIFT_STDLIB_HAS_LOCALE -DSWIFT_THREADING_LINUX -DSWIFT_RUNTIME_OS_VERSIONING -DSWIFT_STDLIB_SHORT_MANGLING_LOOKUPS -DSWIFT_STDLIB_ENABLE_VECTOR_TYPES -DSWIFT_STDLIB_HAS_TYPE_PRINTING -DSWIFT_STDLIB_SUPPORTS_BACKTRACE_REPORTING -DSWIFT_STDLIB_ENABLE_UNICODE_DATA -DSWIFT_STDLIB_OVERRIDABLE_RETAIN_RELEASE -std=c++17 -MD -MT stdlib/public/runtime/CMakeFiles/swiftRuntime-linux-x86_64.dir/Errors.cpp.o -MF stdlib/public/runtime/CMakeFiles/swiftRuntime-linux-x86_64.dir/Errors.cpp.o.d -o stdlib/public/runtime/CMakeFiles/swiftRuntime-linux-x86_64.dir/Errors.cpp.o -c /home/build-user/swift/stdlib/public/runtime/Errors.cpp
/home/build-user/swift/stdlib/public/runtime/Errors.cpp:315:13: error: no matching function for call to 'atomic_compare_exchange_strong_explicit'
315 | } while (!std::atomic_compare_exchange_strong_explicit(&kFatalErrorMessage,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/lib/gcc/x86_64-linux-gnu/7/../../../../include/c++/7/atomic:1121:5: note: candidate template ignored: deduced conflicting types for parameter '_ITp' ('const char ' vs. 'char ')
1121 | atomic_compare_exchange_strong_explicit(atomic<_ITp> __a,
| ^
/usr/lib/gcc/x86_64-linux-gnu/7/../../../../include/c++/7/atomic:1129:5: note: candidate template ignored: deduced conflicting types for parameter '_ITp' ('const char ' vs. 'char ')
1129 | atomic_compare_exchange_strong_explicit(volatile atomic<_ITp> __a,
| ^
/usr/lib/gcc/x86_64-linux-gnu/7/../../../../include/c++/7/bits/shared_ptr_atomic.h:220:5: note: candidate template ignored: could not match 'shared_ptr' against 'atomic'
220 | atomic_compare_exchange_strong_explicit(shared_ptr<_Tp> __p,
| ^
/usr/lib/gcc/x86_64-linux-gnu/7/../../../../include/c++/7/bits/shared_ptr_atomic.h:272:5: note: candidate template ignored: could not match '__shared_ptr' against 'atomic'
272 | atomic_compare_exchange_strong_explicit(__shared_ptr<_Tp, _Lp> __p,
| ^
1 error generated.
~~~

Use an explicit cast to resolve the ambiguity.
2024-04-08 10:28:31 -07:00
Saleem Abdulrasool
32a2dfc566 Runtime: add a non-Darwin error message storage
This introduces a non-Darwin (non-CrashReporter) storage for error
messages to allow extraction for crash reporting. This is initially
meant to be used on Windows, though it is generic enough to be used on
any platform.
2024-04-05 14:02:09 -07:00
Allan Shortlidge
79d0ecafaa NFC: Ignore deprecation of asl_log in the runtime and demangling library.
ASL is deprecated in macOS 10.12. It may be time to transition to os_log now
that deployment targets have been raised to 10.12, but until that project
starts these warnings are just pollution.

Filed rdar://121066531 to track adoption of `os_log()` if appropriate.
2024-01-16 13:27:55 -08:00
Alastair Houghton
9d462a7b69 [Backtracing] Add an indication that we're working on a backtrace.
When we crash, emit a message straight away that says we're working
on a backtrace.  If starting the backtracer fails, report that also.

Finally, add a duration to the messages output by the backtracer, so
that we can see how long it took.

rdar://118055527
2023-11-09 18:12:18 +00:00
Alastair Houghton
003b4556b3 [Backtracing] Fix a Windows build issue.
When backtracing is disabled, don't try to refer to
`_swift_backtraceSettings`.

rdar://117470489
2023-11-08 16:06:16 +00:00
Alastair Houghton
93e05cd1bb [Linux] Disable fatalError() backtraces when the runtime backtracer is active.
There's no need for fatalError() to try to generate its own backtraces
when the runtime's backtracer is enabled.  Not only is the code it uses
more fragile but it also doesn't support async or inline frames and it
can't look-up symbols properly either.

rdar://117470489
2023-11-01 09:18:21 +00:00
Hiroshi Yamauchi
5fc3ad3a81 Fix a fatal error not-terminating issue in Windows.
Fix the issue that fatal errors in certain cases don't terminate the
process and the process keeps running in Windows by disabling the
exception swallowing that supressed the illegal instruction exceptions
coming from llvm.trap.
2023-08-25 13:04:36 -07:00
Alastair Houghton
2dcaa6f14f [Backtracing][Linux] Add Linux crash handler to the runtime.
This also adds a function to demangle a symbol, and a way for the
backtracing code to report warning messages to the same place as
the main runtime.

I'd like to rename the _swift_isThunkFunction() SPI also, but we
can't do that until we've made the changes to the _Backtracing
library, so we'll do that there instead.

rdar://110261430
2023-06-05 15:39:50 +01:00
Alastair Houghton
e73de539b8 Move _swift_win32_withDbgHelpLibrary into the new header.
It makes sense to move this function into the new Win32 header.

rdar://103397975
2022-12-21 11:44:37 +00:00
Jonathan Grynspan
c889270a38 Remove lookupSymbol() and have all callers use SymbolInfo::lookup() instead (#62552) 2022-12-14 08:33:32 -05:00
Jonathan Grynspan
26fc627ad0 Fix a use-after-free bug on Win32 when calling lookupSymbol() (#62484) 2022-12-13 09:04:34 -05:00
Jonathan Grynspan
687f754c8f Rename the runtime function to 'namespace' it in 'win32' 2022-11-30 15:32:24 -05:00
Jonathan Grynspan
e199f0b077 Refactor _swift_withWin32DbgHelpLibrary to avoid using GetCurrentProcess() per Microsoft documentation 2022-11-29 16:02:53 -05:00
Alastair Houghton
ab9e628b72 [Threading][Runtime] Separate threading error function to fix link on Linux.
On Linux it seems that the linker objects, probably because of link order,
to the definition of `swift::threading::fatal()` being in both static
libraries.  Fix by moving `swift::threading::fatal()` to its own file
in the main runtime as well as the Concurrency runtime.

Fixes #59444.
2022-06-15 08:22:53 +01:00
Alastair Houghton
0e9318cec5 [Threading] Put everything through git clang-format.
Just formatting changes.

rdar://90776105
2022-06-07 07:39:53 +01:00
Alastair Houghton
66f6eb6bc6 [Runtime][Windows] A couple of files need to include <windows.h>
We shouldn't include <windows.h> implicitly from .cpp files, but should
do it directly so that we know it's there.

Also, if we're including <windows.h>, do it at the top of the file.

rdar://90776105
2022-06-07 07:39:52 +01:00
Alastair Houghton
f5bdb858e0 [Threading] Create new threading library and use it.
Moved all the threading code to one place.  Added explicit support for
Darwin, Linux, Pthreads, C11 threads and Win32 threads, including new
implementations of Once for Linux, Pthreads, C11 and Win32.

rdar://90776105
2022-06-07 07:39:51 +01:00
Alex Hoppen
4aa2bbbf06 Revert "Merge pull request #42447 from al45tair/eng/PR-90776105"
This reverts commit 8bcb71140f, reversing
changes made to c4dd271d36.
2022-06-02 18:03:23 +02:00
Alastair Houghton
b5bd267ff1 [Threading] Put everything through git clang-format.
Just formatting changes.

rdar://90776105
2022-05-24 14:57:41 +01:00
Alastair Houghton
79e2d0d37d [Runtime][Windows] A couple of files need to include <windows.h>
We shouldn't include <windows.h> implicitly from .cpp files, but should
do it directly so that we know it's there.

Also, if we're including <windows.h>, do it at the top of the file.

rdar://90776105
2022-05-24 14:57:40 +01:00
Alastair Houghton
63a09007a1 [Threading] Create new threading library and use it.
Moved all the threading code to one place.  Added explicit support for
Darwin, Linux, Pthreads, C11 threads and Win32 threads, including new
implementations of Once for Linux, Pthreads, C11 and Win32.

rdar://90776105
2022-05-24 14:57:39 +01:00
Alastair Houghton
7c48b83f79 [Demangling] Use SWIFT_MEMORY_ORDER_CONSUME.
Also rearrange the #ifs to make the two pieces of code match more
closely.

rdar://91095592
2022-03-31 16:40:49 +01:00
Alastair Houghton
3f49b8be32 [Demangling] Fix duplicate _gCRAnnotations symbol problems.
Moved the _gCRAnnotations declarations to their own object module,
which will help to avoid duplicate symbol problems (at least with .a
files).

Also tweaked things to make it so that the demangler and runtime
versions of the message setting code will interoperate (and so that
they'll interoperate better with other implementations that might
creep in from somewhere, like the one in LLVMSupport).

rdar://91095592
2022-03-31 13:04:09 +01:00
Alastair Houghton
eb6f9e0bba Merge pull request #41452 from al45tair/eng/PR-89139049
[Demangler] Make Node::addChild(NULL, ...) always assert.
2022-03-25 10:03:59 +00:00
Alastair Houghton
71efd95052 [Demangler][Runtime] Give the demangler its own error handling.
The demangling library can't use the error handling from the main runtime
because it isn't always linked with it.  However, it's useful to have
some error handling, and in particular to be able to get data into the
crash logs.

This is complicated because of the way the demangling library gets used,
the upshot of which is that I've had to add a second object library just
for libswiftCore's use, so that the demangler will use the runtime's
error handling functions when present, and fall back on its own when
they aren't.

rdar://89139049
2022-03-24 13:05:13 +00:00
Karoy Lorentey
b0a60faf08 [runtime][NFC] Unify reportOnCrash implementations into a single function 2022-02-18 15:02:40 -08:00
Jonathan Grynspan
0db7b5abc4 Ensure Debug Help library calls on Windows are made in as thread-safe a manner as possible by wrapping them in a scoped lock. 2022-01-12 12:37:45 -05:00
David Smith
f1a5e27821 Add a build flag to disable building Unicode support 2021-12-21 17:26:15 -08:00
Kuba (Brecka) Mracek
3d08df9f3c Avoid including unistd.h and replace write(STDERR) with fputs(stderr) (#40177) 2021-11-15 18:41:49 -08:00
Kuba (Brecka) Mracek
2f7bbe6610 Don't include asl.h when SWIFT_STDLIB_HAS_ASL is not set (#40176) 2021-11-14 14:40:03 -08:00
Kuba (Brecka) Mracek
653642df75 Add a SWIFT_STDLIB_HAS_DARWIN_ASL config flag to allow removing asl_log() usage in freestanding build (#39584) 2021-10-12 07:14:33 -07:00
Kuba (Brecka) Mracek
ca0dff803b Turn existing ifdefs around backtrace() API into a CMake SWIFT_SUPPORTS_BACKTRACE_REPORTING flag (#39598) 2021-10-06 14:46:08 -07:00
Kuba (Brecka) Mracek
c2a92722c6 Split the NO_DYLD CMake flag into separate HAS_DLADDR and STATIC_IMAGE_INSPECTION flags (#39339) 2021-09-29 19:57:05 -07:00
Kuba (Brecka) Mracek
de015c6464 Unify asprintf/vasprintf implementations and make them truly portable by using vsnprintf (#39314) 2021-09-15 21:09:03 -07:00
Saleem Abdulrasool
6c50325c2a runtime: replace use of std::mutex with StaticMutex
Replace the `static std::mutex` with Swift's `StaticMutex` so that we
avoid triggering an error due to an exit time destructor.  Repairs the
build after #38562.
2021-07-30 09:16:12 -07:00
Kuba (Brecka) Mracek
db18deaf91 Add a SWIFT_RUNTIME_MACHO_NO_DYLD stdlib mode that doesn't dynamically look up sections in modules, and only assumes a single static module (#33441) 2020-08-18 11:46:42 -07:00
Mike Ash
cd624bf380 [Runtime][Reflection][swift-inspect] Add facilities for tracking and examining backtraces for metadata allocations.
rdar://problem/63674755
2020-06-11 14:49:52 -04:00
Saleem Abdulrasool
2ea11b5428 runtime: remove use of swift/LLVM.h (NFC)
Rather than using the forward declaration for the LLVMSupport types,
expect to be able to use the full declaration.  Because these are
references in the implementation, there is no reason to use a forward
declaration as the full types need to be declared for use.  The LLVM
headers will provide the declaration and definition for the types.  This
is motivated by the desire to ensure that the LLVMSupport symbols are
properly namespaced to avoid ODR violations in the runtime.
2020-05-07 13:37:31 -07:00
Saleem Abdulrasool
e0b0d20cd8 runtime: add and switch to SWIFT_NORETURN (NFC)
Remove the use of the `LLVM_ATTRIBUTE_NORETURN` to trim dependencies on
LLVMSupport.
2020-05-07 09:22:39 -07:00
Saleem Abdulrasool
f465ec0345 runtime: add and switch to SWIFT_NOINLINE (NFC)
This switches the `LLVM_ATTRIBUTE_NOINLINE` to a local copy which is
namespaced in Swift.
2020-05-06 14:07:20 -07:00
Saleem Abdulrasool
9731704cc7 runtime: replace LLVM_LIBRARY_VISIBILITY with SWIFT_LIBRARY_VISIBILITY (NFC)
This replaces `LLVM_LIBRARY_VISIBILITY` with `SWIFT_LIBRARY_VISIBILTIY`
througout the runtime.  The purpose of this attribution is unclear -
building with `-fvisibility=hidden` would accomplish this.  This is an
entirely mechanical change replacing the macro with the Swift namespaced
variant instead.
2020-05-06 08:30:17 -07:00
Dmitri Gribenko
3566e6ed7a Merge pull request #29530 from swiftwasm/swiftwasm-ifdefs
[WebAssembly] Add ifdefs for the WASI target
2020-02-13 17:40:45 +01:00
Max Desiatov
67297904ac [WebAssembly] Add ifdefs for the WASI target 2020-02-08 07:37:10 +00:00
Joe Groff
fb34044408 Merge remote-tracking branch 'origin/master' into master-next 2019-12-10 12:46:41 -08:00
Puyan Lotfi
caf5af4027 [NFCi] Adding inttypes.h to Errors.cpp due to llvm.org change in STLExtras.h.
In Errors.cpp, PRIxPTR is used in a format string:

constexpr const char *format = "%-4u %-34s 0x%0.16" PRIxPTR " %s + %td\n";

This fails to build because of upstream changes in STLExtras:

049043b598 (diff-43fc25e3af55e1ae97f17ef051d68aa4)

This patch merely adds the include for the needed PRIxPTR define.

(cherry picked from commit 0529fbedca)
2019-12-06 14:28:36 -05:00
Adrian Prantl
1d5518236d Add missing include for PRIxPTR (NFC) 2019-11-22 13:18:01 -08:00