Commit Graph

1537 Commits

Author SHA1 Message Date
John McCall
847c060eaf Fix a potential use-after-free in lazy global emission.
Extended existential type shapes can trigger this by introducing
more entities (and thus causing GlobalVars to be rehashed) during
the lazy-emission callback.

Fixes rdar://98995607
2022-08-25 16:31:17 -04:00
Allan Shortlidge
8ec4264d9b IRGen: Fix IR linkage computation for inlined function references from clang modules imported @_weakLinked.
Part of rdar://98521248
2022-08-19 10:33:04 -07:00
Allan Shortlidge
40eb1422bb IRGen/SIL: Fix IR linkage computation for inlined function references from modules imported @_weakLinked.
Include the parent `ModuleDecl` when serializing a `SILFunction` so that it is available on deserialized functions even though the full `DeclContext` is not present. With the parent module always available we can reliably compute whether the `SILFunction` comes from a module that was imported `@_weakLinked`.

Serialize the `DeclContext` member of `SILFunction` so that it can be used to look up the module that a function belongs to in order to compute weak import status.

Resolves rdar://98521248
2022-08-19 09:56:45 -07:00
swift-ci
4eda70de33 Merge remote-tracking branch 'origin/main' into rebranch 2022-08-11 15:15:42 -07:00
Allan Shortlidge
f71a3232cf IRGen: Use extern_weak linkage for Clang symbols from @_weakLinked imported modules.
rdar://96098097
2022-08-11 11:02:57 -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
swift-ci
69e5a83e7d Merge remote-tracking branch 'origin/main' into rebranch 2022-08-02 08:35:16 -07:00
Arnold Schwaighofer
6ce452b928 IRGen: Add a list of class_ro_t referenced from generic class metadata patterns to a section __swift_rodatas
Put pointers to class_ro_t referenced from generic class patterns in a section __swift_rodatas such that they are discoverable by the linker.
The linker can then make the method lists contained in the class_ro_t relative like it can for objective c class metadata from non-generic swift classes.

