Commit Graph

614 Commits

Author SHA1 Message Date
Evan Wilde
f3cd71d2d1 [NFC] updating StringRef API
`StringRef::endswith_insensitive` and
`StringRef::startswith_insensitive` is deprecated and being replaced
with `StringRef::ends_with_insensitive` and
`StringRef::starts_with_insensitive` respectively.
2023-07-25 12:28:28 -07:00
Mike Ash
fe7e13bba5 [Runtime][IRGen] Sign type context descriptor pointers.
Ensure that context descriptor pointers are signed in the runtime by putting the ptrauth_struct attribute on the types.

We use the new __builtin_ptrauth_struct_key/disc to conditionally apply ptrauth_struct to TrailingObjects based on the signing of the base type, so that pointers to TrailingObjects get signed when used with a context descriptor pointer.

We add new runtime entrypoints that take signed pointers where appropriate, and have the compiler emit calls to the new entrypoints when targeting a sufficiently new OS.

rdar://111480914
2023-07-07 18:10:35 -04:00
Rauhul Varma
cc0ea25664 Fixup silly compilation errors 2023-06-15 23:27:21 -07:00
Rauhul Varma
6b9fb171bf Address rewview feedback
- Renames ExperimentalPlatformCCallingConvention to
  PlatformCCallingConvention.
- Removes non-arm calling convention support as this feature is working
  around a clang bug for some arm triples which we hope to see resolved.
- Removes misleading MetaVarName from platform-c-calling-convention
  argument.
- Replaces other uses of LLVM::CallingConv::C with
  IGM.getOptions().PlatformCCallingConvention().
2023-06-15 22:06:43 -07:00
Artem Chikin
f2cf55a472 [Explicit Module Builds] Ensure IRGen uses Swift compiler's target triple when '-clang-target' is set.
The Clang importer's Clang instance may be configured with a different (higher)
OS version than the compilation target itself in order to be able to load
pre-compiled Clang modules that are aligned with the broader SDK, and match the
SDK deployment target against which Swift modules are also built. In this case,
we must use the Swift compiler's OS version triple in order to generate the
binary as-requested.

This change makes 'ClangImporter' 'Implementation' keep track of a distinct
'TargetInfo' and 'CodeGenOpts' containers that are meant to be used by clients
in IRGen. When '-clang-target' is not set, they are defined to be copies of the
'ClangImporter's built-in module-loading Clang instance. When '-clang-target' is
set, they are configured with the Swift compilation's target triple and OS
version (but otherwise identical) instead. To distinguish IRGen clients from
module loading clients, 'getModuleAvailabilityTarget' is added for module
loading clients of 'ClangImporter'.

The notion of using a different triple for loading Clang modules arises for the
following reason:
- Swift is able to load Swift modules built against a different target triple
  than the source module that is being compiled. Swift relies on availability
  annotations on the API within the loaded modules to ensure that compilation
  for the current target only uses appropriately-available API from its
  dependencies.
- Clang, in contrast, requires that compilation only ever load modules (.pcm)
  that are precisely aligned to the current source compilation. Because the
  target triple (OS version in particular) between Swift source compilation and
  Swift dependency module compilation may differ, this would otherwise result in
  builtin multiple copies of the same Clang module, against different OS
  versions, once for each different triple in the build graph.
Instead, with Explicitly-Built Modules, Swift sets a '-clang-target' argument
that ensures that all Clang modules participating in the build are built against
the SDK deployment target, matching the Swift modules in the SDK, which allows
them to expose a maximally-available API surface as required by
potentially-depending Swift modules' target OS version.
--------------------------------------------
For example:
Suppose we are building a source module 'Foo', targeting 'macosx10.0', using an
SDK with a deployment target of 'macosx12.0'. Swift modules in said SDK will be
built for 'macosx12.0' (as hard-coded in their textual interfaces), meaning they
may reference symbols expected to be present in dependency Clang modules at that
target OS version.

Suppose the source module 'Foo' depends on Swift module 'Bar', which then
depends on Clang module `Baz`. 'Bar' must be built targeting 'macosx12.0'
(SDK-matching deployment target is hard-coded into its textual interface). Which
means that 'Bar' expects 'Baz' to expose symbols that may only be available when
targeting at least 'macosx12.0'. e.g. 'Baz' may have symbols guarded with
'__MAC_OS_X_VERSION_MIN_REQUIRED >= __MAC_12_0'. For this reason, we use
'-clang-target' to ensure 'Baz' is built targeting 'macosx12.0', and can be
loaded by both 'Foo' and 'Bar'.

