Commit Graph

225 Commits

Author SHA1 Message Date
Mike Ash
e8ccfa824f [Reflection] Make getSubstMap and visitDependentMemberTypeRef more robust against unexpected data.
Remote mirrors was hitting an assertion failure due to a generic parameter not being concrete. This check catches that case early and returns a clean failure from getSubstMap, which callers can then handle appropriately.

It also hit a casting failure in visitDependentMemberTypeRef, which assumed that SubstBase was either a NominalTypeRef or a BoundGenericTypeRef. This does a dynamic cast with a graceful failure.

In general there is a tension in this code between its use in the runtime, where we usually want to treat bad data as a horrible bug and fail loudly, and its use in remote mirrors, where we need to assume that the data we're examining might be horribly broken and we just want to do the best we can. Longer term we might want to make this code configurable so that we can have an "assert and die" mode for the runtime, and a "fail gracefully" mode for remote mirrors.

rdar://problem/40136609
2018-07-23 14:32:39 -04:00
Davide Italiano
e9d8e0a8ba [ELF] Remove a wrong comment and clarify another one.
<rdar://problem/41901725>
2018-07-19 15:23:58 -07:00
Davide Italiano
a907398872 [RemoteMirrors] Add support for reading ELF.
<rdar://problem/41901725>
2018-07-19 15:21:42 -07:00
Davide Italiano
78f23cc10f [Reflection] Locate __DATA and push into imageRanges.
This brings the current support to parity to the old one.
Thanks to Mike Ash for noticing this.

<rdar://problem/42306551>
2018-07-19 11:30:09 -07:00
Davide Italiano
382e099e60 [Reflection] Remove now dead code. NFCI.
<rdar://problem/42306551>
2018-07-18 15:24:31 -07:00
Davide Italiano
29f45b10cd [Reflection] Fix lifetime issues and out-of-process mapping.
This comes back to the older approach of mapping all __TEXT, as
taking in account the delta between sections seems a little too
complicated for now. Hopefully we'll be back optimizing this
once we're done with debugger integration.

<rdar://problem/42306551>
2018-07-18 14:53:36 -07:00
Davide Italiano
64a1e98634 [Reflection] Be less aggressive with unknown objects.
Instead of asserting, just return false.
2018-07-17 16:20:56 -07:00
Davide Italiano
da448fefc5 [ReflectionContext] Rewrite the Mach reader path.
There are several problems fixed by this commit.
-> It removes the dependency on a system header.
-> It works when the pointer size for host and target don't match
(i.e. 32-bits/64-bits and viceversa)
-> It reads the file lazily, mapping only the sections that are
needed. The old approach mapped the whole __TEXT segment, causing
significant slowdowns when trying to integrate this API in the
debugger. Now it's almost instant (10 seconds vs milliseconds).

<rdar://problem/42306551>
2018-07-17 15:35:40 -07:00
David Zarzycki
da506fc0f5 [Reflection] NFC: Adopt reference storage type meta-programming macros 2018-06-30 06:44:34 -04:00
Doug Gregor
d2a001af17 [ABI] Move the ABI parts of Runtime/Metadata.h into the ABI library.
Runtime/Metadata.h collected a large number of metadata data
structures that are actually part of the ABI. Move those data
structures into a new header, ABI/Metadata.h, and keep the in-process,
runtime-specific bits in Runtime/Metadata.h.
2018-06-12 09:55:39 -07:00
Mike Ash
4d37e2b945 Merge pull request #16996 from mikeash/faster-infoForMetadata
[RemoteMirrors] Put a cache in front of getFieldTypeInfo to avoid repetitive scanning of the target's reflection infos.
2018-06-05 09:26:59 -07:00
Mike Ash
e6a9198444 [RemoteMirrors] Put a cache in front of getFieldTypeInfo to avoid repetitive scanning of the target's reflection infos.
rdar://problem/40705238
2018-06-04 16:37:44 -07:00
Davide Italiano
52531eef00 [Reflection] Fix a member function so that it actually compiles.
Nobody's using it, so nobody noticed. I plan to use this in the
debugger.
2018-05-31 17:02:32 -07:00
Arnold Schwaighofer
cc7f207cec Rename swift sections from swift4 to swift5
rdar://38465220
2018-05-23 12:18:08 -07:00
Bob Wilson
62b9375690 [Reflection] Remove DEPENDENT_TEMPLATE2 macro
The Clang version checks introduced in #16212 and #16221 do not work well.
The __clang_major__ macro is defined differently for Apple builds of Clang,
and the __APPLE_CC__ macro is obsolete and not useful. The good news is that
those checks appear to be unnecessary. The version of Clang used with
Swift 4.2 (based on LLVM 6.0) accepts the code without the template keyword
in the places where the DEPENDENT_TEMPLATE2 macro was being used.

