Commit Graph

1960 Commits

Author SHA1 Message Date
Mike Ash
922b71f900 [Runtime] Refactor HeapObject override checks to use a macro.
This gives us a one-stop shop for making changes to the override mechanism.

rdar://problem/54752086
2019-10-04 16:43:16 -04:00
Saleem Abdulrasool
8db900634d Revert "Fix parsing of ELF images"
This reverts commit e2b6a3d982.  This
broke on the handling of x86_64 relocation as well as the Windows build
process.
2019-09-27 08:14:32 -07:00
Jordan Rose
a6dd630ca3 Eliminate Builtin.UnknownObject as an AST type (#27378)
This removes it from the AST and largely replaces it with AnyObject
at the SIL and IRGen layers. Some notes:

- Reflection still uses the notion of "unknown object" to mean an
  object with unknown refcounting. There's no real reason to make
  this different from AnyObject (an existential containing a
  single object with unknown refcounting), but this way nothing
  changes for clients of Reflection, and it's consistent with how
  native objects are represented.

- The value witness table and reflection descriptor for AnyObject
  use the mangling "BO" instead of "yXl".

- The demangler and remangler continue to support "BO" because it's
  still in use as a type encoding, even if it's not an AST-level
  Type anymore.

- Type-based alias analysis for Builtin.UnknownObject was incorrect,
  so it's a good thing we weren't using it.

- Same with enum layout. (This one assumed UnknownObject never
  referred to an Objective-C tagged pointer. That certainly wasn't how
  we were using it!)
2019-09-26 17:48:04 -07:00
Alexander Shaposhnikov
e2b6a3d982 Fix parsing of ELF images 2019-09-26 14:37:36 -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
Saleem Abdulrasool
c4f448578e Revert "runtime: add a workaround for Windows build"
This reverts commit efaf1fbefa.
Add a much more palatable workaround for the unit tests.  Rather than
adding the dllimport for the symbols, locally define the required
symbols.  This list is sufficient to restore the ability to build tests
for Windows.
2019-09-16 15:31:01 -07:00
Saleem Abdulrasool
efaf1fbefa runtime: add a workaround for Windows build
The runtime tests will statically link the runtime and dynamically link
to the standard library.  This fails to build on Windows.  This is a
horrible workaround for the time being.
2019-09-16 09:20:49 -07:00
Joe Groff
4c3f044a46 Merge pull request #27185 from jckarter/fast-path-short-mangling-lookups
Runtime: Fast path lookup for short manglings.
2019-09-14 07:34:33 -07:00
Joe Groff
78ed70cbb8 Runtime: Fast path lookup for short manglings.
Mangling these common types takes only two bytes, which is shorter than a symbolic reference. We
know where their metadata is in the standard library, too, so we don't need to search the lookup
tables for them.
2019-09-13 18:40:25 -07:00
Joe Groff
413100be33 Merge pull request #27181 from jckarter/demangler-symbolic-reference-api-refactor
Demangler: Make symbolic reference resolver part of `demangle(Symbol|Type)` calls.
2019-09-13 18:12:04 -07:00
Joe Groff
f1e84994ed Demangler: Make symbolic reference resolver part of demangle(Symbol|Type) calls.
This makes for a cleaner and less implicit-context-heavy API, and makes it easier for symbolic
reference resolvers to do context-dependent things (like map the in-memory base address back to a
remote address in MetadataReader).
2019-09-13 15:47:08 -07:00
David Smith
1efa946caf Remove stdlib and runtime dependencies on Foundation and CF 2019-09-12 18:03:14 -07:00
Mike Ash
5decec24e7 [Runtime] Fix gatherWrittenGenericArgs crashing when description is NULL.
rdar://problem/54775582
SR-11374
2019-09-09 10:58:22 -04:00
Joe Groff
5354f9f921 Merge pull request #26911 from jckarter/objc_getClass-untrusted-demangler
Runtime: Hook the ObjC runtime with an untrusted demangler.
2019-08-28 14:22:01 -07:00
Joe Groff
a49e0d5a2e Runtime: Hook the ObjC runtime with an untrusted demangler.
We don't want objc_getClass and NSClassFromString to be able to feed arbitrary symbolic reference
pointers into the Swift runtime. Fixes rdar://problem/54724618.
2019-08-28 11:56:45 -07:00
Mike Ash
9e61d532ed Merge pull request #26516 from mikeash/retain-release-avoid-function-pointer-indirection
[Runtime] Avoid function pointer indirection in refcounting functions.
2019-08-28 10:37:34 -04:00
Arnold Schwaighofer
fe69a86929 Revert "Remove stdlib and runtime dependencies on Foundation and CF"
It is causing bots to fail.

* Revert "The __has_include(<os/system_version.h>) branch here wasn't quite right, we'll just use the dlsym one for now"

This reverts commit f824922456.

* Revert "Remove stdlib and runtime dependencies on Foundation and CF"

This reverts commit 3fe46e3f16.

rdar://54709269
2019-08-26 13:00:08 -07:00
swift-ci
3256392211 Merge pull request #26630 from Catfish-Man/shim-shim-sher-ee 2019-08-23 17:08:59 -07:00
David Smith
3fe46e3f16 Remove stdlib and runtime dependencies on Foundation and CF 2019-08-23 14:10:23 -07:00
Alex Langford
61be4d969f [CMake][NFC] Introduce component targets for proper dependency tracking
This commit introduces a CMake target for each component, adds install targets
for them, and switches build-script-impl to use the target `install-components`
for installation. Each of the targets for each component depends on each
of the individual targets and outputs that are associated with the
corresponding swift-component.

This is equivalent to what already exists, because right now install rules are
only generated for components that we want to install. Therefore, this commit
should be an NFC.

This is a resubmission (with modifications) of an earlier change. I originally
committed this but there were problems with some installation rules.
2019-08-22 10:16:50 -07:00
Mike Ash
51987245f3 [Runtime] Initialize function pointers with the original values, check against those values to call directly.
Instruments relies on the old values being there so it can call the original implementation. This has very slightly worse codegen but the impact should be minimal.
2019-08-16 14:41:12 -04:00
Mike Ash
6295cecfa7 Merge pull request #26638 from mikeash/fix-protocol-conformances-on-unavailable-classes
[Runtime] Fix swift_conformsToProtocol crashing on conformances to unavailable classes.
2019-08-15 19:09:10 -04:00
pschuh
37c6414e77 Fix usage of uninitialized memory in swift_addNewDSOImage. (#26275)
This should address https://bugs.swift.org/browse/SR-6848.

Couldn't transform the unsafeGet to get because it would produce an
infinite loop.
2019-08-13 13:23:33 -07:00
Mike Ash
6473b9d7cd [Runtime] Fix swift_conformsToProtocol crashing on conformances to unavailable classes.
An extension on a class creates a conformance record that's always visible even when that class is not present at runtime. In that case, the type pointer in the conformance record is NULL. The runtime did not like this, and crashed. This fixes it to ignore such records instead.

rdar://problem/54054895
2019-08-13 14:39:20 -04:00
Saleem Abdulrasool
f1861c3bee Merge pull request #26479 from alexshap/modify_swift_rt_elf
Add .note.swift_reflection_metadata
2019-08-09 22:29:20 -07:00
Doug Gregor
b7e245c234 [Runtime] Mark hash_value inline 2019-08-09 11:54:27 -07:00
Doug Gregor
ae477280b4 [Runtime] Make hash_value function inline. 2019-08-09 11:53:17 -07:00
Doug Gregor
e7cedae5fc [Runtime] Fail in +Asserts builds if the context descriptor cache is wrong. 2019-08-09 11:21:21 -07:00
Mike Ash
4bc794f407 Change the context descriptor cache to be a SmallDenseSet instead of a TinyPtrVector to avoid duplicates. 2019-08-09 11:19:12 -07:00
Mike Ash
a2ed459024 Fix _forEach*SectionAfter to update the start parameter. 2019-08-09 11:19:07 -07:00
Doug Gregor
bf7aad2ac9 Populate context descriptor cache from type metadata sections 2019-08-09 11:19:03 -07:00
Doug Gregor
961842def2 Eliminate deadlock in context descriptor cache 2019-08-09 11:18:50 -07:00
Mike Ash
c09adf0394 Add caching based on ABI name to _findContextDescriptor.
This is a one-to-many cache that's more speculative than the cache mapping mangled names to context descriptors. Entries found in the cache need to be verified for a match before they can be returned. However, this allows scanning conformance records up front and building up the cache in one scan rather than performing an expensive scan of all conformance records every time the mangled name cache misses.

rdar://problem/53560010
2019-08-09 11:18:43 -07:00
Joe Groff
625a7c7f1f Merge pull request #26476 from Azoy/fix-tuple-metadata-crash
[Runtime] Fix crash on tuple metadata dump
2019-08-08 18:16:57 -07:00
Ben Langmuir
327c666b8a Revert "[CMake][NFC] Introduce component targets for proper dependency tracking" 2019-08-08 16:35:59 -07:00
Alex Langford
50a0e87c69 [CMake][NFC] Introduce component targets for proper dependency tracking
This commit introduces a CMake target for each component, adds install targets
for them, and switches build-script-impl to use the target `install-components`
for installation. Each of the targets for each component depends on each
of the individual targets and outputs that are associated with the
corresponding swift-component.

This is equivalent to what already exists, because right now install rules are
only generated for components that we want to install. Therefore, this commit
should be an NFC.
2019-08-08 11:50:35 -07:00
Alexander Shaposhnikov
791ca54397 Add .note.swift_reflection_metadata 2019-08-08 01:02:46 -07:00
Michael Munday
bb2740e540 IRGen: fix enum bit packing on big-endian platforms.
This change modifies spare bit masks so that they are arranged in
the byte order of the target platform. It also modifies and
consolidates the code that gathers and scatters bits into enum
values.

All enum-related validation tests are now passing on IBM Z (s390x)
which is a big-endian platform.
2019-08-07 03:54:16 -04:00
Doug Gregor
8340e0b745 Merge pull request #26509 from DougGregor/runtime-protocol-extension-fail-fast-search
[Runtime] Short-circuit search for context descriptor for protocol extensions
2019-08-06 15:26:49 -07:00
Mike Ash
9fd03e24ad [Runtime] Avoid function pointer indirection in refcounting functions.
Functions like swift_retain call through a function pointer so that Instruments can interpose. This slows down the common case where there is no interposition. Instead, initialize the function pointers to NULL and call through directly to the real implementation when it's NULL. The compiler is smart enough to inline this call and the result is a single conditional branch rather than a function pointer call.

rdar://problem/18307425
2019-08-06 14:29:51 -04:00
Doug Gregor
17b917fef9 [Runtime] Short-circuit search for context descriptor for protocol extensions
When looking for a context descriptor for a protocol extension, we
search based on the mangled name--"x", a generic type parameter with
depth and index 0--and are guaranteed to fail because there is no such
concrete type. However, _findContextDescriptor will fail very slowly,
spinning through all of the types and conformances in all of the
loaded images. Moreover, negative results aren't cached, so this can
happen repeatedly.

Short-circuit _findContextDescriptor when it receives a dependent
generic type parameter type, avoiding the expensive search when it
will find nothing.

Potential fix for rdar://problem/53560010.
2019-08-05 22:05:53 -07:00
Azoy
ab5ef84046 Fix crash on tuple metadata dump 2019-08-03 01:27:44 -04:00
swift-ci
d5d4ac672b Merge pull request #26338 from xiaobai/debride-option 2019-08-01 18:42:33 -07:00
JF Bastien
31e6a989f5 [NFC] Don't use LLVM_ALIGNAS (#26411)
It's not useful anymore, and I'm about to remove it in upstream.
2019-07-30 13:14:02 -07:00
Alex Langford
a16c71cc86 [CMake] Remove TARGET_LIBRARY option from add_swift_target_library
If you're calling add_swift_target_library, you already know it's a
target library.
2019-07-24 14:55:08 -07:00
Michael Munday
71fa7ece3f Runtime: simplify loading and storing enum values
This commit centralizes the code that converts variable length
tag values, stored in enum payloads and extra tag bytes, to and
from the 4-byte integer values that the runtime uses to represent
the enum case.

Note that currently big endian machines will store the tag value
in the first word of the destination. This reflects the current
behaviour of the compiler. I am however expecting to change this
so that the value is stored as a true variable-length big-endian
integer in the near future, so the tag value will be stored in
the last 4 bytes of payloads rather than the first 4 bytes like
they are on little-endian systems.
2019-07-16 09:47:46 +01:00
Michael Munday
2f8b5ac9e2 Runtime: print type layout values correctly on big-endian systems
The memcpy in the type layout verifier was not correct for big-
endian systems. While we are here change 'long long' to a fixed
width unsigned type (uint64_t). It doesn't really make sense to
print the value as a signed number since we have zero extended
it from its original bit width using the memcpy.
2019-07-15 03:24:22 -04:00
Jordan Rose
4b8068d1df [runtime] Handle same-type constraints when resolving generic params
Generic parameters for a context are normally classified as "key",
meaning they have actual metadata provided at runtime, or non-key,
meaning they're derivable from somewhere else. However, a nested
context or constrained extension can take what would be a "key"
parameter in a parent context and make it non-key in a child context.
This messes with the mapping between the (depth, index) representation
of generic parameters and the flat list of generic arguments. Fix this
by (1) consistently substituting out extension contexts with the
contexts of the extended types, and (2) using the most nested context
to decide which parameters are key, instead of the context a parameter
was originally introduced in.

Note that (1) may have problems if/when extensions start introducing
their /own/ generic parameters. For now I tried to be consistent with
what was there.

rdar://problem/52364601
2019-07-08 17:46:14 -07:00
Jordan Rose
284b674900 [Runtime] Improve dump() for Metadata and (Type)ContextDescriptor
No functionality change.
2019-07-08 17:46:08 -07:00