Commit Graph

3157 Commits

Author SHA1 Message Date
Alastair Houghton
d67354473f Merge pull request #66335 from al45tair/eng/PR-110261712
[Backtracing][Linux] Add support for Linux in the _Backtracing module.
2023-06-07 13:48:46 +01:00
Alastair Houghton
3042cd742e [Backtracing][Linux] Enable backtrace-on-crash for Linux.
This reverts commit e5f4c2015e.

rdar://101623265
2023-06-07 09:08:18 +01:00
Alastair Houghton
ae9a0c1007 Merge pull request #66334 from al45tair/eng/PR-110261430
[Backtracing][Linux] Add Linux crash handler to the runtime.
2023-06-07 08:41:28 +01:00
Alastair Houghton
1262518ee4 [Backtracing][Linux] Add a comment about __cxa_demangle.
`__cxa_demangle()` is a rather unusual API; one of its "features" is that
the pointer you pass in must either be `nullptr`, in which case it
will call `malloc()` itself, _or_ it has to be a pointer to a block
of memory allocated with `malloc()`, because `__cxa_demangle()` may
`realloc()` it for you.

This seems to me to be something of a non-obvious footgun, so we never
pass the caller's pointer through to `__cxa_demangle()`, which lets them
decide how they want to allocate space.

rdar://110261712
2023-06-07 08:22:40 +01:00
Alastair Houghton
582946b3ee [Backtracing][Linux] Remove status argument.
The `status` argument to the `_swift_backtrace_demangle()` function
isn't especially useful, won't match behaviour on Windows, and we
actually don't use it in the Swift code that calls this SPI.

Remove it.

