Commit Graph

19 Commits

Author SHA1 Message Date
Mike Ash
ae71658c6a [Runtime] Add weak check to use of _dyld_find_pointer_hash_table_entry.
Needed to avoid availability errors in some configurations.

rdar://127621414
2024-05-21 10:59:15 -04:00
Mike Ash
96555ba51c [Runtime] Add pointer-based lookup of prespecialized metadata.
The existing lookup uses a hash table with the type's mangled name as the key. Building that key is costly. Add a new table that uses pointer keys, so that we can use the descriptor and arguments directly as the key.

rdar://127621414
2024-05-17 16:17:03 -04:00
Mike Ash
717b03b5a5 [Runtime] Use StackAllocatedDemangler in getLibPrespecializedMetadata.
Reduce the amount of time spent freeing demangler slabs by starting out with a stack allocation that doesn't need to be freed.

rdar://126932780
2024-04-23 14:44:40 -04:00
Mike Ash
b8f29cfda0 [Runtime] Allow disabling/enabling prespecializations library per-process.
Read a list of disabled process names from the prespecializations library, and turn the feature off if the current process matches. Also allow passing process names in environment variables. Processes can be disabled by name using SWIFT_DEBUG_LIB_PRESPECIALIZED_DISABLED_PROCESSES, and a disable can be overridden with SWIFT_DEBUG_LIB_PRESPECIALIZED_ENABLED_PROCESSES.

rdar://126216786
2024-04-10 14:29:19 -04:00
Mike Ash
deab2fa5ef Merge pull request #72519 from mikeash/fix-validate-prespecialized-metadata
[Runtime] Fix _swift_validatePrespecializedMetadata when type lookup fails.
2024-04-09 09:14:39 -04:00
Mike Ash
2841b5944a Merge pull request #72870 from mikeash/libprespecialize-address-range-rejection
[Runtime] Don't attempt to look up prespecialized metadata involving pointers outside the shared cache.
2024-04-05 14:31:04 -04:00
Mike Ash
98229fe4db [Runtime] Don't attempt to look up prespecialized metadata involving pointers outside the shared cache.
The descriptor and arguments for prespecialized metadata will always be in the shared cache. Skip creating the mangling for any lookup involving pointers outside the shared cache, as an optimization.
2024-04-05 10:19:34 -04:00
Alastair Houghton
419214daf9 [Runtime] Disable prespecialized metadata if we have overridden images.
We need to check for overridden images on every image load, otherwise
XCTest (among others) may `dlopen()` an image that pulls in something
that is overridden, at which point the prespecialized metadata won't
match the image we loaded.

rdar://125727356
2024-04-04 16:20:12 +01:00
Mike Ash
fe9de7beb5 [Runtime] Fix _swift_validatePrespecializedMetadata when type lookup fails.
When we fail to look up a type by name, we print an error, then try to compare anyway, which crashes. Skip the comparison when that happens.

While we're in there, modify _swift_validatePrespecializedMetadata to be more useful for debugging, by removing the parameters and having it print the results directly.
2024-03-22 13:52:32 -04:00
Mike Ash
20d60406cb [Runtime] Harden SWIFT_DEBUG_LIB_PRESPECIALIZED_PATH.
Have SWIFT_DEBUG_LIB_PRESPECIALIZED_PATH use dlopen with RTLD_NOLOAD. We don't want it to allow loading arbitrary dylibs. Instead, a user can use something like DYLD_INSERT_LIBRARIES to load the dylib, which we will then pick up in the runtime, and processes that deny DYLD_INSERT_LIBRARIES will not be able to work around it with SWIFT_DEBUG_LIB_PRESPECIALIZED_PATH.

rdar://123643585
2024-02-26 14:38:09 -05:00
Mike Ash
f66b57c7fb Merge pull request #71666 from mikeash/libprespecialize-no-packs
[Runtime] Skip types with pack parameters in LibPrespecialized.
2024-02-15 23:30:06 -05:00
Mike Ash
dba0859b5c [Runtime] Skip types with pack parameters in LibPrespecialized.
We don't yet support pack parameters anyway, and `_buildDemanglingForGenericType` has trouble with them, so skip them altogether.
2024-02-15 17:37:31 -05:00
Mike Ash
5f7421b7a7 [Runtime] Check for demangling failure when looking up prespecialized metadata.
_buildDemanglingForGenericType can fail, so we need to check for NULL.
2024-02-15 10:25:46 -05:00
Mike Ash
89e5a80847 [ExternalGenericMetadataBuilder] Support ARM64e fixups.
Add ptrauth attributes to the witness tables and descriptor pointers, and have the test support ARM64e.

rdar://122660111
2024-02-14 09:52:58 -05:00
Mike Ash
b8b59c4bac [ExternalGenericMetadataBuilder] Add a test that validates built metadata against the runtime.
We run the builder, then use a small program that converts the JSON output into C code that generates the data. Compile that into a bundle, then load it as the prespecializations library. Then scan all the entries in the table and compare them with what the runtime builds dynamically.
2024-01-31 17:03:27 -05:00
Mike Ash
46ddceb7d4 Merge pull request #71184 from mikeash/libprespecialize-metadata-name-lookup
[Runtime] Do a proper hash table lookup in the prespecializations library.
2024-01-29 12:10:35 -05:00
Mike Ash
ade4b8e989 [Runtime] Fix dyld call for Swift prespecialized data.
Make our variables const to match the call signature, and do a weak check of the symbol before calling it.
2024-01-27 12:53:23 -05:00
Mike Ash
edb292dda5 [Runtime] Do a proper hash table lookup in the prespecializations library.
We were doing a linear scan of the table contents as a stopgap. Stop doing that, and compute the proper key for the lookup, matching the one used in the builder.
2024-01-26 12:04:02 -05:00
Mike Ash
4341102c92 [Tools] Add a library to build specialized generic metadata out of process.
This library uses GenericMetadataBuilder with a ReaderWriter that can read data and resolve pointers from MachO files, and emit a JSON representation of a dylib containing the built metadata.

We use LLVM's binary file readers to parse the MachO files and resolve fixups so we can follow pointers. This code is somewhat MachO specific, but could be generalized to other formats that LLVM supports.

rdar://116592577
2024-01-24 20:45:50 -05:00