11/*
22 This source file is part of the Swift.org open source project
33
4- Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
4+ Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors
55 Licensed under Apache License v2.0 with Runtime Library Exception
66
77 See http://swift.org/LICENSE.txt for license information
@@ -138,18 +138,20 @@ final class BuildPlanTests: XCTestCase {
138138 " /fake/path/to/swiftc " , " -L " , " /path/to/build/debug " ,
139139 " -o " , " /path/to/build/debug/exe " , " -module-name " , " exe " ,
140140 " -emit-executable " ,
141+ " -Xlinker " , " -alias " , " -Xlinker " , " _exe_main " , " -Xlinker " , " _main " ,
141142 " -Xlinker " , " -rpath " , " -Xlinker " , " @loader_path " ,
142143 " @/path/to/build/debug/exe.product/Objects.LinkFileList " ,
143144 " -Xlinker " , " -rpath " , " -Xlinker " , " /fake/path/lib/swift/macosx " ,
144145 " -target " , " x86_64-apple-macosx10.10 " , " -Xlinker " , " -add_ast_path " ,
145- " -Xlinker " , " /path/to/build/debug/exe.build/exe. swiftmodule " , " -Xlinker " , " -add_ast_path " ,
146+ " -Xlinker " , " /path/to/build/debug/exe.swiftmodule " , " -Xlinker " , " -add_ast_path " ,
146147 " -Xlinker " , " /path/to/build/debug/lib.swiftmodule " ,
147148 ]
148149 #else
149150 let linkArguments = [
150151 " /fake/path/to/swiftc " , " -L " , " /path/to/build/debug " ,
151152 " -o " , " /path/to/build/debug/exe " , " -module-name " , " exe " ,
152153 " -static-stdlib " , " -emit-executable " ,
154+ " -Xlinker " , " --defsym " , " -Xlinker " , " main=exe_main " ,
153155 " -Xlinker " , " -rpath=$ORIGIN " ,
154156 " @/path/to/build/debug/exe.product/Objects.LinkFileList " ,
155157 " -target " , defaultTargetTriple,
@@ -450,6 +452,7 @@ final class BuildPlanTests: XCTestCase {
450452 XCTAssertEqual ( try result. buildProduct ( for: " exe " ) . linkArguments ( ) , [
451453 " /fake/path/to/swiftc " , " -g " , " -L " , " /path/to/build/release " ,
452454 " -o " , " /path/to/build/release/exe " , " -module-name " , " exe " , " -emit-executable " ,
455+ " -Xlinker " , " -alias " , " -Xlinker " , " _exe_main " , " -Xlinker " , " _main " ,
453456 " -Xlinker " , " -rpath " , " -Xlinker " , " @loader_path " ,
454457 " @/path/to/build/release/exe.product/Objects.LinkFileList " ,
455458 " -Xlinker " , " -rpath " , " -Xlinker " , " /fake/path/lib/swift/macosx " ,
@@ -459,6 +462,7 @@ final class BuildPlanTests: XCTestCase {
459462 XCTAssertEqual ( try result. buildProduct ( for: " exe " ) . linkArguments ( ) , [
460463 " /fake/path/to/swiftc " , " -g " , " -L " , " /path/to/build/release " ,
461464 " -o " , " /path/to/build/release/exe " , " -module-name " , " exe " , " -emit-executable " ,
465+ " -Xlinker " , " --defsym " , " -Xlinker " , " main=exe_main " ,
462466 " -Xlinker " , " -rpath=$ORIGIN " ,
463467 " @/path/to/build/release/exe.product/Objects.LinkFileList " ,
464468 " -target " , defaultTargetTriple,
@@ -779,16 +783,18 @@ final class BuildPlanTests: XCTestCase {
779783 XCTAssertEqual ( try result. buildProduct ( for: " exe " ) . linkArguments ( ) , [
780784 " /fake/path/to/swiftc " , " -L " , " /path/to/build/debug " ,
781785 " -o " , " /path/to/build/debug/exe " , " -module-name " , " exe " , " -emit-executable " ,
786+ " -Xlinker " , " -alias " , " -Xlinker " , " _exe_main " , " -Xlinker " , " _main " ,
782787 " -Xlinker " , " -rpath " , " -Xlinker " , " @loader_path " ,
783788 " @/path/to/build/debug/exe.product/Objects.LinkFileList " ,
784789 " -Xlinker " , " -rpath " , " -Xlinker " , " /fake/path/lib/swift/macosx " ,
785790 " -target " , " x86_64-apple-macosx10.10 " ,
786- " -Xlinker " , " -add_ast_path " , " -Xlinker " , " /path/to/build/debug/exe.build/exe. swiftmodule " ,
791+ " -Xlinker " , " -add_ast_path " , " -Xlinker " , " /path/to/build/debug/exe.swiftmodule " ,
787792 ] )
788793 #else
789794 XCTAssertEqual ( try result. buildProduct ( for: " exe " ) . linkArguments ( ) , [
790795 " /fake/path/to/swiftc " , " -L " , " /path/to/build/debug " ,
791796 " -o " , " /path/to/build/debug/exe " , " -module-name " , " exe " , " -emit-executable " ,
797+ " -Xlinker " , " --defsym " , " -Xlinker " , " main=exe_main " ,
792798 " -Xlinker " , " -rpath=$ORIGIN " ,
793799 " @/path/to/build/debug/exe.product/Objects.LinkFileList " ,
794800 " -target " , defaultTargetTriple,
@@ -989,16 +995,18 @@ final class BuildPlanTests: XCTestCase {
989995 XCTAssertEqual ( try result. buildProduct ( for: " exe " ) . linkArguments ( ) , [
990996 " /fake/path/to/swiftc " , " -L " , " /path/to/build/debug " ,
991997 " -o " , " /path/to/build/debug/exe " , " -module-name " , " exe " , " -emit-executable " ,
998+ " -Xlinker " , " -alias " , " -Xlinker " , " _exe_main " , " -Xlinker " , " _main " ,
992999 " -Xlinker " , " -rpath " , " -Xlinker " , " @loader_path " ,
9931000 " @/path/to/build/debug/exe.product/Objects.LinkFileList " ,
9941001 " -Xlinker " , " -rpath " , " -Xlinker " , " /fake/path/lib/swift/macosx " ,
9951002 " -target " , " x86_64-apple-macosx10.10 " ,
996- " -Xlinker " , " -add_ast_path " , " -Xlinker " , " /path/to/build/debug/exe.build/exe. swiftmodule " ,
1003+ " -Xlinker " , " -add_ast_path " , " -Xlinker " , " /path/to/build/debug/exe.swiftmodule " ,
9971004 ] )
9981005 #else
9991006 XCTAssertEqual ( try result. buildProduct ( for: " exe " ) . linkArguments ( ) , [
10001007 " /fake/path/to/swiftc " , " -L " , " /path/to/build/debug " ,
10011008 " -o " , " /path/to/build/debug/exe " , " -module-name " , " exe " , " -emit-executable " ,
1009+ " -Xlinker " , " --defsym " , " -Xlinker " , " main=exe_main " ,
10021010 " -Xlinker " , " -rpath=$ORIGIN " ,
10031011 " @/path/to/build/debug/exe.product/Objects.LinkFileList " ,
10041012 " -target " , defaultTargetTriple,
@@ -1086,12 +1094,13 @@ final class BuildPlanTests: XCTestCase {
10861094 #if os(macOS)
10871095 XCTAssertEqual ( fooLinkArgs, [
10881096 " /fake/path/to/swiftc " , " -L " , " /path/to/build/debug " ,
1089- " -o " , " /path/to/build/debug/Foo " , " -module-name " , " Foo " , " -lBar-Baz " , " -emit-executable " ,
1090- " -Xlinker " , " -rpath " , " -Xlinker " , " @loader_path " ,
1097+ " -o " , " /path/to/build/debug/Foo " , " -module-name " , " Foo " , " -lBar-Baz " , " -emit-executable " ,
1098+ " -Xlinker " , " -alias " , " -Xlinker " , " _Foo_main " , " -Xlinker " , " _main " ,
1099+ " -Xlinker " , " -rpath " , " -Xlinker " , " @loader_path " ,
10911100 " @/path/to/build/debug/Foo.product/Objects.LinkFileList " ,
10921101 " -Xlinker " , " -rpath " , " -Xlinker " , " /fake/path/lib/swift/macosx " ,
10931102 " -target " , " x86_64-apple-macosx10.10 " ,
1094- " -Xlinker " , " -add_ast_path " , " -Xlinker " , " /path/to/build/debug/Foo.build/Foo. swiftmodule "
1103+ " -Xlinker " , " -add_ast_path " , " -Xlinker " , " /path/to/build/debug/Foo.swiftmodule "
10951104 ] )
10961105
10971106 XCTAssertEqual ( barLinkArgs, [
@@ -1108,6 +1117,7 @@ final class BuildPlanTests: XCTestCase {
11081117 XCTAssertEqual ( fooLinkArgs, [
11091118 " /fake/path/to/swiftc " , " -L " , " /path/to/build/debug " ,
11101119 " -o " , " /path/to/build/debug/Foo " , " -module-name " , " Foo " , " -lBar-Baz " , " -emit-executable " ,
1120+ " -Xlinker " , " --defsym " , " -Xlinker " , " main=Foo_main " ,
11111121 " -Xlinker " , " -rpath=$ORIGIN " ,
11121122 " @/path/to/build/debug/Foo.product/Objects.LinkFileList " ,
11131123 " -target " , defaultTargetTriple,
@@ -1615,6 +1625,7 @@ final class BuildPlanTests: XCTestCase {
16151625 " /fake/path/to/swiftc " ,
16161626 " -L " , " /path/to/build/debug " , " -o " , " /path/to/build/debug/exe.exe " ,
16171627 " -module-name " , " exe " , " -emit-executable " ,
1628+ " -Xlinker " , " --defsym " , " -Xlinker " , " main=exe_main " ,
16181629 " @/path/to/build/debug/exe.product/Objects.LinkFileList " ,
16191630 " -target " , " x86_64-unknown-windows-msvc " ,
16201631 ] )
@@ -1692,6 +1703,7 @@ final class BuildPlanTests: XCTestCase {
16921703 " /fake/path/to/swiftc " , " -L " , " /path/to/build/debug " ,
16931704 " -o " , " /path/to/build/debug/app.wasm " ,
16941705 " -module-name " , " app " , " -static-stdlib " , " -emit-executable " ,
1706+ " -Xlinker " , " --defsym " , " -Xlinker " , " main=app_main " ,
16951707 " @/path/to/build/debug/app.product/Objects.LinkFileList " ,
16961708 " -target " , " wasm32-unknown-wasi "
16971709 ]
@@ -2340,10 +2352,10 @@ final class BuildPlanTests: XCTestCase {
23402352 XCTAssertMatch ( contents, . contains( """
23412353 " /path/to/build/debug/exe.build/exe.swiftmodule.o " :
23422354 tool: shell
2343- inputs: [ " /path/to/build/debug/exe.build/exe. swiftmodule " ]
2355+ inputs: [ " /path/to/build/debug/exe.swiftmodule " ]
23442356 outputs: [ " /path/to/build/debug/exe.build/exe.swiftmodule.o " ]
23452357 description: " Wrapping AST for exe for debugging "
2346- args: [ " /fake/path/to/swiftc " , " -modulewrap " , " /path/to/build/debug/exe.build/exe. swiftmodule " , " -o " , " /path/to/build/debug/exe.build/exe.swiftmodule.o " , " -target " , " x86_64-unknown-linux-gnu " ]
2358+ args: [ " /fake/path/to/swiftc " , " -modulewrap " , " /path/to/build/debug/exe.swiftmodule " , " -o " , " /path/to/build/debug/exe.build/exe.swiftmodule.o " , " -target " , " x86_64-unknown-linux-gnu " ]
23472359 """ ) )
23482360 XCTAssertMatch ( contents, . contains( """
23492361 " /path/to/build/debug/lib.build/lib.swiftmodule.o " :
0 commit comments