rdar://66634459
2022-07-29 11:38:20 -07:00
Arnold Schwaighofer
4ce47b618a IRGen: Add definitions to compiler.used at Onone
LLVM's O0 pipeline has decided to run GlobalDCE (if there are coro intrinsics present in the module).
Add definitions to compiler.used to counter act that.
2022-07-26 12:27:57 -07:00
swift-ci
a26de5732d Merge remote-tracking branch 'origin/main' into rebranch 2022-07-21 14:14:40 -07:00
Arnold Schwaighofer
bacef19bfb IRGen: Add auto_dynamic_replacements_some entries to llvm.used
The new pass manager pipeline will otherwise remove them and tests will fail
2022-07-21 09:01:22 -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
8a59b92e7d Merge remote-tracking branch 'origin/main' into rebranch 2022-06-10 11:13:11 -07:00
Alex Lorenz
f78f226e19 NFC, extract param & return type for type metadata access function to accessors for reuse
They will be reused to provide information about the signature of the type metadata access function to the Clang printer for C++ interop
2022-06-10 07:14:59 -07: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
Ben Barham
cedf5b6c92 [next] Add missing include
Not sure which header it was removed from. Could be worth trying IWYU at
some point.
2022-05-05 16:25:10 -07:00
Ben Barham
b521dc7c42 [next] Handle new ObjectFormatTypes
LLVM has added two new object format types, add them as unhandled for
now.
2022-05-05 16:25:10 -07:00
Ben Barham
04035b43b7 [next] Temporarily use getPointerElementType
`PointerType::getElementType` has been removed entirely as part of the
opaque pointers migration. Update to `getPointerElementType` for now
until we've also migrated.
2022-05-05 16:25:10 -07:00
Josh Soref
9fa14ca215 Spelling irgen (#42470)
* spelling: abstractable

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: across

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: clazz

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: command

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: components

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: current

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: declared

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: discrimination

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: entities

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: except

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: existential

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: generic

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: initialization

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: initialize

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: inserted

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: instantiate

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: instantiation

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: interfere

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: interferes

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: intrinsic

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: metadata

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: might

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: multiple

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: necessary

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: objective

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: occurrences

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: outlined

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: parameters

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: payload

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: rearchitecting

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: replaceable

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: reverse

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: rewritable

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: shareably

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: specializations

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: speedup

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: template

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: that

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: the

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: transferred

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: uninitialized

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: witness

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

Co-authored-by: Josh Soref <jsoref@users.noreply.github.com>
2022-04-21 14:02:03 -07:00
John McCall
f7290c9bfd [NFC] Add a utility to easily emit lazy variable definitions 2022-04-11 22:26:01 -04:00
Yuta Saito
26ba09738e Merge pull request #42094 from kateinoigakukun/katei/wasm-uncond-abs-func-ptr
[Wasm][IRGen] Add initial support for unconditional absolute function pointer
2022-03-31 23:50:30 +09:00
Arnold Schwaighofer
3930fc4cfe IRGen: Fix enable-testing of internal with resilient super class
Enable testing makes `internal` types visible from outside the module.
We can no longer treat super classes as resilient.

Follow-up to #41044.

rdar://90489618
2022-03-30 07:12:14 -07: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
1330e345b7 [Distributed] IRGen: Drop marker protocol requirements from accessible function generic environments
Since marker protocol do not exist at runtime, it's harmful to keep them
in a generic environment because they cannot be checked.

Resolves: rdar://90293494
2022-03-17 15:06:54 -07:00
Erik Eckstein
6a020f8f15 Stabilize and simplify SIL linkage and serialization
The main point of this change is to make sure that a shared function always has a body: both, in the optimizer pipeline and in the swiftmodule file.
This is important because the compiler always needs to emit code for a shared function. Shared functions cannot be referenced from outside the module.
In several corner cases we missed to maintain this invariant which resulted in unresolved-symbol linker errors.

As side-effect of this change we can drop the shared_external SIL linkage and the IsSerializable flag, which simplifies the serialization and linkage concept.
2022-03-09 15:28:05 +01:00
Saleem Abdulrasool
e5cc525136 IRGen: loosen linkage on vtable stubs for static linking
The linkage inferred by internal linking is overly restrictive.  It uses
the "internal linkage type" which is for translation unit local symbols,
that is `static` storage.  These symbols participate in linking and need
to be given external storage but hidden visibility and no DLL storage in
static linking.  This permits them to participate in symbolic resolution
during linking but are made module local, not LLVM module local.
2022-03-01 08:09:37 -08:00
Saleem Abdulrasool
c83f65febf IRGen: address TODO for Windows static linking
This improves the static linking story on Windows by wiring up
information about the static vs dynamic build of the module into the
code generation for references to module external symbols.  We now can
indicate a module external symbol to be known local if it is expected to
be internalized due to static linking.  Even though the symbol may not
be defined in the same module, the definition will be provided locally
at link time.  This avoids needing to resolve a dllimport'ed symbol to a
local symbol at link time.
2022-02-22 14:41:04 -08:00
Saleem Abdulrasool
d526dcf309 Merge pull request #41431 from compnerd/externally-consumed-internally
IRGen: internalize symbols with `-static`
2022-02-21 09:12:11 -08:00
zoecarver
57ae206c85 [cxx-interop] Link against -lc++ on Darwin and -lstdc++ on Linux. 2022-02-18 16:01:09 -08:00
Saleem Abdulrasool
98bd2dba57 IRGen: internalize symbols with -static
This pipes the `-static` flag when building a static library into IRGen.
This should have no impact on non-Windows targets as the usage of the
information simply removes the `dllexport` attribute on the generated
interfaces.  This ensures that a library built with `-static` will not
re-export its interfaces from the consumer.  This is important to ensure
that the consumer does not vend the API surface when it statically links
a library.  In conjunction with the removal of the force load symbol,
this allows the generation of static libraries which may be linked
against on Windows.  However, a subsequent change is needed to ensure
that the consumer does not mark the symbol as being imported from a
foreign module (i.e. `dllimport`).
2022-02-18 19:42:08 +00:00
John McCall
58fe89f359 [NFC] Split up the "special convention" for runtime async functions
The special convention currently means three things:

1. There is no async FP symbol for the function.  Calls should go directly
to the function symbol, and an async context of fixed static size should be
allocated.  This is mandatory for calling runtime-provided async functions.

2. The callee context should be allocated but not initialized.  The main
context pointer passed should be the caller's context, and the continuation
function pointer and callee context should be passed as separate arguments.
The function will resume the continuation function pointer with the caller's
context.  This is a micro-optimization appropriate for functions that are
expected to frequently return immediately; other functions shouldn't bother.

3. Generic arguments should be suppressed.  This is a microoptimization for
certain specific runtime functions where we happen to know that the runtime
already stores the appropriate information internally.  Other functions
probably don't want this.

Obviously, these different treatments should be split into different
predicates so that functions can opt in to different subsets of them.

I've also set the code up so that runtime functions can more easily
request a specific static async context size.  Previously, it was a
confusingly embedded assumption that the static context size was always
exactly two pointers more than the header.
2022-02-15 04:12:05 -05:00
Pavel Yaskevich
2bd7a49d75 [IRGen] Record generic environment associated with accessible function
Without this piece of information it wouldn't be possible to form
a call to the recorded function at runtime if it's generic.
2022-01-24 10:17:59 -08:00
swift-ci
1d3d03260a Merge remote-tracking branch 'origin/main' into rebranch 2022-01-17 16:54:06 -08:00
Zoe Carver
be39f38ed0 Merge pull request #40867 from zoecarver/interop-fix-linker-errors
[cxx-interop] Fix linker errors when using std-vector.
2022-01-17 16:38:17 -08:00
zoecarver
ba44bfecce [cxx-interop] Add -lc++ when C++ interop is enabled on Darwin. 2022-01-17 12:11:06 -08:00
swift-ci
ff423884c7 Merge remote-tracking branch 'origin/main' into rebranch 2022-01-13 14:53:35 -08:00
Arnold Schwaighofer
3e077e7d67 IRGen: Use the 'right' async context index in the dynamic replacement prolog
The right index is the index derived for calling a function
(Signature::forAsyncEntry) rather then for receiving the results
(Signature::forAsyncAwait(); the resume fn signature).

rdar://86863272
2022-01-12 15:09:21 -08:00
swift-ci
f63372b795 Merge remote-tracking branch 'origin/main' into rebranch 2022-01-06 01:13:44 -08:00
Pavel Yaskevich
1c9bcc9092 Merge pull request #40699 from xedin/rename-dist-accessor-apis
[Distributed] NFC: Remove `Method` from accessor APIs
2022-01-06 01:03:45 -08:00
swift-ci
574959ebcb Merge remote-tracking branch 'origin/main' into rebranch 2022-01-04 19:34:06 -08:00
Kuba (Brecka) Mracek
243141e8b5 [IRGen] When emitting llvm.used.conditional list, strip all pointer casts in dependencies (#40678) 2022-01-04 19:32:45 -08:00
Pavel Yaskevich
d516281da9 [Distributed] NFC: Remove Method from accessor APIs
The API is not constrained to methods only, it should support
computed properties as well.
2021-12-23 14:10:05 -08:00
swift-ci
134e17c8ec Merge remote-tracking branch 'origin/main' into rebranch 2021-12-17 16:54:09 -08:00
Pavel Yaskevich
7ac42e11b6 [Distributed] IRGen: Store async function pointer to distributed accessor
Direct pointer to the accessor cannot be called at runtime,
so here is how everything is stored:

- For `distributed` and `async` functions -> async function pointer;
- For regular functions -> function pointer.
2021-12-17 10:52:56 -08:00