Commit Graph

122 Commits

Author SHA1 Message Date
Allan Shortlidge
272a1a4b18 NFC: Resolve -Wauto-var-id warning in ErrorObject.mm. 2024-01-12 17:40:46 -08:00
Mike Ash
fe7e13bba5 [Runtime][IRGen] Sign type context descriptor pointers.
Ensure that context descriptor pointers are signed in the runtime by putting the ptrauth_struct attribute on the types.

We use the new __builtin_ptrauth_struct_key/disc to conditionally apply ptrauth_struct to TrailingObjects based on the signing of the base type, so that pointers to TrailingObjects get signed when used with a context descriptor pointer.

We add new runtime entrypoints that take signed pointers where appropriate, and have the compiler emit calls to the new entrypoints when targeting a sufficiently new OS.

rdar://111480914
2023-07-07 18:10:35 -04:00
David Smith
e20be0edc6 Revert [Runtime] Let CF provide us with state, avoiding runtime lookup. rdar://111104451 (#66606) 2023-06-22 10:24:51 -07:00
David Smith
7eb8283a49 [Runtime] Let CF provide us with state, avoiding runtime lookup. rdar://111104451 (#66606)
Provide a hook for CF to tell us about the state we need from it, rather than us having to look it up at runtime
2023-06-21 08:38:14 -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
zoecarver
13b0a5bc37 [nfc] Clang format changes. 2022-07-21 17:34:36 -04:00
zoecarver
c9f54e1417 [nfc] Rename CxxCustom -> Custom and fix comments based on review feedback. 2022-07-21 10:25:57 -04:00
zoecarver
f972f664d3 [cxx-interop] Runtime support for foreign reference types. 2022-06-14 12:18:05 -07:00
tbkka
8c5e9850b8 Harden isKindOfClass: check (#35797)
* Harden `isKindOfClass:` check

We've seen some Obj-C NSProxy subclass implementations that are broken and will
crash if you send them a standard `isKindOfClass:` message.  This came out because
the casting machinery is now more aggressive about trying different casting options which
means some of these broken objects are being queried in new ways.

This adds an additional check before calling `isKindOfClass:` to verify that
this object is not using the default NSProxy selector routing.  If it is,
we just assume it's not whatever class is being tested for since we cannot
do anything better.

Resolves rdar://73799124

* Fixes from Mike Ash

* Fix build
2021-02-08 07:46:09 -08:00
Mike Ash
2763e13a9a [Stdlib] Fix an overrelease in -[__SwiftNativeNSError description].
getDescription takes its argument at +1, but the implementation was passing the value directly. This caused the contained error value to be destroyed.

rdar://problem/59512630
2020-02-18 11:30:03 -05:00
Suyash Srijan
c02b95ebf9 [Runtime] A Swift Error bridged to NSError should return its description, rather than NSError.description (#29224) 2020-01-16 00:13:55 +00:00
Doug Gregor
905c830c45 [Runtime] Handle Error bridging as a last chance to cast to NSError/NSObject.
Rather than attempting Error bridging early when trying to dynamically
cast to NSError or NSObject, treat it as the *last* thing we do when
all else fails. Push most of this code over into Objective-C-specific
handling rather than #ifdef'd into the main casting logic to make that
slightly more clear.

One oddity of Error/NSError bridging is that a class that conforms to
Error can be dynamically cast to NSObject via Error bridging. This has
always been known to the static compiler, but the runtime itself was
not always handling such a cast uniformly. Do so now,
uniformly. However, this forced us to weaken an assertion, because
casting a class type to NSError or NSObject can produce an object with
a different identity.

Fixes rdar://problem/57393991.
2019-12-13 23:55:13 -08:00
Karoy Lorentey
c34389ce72 [Foundation][runtime] Remove swift_errorBridgingInfo
To implement swift_errorBridgingInfo, the Foundation overlay needs to import private runtime headers. Now that we cannot statically link the Foundation overlay, there is no point to keeping this workaround in the overlay any more.

This effectively reverts https://github.com/apple/swift/pull/16677.

rdar://problem/57809306
2019-12-10 15:33:24 -08:00
David Smith
406d03bdef Merge pull request #27974 from Catfish-Man/erroneous-errors
Don't try to speculatively bridge tagged pointers to Errors
2019-10-30 18:31:16 -07:00
David Smith
acb5b570f5 Don't try to speculatively bridge tagged pointers to Errors 2019-10-30 15:16:10 -07:00
Mike Ash
b8f5e841e2 [Runtime] Add a function pointer for intercepting swift_willThrow calls.
rdar://problem/53400364
2019-10-24 14:06:14 -04:00
David Smith
1efa946caf Remove stdlib and runtime dependencies on Foundation and CF 2019-09-12 18:03:14 -07:00
Arnold Schwaighofer
fe69a86929 Revert "Remove stdlib and runtime dependencies on Foundation and CF"
It is causing bots to fail.

* Revert "The __has_include(<os/system_version.h>) branch here wasn't quite right, we'll just use the dlsym one for now"

This reverts commit f824922456.

* Revert "Remove stdlib and runtime dependencies on Foundation and CF"

This reverts commit 3fe46e3f16.

rdar://54709269
2019-08-26 13:00:08 -07:00
David Smith
3fe46e3f16 Remove stdlib and runtime dependencies on Foundation and CF 2019-08-23 14:10:23 -07:00
Saleem Abdulrasool
41d9c2cc59 stdlib: restructure for OS family layout of SDK overlay
The SDK directory is now confusing as the Windows target also has a SDK
overlay.  In order to make this more uniform, move the SDK directory to
Darwin which covers the fact that this covers the XNU family of OSes.
The Windows directory contains the SDK overlay for the Windows target.
2018-12-06 11:32:05 -08:00
Doug Gregor
dd154f6668 [Runtime] Rename swift_instantiateWitnessTable() -> swift_getWitnessTable()
This runtime function doesn’t always perform instantiation; it’s how we
get a witness table given a conformance, type, and set of instantiation
arguments. Name it accordingly.
2018-10-25 20:35:27 -07:00
Doug Gregor
b5bc06e552 [ABI] Eliminate witness table accessors.
Witness table accessors return a witness table for a given type's
conformance to a protocol. They are called directly from IRGen
(when we need the witness table instance) and from runtime conformance
checking (swift_conformsToProtocol digs the access function out of the
protocol conformance record). They have two interesting functions:

1) For witness tables requiring instantiation, they call
swift_instantiateWitnessTable directly.
2) For synthesized witness tables that might not be unique, they call
swift_getForeignWitnessTable.

