Commit Graph

1572 Commits

Author SHA1 Message Date
Doug Gregor
bce3fa000b [IRGen] Correctly assign lazily-emitted global variables in multi-threaded IRGen
With multi-threaded IRGen, the global variables associated with "once"
initialization tokens were not getting colocated with their actual
global variables, which caused the initialization code to get split
across different files. This issue manifest as autolinking errors in
some projects.

Fixes rdar://162400654.
2025-11-10 23:08:57 -08:00
Yuta Saito
3e834ccf9f Merge pull request #85106 from kateinoigakukun/yt/fix-dead-stub-comdat-wasm
[wasm][IRGen] Stop attaching COMDATs to dead stub methods
2025-10-29 15:29:48 +09:00
Yuta Saito
50298bd8e5 [wasm][IRGen] Stop attaching COMDATs to dead stub methods
When generating dead stub methods for vtable entries, we should not
attach COMDATs to their definitions. This is because such stubs may be
referenced only through aliases, and the presence of a COMDAT on the
stub definition would cause the aliased symbol, we want to keep, to be
discarded from the symbol table when other object files also have a
dead stub method.

Given the following two object files generated:

```mermaid
graph TD
    subgraph O0[A.swift.o]
        subgraph C0[COMDAT Group swift_dead_method_stub]
            D0_0["[Def] swift_dead_method_stub"]
        end
        S0_0["[Symbol] swift_dead_method_stub"] --> D0_0
        S1["[Symbol] C1.dead"] --alias--> D0_0
    end

    subgraph O1[B.swift.o]
        subgraph C1[COMDAT Group swift_dead_method_stub]
            D0_1["[Def] swift_dead_method_stub"]
        end
        S0_1["[Symbol] swift_dead_method_stub"] --> D0_1
        S2["[Symbol] C2.beef"] --alias--> D0_1
    end
```

When linking these two object files, the linker will pick one of the
COMDAT groups of `swift_dead_method_stub`. The other COMDAT group will be
discarded, along with all symbols aliased to the discarded definition,
even though those aliased symbols (`C1.dead` and `C2.beef`) are the
ones we want to keep to construct vtables.

This change stops attaching COMDATs to dead stub method definitions.
This effectively only affects WebAssembly targets because MachO's
`supportsCOMDAT` returns false, and COFF targets don't use
`linkonce_odr` for dead stub methods.

The COMDAT was added in 7e8f782457
2025-10-29 01:17:38 +00:00
Kuba Mracek
adeb40f261 SE-0492: Stabilize @_section/@_used into @section/@used
Removes the underscored prefixes from the @_section and @_used attributes, making them public as @section and @used respectively. The SymbolLinkageMarkers experimental feature has been removed as these attributes are now part of the standard language. Implemented expression syntactic checking rules per SE-0492.

Major parts:
- Renamed @_section to @section and @_used to @used
- Removed the SymbolLinkageMarkers experimental feature
- Added parsing support for the old underscored names with deprecation warnings
- Updated all tests and examples to use the new attribute names
- Added syntactic validation for @section to align with SE-0492 (reusing the legality checker by @artemcm)
- Changed @DebugDescription macro to explicitly use a tuple type instead of type inferring it, to comply with the expression syntax rules
- Added a testcase for the various allowed and disallowed syntactic forms, `test/ConstValues/SectionSyntactic.swift`.
2025-10-22 16:05:39 -07:00
Doug Gregor
081b5cd1e8 [SIL] Serialize section name correctly and model it on global variables
Fixes rdar://162549960.
2025-10-15 20:44:11 -07:00
Doug Gregor
bccfe3351e [IRGen] Leave _swift_dead_method_stub Internal for COFF
COFF linkers don't merge linkonce_odr symbols, leading to multiple
definition errors.
2025-10-13 08:47:18 -07:00
Doug Gregor
7e8f782457 [IRGen] Use linkonce_odr hidden linkage for _swift_dead_method_stub
IRGen introduces the symbol _swift_dead_method_stub for dead vtable
entries to point to. This symbol was given internal linkage, which
would result in multiply-defined symbols when combined with Embedded
Swift's use of aggressive CMO. Switch to linkonce_odr hidden linkage
so multiple versions of this symbol can be coalesced by the linker
(and dropped if not needed).