As a result, we cannot direclty use the Clang instance's target triple here and
must check if we need to instead use the triple of the Swift compiler instance.

Resolves rdar://109228963
2023-05-16 09:42:30 -07:00
Juergen Ributzka
17c5010d0b [swift][AutoLinkExtract] Don't add autolink hint for frameworks. (#65051)
Default system linkers on non-Darwin platforms do not support the `-framework`
argument for framework linking. This change updates autolinking to not emit
`-framework` into the .o _swift1_autolink_entries metadata when there is no
native linker support.

This is related to rdar://106578342.
2023-04-14 09:15:05 -07:00
Augusto Noronha
dbaf5e53f0 Emit cxx interop into DW_AT_APPLE_flags
When compiling with interop enabled, emit the C++ interop compiler flag
into the DW_AT_APPLE_flags, to make it so LLDB can accurately match the
C++ interop mode when initializing its compiler instance.

rdar://97610458
(cherry picked from commit b1dbb0a321)
2023-04-11 10:40:09 -07:00
Steven Wu
09b8af86fb Virtualize swift compiler outputs (#63206)
Using a virutal output backend to capture all the outputs from
swift-frontend invocation. This allows redirecting and/or mirroring
compiler outputs to multiple location using different OutputBackend.

As an example usage for the virtual outputs, teach swift compiler to
check its output determinism by running the compiler invocation
twice and compare the hash of all its outputs.

Virtual output will be used to enable caching in the future.
2023-04-05 23:34:37 +08:00
Arnold Schwaighofer
1dfc30eb1f Merge remote-tracking branch 'origin/main' into rebranch 2023-02-27 09:18:56 -08:00
Dario Rexin
a8d4d57f11 [IRGen] Generate compressed representation of value witnesses (#63813)
rdar://105837040

* WIP: Store layout string in type metadata

* WIP: More cases working

* WIP: Layout strings almost working

* Add layout string pointer to struct metadata

* Fetch bytecode layout strings from metadata in runtime

* More efficient bytecode layout

* Add support for interpreted generics in layout strings

* Layout string instantiation, take and more

* Remove duplicate information from layout strings

* Include size of previous object in next objects offset to reduce number of increments at runtime

* Add support for existentials

* Build type layout strings with StructBuilder to support target sizes and metadata pointers

* Add support for resilient types

* Properly cache layout strings in compiler

* Generic resilient types working

* Non-generic resilient types working

* Instantiate resilient type in layout when possible

* Fix a few issues around alignment and signing

* Disable generics, fix static alignment

* Fix MultiPayloadEnum size when no extra tag is necessary

* Fixes after rebase

* Cleanup

* Fix most tests

* Fix objcImplementattion and non-Darwin builds

* Fix BytecodeLayouts on non-Darwin

* Fix Linux build

* Fix sizes in linux tests

* Sign layout string pointers

* Use nullptr instead of debug value
2023-02-24 15:40:28 -08:00
swift-ci
5eb07d8c67 Merge remote-tracking branch 'origin/main' into rebranch 2023-02-09 08:33:12 -08:00
Arnold Schwaighofer
8546e434b2 Merge pull request #63518 from aschwaighofer/frame-pointer-non-leaf
IRGen: Change to using frame-pointer=non-leaf for functions that request no framepointer
2023-02-09 09:21:39 -07:00
swift-ci
b8a936d83a Merge remote-tracking branch 'origin/main' into rebranch 2023-02-08 19:33:03 -08:00
Doug Gregor
956e81c14e Add API to get the "outermost" parent source file. 2023-02-08 15:40:00 -08:00
Arnold Schwaighofer
d7852025a9 IRGen: Change to using frame-pointer=non-leaf for functions that request no framepointer
Using frame-pointer=none inhibits usage of compact unwind info.

rdar://98857255
2023-02-08 08:54:41 -08:00
swift-ci
f476abf4a1 Merge remote-tracking branch 'origin/main' into rebranch 2022-12-20 17:13:36 -08:00
Pavel Yaskevich
59d6509d55 [IRGen] Make it possible to get address of accessible func record
Runtime metadata attributes need a pointer to a generator that
could be used to instantiate an attribute value.
2022-12-20 09:45:01 -08:00
Pavel Yaskevich
b8819373d9 [IRGen] RuntimeMetadata: Add linking record for runtime discoverable attrs
Utilize newly added `Ha` postfix mangling for the entry.
2022-12-20 09:45:01 -08:00
swift-ci
a17902d0c1 Merge remote-tracking branch 'origin/main' into rebranch 2022-12-15 09:55:13 -08:00
Meghana Gupta
4dccf760bd #if 0 unreachable code to disable warning 2022-12-14 02:14:44 -08:00
Ben Barham
68d5d1f9ca Merge remote-tracking branch 'origin/main' into rebranch
Conflicts:
  lib/Frontend/CompilerInvocation.cpp - legacy pass manager removed
2022-12-07 10:13:47 -08:00
Hamish Knight
6d3545f4d5 [IRGen] Don't emit multiple copies of coverage maps
Iterating over the IRGenModules and emitting every
SILCoverageMap in the SILModule meant that we
were emitting N copies of the coverage maps for
parallel IRGen, where N is the number of output
object files.

This has always been wrong, but was previously
saved by the fact that we would drop the coverage
map on the floor if we didn't have the name data
available. This would only be the case for the
IRGenModule that had the emitted entity to
profile, in addition to any IRGenModules that
had inlined the body of a profiled enitity. As
such, this prevented the duplication from being
too egregious. However with the recent change to
emit unused name data in the case where we don't
already have name data available, we're now fully
duplicating every coverage mapping, and emitting a
ton of redundant name data.

Fix things such that we only emit coverage mapping
records for the IRGenModule that corresponds to
the entity being profiled.

rdar://102905496
2022-12-06 14:28:35 +00:00
swift-ci
33eae17f45 Merge remote-tracking branch 'origin/main' into rebranch 2022-11-09 20:34:12 -08:00
swift-ci
627dc1f69c Merge pull request #61911 from apple/rokhinip/99977665-continuations-support
Implement continuations in task-to-thread model.
2022-11-09 20:16:14 -08:00
Rokhini Prabhu
b2f51dd3de Implement continuations in task-to-thread model.
This is done using a condition variable upon which the awaiting thread
will block if the continuation has not be resumed by the point of await.
The resuming thread will signal this condition variable, thereby
unblocking the awaiting thread.

Rdar://99977665
2022-11-09 15:58:53 -08:00
Erik Eckstein
e204db7a69 IRGen: don't enable opaque pointers by default 2022-11-04 20:44:19 +01:00
Allan Shortlidge
5c7a34bccb NFC: Remove unused function createStructPointerType(). 2022-11-02 21:38:33 -07:00
Tim Kientzle
adb456270d Forcibly disable static constant array emission for now
This code currently uses the "empty array" metadata for static arrays (because
the "empty array" can never be freed and the metadata on the array storage is
not actually used in Swift).

But that doesn't work if the array is passed to Objective-C,
which does rely on the metadata.  So Objective-C code would
see bridged arrays of this type as empty.

Workaround for: rdar://101126543
2022-10-31 14:12:34 -07:00
Arnold Schwaighofer
92edb70e37 Transfer code gen option OpaquePointers to LLVMContext 2022-10-07 08:29:18 -07:00
Arnold Schwaighofer
3905955589 Merge pull request #61232 from aschwaighofer/wip_opaque_ptr_2
IRGen: Pass the elementType of pointers through to operations
2022-10-04 10:56:41 -07:00
Arnold Schwaighofer
d810b0f7e4 IRGen: Pass the elementType of pointers through to operations
In preparation for moving to llvm's opaque pointer representation
replace getPointerElementType and CreateCall/CreateLoad/Store uses that
dependent on the address operand's pointer element type.

This means an `Address` carries the element type and we use
`FunctionPointer` in more places or read the function type off the
`llvm::Function`.
2022-10-03 15:27:12 -07:00
Hamish Knight
0431bb2d1c [IRGen] Don't emit coverage maps for synthesized Clang decls
We don't need to perform coverage mapping for any
Clang decls we've synthesized, as they have no
user-written code. This is also needed to avoid a
Clang crash when attempting to emit coverage for
decls without source locations (rdar://100172217).

rdar://82820628
2022-09-20 15:58:07 +01:00
Erik Eckstein
1ae1c51022 IRGen: add sppreq instead of sspstrong for functions which need stack protection.
Now that Swift decides whether or not we need stack protection we should force LLVM to emit stack protection when we request it.
2022-09-08 08:42:25 +02:00
Argyrios Kyrtzidis
5c058d9c48 [IRGen] Update for upstream clang::CreateLLVMCodeGen() API change 2022-08-10 09:07:17 -07:00
Ben Barham
22d62bb4e0 Merge remote-tracking branch 'origin/main' into rebranch
Trivial conflict caused by the line above the
`IGM.constructInitialFnAttributes` change in `lib/IRGen/GenDecl.cpp`
having an extra argument passed in rebranch (due to the new LLVM API).
2022-08-03 19:12:06 -07:00
Arnold Schwaighofer
0379719052 IRGen: Add option to enable stack protector
Adds frontend option -enable-stack-protector to enable emission of a
stack protector.

Disabled by default.

When enabled enables LLVM's strong stack protection mode.

rdar://93677524
2022-08-02 09:05:37 -07:00
Arnold Schwaighofer
10ec81edf0 IRGen: Add force import thunk to used globals on windows
LLVM's new pass pipeline will otherwise remove the internal symbol.
2022-07-26 17:07:50 -07:00
swift-ci
7382a9c41e Merge remote-tracking branch 'origin/main' into rebranch 2022-07-11 07:53:46 -07:00
Nate Chandler
34c08b8344 [TaskToThread] Add Task.runInline.
The new intrinsic, exposed via static functions on Task<T, Never> and
Task<T, Error> (rethrowing), begins an asynchronous context within a
synchronous caller's context.  This is only available for use under the
task-to-thread concurrency model, and even then only under SPI.
2022-07-08 08:44:18 -07:00
swift-ci
bc8cecbd9a Merge remote-tracking branch 'origin/main' into rebranch 2022-06-22 22:13:18 -07:00
Erik Eckstein
24d077e78b IRGen: re-enable generate static arrays in read-only data sections.
So far, static arrays had to be put into a writable section, because the isa pointer and the (immortal) ref count field were initialized dynamically at the first use of such an array.

But with a new runtime library, which exports the symbols for the (immortal) ref count field and the isa pointer, it's possible to put the whole array into a read-only section. I.e. make it a constant global.

rdar://94185998

This reverts the revert commit df353ff3c0.
Also, I added a frontend option to disable this optimization: `-disable-readonly-static-objects`
2022-06-21 18:30:42 +02:00
swift-ci
743cd8cb76 Merge remote-tracking branch 'origin/main' into rebranch 2022-06-17 13:55:02 -07:00
Erik Eckstein
df353ff3c0 Revert "IRGen: generate static arrays in read-only data sections."
This reverts commit aca0d8358b.

I need to fix a problem before this can actually land.
2022-06-17 20:32:32 +02:00
swift-ci
0c25b6259b Merge remote-tracking branch 'origin/main' into rebranch 2022-06-17 06:34:50 -07:00
Erik Eckstein
aca0d8358b IRGen: generate static arrays in read-only data sections.
So far, static arrays had to be put into a writable section, because the isa pointer and the (immortal) ref count field were initialized dynamically at the first use of such an array.

But with a new runtime library, which exports the symbols for the (immortal) ref count field and the isa pointer, it's possible to put the whole array into a read-only section. I.e. make it a constant global.

rdar://94185998
2022-06-17 11:21:29 +02:00
swift-ci
7cb90dc351 Merge remote-tracking branch 'origin/main' into rebranch 2022-06-10 15:33:41 -07:00
Arnold Schwaighofer
821ba47079 IRGen: Add a frontend option to force single LLVM module emission in multithreaded mode
This allows to experiment with single module LLVM emission without
having to change drivers that expect multiple output files.

rdar://94744623
2022-06-10 09:46:07 -07:00
swift-ci
26cf6542ba Merge remote-tracking branch 'origin/main' into rebranch 2022-05-28 07:14:52 -07:00
Max Desiatov
950792a260 IRGen: fix swifterror attribute mismatch for WebAssembly 2022-05-28 17:31:44 +09:00
Ben Barham
caa5003c7c [next] Pass LLVM context to AttrBuilder constructor
The `AttrBuilder` API was changed in llvm/llvm-project
d2cc6c2d0c2f8a6e272110416a3fd579ed5a3ac1 to now take a `LLVMContext &`
as part of its constructor. Update uses to pass one in.
2022-05-05 16:25:10 -07:00