rdar://110261712
2023-06-07 08:19:13 +01:00
Dario Rexin
fe6f8f5404 [IRGen] Implement support for multi payload enums in layout strings (#66354)
* [IRGen] Implement support for multi payload enums in layout strings

rdar://105837114

* Implement multi payload enum cases in swift_resolve_resilientAccessors

* Add missing const
2023-06-06 23:51:57 -07:00
swift-ci
e4debda4e3 Merge pull request #66305 from mikeash/dont-cache-malloc-default-zone
[Runtime] Don't cache malloc_default_zone.
2023-06-06 22:35:57 -07:00
Mike Ash
007ac9a129 [Runtime] Don't cache malloc_default_zone.
Caching the default zone should no longer be necessary.

rdar://102870625
2023-06-06 21:25:31 -04:00
Dario Rexin
1425e32c86 [Runtime] Refactor swift_generic_initWithTake to use shared abstraction (#66379)
We introduced shared abstractions for handling the different tags for the other runtime functions, so we should use them here as well.
2023-06-06 14:27:56 -07:00
Alastair Houghton
438ab7fa29 [Backtracing][Linux] Add Linux support to the _Backtracing module.
Use the new module structure rather the old SwiftShims header.  This
is much cleaner and lets us include operating system headers to get
the relevant definitions where possible.

Add code to support ELF and DWARF, including decompression using
zlib, zstd and liblzma if those turn out to be required and available.

rdar://110261712
2023-06-06 16:16:20 +01:00
Alastair Houghton
979b749a0d [Backtracing][Linux] Move doc comment to header.
Moved the comment for `_swift_backtrace_demangle` into the header file
instead of it being in the implementation.

rdar://110261430
2023-06-06 16:12:47 +01:00
Alastair Houghton
14fcdbd389 [Backtracing][Linux] Tidy a few things up after review.
Mike and Max made various helpful suggestions, so I've added and updated
various comments and amended the code to cope with partial reads and
writes.

rdar://110261430
2023-06-06 16:06:21 +01:00
Tim Kientzle
71c9dd3727 [Dynamic Casting] Use old boxing semantics for pre-Fall-2023 apps
For Apple platforms, enable the new stricter boxing semantics only
for apps built against the Fall 2023 or later SDK.  This
avoids breaking apps that relied on the old behavior and
have not been updated since then.
2023-06-05 17:01:20 -07:00
Alastair Houghton
e5f4c2015e [Backtracing][Linux] Disable backtrace-on-crash until enabling PR.
This should have been disabled until #66338.

rdar://110261430
2023-06-05 22:28:53 +01: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
Dario Rexin
5cbf9f9641 [IRGen] Handle complex single payload enum cases (#66289)
* [IRGen] Handle complex single payload enum cases

rdar://110138498

Handles single payload enum cases with more complex bit patterns (e.g. >64 bits or scattered) by storing a relative pointer to a function that reads the tag.

* Use proper symbol for enum tag helper
2023-06-02 11:49:57 -07:00
Mike Ash
01300a6f86 [Runtime] Fix memory leak in -[__SwiftNativeNSError description] for large error values.
Balance the call to allocateBufferIn with a call to deallocateBufferIn. When an error value is small, the missing deallocateBufferIn doesn't do anything. But when the error value is a larger struct that doesn't fit inline, we need deallocateBufferIn to avoid leaking the allocation.

rdar://109933822
2023-06-01 12:54:19 -04:00
Kuba (Brecka) Mracek
9124c0ef36 Guard packIdx with #ifndef NDEBUG (#66228) 2023-05-31 15:18:08 -07:00
Dario Rexin
5db2b28420 [Runtime] Handle single payload enums in swift_resolve_resilientAccessors (#66218)
rdar://109803119

It is sufficient to skip the header, because everything after that are regular ref counts
2023-05-30 18:27:00 -07:00
Dario Rexin
658f0ea3c8 [Runtime] Refactor layout string runtime functions to simplify future specialization work (#66105)
rdar://109787818

Templatized and abstracted handling of layout strings to simplify future specializations. E.g. specilizing for a particular number of reference count operations can be done by passing the expected size as a template param:

```
extern "C" void
swift_generic_destroy_2(swift::OpaqueValue *address, const Metadata *metadata) {
  handleRefCounts<2, DestroyHandler>(metadata, (uint8_t *)address);
}
```
2023-05-26 08:30:50 -07:00
Dario Rexin
ca004c2316 [Runtime] Fix UB in layout string runtime functions (#66112)
rdar://109790722

Layout strings are not guaranteed to be properly aligned, so we can't directly read from and write to it, but have to use memcpy instead.
2023-05-25 08:33:53 -07:00
Mike Ash
8f9a4cbdae Merge pull request #66109 from mikeash/dont-scan-objc-classes
[Runtime] Skip metadata records search for classes in the __C module.
2023-05-25 11:15:14 -04:00
Mike Ash
f9599ddcb1 [Runtime] Skip metadata records search for classes in the __C module.
ObjC classes won't be found, so don't spend lots of time searching for them.

rdar://109783948
2023-05-24 16:23:51 -04:00
Mike Ash
dfd313cd6c [Runtime] Fast lookups of Concurrency types with standard manglings.
Have the Concurrency runtime register a struct containing pointers to all of its type descriptors with standard manglings. Then have the runtime use that struct to quickly look up those types, instead of using the standard, slower type lookup code.

rdar://109783861
2023-05-24 16:08:23 -04:00
Dario Rexin
97381e6411 [IRGen] Support additional single payload enum cases in layout strings (#66042)
* [IRGen] Support additional single payload enum cases in layout strings

rdar://105837101

Adds layout string support for single payload enums with simple (non-scattered) extra inhabitant patterns

* Add more test cases
2023-05-23 13:17:51 -07:00
Kuba (Brecka) Mracek
fbaff97c1a Don't #include <thread> in HeapObject.cpp, it's not used (#66059) 2023-05-22 20:38:53 -07:00
Dario Rexin
cae740d902 [Runtime] Use MetadataAllocator to allocate runtime instantiated layout strings (#66055)
rdar://109660582

This will create more visibility into layout string allocations when using swift-inspect.
2023-05-22 12:55:09 -07:00
swift-ci
8dcf7575d5 Merge pull request #65972 from apple/better-deinit-escape-wording
[Runtime] Improve wording of deinit escape warning.
2023-05-19 12:23:53 -07:00
Mike Ash
dc3416bd72 [Runtime] Improve wording of deinit escape warning.
Describe in more detail how an object can end up with a non-zero refcount on deallocation, and the consequences.

rdar://109045333
2023-05-17 11:01:32 -04:00
Alastair Houghton
d58183306f [Runtime][Backtracing] Conditionalise initialisation of the spawnattr.
We don't need to initialise the posix_spawnattr unless we're enabling the
backtracer, so don't.

rdar://109354306
2023-05-15 16:07:58 +01:00
Kuba (Brecka) Mracek
1028050d34 ImageInspectionMachO.cpp: Guard including objc/runtime.h under SWIFT_OBJC_INTEROP (#65890) 2023-05-12 15:12:35 -07:00
Kuba (Brecka) Mracek
1125e45cca Don't include <thread> in MetadataCache.h, all we need there is <atomic> (#65826) 2023-05-12 10:34:31 -07:00
swift-ci
8db4b9fb55 Merge pull request #65776 from mikeash/dealloc-partial-class-instance-setclass-readonly
[Runtime] Immediate release and return when destroying partial instance of pure ObjC class.
2023-05-09 19:08:22 -07:00
Mike Ash
3a396af086 [Runtime] Immediate release and return when destroying partial instance of pure ObjC class.
Make swift_deallocPartialClassInstance check if the object's class is a pure ObjC class, in which case there are no ivar destroyers and we can just return immediately.

It's possible for an allocWithZone: override to cause self to be a special object constructed in read-only memory. swift_deallocPartialClassInstance calls object_setClass to avoid running the dealloc method of any Swift subclasses, but this call crashes if self is read-only. It's unnecessary when the object's class is pure ObjC and therefore there are no Swift subclasses, so just skip it entirely.

rdar://107756747
2023-05-09 16:47:47 -04:00
Alastair Houghton
18a753cd87 [Runtime] Print type names in escape-from-deinit messages.
In addition to giving the object's address, we can print the name of its
type (since the object is still live at this point).

rdar://108882759
2023-05-05 11:51:49 +01:00
Alastair Houghton
2e36235451 Merge pull request #65140 from al45tair/eng/PR-107718586
[Runtime] Ensure we *always* generate names for ObjC classes.
2023-04-27 13:53:46 +01:00
Kuba (Brecka) Mracek
b58818f153 To be able to correctly exercise Concurrency on freestanding, default to using 'pthread' threading package (#65329)
To be able to correctly exercise Concurrency on freestanding, default to using 'pthread' threading package

rdar://102259828
2023-04-21 14:47:51 -07:00
Dario Rexin
022311e438 [IRGen] Fix layout string generation for pre-specialized metadata (#65162)
* [IRGen] Fix layout string generation for pre-specialized metadata

rdar://108012057

Pre-specialized metadata has to be specifically handled by using the bound generic type instead of the unbound one. All the necessary information is already being passed down as BoundGenericTypeCharacteristics, we just need to apply them when present.

* Add tests and a few fixes

* Fixes after rebase

* Attempt to fix Windows linker issue in test
2023-04-20 13:26:41 -07:00
Alastair Houghton
6f8b2ef9e5 [Runtime] Fix swift_weakTakeStrong().
It turns out that when taking the last weak reference for an object that
has been deallocated, we might have returned a non-null pointer when we
shouldn't have.  Which is exciting.

rdar://106375185
2023-04-14 19:15:38 +01:00
Alastair Houghton
2f6baac55e [Runtime] Ensure we *always* generate names for ObjC classes.
If something fails while trying to generate a name for an ObjC class,
we fall back to a generated name based on the metadata pointer.  This
ensures that we won't crash, and if the name turns up in the debugger
or somewhere it should be obvious that something went wrong.

rdar://107718586
2023-04-13 15:34:03 +01:00
Alastair Houghton
e5680de071 [Backtracing] Security improvements.
Use `task_read_for_pid()` rather than having the crashing program pass its
own task port through.  This opts us in to additional OS security measures
surrounding the use of this call.

rdar://107362003
2023-04-12 12:48:33 +01:00
Evan Wilde
f47d56336e Replace mismatched delete with swift_cxx_deleteObject
The `allocatedEntry` is allocated with `swift_cxx_newObject` so it
should be deallocated with the `swift_cxx_deleteObject`.
2023-04-11 14:15:24 -07:00
Alastair Houghton
316dfaffa1 Merge pull request #64714 from al45tair/eng/PR-107360391
[Backtracing] Support specifying a hard-coded path for swift-backtrace.
2023-03-30 18:28:48 +01:00
Mike Ash
e439d271b2 [Runtime] Redeclare _dyld_lookup_section_info as weak.
This lets us build against it and still run on systems without it.
2023-03-29 15:39:01 -04:00
Alastair Houghton
0261a29fee [Backtracing] Support specifying a hard-coded path for swift-backtrace.
Add a way to disable dynamic lookup of the backtracer path, for situations
where a hard-coded path makes more sense.

rdar://107360391
2023-03-29 15:08:48 +01:00
Mike Ash
f7e325663a [Runtime] Avoid referring to enum _dyld_section_location_kind.
If the SDK has dyld_priv.h but doesn't have enum _dyld_section_location_kind, we can't use enum _dyld_section_location_kind and it's hard to detect that. Instead, just use `int`, and use #defines for the values.
2023-03-29 09:33:27 -04:00
Ben Barham
20ba6125ae Revert "[Runtime] Redeclare _dyld_lookup_section_info as weak."
This reverts commit a4c572fc03, to be
added back in after https://github.com/apple/swift/pull/64042.
2023-03-28 14:32:23 -07:00
Konrad `ktoso` Malawski
0586c14b60 [Concurrency] SerialExecutor.isSameExclusiveExecutionContext (#64604) 2023-03-28 15:56:28 +09:00
Alastair Houghton
0f98eccb73 Merge pull request #64611 from al45tair/eng/PR-107192120
[Backtracing] Add an option to output to stderr.
2023-03-27 15:37:05 +01:00
Alastair Houghton
9209bdd8c4 [Backtracing] Add an option to output to stderr.
In CI, it would be better if the backtraces went to stderr rather than
stdout, so provide an option for that.

rdar://107192120
2023-03-24 17:13:52 +00:00