Commit Graph

25 Commits

Author SHA1 Message Date
Saleem Abdulrasool
10c804b0bb runtime: adjust the program name reference
`__progname` is not available on Windows, and is provided by libbsd on
Linux. This provides a replacement for the functional aspect of the
symbol on Windows.
2025-02-22 07:14:26 -08:00
Kuba Mracek
9c77074cac [Mangling] Establish a new mangling prefix for Embedded Swift: $e 2024-12-02 15:01:24 -08:00
Allan Shortlidge
2de8e5afc2 Gardening: Address -Wunused-but-set-variable warnings. 2024-10-29 15:52:53 -07:00
Alejandro Alonso
7c85261a77 Add runtime support 2024-09-04 15:13:27 -07:00
Mike Ash
4b3a197dc2 [Runtime] Support type descriptor map in LibPrespecialized.
The descriptor map is keyed by a simplified mangling that canonicalizes the differences that we accept in _contextDescriptorMatchesMangling, such as the ability to specify any kind of type with an OtherNominalType node.

This simplified mangling is not necessarily unique, but we use _contextDescriptorMatchesMangling for the final equality checking when looking up entries in the map, so occasional collisions are acceptable and get resolved when probing the table.

The table is meant to be comprehensive, so it includes all descriptors that can be looked up by name, and a negative result means the descriptor does not exist in the shared cache. We add a flag to the options that can mark it as non-definitive in case we ever need to degrade this, and fall back to a full search after a negative result.

The map encompasses the entire shared cache but we need to reject lookups for types in images that aren't loaded. The map includes an image index which allows us to cheaply query whether a given descriptor is in a loaded image or not, so we can ignore ones which are not.

TypeMetadataPrivateState now has a separate sections array for sections within the shared cache. _searchTypeMetadataRecords consults the map first. If no result is found in the map and the map is marked as comprehensive, then only the sections outside the shared cache need to be scanned.

Replace the SWIFT_DEBUG_ENABLE_LIB_PRESPECIALIZED environment variable with one specifically for metadata and one for descriptor lookup so they can be controlled independently. Also add SWIFT_DEBUG_VALIDATE_LIB_PRESPECIALIZED_DESCRIPTOR_LOOKUP which consults the map and does the full scan, and ensures they produce the same result, for debugging purposes.

Enhance the environment variable code to track whether a variable was set at all. This allows SWIFT_DEBUG_ENABLE_LIB_PRESPECIALIZED to override the default in either direction.

Remove the disablePrespecializedMetadata global and instead modify the mapConfiguration to disable prespecialized metadata when an image is loaded that overrides one in the shared cache.

rdar://113059233
2024-08-01 18:43:15 -04:00
Mike Ash
9bbcef3bc5 [Runtime] Fix missing return in getMetadataFromPointerKeyedMap.
When DYLD_FIND_POINTER_HASH_TABLE_ENTRY_DEFINED is set but the function is not found at runtime, we're missing a return statement.
2024-07-03 15:26:11 -04:00
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