Fixes rdar://162392119.
2025-10-13 08:47:16 -07:00
Doug Gregor
70f3b2ef9c Merge pull request #84752 from DougGregor/nonunique-linkonce 2025-10-07 21:19:33 -07:00
Doug Gregor
4952a2c9ef [Embedded] Prefer linkonce_odr to weak_odr for nonunique definitions
This allows the implementation to drop definitions that it does need.
2025-10-07 14:57:31 -07:00
Ellis Hoag
4f254950c1 Merge pull request #84661 from ellishg/fix-objc-cstr-sections
[ObjC][Gen] Emit strs into __cstring if willBeRelativelyAddressed
2025-10-06 23:08:47 -07:00
Mishal Shah
03a599c5be Merge pull request #84606 from swiftlang/rebranch
Merge clang 21.x rebranch into main
2025-10-02 20:17:05 -07:00
Arnold Schwaighofer
7853ba0a7f Merge pull request #84178 from aschwaighofer/inline_always
Add experimental feature `@inline(always)`
2025-10-01 07:23:24 -07:00
swift-ci
c00e3621eb Merge remote-tracking branch 'origin/main' into rebranch 2025-09-30 08:56:26 -07:00
Ellis Hoag
2c919e138e [ObjC][Gen] Emit ObjC strings to respective sections (#84300)
Clang emits ObjC strings into special sections

d5e7c27d53/clang/lib/CodeGen/CGObjCMac.cpp (L4056-L4072)

As far as I can tell from `CGObjCMac.cpp`:
* types go into `__objc_methtype`
* class, category, and protocol names go into `__objc_classname`
* method names, property names, and property types go into
`__objc_methname`

See also https://github.com/swiftlang/swift/pull/84236.
2025-09-30 08:42:11 -07:00
Arnold Schwaighofer
25a071efc8 Add experimental feature @inline(always)
The intent for `@inline(always)` is to act as an optimization control.
The user can rely on inlining to happen or the compiler will emit an error
message.

Because function values can be dynamic (closures, protocol/class lookup)
this guarantee can only be upheld for direct function references.

In cases where the optimizer can resolve dynamic function values the
attribute shall be respected.

rdar://148608854
2025-09-30 08:36:26 -07:00
swift-ci
4bbfc9db04 Merge remote-tracking branch 'origin/main' into rebranch 2025-09-13 17:40:42 -07:00
Ellis Hoag
f5b70998ab [ObjC][GenDecl] Emit ObjC properties in __objc_methname section 2025-09-11 12:22:24 -07:00
swift-ci
7f8473a16c Merge remote-tracking branch 'origin/main' into rebranch 2025-09-10 02:51:07 -07:00
Anton Korobeynikov
7668666ad2 Support differentiation of wrapped value modify accessors (#78794)
Some fixes for coroutines with normal results and `partial_apply` of coroutines were required.

Fixes #55084
2025-09-10 02:30:26 -07:00
Yuta Saito
401b705295 Merge pull request #81348 from kateinoigakukun/yt/dyn-replace-asan
IRGen: Disable ASan for the auto dynamic replacement array
2025-09-10 17:46:04 +09:00
swift-ci
e84e776fc3 Merge remote-tracking branch 'origin/main' into rebranch 2025-09-09 07:15:59 -07:00
Doug Gregor
66a730b638 [Embedded] Remove -mergeable-symbols
This option is no longer necessary, because we emit weak definitions
for any imported modules. Fixes rdar://158364032.
2025-09-08 17:44:51 -07:00
swift-ci
2fc9025c9a Merge remote-tracking branch 'origin/main' into rebranch 2025-09-05 13:49:08 -07:00
Doug Gregor
dbc30dc5c9 [IRGen] Cache the layout of the LLVM struct type for statically-initialized objects
Lazy emission of SIL global variables caused us to go through the
creation of two different LLVM struct types for the same
initialization, tripping an assertion in LLVM. Cache it along with
other information about the static-initialized object rather than
rebuilding it.

Also fix the lazy_globals test to account for the laziness,
generalizing it to also run on arm64 so I won't miss it locally.
2025-09-04 15:58:32 -07:00
Doug Gregor
4009814783 [IRGen] Lazily emit SIL global variables
Delay the emission of SIL global variables that aren't externally
visible until they are actually used. This is the same lazy emission
approach that we use for a number of other entities, such as SIL
functions.

Part of rdar://158363967.
2025-09-04 13:03:15 -07:00
swift-ci
fd22790987 Merge remote-tracking branch 'origin/main' into rebranch 2025-08-18 05:56:12 -07:00
Doug Gregor
9a20ebac5b [Embedded] Emit weak definitions for imported symbols
When Embedded Swift emits a symbol that was imported from another
module, ensure that the symbol is emitted as a weak definition. This
way, importing the same module (and using its symbol) into several
different modules doesn't cause duplicate-symbol errors at link time.
Rather, the linker will merge the different symbol definitions. This
makes Embedded Swift libraries work without resorting to
`-mergeable-symbols` or `-emit-empty-object-file`.
2025-08-17 15:26:08 -07:00
Yuta Saito
b9128d48b5 IRGen: Disable ASan for the auto dynamic replacement array 2025-08-11 06:53:36 +00:00
swift-ci
367f0082fc Merge remote-tracking branch 'origin/main' into rebranch 2025-07-22 22:17:45 -07:00
Anthony Latsis
b04d6085f3 IRGen: Address llvm::InsertPosition ctor deprecation
See https://github.com/llvm/llvm-project/pull/102608.
2025-07-21 12:50:39 +01:00
Anthony Latsis
f8577a2731 IRGen: Address llvm::Type::getPointerTo deprecation
See https://github.com/llvm/llvm-project/pull/113331.
2025-07-21 12:37:15 +01:00
Saleem Abdulrasool
d0b34c2b67 Merge pull request #82170 from compnerd/internalise
IRGen: internalise well known types with static linking
2025-06-23 19:31:22 -07:00
Saleem Abdulrasool
7fa316c71d IRGen: internalise well known types with static linking
When statically linking the standard library ensure that we emit the
well known metadata and accessors with internal linkage. This fixes a
number of warnings about incorrect DLL storage when building Foundation
on Windows for static linking.
2025-06-11 11:23:21 -07:00
Alastair Houghton
cc6389366c [IRGen] Don't use GOTPCREL relocations for x86 ELF.
Unforunately, x86 ELF linkers like to optimize GOTPCREL relocations by
replacing `mov` instructions that go via the GOT with `lea` instructions
that do not.

That would be fine, but they aren't very selective and will happily
perform this transformation in non-code sections if they think that
the bytes before a relocation look like a `mov` instruction.

This corrupts our metadata.

rdar://148168098
2025-06-11 12:03:38 +01:00
Pavel Yaskevich
aabfebec03 [AST] Add new declaration - using
Initially this declaration is going to be used to determine
per-file default actor isolation i.e. `using @MainActor` and
`using nonisolated` but it could be extended to support other
file-global settings in the future.
2025-05-30 00:39:06 -07:00
Augusto Noronha
cac0abbfde Merge pull request #80380 from augusto2112/fix-opaque
[DebugInfo] Use underlying type of global variables with opaque type
2025-04-03 15:39:11 -07:00
Augusto Noronha
6abbc0d754 [DebugInfo] Use underlying type of global variables with opaque type
rdar://144881938
2025-03-31 15:52:09 -07:00
Nate Chandler
24bb9bb738 [CoroutineAccessors] Adopt swiftcoro param attr. 2025-03-28 17:10:53 -07:00
Nate Chandler
2cdbfa77bf [DefaultOverrides] IRGen. 2025-03-25 07:22:43 -07:00
Kuba (Brecka) Mracek
605f1c94cf Merge pull request #79892 from kubamracek/embedded/mergeable-weakodr
[embedded] Emit weak_odr instead of linkonce_odr symbols under -Xfrontend -mergeable-symbols
2025-03-20 10:27:13 -07:00
Tony Allevato
d94bd80c62 Add support for raw identifiers.
Raw identifiers are backtick-delimited identifiers that can contain any
non-identifier character other than the backtick itself, CR, LF, or other
non-printable ASCII code units, and which are also not composed entirely
of operator characters.
2025-03-11 17:18:43 -04:00
Kuba Mracek
d25f1fa86f [embedded] Emit weak_odr instead of linkonce_odr symbols under -Xfrontend -mergeable-symbols 2025-03-10 15:01:23 -07:00
Kuba (Brecka) Mracek
43919e8b8a Merge pull request #79706 from kubamracek/embedded-concurrency-deleted-method
[embedded][Concurrency] Fix missing swift_deletedAsyncMethodError
2025-03-10 12:27:00 -07:00
Rintaro Ishizaki
accd108e4a Merge pull request #79857 from rintaro/retire-pound-diagnostics-decl
[Parse/AST] Remove PoundDiagnosticDecl
2025-03-09 21:23:16 -07:00
Saleem Abdulrasool
50531f2681 Merge pull request #79820 from compnerd/info
IRGen: compute locality for type declarations
2025-03-08 08:03:51 -08:00
Rintaro Ishizaki
002d7d7cdf [Parse/AST] Remove PoundDiagnosticDecl
There is no reson to make a AST node for '#error' and '#warning'
directives. Parser knows the diagnostics should be emitted or not.
2025-03-07 21:48:01 -08:00
Saleem Abdulrasool
dec54ddec6 IRGen: compute locality for type metadata accessor
We previously did not properly compute the link info for type metadata
accessor. This becomes a problem for metadata accessors which are
canonically remote (e.g. the type metadata accessor for `NSError`). This
fixes the incorrect DLLStorage that was being attributed to these
functions.
2025-03-07 17:50:18 -08:00
Nate Chandler
6581fec9e1 [CoroutineAccessors] PtrAuth. 2025-03-07 11:46:51 -08:00
Nate Chandler
35d06c325d [CoroutineAccessors] Witness and vtable dispatch.
And thunking.
2025-03-07 11:46:50 -08:00
Kuba Mracek
71a5e397e4 [embedded][Concurrency] Fix missing swift_deletedAsyncMethodError 2025-03-01 06:48:39 -08:00