Commit Graph

777 Commits

Author SHA1 Message Date
Bryan Chan
71abe8b7ca swift_allocError should use the Swift calling convention 2016-05-24 20:04:03 -04:00
Bryan Chan
85fde8b1fb Add support for Linux s390x. LLVM's Swift calling convention support is used to ensure correct operations of C++ code in the runtime. This patch also includes some (incomplete) changes to enum handling to make enums work in most common cases. 2016-05-24 20:03:28 -04:00
John McCall
b1983621d3 Fix the declaration of shim visibility on ELF platforms.
Declarations with protected visibility are assumed to be defined
within the current linkage unit, so we have to use default visibility
if we don't know that we're building that.  Teach the shim
visibility header to only use protected visibility when the
__SWIFT_CURRENT_DYLIB macro is defined, and define it when building
the standard library.  Eventually we should change
SWIFT_RUNTIME_STDLIB_INTERFACE and SWIFT_RUNTIME_EXPORT to be
parameterized by the defining dylib so that this works for all the
overlay stubs, too; for now, special-casing swiftCore is necessary
to fix the LInux build.
2016-05-19 14:38:34 -06:00
David Farler
2799cabcfb SwiftRemoteMirror: Dig into generic SIL boxes
Part 1: Generic SIL Boxes always have instatiated metadata with kind
HeapGenericLocalVariable, which includes a metadata pointer for the
boxed type.

Part 2, after this, is to provide some kind of outgoing pointer map for
fixed heap boxes, whose metadata may be shared among different but
destructor-compatible types.

rdar://problem/26240419
2016-05-17 01:30:28 -07:00
Michael Gottesman
8308ad85e2 Merge pull request #2485 from gottesmm/change-backtrace-to-use-dladdr-directly-instead-of-backtrace_symbol
When producing backtraces, do not use backtrace_symbol, invoke dladdr…
2016-05-11 17:28:36 -07:00
Michael Gottesman
7523d1a60b When producing backtraces, do not use backtrace_symbol, invoke dladdr directly.
Previously, we were using backtrace_symbol and then parsing/modifying its
output. By just using dladdr directly, we have a cleaner and more robust
solution.

rdar://25064742
2016-05-11 15:40:10 -07:00
Saleem Abdulrasool
81661fca61 stdlib: use the reserved attribute spellings
This is a purely mechanical change replacing the attributes with the reserved
spelling.  Compilers are to not error when they encounter a reserved spelling
for an attribute which they do not support.
2016-05-11 11:30:24 -07:00
Joe Groff
4ce8645501 Wanton microoptimization for -[_SwiftNativeNSError classForCoder]
We have a static cache var for [NSError class], so save an objc_msgSend here
2016-05-09 11:18:34 -07:00
swift-ci
dd715df6a7 Merge pull request #2432 from jckarter/bridged-error-coding 2016-05-07 10:02:45 -07:00
Chris Lattner
7e201996e8 Update the reflection printer to not omit parens from single argument
function types.  This exposes something which I think is a bug in the
reflection encoding, I'll chat with Slava about it.
2016-05-06 21:07:08 -07:00
Joe Groff
f7455a8409 Runtime: Archive _SwiftNativeNSErrors as NSErrors.
_SwiftNativeNSError is a runtime-private subclass, and NSError's inherited NSCoding implementation doesn't handle the Swift payload of bridged errors. We can't really archive arbitrary Swift values anyway yet, so just archive bridged NSError subclasses as regular NSErrors. Fixes rdar://problem/23051728.
2016-05-06 14:31:16 -07:00
Joe Groff
233a2bad9e Runtime: Fix _SwiftNativeNSError's copyWithZone:.
The default implementation from NSObject doesn't know how to copy the Swift error payload, and the object's immutable anyway, so we just need to retain and return the object we already have.
2016-05-06 11:44:23 -07:00
Jacob Mizraji
f8a79282f2 Resolve ambiguity in mutex declaration 2016-05-05 12:01:23 -07:00
rjmccall
9d2dfc0934 Merge pull request #1454 from glessard/weakref-threadsafety
[runtime] Thread safety for weak references
2016-05-04 11:03:46 -07:00
John McCall
50d58b2732 Add a lot of calling-convention annotations to the standard library / runtime.
The general rule here is that something needs to be SWIFT_CC(swift)
if it's just declared in Swift code using _silgen_name, as opposed to
importing something via a header.

