Commit Graph

113 Commits

Author SHA1 Message Date
Davide Italiano
32fc8f14d1 [ReflectionContext] Take slide in account. 2018-12-10 18:19:45 -08:00
Davide Italiano
fcc74e82de [Reflection] Try to read only the reflection sections.
(instead of the whole object).
2018-12-10 15:41:14 -08:00
Slava Pestov
00c1279dbb Reflection: Compute if types are bitwise takable
Bitwise takability is now part of the layout of a type, because
non-bitwise takable types are never stored inline in an
existential or resilient global's buffer, even if they would
fit.

The basic rule is that weak references, unknown-refcounted
unowned references, and aggregates that contain them, are not
bitwise takable, whereas everything else is bitwise takable.

Also, since the bitwise takable for an unowned reference
depends on the reference counting style, we have to record the
superclass of a protocol, if any, to correctly determine the
reference counting style of the protocol existential.
2018-11-07 00:32:12 -05:00
Mike Ash
8624325713 [RemoteMirrors] Fix the computation of the section start address in readMachOSections.
rdar://problem/45271231
2018-10-16 17:16:34 -04:00
Davide Italiano
fdf2ba19ac [ReflectionContext] Remove dead code. NFCI.
This is untested, and unused. I originally planned to use it
in the debugger, but I changed my mind.
2018-08-06 18:45:06 -07:00
Davide Italiano
5dc41566fb [Reflection] Hoist computation of error existentials to the reader.
<rdar://problem/41546568>
2018-07-26 10:23:31 -07:00
Davide Italiano
055c789915 [Reflection] Hoist computation of metadata/value for opaque existential to the reader.
This will allow re-use of this code in RemoteAST (and, transitively,
in lldb).

<rdar://problem/41546568>
2018-07-25 16:02:46 -07: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
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
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
4c7d203574 [Reflection] Implement more interop API calls.
rdar://problem/37538580
2018-02-23 11:47:24 -05: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
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
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
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
Slava Pestov
55cd329cb3 Reflection: Remove logic for the parent metadata source 2017-09-25 15:45:17 -07:00
Slava Pestov
61639cf971 RemoteAST: Stop looking at parent metadata field 2017-09-25 15:45:16 -07:00
Arnold Schwaighofer
ca63326e1b Delete unused existential value witnesses from the old existential
implementation

And remove the SWIFT_RUNTIME_ENABLE_COW_EXISTENTIALS flag.
2017-06-02 14:34:41 -07:00
Slava Pestov
8416b1caf7 Reflection: Don't crash if closure capture type cannot be demangled
I don't have a test case, but this will address the
crashes in <rdar://problem/30398155> and
<rdar://problem/31961386>.
2017-05-04 15:45:49 -07:00
Arnold Schwaighofer
d5cbb0bd62 Runtime changes for the copy-on-write existential implementation
Adds the runtime implementation for copy-on-write existentials. This support is
enabled if SWIFT_RUNTIME_ENABLE_COW_EXISTENTIALS is defined. Focus is on
correctness -- not performance yet.

Don't use allocate/deallocate/projectBuffer witnesses for globals in cow
existential mode.

Use SWIFT_RUNTIME_ENABLE_COW_EXISTENTIALS configuration to set the default for
SILOptions.

This includes an IRGen fix to use the right projection in
emitMetatypeOfOpaqueExistential if SWIFT_RUNTIME_ENABLE_COW_EXISTENTIALS is set.

Use unknownRetain instead of native retain in dynamicCastToExistential.
2017-03-15 14:54:55 -07:00
Hugh Bellamy
818099ecbe Rename swift_unreachable to swift_runtime_unreachable 2017-01-26 15:31:34 +00:00
Hugh Bellamy
5a59971b95 Move Unreachable.h from include/Basic to include/Runtime 2017-01-26 15:31:33 +00:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
Hugh Bellamy
137b2ab295 Fix errors and warnings building swift/reflection on Windows with MSVC 2016-12-11 10:00:32 +00:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
Slava Pestov
1c7a50dcc5 Reflection: Fix class layout, again
There were a few problems here with subclasses of Objective-C classes.
Use the InstanceStart field from rodata to correctly lay out instance
variables, and verify the results match with dynamic and static layout.

Better fix for <rdar://problem/27932061>.
2016-11-16 19:31:18 -08:00
Slava Pestov
db79762c3b Reflection: Fix class layout start offset calculations
Fixes <rdar://problem/29115967>.
2016-11-11 03:13:22 -08:00
Doug Gregor
823c24b355 [SE-0112] Rename ErrorProtocol to Error.
This is bullet (5) of the proposed solution in SE-0112, and the last
major piece to be implemented.
2016-07-12 10:53:52 -07:00
Slava Pestov
48c928938a Reflection: Single-payload enum layout
Attempt to lay out single-payload enums, using knowledge of extra
inhabitants where possible.

- The extra inhabitants of an aggregate are the extra inhabitants of
  the first field. If the first field is empty, there are no extra
  inhabitants, and subsequent fields do not affect anything.

- Function pointers and metatypes have different extra inhabitants
  than Builtin.RawPointer, so have IRGen emit distinct builtin type
  descriptors for those.

- Opaque existentials do not have extra inhabitants.

- Weak references do not have extra inhabitants.

Also, fix IRGen to emit more accurate enum reflection metadata in
these two cases:

- We now record whether enum cases are indirect or not. An indirect
  case is the same as a payload case with Builtin.NativeObject.

- We now record whether a case is empty or not using the same logic
  as the rest of IRGen. Previously, we would incorrectly emit a
  payload type for a case with a payload that is an empty struct,
  for example.

At this point we don't have a way to get the currently inhabited
enum case from a value. However, this is still an improvement because
we can still reflect other fields of aggregates containing enums,
instead of just giving up.

Finally make some methods on TypeCoverter private, and use 'friend'
to allow them to be accessed from other internal classes, making the
public API simpler.
2016-06-30 12:57:14 -06:00
David Farler
2799cabcfb SwiftRemoteMirror: Dig into generic SIL boxes
Part 1: Generic SIL Boxes always have instatiated metadata with kind
HeapGenericLocalVariable, which includes a metadata pointer for the
boxed type.

Part 2, after this, is to provide some kind of outgoing pointer map for
fixed heap boxes, whose metadata may be shared among different but
destructor-compatible types.

rdar://problem/26240419
2016-05-17 01:30:28 -07:00
David Farler
c9e0df7d4d Add an opaque field for necessary bindings struct
Without this, offsets of captures in closure contexts may be
incorrect if there is a non-empty necessary bindings structure
at the front.

rdar://problem/26312900
2016-05-16 20:25:35 -07:00
practicalswift
21c872c590 [gardening] Fix recently introduced typos. 2016-05-14 20:33:28 +02:00
Slava Pestov
710d7ede71 Reflection: Break out SWIFT_RAW_POINTER vs SWIFT_BUILTIN in the C API
Also, use "opaque existential" consistently to refer to non-class
existentials, and clean up some other random bits.
2016-05-12 18:27:35 -07:00