This also corrects a mistake in #16221 where the non-Clang/GCC definition
of DEPENDENT_TEMPLATE was changed to use the template keyword.
2018-05-03 22:02:37 -07:00
David Zarzycki
468b918eb3 Fix macOS build regression after #16212 (#16221) 2018-04-27 16:40:03 -04:00
David Zarzycki
4732be155a [Reflection] NFC: Enable building after clang r331013 (#16212) 2018-04-27 09:01:36 -04:00
Sho Ikeda
e71a065e97 [gardening][Reflection][Remote] Replace typedef with using 2018-04-02 13:43:39 +09:00
Mike Ash
979b75699a Merge branch 'master' into remotemirror-hide-reflection-sections 2018-03-16 16:24:57 -04:00
Arnold Schwaighofer
0c11e1a0a3 Mark swift sections as swift4 for Swift 4.2
rdar://36363251
2018-03-14 10:27:28 -07:00
Mike Ash
ac026128d1 [RemoteMirrors] Provide interop function for converting a raw metadata pointer into a swift_metadata_interop_t.
rdar://problem/37538580
2018-03-08 13:25:09 -05:00
Mike Ash
9a27add5f8 [RemoteMirrors] Fix ReflectionContext.h cast on 32-bit. 2018-03-02 13:53:44 -05:00
Mike Ash
553ef86a4b [RemoteMirrors] Change MemoryReader::readBytes to return a unique_ptr instead of a tuple so that the destructor handles freeing the memory. 2018-03-02 12:05:36 -05:00
Mike Ash
1434fce417 [RemoteMirrors] Switch #ifdef __APPLE__ to #if defined(__APPLE__) && defined(__MACH__) to be more specific about the fact that this code is for MachO. 2018-03-02 11:03:45 -05:00
Mike Ash
7a4ca828d8 [RemoteMirrors] Wrap MachO code in #ifdef __APPLE__. 2018-02-27 15:54:48 -05:00
Mike Ash
e4564087af [RemoteMirrors] Move ownsObject into ReflectionContext. 2018-02-27 10:32:32 -05:00
Davide Italiano
ec39bbb08c [RemoteMirrors] Move addImage from stdlib to Reflection. 2018-02-26 17:41:08 -08:00
Mike Ash
6f887475a3 [Reflection] Lots of smaller fixes and API changes due to testing the interop code.
* Remove getPointerSize and getSizeSize functions, replace with a single PointerSize value.
* Remove imageLength parameter from addImage, calculate it internally instead.
* Check remote mirrors libraries' metadata version and reject them if it's too old.
* Shim GetStringLength and GetSymbolAddress for the legacy library since we don't pass the caller's context pointer through directly.
* Actually set the IsLegacy flag in the Library struct.
* Implement ownsObject by tracking each added image's data segment and checking metadata pointers against them. The previous approach didn't work.
2018-02-26 16:56:54 -05:00
Mike Ash
7029967c99 Merge branch 'remotemirror-hide-reflection-sections' of https://github.com/mikeash/swift into remotemirror-hide-reflection-sections 2018-02-23 13:59:06 -05:00
Mike Ash
4c7d203574 [Reflection] Implement more interop API calls.
rdar://problem/37538580
2018-02-23 11:47:24 -05:00
Pavel Yaskevich
0da5e48a0e [Runtime/Reflection] Add swift_getFieldAt runtime accessor
Use information from reflection section of the binary to lookup
type field info such as name and it's type and return it using
new `swift_getFieldAt` method based on nominal type and field index.
2018-02-20 18:20:09 -08:00
Alex Blewitt
84148c73b2 [SR-7036] Use || instead of && for kind comparison 2018-02-20 16:12:08 +00:00
Joe Groff
953dddd5d3 IRGen/Runtime: Allow mangled type refs to embed "symbolic references" to type context descriptors.
This makes resolving mangled names to nominal types in the same module more efficient, and for eventual secrecy improvements, also allows types in the same module to be referenced from mangled typerefs without encoding any source-level name information about them.
2018-02-10 10:43:47 -08:00
Pavel Yaskevich
8f05d64770 [Reflection] Add support for imported structs with recorded fields
Update IRGen to trigger generation of type metadata for foreign
struct types found in fields. And fix TypeRefBuilder to handle
the case where struct has fields but at the same time has opaque
metadata.
2018-02-06 15:50:52 -08:00
Mark Lacey
8667eb6f91 Revert "[WIP][IRGen] Emit type field descriptors for imported structs" 2018-02-03 10:27:34 -08:00
Pavel Yaskevich
9e08ea4c56 [Reflection] Add support for imported structs with recorded fields
Update IRGen to trigger generation of type metadata for foreign
struct types found in fields. And fix TypeRefBuilder to handle
the case where struct has fields but at the same time has opaque
metadata.
2018-02-02 15:54:12 -08:00
Joe Groff
3258902f77 Preserve whether fields are var or let in the reflection metadata.
Useful for future mutable reflection features to know whether they're allowed to mutate a field after initialization.
2018-01-31 19:04:39 -08:00
Joe Groff
a7a3b17597 Replace nominal type descriptors with a hierarchy of context descriptors.
This new format more efficiently represents existing information, while
more accurately encoding important information about nested generic
contexts with same-type and layout constraints that need to be evaluated
at runtime. It's also designed with an eye to forward- and
backward-compatible expansion for ABI stability with future Swift
versions.
2018-01-29 16:19:25 -08:00
Doug Gregor
d0b73b85d0 [Type decoder] Generalize the canonicalization of nominal type decl references.
Various TypeDecoder clients will depend on having the "bare" nominal
type declaration demangled node for looking up nominal type descriptors,
so move the generic argument-stripping code into TypeDecoder.
2018-01-12 15:35:12 -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
Doug Gregor
61884f7702 [Type decoder] Rework the builder contract for protocols.
TypeDecoder's interface with its builders already treated protocols as
a type (due to their being mangled as "protocol composition containing
one type"), and intermixed protocols with superclasses when forming
compositions. This makes for some awkwardness when working with
protocol descriptors, which are very much a distinct entity from a
type.

Separate out the notion of a "protocol declaration" (now represented
by the builder-provided BuiltProtocolDecl type) from "a protocol
composition containing a single type", similarly to the way we handle
nominal type declarations. Teach remote mirrors and remote AST to
handle the new contract.
2018-01-09 10:46:31 -08:00
Doug Gregor
e28e856595 [Runtime] Use bare protocol mangling for protocol descriptors.
The mangled name of protocol descriptors was the “protocol composition”
type consisting of a single protocol, which is a little odd. Instead,
use a bare protocol reference (e.g., “6Module5ProtoP”) with the “$S”
prefer to be more in line with nominal type descriptor names while still
making it clear that this is a Swift (not an Objective-C) protocol.
2018-01-09 10:21:55 -08:00
Saleem Abdulrasool
df54b2af11 reflection: handle LMA != VMA for ELF
ELF is segment mapped, where the segment which contains a particular
section may be mapped to an address which does not correspond to the
address on disk.  Since the reflection dumper does not use the loader to
load the image into memory, we must manually account for any section
offsets.  Calculate this value when we query the mmap'ed image and wire
it through to the relative direct pointer accesses.

When switching to the linker table approach for the ELF metadata
introspection, this was uncovered as the segment containing the orphaned
sections was coalesced into a separate PT_LOAD header which had a non-0
offset for the mapping.
2017-11-29 17:56:15 -08:00
Pavel Yaskevich
cbee90cf5d Merge pull request #12812 from xedin/bring-back-function-metadata-changes
[IRGen] Improve function type metadata representation
2017-11-08 12:03:54 -08:00
Greg Parker
9a38e609af [IRGen][runtime] Reduce object header to 8 bytes on 32-bit platforms. (#12790)
SR-4353, rdar://29765800
2017-11-08 02:50:11 -08:00
Pavel Yaskevich
622cc1c64a [ABI/IRGen] Add custom function parameter flags representation for metadata use 2017-11-07 12:45:32 -08:00
Pavel Yaskevich
aa89c4f4a8 Revert "[ABI/IRGen] Add custom function parameter flags representation for metadata use"
This reverts commit f6b0d2d2cf.
2017-11-07 00:24:21 -08:00
Pavel Yaskevich
f6b0d2d2cf [ABI/IRGen] Add custom function parameter flags representation for metadata use 2017-11-06 11:16:46 -08:00
Pavel Yaskevich
51d9542a2a [Reflection] Add label and flags to function type reference parameters 2017-10-16 16:46:45 -07:00
Pavel Yaskevich
bf8d6f591e [Reflection] NFC: Rename FunctionTypeRef::{getArguments() -> getParameters()} 2017-10-16 16:46:45 -07:00