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
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>
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>
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.
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.
* 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.
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.
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.
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.
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.
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.
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.
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
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.
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.
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.