`__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
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
* [IRGen] Implement support for multi payload enums in layout strings
rdar://105837114
* Implement multi payload enum cases in swift_resolve_resilientAccessors
* Add missing const
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
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
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.
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
* [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
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
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);
}
```
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.
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
* [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
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
* [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
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
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
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
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.