Of course, SWIFT_CC(swift) expands to nothing by default for now, and
I haven't made an effort yet to add the indirect-result / context
parameter ABI attributes.  This is just a best-effort first pass.

I also took the opportunity to shift a few files to just implement
their shims header and to demote a few things to be private stdlib
interfaces.
2016-05-04 10:31:23 -07:00
Guillaume Lessard
94a9c512b9 [runtime] thread safety for weak references
It has been fairly easy to cause the runtime to crash on multithreaded read-read access to weak references (e.g. https://bugs.swift.org/browse/SR-192). Although weak references are value types, they can get elevated to the heap in multiple ways, such as when captured by a closure or when used as a property in a class object instance. In such cases, race conditions involving weak references could cause the runtime to perform to multiple decrement operations of the unowned reference count for a single increment; this eventually causes early deallocation, leading to use-after-free, modify-after-free and double-free errors.

This commit changes the weak reference operations to use a spinlock rather than assuming thread-exclusive access, when appropriate.
With this change, the crasher discussed in SR-192 no longer encounters crashes due to modify-after-free or double-free errors.
2016-05-03 20:58:44 -06:00
Brian Gesiak
fd641cdbca Merge pull request #2363 from compnerd/unused-function
stdlib: remove an unused-function
2016-05-03 09:51:57 -07:00
Jacob Mizraji
880026194e Changed StaticUnsafeMutex to have the swift:: namespace
to fix upstream clang build errors.
2016-05-02 18:14:21 -07:00
John McCall
51feb0095e Fix race condition in MetadataAllocator. 2016-05-02 16:10:57 -07:00
Saleem Abdulrasool
a35843c49a stdlib: remove an unused-function
This function is only used in the ObjC interop case.  Control it via the
preprocesor.
2016-05-01 18:52:11 -07:00
practicalswift
8e3ba900b0 [gardening] Fix recently introduced headers. 2016-05-01 12:59:13 +02:00
swift-ci
58eafc7a60 Merge pull request #2331 from rintaro/runtime-cmake-add_custom_command_target 2016-04-28 23:02:59 -07:00
Greg Parker
3af0796d4c [runtime] addressed review comments outlined in #1950 (Merge pull request #2332 from shawnce/SR-946_polish)
[runtime] addressed review comments outlined in #1950
2016-04-28 21:01:25 -07:00
Shawn Erickson
d78c6e3403 [runtime] addressed review comments outlined in #1950 2016-04-28 10:39:35 -07:00
Rintaro Ishizaki
93b4ed151a [Runtime] Don't install libsection_magic_{begin,end}.a 2016-04-29 01:45:06 +09:00
Rintaro Ishizaki
9114293af7 [Runtime] Correct add_custom_command_target usage in CMakeLists.txt
- COMMAND arguments must immediately follow dependency_out_var_name.
- Use generated target name instead of output file names.
- Unify 2 file copy COMMAND into 1 add_custom_command_target.
2016-04-29 01:44:51 +09:00
Joe Groff
804f78bfa8 Runtime: Don't leak bridged object when value-to-bridged-object cast fails.
Fixes a leak when a bridgeable value type is dynamically cast to a class type, and the cast fails, for instance:

  ```
  let x: Any = "string"
  x is NSNumber
  ```

We would fail to release the bridging object after attempting the cast.
2016-04-27 17:21:38 -07:00
Greg Parker
590d41c00a [runtime] enhanced and refactored recently added Mutex abstraction (Merge pull request #1950 from shawnce/SR-946_rw)
[runtime] enhanced and refactored recently added Mutex abstraction
2016-04-26 16:18:12 -07:00
Slava Pestov
ee0e44ae71 Runtime: Fix memory management snafu in swift_EnumCaseName()
I don't have a good way to test for leaking a box. Once I come up
with one, I will write a test for this patch as well as the earlier
patch "Runtime: Tweak Mirrors for resilience".

Fixes <rdar://problem/25797038>.
2016-04-21 17:58:10 -07:00
Han Sangjin
bf9413316e stdlib/cygwin: Modified SwiftGlibc for Cygwin and some fix
'import SwiftGlibc' is now work in Cygwin.
Add workaround about USER_LABEL_PREFIX for Clang bug.
2016-04-18 07:49:57 +09:00
Greg Parker
86faf7c15d [runtime] Don't install libswiftRuntime.a
libswiftRuntime.a is an internal object file. Its contents are incorporated
into libswiftCore.dylib and libswiftCore.a.

rdar://25353757
2016-04-15 19:15:27 -07:00
practicalswift
0927538208 [gardening] Fix file header formatting. 2016-04-14 22:26:44 +02:00
Anna Zaks
eac72f078c [runtime] Add implementation of _swift_strlcpy
This safer function is missing on Linux.
2016-04-14 11:01:57 -07:00
Anna Zaks
4ba7e418cb [runtime] Fortify the swift_demangle API.
Remove the reference to String, which leaks internal implementation details,
check for invalid inputs, and make the API more flexible. Remove the similar
Swift API, since it provides no additional value.
2016-04-14 11:01:57 -07:00
swift-ci
728d21a00d Merge pull request #1442 from SwiftAndroid/master 2016-04-12 23:30:17 -07:00
Zhuowei Zhang
7c502b6344 Port to Android
This adds an Android target for the stdlib. It is also the first
example of cross-compiling outside of Darwin.

Mailing list discussions:

1. https://lists.swift.org/pipermail/swift-dev/Week-of-Mon-20151207/000171.html
2. https://lists.swift.org/pipermail/swift-dev/Week-of-Mon-20151214/000492.html

The Android variant of Swift may be built using the following `build-script`
invocation:

```
$ utils/build-script \
  -R \                                           # Build in ReleaseAssert mode.
  --android \                                    # Build for Android.
  --android-ndk ~/android-ndk-r10e \             # Path to an Android NDK.
  --android-ndk-version 21 \
  --android-icu-uc ~/libicu-android/armeabi-v7a/libicuuc.so \
  --android-icu-uc-include ~/libicu-android/armeabi-v7a/icu/source/common \
  --android-icu-i18n ~/libicu-android/armeabi-v7a/libicui18n.so \
  --android-icu-i18n-include ~/libicu-android/armeabi-v7a/icu/source/i18n/
```

Android builds have the following dependencies, as can be seen in
the build script invocation:

1. An Android NDK of version 21 or greater, available to download
   here: http://developer.android.com/ndk/downloads/index.html.
2. A libicu compatible with android-armv7.
2016-04-12 19:26:21 -04:00
practicalswift
c760f6dfbf [gardening] Add whitespace: "foo,bar" → "foo, bar" 2016-04-12 22:31:46 +02:00
Jordan Rose
bc83940301 Make pointer nullability explicit using Optional.
Implements SE-0055: https://github.com/apple/swift-evolution/blob/master/proposals/0055-optional-unsafe-pointers.md

- Add NULL as an extra inhabitant of Builtin.RawPointer (currently
  hardcoded to 0 rather than being target-dependent).
- Import non-object pointers as Optional/IUO when nullable/null_unspecified
  (like everything else).
- Change the type checker's *-to-pointer conversions to handle a layer of
  optional.
- Use 'AutoreleasingUnsafeMutablePointer<NSError?>?' as the type of error
  parameters exported to Objective-C.
- Drop NilLiteralConvertible conformance for all pointer types.
- Update the standard library and then all the tests.

I've decided to leave this commit only updating existing tests; any new
tests will come in the following commits. (That may mean some additional
implementation work to follow.)

The other major piece that's missing here is migration. I'm hoping we get
a lot of that with Swift 1.1's work for optional object references, but
I still need to investigate.
2016-04-11 20:06:38 -07:00
practicalswift
fa40ad2f0c [gardening] "Objective C" → "Objective-C" 2016-04-09 12:22:18 +02:00
Greg Parker
41b12e7929 [runtime] Fix ObjC SwiftObject's header so it matches HeapObject.
rdar://25476641 and SR-1096.
2016-04-09 01:59:20 -07:00
Greg Parker
9a94aa5a82 [runtime] Remove a workaround in SwiftObject for an old clang bug.
Reverts the functionality of b50293b2, but leaves that commit's tests in place.
2016-04-09 01:51:58 -07:00
AnnaZaks
5d34f6629e Merge pull request #2076 from apple/asan
Add experimental support for Thread Sanitizer
2016-04-06 14:45:44 -07:00
Greg Parker
709951e82e [runtime] Fix a leak when a cast from an existential fails.
rdar://25011739.
2016-04-06 14:42:33 -07:00
Shawn Erickson
a0452be947 [runtime] enhanced and refactored recently added Mutex abstraction
- added read / write lock support
- added non-fatal error support to allow use of mutex in fatal error reporting pathway
- isolated pthread implementation to it own header/cpp file pair
- expanded unit tests to cover new code as well as better test existing mutex
- removed a layer of complexity that added no real value
2016-04-06 13:02:37 -07:00
Anna Zaks
f49e6ad8dd Fix a data race in the conformsToProtocol method.
This bug was reported by TSan.
2016-04-06 11:54:01 -07:00
Slava Pestov
03cdc17b19 stdlib: Rewrite _getClassPlaygroundQuickLook() in Swift
The C++ code was very fragile in terms of ABI dependencies and broke
when the standard library was built with -enable-resilience.

The actual reason it broke is that case numbering changes when
resilience is enabled, but instead of messing with that, it seemed
more logical to rewrite this routine in Swift instead, to avoid
ABI dependencies altogether.

This requires using the "shadow protocol" trick to call NSNumber
methods, since we cannot import NSNumber from the stdlib.
2016-04-05 00:29:49 -07:00
Slava Pestov
9ce9784180 Runtime: Tweak Mirrors for resilience
Make _MagicMirrorData @_fixed_layout, but not the concrete mirror
implementations.

To make the calling convention work in resilient builds, make the
runtime entry points into top-level functions that take a
_MagicMirrorData, instead of adding @_silgen_name attributes on
methods.

This involves changing the convention on the 'owner' parameter
from +0 to +1.

Also, there was a memory leak in the old enum code that I noticed
by inspection. We would copy the enum value into a box, strip
the enum tag bits, take the box contents but never free the box
itself.

The fix isn't very satisfying either -- we have to modify the
source enum in-place to strip tag bits, then we copy it into a
box having the right payload type, and add the tag bits back.
At least this way, we can free the box after.
2016-04-04 00:05:01 -07:00
Slava Pestov
7c0bd2f660 Runtime: Fix problems with nil-to-nil casts
We have a special rule that Optional<T>.none successfully dynamically casts
to Optional<U>.none for any T and U. However the implementation was incorrect
if the source and destination types had a different size. We would initialize
the source to nil, and then copy to the result.

The correct implementation is to initialize the result using the result
payload type directly, and not call _succeed() at all.

Fixes <https://bugs.swift.org/browse/SR-1056>.
2016-03-31 17:21:20 -07:00
swiftix
fa0d270a69 Merge pull request #1909 from swiftix/wip-non-atomic-apis
Provide non-atomic versions of many reference counting operations.
2016-03-31 14:26:02 -07:00
Ben Langmuir
f8287f4376 Revert "Runtime: Fix problems with nil-to-nil casts"
This was causing test failures in -optimize mode (build-sript -o).

This reverts commit e72caad3d7.
2016-03-31 08:59:49 -07:00