Commit Graph

24 Commits

Author SHA1 Message Date
John McCall
e7f6c8c302 [NFC] Add a ConstantInitBuilder method to add a UniqueHash
structure for a string
2022-04-11 22:25:11 -04:00
Yuta Saito
43a25e89b7 [Wasm][IRGen] Add initial support for absolute function pointer
On some Harvard architectures like WebAssembly that allow sliding code
and data address space offsets independently, it's impossible to make
direct relative reference to code from data because the relative offset
between them is not representable.
Use absolute function references instead of relative ones on such targets.
2022-03-30 08:12:23 +00:00
Pavel Yaskevich
cee7d1c112 [IRGen] Pad generic environment descriptor before adding requirements
Since `TargetGenericEnvironmentDescriptor` uses trailing objects to
store parameters, requirements and other information. IR Emission
should pad the structure to be 4 bytes aligned before adding generic
requirements, because that's the alignment expected by
`TargetGenericRequirementDescriptor`.
2022-01-22 00:53:26 -08:00
Nate Chandler
2b50150e61 [metadata prespecialization] Zero trailing flags.
Previously, the trailing flags field of runtime instantiated generic
metadata for types which had prespecialization enabled were not zeroed.
Consequently, the field always contained garbage.  Often, metadata was
instantiated on new (and so, zeroed) pages, so the garbage happened to
be zero as is appropriate.  However, when the metadata was instantiated
on pages which had previously been dirtied, the garbage value would
sometimes indicate that the metadata was canonical statically
specialized.  When that occurred, swift_checkMetadataState would
incorrectly return a metadata state of complete, despite the fact that
the metadata might not in fact be complete.  As a result, the runtime
was trafficking in incomplete metadata as if it were complete, resulting
in various crashes that would arise from for example missing a witness
table or a value witness table.

Here the problem is corrected.  The trailing flags field of structs and
enums that have the field is set to 0.

For structs, this is accomplished by modifying the extra data pattern to
exist not only when there is fixed type info for the type but also when
the type is being prespecialized.  Specifically, the extra data for a
struct is, rather than an i32 array of field offsets, a struct
consisting of none, one, or both of the following: (1) the array of
field offsets, (2) the trailing flags.

Similarly, enums now have an extra data pattern which consists of none,
one, or both of the following: (1) the payload size, (2) the trailing
flags.  Enum metadata extra data setting was previously achieved by
customizing the metadata allocation function; that customization is now
eliminated, being replaced with the shared runtime code for copying
extra data into place, a modest code size savings.

rdar://problem/61465515
2020-04-23 18:18:40 -07:00
Nate Chandler
05c812be05 [IRGen] Corrected size of trailing flags field.
The struct and enum metadata scanners were both adding a pointer for the
trailing flags field.  That was only correct for 64-bit platforms.
Instead, add an Int64.
2020-04-15 17:21:37 -07:00
Kuba Mracek
84c4864911 [arm64e] Add Swift compiler support for arm64e pointer authentication 2020-02-27 16:10:31 -08:00
Joe Groff
65a4531467 IRGen/Runtime: Make key path pattern format true-const.
Use relative references instead of pointers so that the pattern can be true-const. Instead of trying
to instantiate a constant key path literal in-place, point to a cache variable that we can store
a pointer to the shared instance into when instantiated. Now that the pattern format has diverged
significantly from the instance format, simplify and refactor the instantiation code using a walker
for the pattern format instead of trying to reuse the code for working with instantiated instances.
rdar://problem/42674576
2018-11-05 12:30:49 -08:00
Pavel Yaskevich
78822bc23e [IRGen] Adjust element size of offset vector to 32-bit for structs
Type of elements contained by field offsets vector can be adjusted
to 32-bit integers (from being pointer sized) to safe space in the
binary since segment size is limited to 4 GB.

Resolves: rdar://problem/36560486
2018-04-03 13:32:06 -07:00
Slava Pestov
fd6bfcab3f Runtime: New RelativeIndirectPointer template
We have RelativeDirectPointer and RelativeIndirectablePointer. The latter
cannot be used with function pointers because it assumes the payload is
2-byte aligned and uses the least significant bit to dynamically
distinguish a direct pointer from an indirect pointer.

For resilient conformances, we want to use protocol dispatch thunks as
keys in the witness table template. They're not 2 byte aligned, and
they're always defined in a different image, so we need an unconditional
indirect relative pointer template.
2018-03-27 16:24:18 -07:00
Saleem Abdulrasool
086c12114d IRGen: switch to absolute pointers for nominal type descriptors
Alter the value metadata layout to use an absolute pointer for the
nominal type descriptor rather than a relative offset relative to the
complete type metadata.  Although this is slightly less efficient in
terms of load times, this is more portable across different
environments.  For example, PE/COFF does not provide a cross-section
relative offset relocation.  Other platform ports are unable to provide
a 64-bit relative offset encoding.

