Skip to content

[Concurrency] Hide async_Main from other object files #69113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

kateinoigakukun
Copy link
Member

@kateinoigakukun kateinoigakukun commented Oct 11, 2023

Multiple executable targets with asyc entrypoints within a single package were not able to be tested due to the following linkage failure.
The sync main entrypoint is usually referenced by crt, so it should be visible from the outside of the object file and linked image unit. Therefore, the sync main entrypoints are renamed using -entry-point-function-name by SwiftPM to avoid conflicting with other executable targets.
On the other hand, the async async_Main entrypoint is only referenced from the sync main, so it doesn't need to be visible from other object files. Therefore, we can just hide it from other object files to avoid static link-time conflicts.

The async_Main symbol was defined as hidden SIL visibility, but hidden is still visible from other object files (not visible from other image unit), so this PR makes it private, which corresponds to internal LLVM visibility.

Resolves rdar://114231968

$ ../swift-DEVELOPMENT-SNAPSHOT-2023-10-09-a-ubuntu20.04/usr/bin/swift test
Building for debugging...
error: link command failed with exit code 1 (use -v to see invocation)
/usr/bin/ld.gold: error: /tmp/tmp.o984OA4fPZ/spm-async-main-repro/.build/x86_64-unknown-linux-gnu/debug/b.build/B.swift.o: multiple definition of 'async_Main'
/usr/bin/ld.gold: /tmp/tmp.o984OA4fPZ/spm-async-main-repro/.build/x86_64-unknown-linux-gnu/debug/a.build/A.swift.o: previous definition here
/usr/bin/ld.gold: error: /tmp/tmp.o984OA4fPZ/spm-async-main-repro/.build/x86_64-unknown-linux-gnu/debug/b.build/B.swift.o: multiple definition of 'async_MainTu'
/usr/bin/ld.gold: /tmp/tmp.o984OA4fPZ/spm-async-main-repro/.build/x86_64-unknown-linux-gnu/debug/a.build/A.swift.o: previous definition here
clang-15: error: linker command failed with exit code 1 (use -v to see invocation)
error: fatalError
[39/40] Linking spm-async-main-reproPackageTests.xctest
error: fatalError
let package = Package(
    name: "spm-async-main-repro",
    dependencies: [ ],
    targets: [
        .executableTarget(name: "a", dependencies: []),
        .executableTarget(name: "b", dependencies: []),

        .testTarget(name: "reproTests", dependencies: ["a", "b"]),
    ]
)

@kateinoigakukun
Copy link
Member Author

@swift-ci Please build toolchain

@kateinoigakukun
Copy link
Member Author

Please test with following pull request:
swiftlang/swift-package-manager#6986

@swift-ci Please smoke test

@neonichu
Copy link
Contributor

Thanks @kateinoigakukun 🥳

@kateinoigakukun kateinoigakukun merged commit 0329545 into swiftlang:main Oct 11, 2023
@kateinoigakukun kateinoigakukun deleted the yt/private-async-main branch October 11, 2023 18:45
neonichu pushed a commit to swiftlang/swift-package-manager that referenced this pull request Oct 13, 2023
Test [swiftlang/swift#69113: \[Concurrency\] Hide async_Main from other
object files](swiftlang/swift#69113)

Merge after the above fix will be merged 

### Motivation:

To verify that multiple executable targets with async entrypoints can be
linked within a single test executable

Resolves rdar://114231968

### Modifications:

Added a new test case
@etcwilde
Copy link
Member

We're seeing test failures here. I believe the symbol should be both private linkage and have hidden visibility.

https://ci.swift.org/job/swift-PR-Linux/11278/

/usr/bin/ld.gold: error: /tmp/Miscellaneous_TestableAsyncExe.itEwsM/Miscellaneous_TestableAsyncExe/.build/x86_64-unknown-linux-gnu/debug/TestableAsyncExe2.build/main.swift.o: multiple definition of 'async_MainTu'
/usr/bin/ld.gold: /tmp/Miscellaneous_TestableAsyncExe.itEwsM/Miscellaneous_TestableAsyncExe/.build/x86_64-unknown-linux-gnu/debug/TestableAsyncExe1.build/main.swift.o: previous definition here
/usr/bin/ld.gold: error: /tmp/Miscellaneous_TestableAsyncExe.itEwsM/Miscellaneous_TestableAsyncExe/.build/x86_64-unknown-linux-gnu/debug/TestableAsyncExe2.build/main.swift.o: multiple definition of 'async_Main'
/usr/bin/ld.gold: /tmp/Miscellaneous_TestableAsyncExe.itEwsM/Miscellaneous_TestableAsyncExe/.build/x86_64-unknown-linux-gnu/debug/TestableAsyncExe1.build/main.swift.o: previous definition here
/usr/bin/ld.gold: error: /tmp/Miscellaneous_TestableAsyncExe.itEwsM/Miscellaneous_TestableAsyncExe/.build/x86_64-unknown-linux-gnu/debug/TestableAsyncExe3.build/NonMain.swift.o: multiple definition of 'async_Main'
/usr/bin/ld.gold: /tmp/Miscellaneous_TestableAsyncExe.itEwsM/Miscellaneous_TestableAsyncExe/.build/x86_64-unknown-linux-gnu/debug/TestableAsyncExe1.build/main.swift.o: previous definition here
/usr/bin/ld.gold: error: /tmp/Miscellaneous_TestableAsyncExe.itEwsM/Miscellaneous_TestableAsyncExe/.build/x86_64-unknown-linux-gnu/debug/TestableAsyncExe3.build/NonMain.swift.o: multiple definition of 'async_MainTu'
/usr/bin/ld.gold: /tmp/Miscellaneous_TestableAsyncExe.itEwsM/Miscellaneous_TestableAsyncExe/.build/x86_64-unknown-linux-gnu/debug/TestableAsyncExe1.build/main.swift.o: previous definition here
/usr/bin/ld.gold: error: /tmp/Miscellaneous_TestableAsyncExe.itEwsM/Miscellaneous_TestableAsyncExe/.build/x86_64-unknown-linux-gnu/debug/TestableAsyncExe4.build/NonMain.swift.o: multiple definition of 'async_Main'
/usr/bin/ld.gold: /tmp/Miscellaneous_TestableAsyncExe.itEwsM/Miscellaneous_TestableAsyncExe/.build/x86_64-unknown-linux-gnu/debug/TestableAsyncExe1.build/main.swift.o: previous definition here
/usr/bin/ld.gold: error: /tmp/Miscellaneous_TestableAsyncExe.itEwsM/Miscellaneous_TestableAsyncExe/.build/x86_64-unknown-linux-gnu/debug/TestableAsyncExe4.build/NonMain.swift.o: multiple definition of 'async_MainTu'
/usr/bin/ld.gold: /tmp/Miscellaneous_TestableAsyncExe.itEwsM/Miscellaneous_TestableAsyncExe/.build/x86_64-unknown-linux-gnu/debug/TestableAsyncExe1.build/main.swift.o: previous definition here
clang-15: error: linker command failed with exit code 1 (use -v to see invocation)
<unknown>:0: error: link command failed with exit code 1 (use -v to see invocation)

@etcwilde
Copy link
Member

Actually, scratch that. The above link failure is on the 5.10 branch in a SwiftPM test.
I think this needs cherry-picking into the 5.10 branch. SwiftPM is still automerging changes from main to release/5.10, but Swift is not, so the tests copied into SwiftPM in swiftlang/swift-package-manager@f258cd5 are failing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
concurrency Feature: umbrella label for concurrency language features linker error
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants