Commit Graph

99 Commits

Author SHA1 Message Date
Mike Ash
a317b8737a Merge pull request #30739 from mikeash/remote-mirror-fix-ownsaddress
[Reflection] Fix the ownsAddress function to claim heap-allocated Metadatas
2020-04-01 14:46:49 -04:00
tbkka
3c8fde7885 Implement MultiPayloadEnum support for projectEnumValue (#30635)
This code rearchitects and simplifies the projectEnumValue support by
introducing a new `TypeInfo` subclass for each kind of enum, including trivial,
no-payload, single-payload, and three different classes for multi-payload enums:

* "UnsupportedEnum" that we don't understand.  This returns "don't know" answers for all requests in cases where the runtime lacks enough information to accurately handle a particular enum.

* MP Enums that only use a separate tag value.  This includes generic enums and other dynamic layouts, as well as enums whose payloads have no spare bits.

* MP Enums that use spare bits, possibly in addition to a separate tag.  This logic can only be used, of course, if we can in fact compute a spare bit mask that agrees with the compiler.

The final challenge is to choose one of the above three handlings for every MPE.  Currently, we do not have an accurate source of information for the spare bit mask, so we never choose the third option above.  We use the second option for dynamic MPE layouts (including generics) and the first for everything else.

TODO: Once we can arrange for the compiler to expose spare bit mask data, we'll be able to use that to drive more MPE cases.
2020-03-31 15:12:44 -07:00
Mike Ash
5da118eef2 [Reflection] Fix the ownsAddress function to claim heap-allocated Metadatas.
ownsAddress was a simple range check on images, but that won't find Metadatas that get allocated on the heap. If an address isn't found, try reading it as a Metadata and doing a range check on the type context descriptor too.

rdar://problem/60981575
2020-03-31 16:49:56 -04:00
Mike Ash
15468ee70a [RemoteMirror] Remove C++isms from interop header and clean up.
* Change nullptr to NULL.
* Change bool to int.
* Fix missing DataLayout parameter in createReflectionContext.
* Silence unused parameter warnings in the minimalDataLayoutQueryFunctions.

rdar://problem/59909982
2020-03-23 13:53:35 -04:00
Mike Ash
308695b7f3 [RemoteMirror] Add copyDemangledNameForTypeRef to interop header.
rdar://problem/59909982
2020-03-23 13:53:35 -04:00
Mike Ash
e05720cd09 [RemoteMirror] Add a call to get the demangled name for a typeref.
rdar://problem/59909982
2020-03-23 13:53:35 -04:00
Kuba (Brecka) Mracek
ab6533a40f Merge branch 'master' into mracek/arm64e 2020-03-06 15:07:01 -08:00
tbkka
0d361bd3ea Teach RemoteMirror how to project enum values (#30161)
Teach RemoteMirror how to project enum values

This adds two new functions to the SwiftRemoteMirror
facility that support inspecting enum values.

Currently, these support non-payload enums and
single-payload enums, including nested enums and
payloads with struct, tuple, and reference payloads.
In particular, it handles nested `Optional` types.

TODO: Multi-payload enums use different strategies for
encoding the cases that aren't yet supported by this
code.

Note: This relies on information from dataLayoutQuery
to correctly decode invalid pointer values that are used
to encode enums.  Existing clients will need to augment
their DLQ functions before using these new APIs.

Resolves rdar://59961527

```
/// Projects the value of an enum.
///
/// Takes the address and typeref for an enum and determines the
/// index of the currently-selected case within the enum.
///
/// Returns true iff the enum case could be successfully determined.
/// In particular, note that this code may fail for valid in-memory data
/// if the compiler is using a strategy we do not yet understand.
SWIFT_REMOTE_MIRROR_LINKAGE
int swift_reflection_projectEnumValue(SwiftReflectionContextRef ContextRef,
                                      swift_addr_t EnumAddress,
                                      swift_typeref_t EnumTypeRef,
                                      uint64_t *CaseIndex);

/// Finds information about a particular enum case.
///
/// Given an enum typeref and index of a case, returns:
/// * Typeref of the associated payload or zero if there is no payload
/// * Name of the case if known.
///
/// The Name points to a freshly-allocated C string on the heap.  You
/// are responsible for freeing the string (via `free()`) when you are finished.
SWIFT_REMOTE_MIRROR_LINKAGE
int swift_reflection_getEnumCaseTypeRef(SwiftReflectionContextRef ContextRef,
                                        swift_typeref_t EnumTypeRef,
                                        unsigned CaseIndex,
                                        char **CaseName,
                                        swift_typeref_t *PayloadTypeRef);
```


Co-authored-by: Mike Ash <mikeash@apple.com>
2020-03-06 13:17:40 -08:00
Kuba Mracek
84c4864911 [arm64e] Add Swift compiler support for arm64e pointer authentication 2020-02-27 16:10:31 -08:00
Max Desiatov
67297904ac [WebAssembly] Add ifdefs for the WASI target 2020-02-08 07:37:10 +00:00
Daniel Duan
ff4ecd2e5b [include] Use nullptr instead of NULL (#28509)
NFC, gardening.
2019-12-01 23:20:10 -08:00
Joe Groff
633471c092 Reflection: Share demangler with MetadataReader.
TypeRefBuilder and MetadataReader had nearly identical symbolic reference resolvers,
but diverged because TypeRefBuilder had its own local/remote address management mechanism,
and because TypeRefBuilder tries to resolve opaque types to their underlying types, whereas
other MetadataReader clients want to preserve them as written in source. The first problem
has been addressed by making TypeRefBuilder use `RemoteRef` everywhere, and the second
can be handled with a flag (and might be able to be handled more elegantly with some more
refactoring of general opaque type handling in MetadataReader).
2019-09-26 11:28:00 -07:00
Joe Groff
8c4df3b4c2 Reflection: Traffic in RemoteRefs.
Instead of passing around raw local pointers and references, and spreading
tricky offset arithmetic around with the Local/RemoteAddress fields in
ReflectionInfo, have the TypeRefBuilder code use RemoteRefs everywhere,
which keep the remote/local mapping together in one unit and provide
centralized API for this logic.

This doesn't yet change how code uses the RemoteRef address data to
follow pointers across objects, for things like reading type refs, but
that should be much easier to do after this lands.
2019-09-25 20:28:03 -07:00
Joe Groff
bc3795eb53 Reflection: Remove vestigial Offset fields from ReflectionInfo
These are now always zero, because memory readers handle virtual address mapping.
The `swift_reflection_info_t` structure used by the C RemoteMirror API keeps
its offset fields because it's supposed to be a stable API, but we now assert that
the values are always zero.
2019-09-23 14:32:26 -07:00
Mike Ash
eb830231ba [RemoteMirror] Add support for QueryDataLayoutFunction to the interop header.
Remote Mirror added a new callback, QueryDataLayoutFunction, which provides a nicer and more extensible way to provide things like the target pointer size. Add support for that in the interop header. Search for and call the new creation function when it exists, and shim in support for older libraries that don't have it.

rdar://problem/52849572
2019-07-09 16:25:20 -04:00
Mike Ash
5b2df468fc [Reflection] Include TargetConditionals.h for WatchOS detection, not Availability.h.
While we're in there, make SwiftReflectionTest's debugLog function take an @autoclosure so we don't waste a ton of time constructing log messages that are never logged.
2019-05-08 17:51:33 -04:00
Mike Ash
0ce7732d95 [Reflection] Switch Remote Mirror back to uintptr_t for pointers on watchOS.
Existing Remote Mirror dylibs are compiled this way, and changing it breaks binary compatibility. We want to use uint64_t everywhere else, since the target's pointer size may not match ours.

rdar://problem/50279443
2019-05-06 15:58:30 -04:00
Saleem Abdulrasool
2e7c328077 Merge pull request #24168 from xiaobai/sink_component_arg
[CMake] Modify swift_install_in_component to support cmake install components
2019-04-30 21:06:32 -07:00
Saleem Abdulrasool
89629550a3 SwiftRemoteMirror: do not mark as weak import on Windows
Weak import semantics are not available on PE/COFF.  Ensure that we do not mark
the type as having weak import semantics.  Otherwise, the dllimport'ed symbol is
marked as `dso_local` which is invalid.
2019-04-24 12:27:30 -07:00
Mike Ash
8b0ab1cc49 [RemoteMirror] Mark swift_reflection_classIsSwiftMask as a weak import.
Also have swift-reflection-test check if the symbol exists. This allows swift-reflection-test to work with older Remote Mirror dylibs that don't have it.

rdar://problem/50030805
2019-04-23 11:37:37 -04:00
Alex Langford
3d9a28925b [CMake] Modify swift_install_in_component to support cmake install components
CMake supports the notion of installation components. Right now we have some
custom code for supporting swift components. I think that for installation
purposes, it would be nice to use the CMake component system.

This should be a non-functional change. We should still only be generating
install rules for targets and files in components we want to install, and we
still use the install ninja target to install everything.
2019-04-19 14:06:11 -07:00
Saleem Abdulrasool
fbd456b84d SwiftRemoteMirror: repair the windows build
This symbol is meant to be exposed to users of the SwiftRemoteMirror
library which requires that it is explicitly marked with the appropriate
DLL storage on Windows.  This should repair the Windows build.
2019-03-08 07:59:21 -08:00
Mike Ash
fbe990481b [Runtime] Dynamically select the is-Swift bit at runtime on Apple platforms.
Recent Swift uses 2 as the is-Swift bit when running on newer versions, and 1 on older versions. Since it's difficult or impossible to know what we'll be running on at build time, make the selection at runtime.
2019-03-07 10:12:27 -05: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
3df60b4a84 SwiftRemoteMirror: fix static library builds for Windows
We were previously treating all the builds as shared, which is not the
case for the host library build of SwiftRemoteMirror.  The warnings were
lost in the interminable spew from the build which is now fixed and this
stands out.
2019-02-22 10:46:32 -08:00
Mike Ash
2b89074944 [RemoteMirror] Add a call to the interop header to set the upcoming classIsSwiftMask value. 2019-02-13 14:59:05 -05:00
Adrian Prantl
ff63eaea6f Remove \brief commands from doxygen comments.
We've been running doxygen with the autobrief option for a couple of
years now. This makes the \brief markers into our comments
redundant. Since they are a visual distraction and we don't want to
encourage more \brief markers in new code either, this patch removes
them all.

Patch produced by

      for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done
2018-12-04 15:45:04 -08:00
Mike Ash
7c9388127a [RemoteMirror] Fix various interop warnings in the headers. 2018-11-26 11:12:16 -05:00
Mike Ash
47be50cccc [RemoteMirror] Update interop to handle 4.2 libraries.
The Remote Mirror interop header now accepts an arbitrary number of remote mirror libraries so that it can have 4.1, 4.2, and 5.0 loaded side by side.

rdar://problem/45808282
2018-11-26 11:12:16 -05:00
David Zarzycki
da506fc0f5 [Reflection] NFC: Adopt reference storage type meta-programming macros 2018-06-30 06:44:34 -04:00
Mike Ash
ce0ef072f7 Merge pull request #15395 from mikeash/remotemirror-hide-reflection-sections
[RemoteMirrors] Interop header fixes and library lookup caching.
2018-03-21 14:43:43 -07:00
Kuba (Brecka) Mracek
84e71b8d7a Change the RemoteMirror API to have extensible data layout callback (#15291)
* Change the RemoteMirror API to have extensible data layout callback

* Use DLQ_Get prefix on DataLayoutQueryType enum values

* Simplify MemoryReaderImpl and synthesize minimalDataLayoutQueryFunction
2018-03-16 14:54:04 -07:00
Mike Ash
ef863ab00a [RemoteMirrors] Have interop header cache address->library lookups.
rdar://problem/37538580
2018-03-16 16:24:54 -04:00
Mike Ash
cdf890b8be [RemoteMirrors] Document lookupMetadata.
rdar://problem/37538580
2018-03-08 13:31:50 -05:00
Mike Ash
da2649a433 [RemoteMirrors] Fix the declaration of lookupMetadata.
rdar://problem/37538580
2018-03-08 13:29:51 -05: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
0e3044bd3a [RemoteMirrors] Provide interop types for typeinfo and childinfo.
rdar://problem/37538580
2018-03-08 10:28:11 -05:00
Mike Ash
c01b9e05ca [RemoteMirrors] Fix a bunch of missing static inlines from SwiftRemoteMirrorLegacyInterop.h. 2018-03-05 10:26:36 -05:00
Mike Ash
a2d973dbbd Merge branch 'master' into remotemirror-hide-reflection-sections 2018-03-05 09:48:58 -05:00
Mike Ash
acb4142b1a [RemoteMirrors] Move the interop typedefs into a separate header for API clients that just want to pass the types around. 2018-03-05 09:36:44 -05:00
Saleem Abdulrasool
fbf646aa2c SwiftRemoteMirror: annotate public interfaces
Mark the public interfaces with the appropriate visibility/dll storage.
This fixes an issue with the Windows build which keeps the
SwiftRemoteMirror.dll out of date constantly as no import library is
created.  That occurs due to the fact that the library does not export
any interfaces.

Take the opportunity to move the public interfaces to protected
visibility on ELF.
2018-03-02 10:28:56 -08: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
83837ccd12 [RemoteMirrors] Clean up some documentation, comments and macros. Add an assert for pointer sizes that don't match what SwiftRemoteMirror.cpp was built with. 2018-03-01 15:39:14 -05:00
Mike Ash
b3522fa139 [RemoteMirrors] Read the TEXT segment into local memory when getting legacy reflection sections. Test that this works when memory is read into a dynamic buffer. 2018-03-01 13:56:29 -05:00
Mike Ash
09181712d4 [RemoteMirrors] Move up the typedef for SwiftReflectionInteropContextRef so things compile again. 2018-03-01 13:55:20 -05:00
Mike Ash
4424b2757f [RemoteMirrors] Add some header documentation and add prototypes for the "public" interop functions. 2018-02-28 16:36:17 -05:00
Mike Ash
c059ff2a5c [RemoteMirrors] Fix the ownership check for legacy libraries. The working implementation requires a non-legacy library to be present. Fall back to always saying "yes" otherwise. 2018-02-27 17:06:37 -05:00
Mike Ash
0b5876607e [RemoteMirrors] Implement object ownership interop for the legacy library. This avoids crashing when inspecting newer metadata with only the legacy library loaded. 2018-02-27 15:16:16 -05:00
Mike Ash
d775f72d19 [RemoteMirrors] Support passing NULL for the FreeBytesFunction. 2018-02-27 15:16:15 -05:00
Mike Ash
71f1c391ab [RemoteMirrors] Move FreeBytesFunction from an out-parameter on ReadBytesFunction to a function pointer passed in when creating a reflection context. 2018-02-27 12:51:04 -05:00