Commit Graph

121 Commits

Author SHA1 Message Date
Daniel Rodríguez Troitiño
3f76e63b6e Merge pull request #22899 from drodriguez/reflection-context-fix-2
Reflection: try holding 32/64 address offset in target machine pointers.
2019-02-27 11:34:36 -08:00
Alexander Shaposhnikov
848b8efd34 [Reflection] Add first bits to support COFF
In this diff we add first bits to make reflection work on Windows,
in particular, properly extract the metadata from the corresponding sections.
With this diff box_descriptors.sil and capture_descriptors.sil start passing on Windows
after some minor tweaks to the lit testing infrastructure.
2019-02-26 17:12:53 -08:00
Daniel Rodríguez Troitiño
8bee95d232 Reflection: try holding 32/64 address offset in type big enough for all architectures.
When compiling for a 32 bit machine, uintptr_t from ReflectionInfo will
be the integer sized to hold a 32 bit pointer, so a 64 bit pointer might
not fit.

This commit removes the solution in
0f20c486e0 and does a runtime check that
the calculated offset will fit into the target machine uintptr_t, which
might not be true for 32 bits machines trying to read 64 bits images,
which should not be that common (and those images have to have offsets
bigger than what a 32 bits number can hold).
2019-02-26 13:31:35 -08:00
Saleem Abdulrasool
0f20c486e0 Reflection: prevent address truncation on ELF64
Ensure that we use the address type as specified by ELF rather than
truncate to a 32-bit value.
2019-02-24 15:40:48 -08:00
Daniel Rodríguez Troitiño
ec86064209 [swift-reflection-dump] Support for ELF32.
Split the addImage method for ELF into two branches for ELF32 and for
ELF64 depending on the value stored in the identifier of the image.

Most of the code of the previous function moves into readELFSections,
which is build similar to the already existing readMachOSections. The
code is only modified to use the types from the template parameter.

This fixes a couple of reflection tests in Android armv7 (and I suppose
it should also fix the same problem in other 32 bits platforms which use
ELF).
2019-02-19 13:06:10 -08:00
Slava Pestov
905a6def79 RemoteAST: Clean up use of std::pair and std::tuple for opened existentials with named structs 2019-02-12 15:18:03 -05:00
Slava Pestov
76ebaee078 MetadataReader: Add support for NSError toll-free bridging
An Error existential value can directly store a
reference to an NSError instance without wrapping
it in an Error container.

When "projecting" such an existential, the dynamic type
is the NSError's isa pointer, and the payload is the
address of the instance itself.
2019-02-12 14:59:57 -05:00
Davide Italiano
29a5605c13 [ReflectionContext] Save buffers and set the correct addresses. 2018-12-11 09:55:20 -08:00
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