Extend swift_instantiateWitnessTable() to handle both runtime
uniquing (for #2) as well as handling witness tables that don't have
a "generic table", i.e., don't need any actual instantiation. Use it
as the universal entry point for "get a witness table given a specific
conformance descriptor and type", eliminating witness table accessors
entirely.

Make a few related simplifications:

* Drop the "pattern" from the generic witness table. Instead, store
  the pattern in the main part of the conformance descriptor, always.
* Drop the "conformance kind" from the protocol conformance
  descriptor, since it was only there to distinguish between witness
  table (pattern) vs. witness table accessor.
* Internalize swift_getForeignWitnessTable(); IRGen no longer needs to
  call it.

Reduces the code size of the standard library (+assertions build) by
~149k.

Addresses rdar://problem/45489388.
2018-10-25 20:35:27 -07:00
Mike Ash
317451c8ee [Runtime][Stdlib][Overlays] Add comments to all the renamed classes explaining the rename and noting that the old name cannot be used due to conflicts.
rdar://problem/35768222
2018-09-20 12:07:30 -04:00
Mike Ash
798edb9d0e [Runtime][Stdlib][Overlays] Rename various Objective-C classes and methods that would conflict when loading old Swift libraries into a process alongside ABI-stable libraries.
rdar://problem/35768222
2018-09-13 16:55:10 -04:00
Mike Ash
3e4a5a2d79 [Runtime][ABI] Have swift_willThrow take the error value in the return register.
rdar://problem/37578477
2018-08-22 15:04:49 -04:00
Doug Gregor
bec722df57 [Runtime/IRGen] Switch swift_getExistentialTypeMetadata() to ProtocolDescriptorRef.
Switch one entry point in the runtime (swift_getExistentialTypeMetadata)
to use ProtocolDescriptorRef rather than a protocol descriptor. Update
IRGen to produce ProtocolDescriptorRef instances for its calls, setting
the discriminator bit appropriately.

Within the runtime, verify that all instances of ProtocolDescriptorRef have
the right layout, i.e., the discriminator bit is set for @objc protocols
but not Swift protocols.
2018-07-21 07:48:34 -07:00
Michael Gottesman
5648ef219d [+0-all-args] Clean up remains of +1 convention from the runtime. 2018-07-06 23:10:12 -07:00
Mike Ash
e992f46764 [Runtime] Extend ObjC bridging casts to convert NSError to Error when nested in a container type.
rdar://problem/39349762
2018-06-28 13:35:25 -04:00
Mike Ash
5b991f30b8 [Runtime] Redo the ErrorObject/dlsym interface to use a struct containing all the bridging points. This allows for better static typing and reduces the amount of dynamic symbol lookups.
rdar://problem/39810532
2018-05-21 17:10:46 -04:00
Ben Langmuir
2e6c7ee76d Revert "[Runtime] Look up Error bridging symbols indirectly through special symbols that won't be stripped in static builds." 2018-05-19 10:05:00 -07:00
Joe Groff
3ec7fc169d Merge pull request #16698 from jckarter/metadata-forward-compatibility
Runtime: Tolerate unknown metadata kinds.
2018-05-18 09:50:13 -07:00
Joe Groff
681a96b45c Runtime: Tolerate unknown metadata kinds.
We want to be able to potentially introduce new metadata kinds in future Swift compilers, so a runtime ought to be able to degrade gracefully in the face of metadata kinds it doesn't know about. Remove attempts to exhaustively switch over metadata kinds and instead treat unknown metadata kinds as opaque.
2018-05-17 15:35:06 -07:00
Mike Ash
3cc86eb836 [Runtime] Look up Error bridging symbols indirectly through special symbols that won't be stripped in static builds.
This fixes a problem where error bridging didn't work in stripped executables using the static versions of the Swift libraries. ErrorObject.mm looks up some symbols with dlsym, but stripping makes it so it can't find those. This change makes a separate set of symbols explicitly made for ErrorObject.mm to look up, and marks them as dynamically referenced so stripping won't remove them. Longer term, we'd like a better solution for looking up these symbols, but this will do for now.

rdar://problem/39810532
2018-05-17 11:43:15 -04:00
Michael Gottesman
87681375e2 [+0-all-args] Change _swift_stdlib_bridgeErrorToNSError to take its parameter at +1.
This is truly a consuming operation. This can be seen since we always would need
to retain the argument here. This makes guaranteed -> owned less transformation
effective. Instead represent it taking a +1 argument so that the retain happens
outside the builtin instead of inside the builtin.

This also allows me to remove an extra copy from dynamicCastValueToNSError

rdar://38771331
2018-04-30 10:16:41 -07:00
Joe Groff
78b5ff8b6b Runtime: Bridge Error-conforming types to id as NSError instances.
NSError is a more useful box for a swift Error than the generic box. Fixes rdar://problem/38631791 | SR-7232.
2018-04-10 12:23:49 -07:00
Slava Pestov
4671f89925 Runtime: Use witness table accessors instead of direct witness table references for Error bridging
This breaks with resilient conformances once the pattern symbol
is no longer public.
2018-03-28 19:47:18 -07:00
Michael Gottesman
bb8a273386 [+0-all-args] Swift expects the returned object from bridgeErrorToNSError to be at +1 even if the bridge is a no-op.
rdar://34222540
2018-03-09 10:53:08 -08:00
Michael Gottesman
eb96da521f [+0-all-args] Update tryDynamicCastNSErrorToValue for +0 all arguments. 2018-03-06 02:05:43 -08:00
troughton
cf28ff448c Remove TwoWordPair and use SwiftCC instead. 2018-02-03 09:43:00 +13:00
Michael Gottesman
ce0c40e40b [+0-all] Update more runtime files for +0 normal arguments.
This is NFC when --enable-guaranteed-normal-arguments isn't passed into
build-script.

rdar://34222540
2018-01-29 12:13:45 -08:00
Greg Parker
7b9224794e [runtime] Reinstate TwoWordPair hack for swiftcall returns. (#14079)
clang is miscompiling some swiftcall functions on armv7s.
Stop using swiftcall in some places until it is fixed.

Reverts c5bf2ec (#13299).

rdar://35973477
2018-01-23 01:04:01 -08:00
Jordan Rose
38e2cfe1e2 Mangle imported declarations using their C names.
This makes them consistent no matter what shenanigans are pulled by
the importer, particularly NS_ENUM vs. NS_OPTIONS and NS_SWIFT_NAME.

The 'NSErrorDomain' API note /nearly/ works with this, but the
synthesized error struct is still mangled as a Swift declaration,
which means it's not rename-stable. See follow-up commits.

The main place where this still falls down is NS_STRING_ENUM: when
this is applied, a typedef is imported as a unique struct, but without
it it's just a typealias for the underlying type. There's also still a
problem with synthesized conformances, which have a module mangled
into the witness table symbol even though that symbol is linkonce_odr.

rdar://problem/31616162
2018-01-09 17:55:24 -08:00
Pavel Yaskevich
10c385d1b7 [Mangling/ABI] Add special LabelList to store parameter labels
Instead of mangling parameter labels as part of the function type
move them to the end of the function name instead, to match the
language semantics.
2017-12-18 15:44:24 -08:00
Thomas Roughton
c5bf2ec553 [runtime] Remove TwoWordPair and use the Swift calling convention instead. (#13299) 2017-12-07 19:27:24 -08:00
Greg Parker
1e894cd80b [runtime] Clean up symbols in error machinery. (#12853)
* [runtime] Clean up symbols in error machinery.

* [runtime] Clean up symbols in Foundation overlay.

* [runtime] Clean up symbols in collections and hashing.

* [runtime] Remove symbol controls from the Linux definition of swift_allocError.

* [tests] Add more stub functions for tests that link directly to the runtime.
2017-11-15 22:20:11 -08:00
Greg Parker
e00745ce1a [runtime] Fix lookup of NSObject : Hashable conformance. (#12656) 2017-11-01 18:44:58 -07:00
Greg Parker
ac6e0bd164 [runtime] Remove function pointer hooks from Error implementation. 2017-10-24 13:13:09 -07:00
Greg Parker
dd38ace506 [runtime] Fix more const cast warnings. (#11725)
* [runtime] Fix more const cast warnings.
2017-09-05 13:13:01 -07:00
John McCall
2c40b39f26 Move runtime functions for casting into their own header. 2017-04-17 17:16:13 -04:00
Erik Eckstein
1625345b90 Remove the old mangler.
NFC
2017-03-17 16:10:36 -07:00