Given that the value witness table reference in the value metadata is
currently an absolute pointer, this page is most likely going to be
dirtied by the loader.
2017-10-03 14:45:45 -07:00
Joe Groff
752beac4f1 KeyPaths: Pointer-align pointer fields within key path patterns.
To get the full benefit of dyld3 on Darwin platforms, pointer relocations need to be pointer-aligned, which unfortunately requires growing some key path data structures a little bit. This does tidy up some code that had to hack around our lack of unaligned load/store operations on UnsafeRawPointer, at least. While we're here, we can also simplify the identification strategy for reabstracted stored properties; we only need the property index to identify, not the absolute offset. rdar://problem/32318829
2017-06-20 14:42:05 -07:00
Erik Eckstein
1625345b90 Remove the old mangler.
NFC
2017-03-17 16:10:36 -07:00
John McCall
2e4d154e71 Remove Swift's own ConstantBuilder, since it is no longer used. NFC. 2017-03-06 15:15:50 -05:00
John McCall
d61d966451 Use ConstantInitBuilder in most kinds of metadata emission.
This is NFC in intent, but I had to restructure the code to emit more
of the lists "inline", which means I inevitably altered some IRGen
emission patterns in ways that are visible to tests:

- GenClass emits property/ivar/whatever descriptors in a somewhat
  different order.

- An ext method type list is now emitted as just an array, not a struct
  containing only that array.

- Protocol descriptors are no longer emitted as packed structs.

I was sorely tempted to stop using packed structs for all the metadata
emission, but didn't really want to update that many tests in one go.
2017-03-06 14:18:47 -05:00
John McCall
ec667cae55 Adopt ConstantInitBuilder in a few places. 2017-03-06 14:18:47 -05:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01: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
John McCall
0ffb7278bc Only use metadata patterns for generic types; perform other
initialization in-place on demand.  Initialize parent metadata
references correctly on struct and enum metadata.

Also includes several minor improvements related to relative
pointers that I was using before deciding to simply switch the
parent reference to an absolute reference to get better access
patterns.

Includes a fix since the earlier commit to make enum metadata
writable if they have an unfilled payload size.  This didn't show
up on Darwin because "constant" is currently unenforced there in
global data containing relocations.

This patch requires an associated LLDB change which is being
submitted in parallel.
2016-03-24 15:10:31 -07:00
John McCall
abba7f0c8b Revert "Only use metadata patterns for generic types; perform other"
This reverts commit 41efb3d4d3.
LLDB has too many tendrils into our metadata.
2016-03-23 20:26:43 -07:00
John McCall
41efb3d4d3 Only use metadata patterns for generic types; perform other
initialization in-place on demand.  Initialize parent metadata
references correctly on struct and enum metadata.

Also includes several minor improvements related to relative
pointers that I was using before deciding to simply switch the
parent reference to an absolute reference to get better access
patterns.
2016-03-23 17:04:04 -07:00
David Farler
7e8b8f83e8 Emit reflection metadata by default
This turns on the remote reflection metadata by default for swift
invocations and the standard library. The size delta for all of the
sections is:

Section __swift3_typeref: 20176
Section __swift3_reflstr: 2556
Section __swift3_fieldmd: 8172
Section __swift3_assocty: 18112

Recognizing that this is a nontrivial increase in binary size, we can
reduce this with a few methods:

- Trie for strings (typerefs and field names are both strings) but would
  need an implementation
- Compress the entire sections: this would need an implementation
  available on all platforms where we support the functionality.
- Don't use the AST mangler but a custom mangling, which may be slightly
  more compact because it can specialize by need and maybe not include
  some mangle nodes that typerefs don't need.
2016-03-18 17:50:32 -07:00
Joe Groff
32872cb74a IRGen/Runtime: Relative-reference the nominal type descriptor and parent type from metadata.
Save a couple relocations per concrete value type, leaving only the value witness table as an absolute symbol.
2016-02-09 15:17:03 -08:00
practicalswift
746c432d45 [gardening] Emacs language marker required for *.h files 2016-02-04 13:05:05 +01:00
David Farler
a6a5ece206 IRGen: Emit type references for remote reflection
- Implement emission of type references for nominal type field
  reflection, using a small custom encoder resulting in packed
  structs, not strings. This will let us embed 7-bit encoded
  32-bit relative offsets directly in the structure (not yet
  hooked in).
- Use the AST Mangler for encoding type references
  Archetypes and internal references were complicating this before, so we
  can take the opportunity to reuse this machinery and avoid unique code
  and new ABI.

Next up: Tests for reading the reflection sections and converting the
demangle tree into a tree of type references.

Todo: For concrete types, serialize the types for associated types of
their conformances to bootstrap the typeref substitution process.

rdar://problem/15617914
2016-02-03 13:52:26 -08:00