Skip to content

Commit cb5ee46

Browse files
authored
Merge pull request #814 from owenv/owenv/dead-strip-swiftc
Fix the combination of DEAD_CODE_STRIPPING=YES and LINKER_DRIVER=swiftc
2 parents b14cb57 + 84ecf78 commit cb5ee46

File tree

5 files changed

+15
-13
lines changed

5 files changed

+15
-13
lines changed

Sources/SWBCore/SpecImplementations/Tools/LinkerTools.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,18 +1078,18 @@ public final class LdLinkerSpec : GenericLinkerSpec, SpecIdentifierType, @unchec
10781078

10791079
let argPrefix = "-Xlinker"
10801080

1081-
// Args without parameters
1082-
for arg in ["-dynamiclib", "-bundle", "-r", "-dead_strip", "-nostdlib", "-rdynamic"] {
1081+
// Args without parameters (-Xlinker-prefixed, e.g. -Xlinker)
1082+
for arg in ["-export_dynamic", "-sdk_imports_each_object", "-dead_strip"] {
10831083
while let index = commandLine.firstIndex(of: arg) {
1084-
commandLine.remove(at: index)
1084+
guard index > 0, commandLine[index - 1] == argPrefix else { break }
1085+
commandLine.removeSubrange(index - 1 ... index)
10851086
}
10861087
}
10871088

1088-
// Args without parameters (-Xlinker-prefixed, e.g. -Xlinker)
1089-
for arg in ["-export_dynamic", "-sdk_imports_each_object"] {
1089+
// Args without parameters
1090+
for arg in ["-dynamiclib", "-bundle", "-r", "-dead_strip", "-nostdlib", "-rdynamic"] {
10901091
while let index = commandLine.firstIndex(of: arg) {
1091-
guard index > 0, commandLine[index - 1] == argPrefix else { break }
1092-
commandLine.removeSubrange(index - 1 ... index)
1092+
commandLine.remove(at: index)
10931093
}
10941094
}
10951095

Sources/SWBUniversalPlatform/Specs/Ld.xcspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@
461461
DefaultValue = NO;
462462
Condition = "$(MACH_O_TYPE) != mh_object";
463463
CommandLineArgs = {
464-
YES = ("-dead_strip");
464+
YES = ("-Xlinker", "-dead_strip");
465465
NO = ();
466466
};
467467
},

Tests/SWBBuildSystemTests/PreviewsBuildOperationTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ fileprivate struct PreviewsBuildOperationTests: CoreBasedTests {
308308
linkerCommandLine.remove(at: idx)
309309
}
310310
}
311-
XCTAssertEqualSequences(linkerCommandLine, ["\(core.developerPath.path.str)/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang", "-Xlinker", "-reproducible", "-target", "\(results.runDestinationTargetArchitecture)-apple-ios\(core.loadSDK(.iOSSimulator).defaultDeploymentTarget)-simulator", "-dynamiclib", "-isysroot", core.loadSDK(.iOSSimulator).path.str, "-Os", "-Xlinker", "-warn_unused_dylibs", "-L\(srcRoot.str)/build/EagerLinkingTBDs/Debug-iphonesimulator", "-L\(srcRoot.str)/build/Debug-iphonesimulator", "-F\(srcRoot.str)/build/EagerLinkingTBDs/Debug-iphonesimulator", "-F\(srcRoot.str)/build/Debug-iphonesimulator", "-filelist", "\(srcRoot.str)/build/ProjectName.build/Debug-iphonesimulator/AppTarget.build/Objects-normal/\(results.runDestinationTargetArchitecture)/AppTarget.LinkFileList", "-install_name", "@rpath/AppTarget.debug.dylib", "-dead_strip", "-Xlinker", "-object_path_lto", "-Xlinker", "\(srcRoot.str)/build/ProjectName.build/Debug-iphonesimulator/AppTarget.build/Objects-normal/\(results.runDestinationTargetArchitecture)/AppTarget_lto.o", "-rdynamic", "-Xlinker", "-objc_abi_version", "-Xlinker", "2", "-Xlinker", "-dependency_info", "-Xlinker", "\(srcRoot.str)/build/ProjectName.build/Debug-iphonesimulator/AppTarget.build/Objects-normal/\(results.runDestinationTargetArchitecture)/AppTarget_dependency_info.dat", "-L\(core.developerPath.path.str)/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator", "-L/usr/lib/swift", "-Xlinker", "-add_ast_path", "-Xlinker", "\(srcRoot.str)/build/ProjectName.build/Debug-iphonesimulator/AppTarget.build/Objects-normal/\(results.runDestinationTargetArchitecture)/AppTarget.swiftmodule", "-Xlinker", "-alias", "-Xlinker", "_main", "-Xlinker", "___debug_main_executable_dylib_entry_point", "-Xlinker", "-no_adhoc_codesign", "-o", "\(srcRoot.str)/build/Debug-iphonesimulator/AppTarget.app/AppTarget.debug.dylib"])
311+
XCTAssertEqualSequences(linkerCommandLine, ["\(core.developerPath.path.str)/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang", "-Xlinker", "-reproducible", "-target", "\(results.runDestinationTargetArchitecture)-apple-ios\(core.loadSDK(.iOSSimulator).defaultDeploymentTarget)-simulator", "-dynamiclib", "-isysroot", core.loadSDK(.iOSSimulator).path.str, "-Os", "-Xlinker", "-warn_unused_dylibs", "-L\(srcRoot.str)/build/EagerLinkingTBDs/Debug-iphonesimulator", "-L\(srcRoot.str)/build/Debug-iphonesimulator", "-F\(srcRoot.str)/build/EagerLinkingTBDs/Debug-iphonesimulator", "-F\(srcRoot.str)/build/Debug-iphonesimulator", "-filelist", "\(srcRoot.str)/build/ProjectName.build/Debug-iphonesimulator/AppTarget.build/Objects-normal/\(results.runDestinationTargetArchitecture)/AppTarget.LinkFileList", "-install_name", "@rpath/AppTarget.debug.dylib", "-Xlinker", "-dead_strip", "-Xlinker", "-object_path_lto", "-Xlinker", "\(srcRoot.str)/build/ProjectName.build/Debug-iphonesimulator/AppTarget.build/Objects-normal/\(results.runDestinationTargetArchitecture)/AppTarget_lto.o", "-rdynamic", "-Xlinker", "-objc_abi_version", "-Xlinker", "2", "-Xlinker", "-dependency_info", "-Xlinker", "\(srcRoot.str)/build/ProjectName.build/Debug-iphonesimulator/AppTarget.build/Objects-normal/\(results.runDestinationTargetArchitecture)/AppTarget_dependency_info.dat", "-L\(core.developerPath.path.str)/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator", "-L/usr/lib/swift", "-Xlinker", "-add_ast_path", "-Xlinker", "\(srcRoot.str)/build/ProjectName.build/Debug-iphonesimulator/AppTarget.build/Objects-normal/\(results.runDestinationTargetArchitecture)/AppTarget.swiftmodule", "-Xlinker", "-alias", "-Xlinker", "_main", "-Xlinker", "___debug_main_executable_dylib_entry_point", "-Xlinker", "-no_adhoc_codesign", "-o", "\(srcRoot.str)/build/Debug-iphonesimulator/AppTarget.app/AppTarget.debug.dylib"])
312312
}
313313
}
314314

@@ -615,7 +615,7 @@ fileprivate struct PreviewsBuildOperationTests: CoreBasedTests {
615615
linkerCommandLine.remove(at: idx)
616616
}
617617
}
618-
XCTAssertEqualSequences(linkerCommandLine, ["\(core.developerPath.path.str)/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang", "-Xlinker", "-reproducible", "-target", "\(results.runDestinationTargetArchitecture)-apple-ios\(core.loadSDK(.iOSSimulator).defaultDeploymentTarget)-simulator", "-dynamiclib", "-isysroot", core.loadSDK(.iOSSimulator).path.str, "-Os", "-L\(srcRoot.str)/build/EagerLinkingTBDs/Debug-iphonesimulator", "-L\(srcRoot.str)/build/Debug-iphonesimulator", "-F\(srcRoot.str)/build/EagerLinkingTBDs/Debug-iphonesimulator", "-F\(srcRoot.str)/build/Debug-iphonesimulator", "-filelist", "\(srcRoot.str)/build/ProjectName.build/Debug-iphonesimulator/AppTarget.build/Objects-normal/\(results.runDestinationTargetArchitecture)/AppTarget.LinkFileList", "-install_name", "@rpath/AppTarget.debug.dylib", "-dead_strip", "-Xlinker", "-object_path_lto", "-Xlinker", "\(srcRoot.str)/build/ProjectName.build/Debug-iphonesimulator/AppTarget.build/Objects-normal/\(results.runDestinationTargetArchitecture)/AppTarget_lto.o", "-rdynamic", "-Xlinker", "-objc_abi_version", "-Xlinker", "2", "-Xlinker", "-dependency_info", "-Xlinker", "\(srcRoot.str)/build/ProjectName.build/Debug-iphonesimulator/AppTarget.build/Objects-normal/\(results.runDestinationTargetArchitecture)/AppTarget_dependency_info.dat", "-fobjc-link-runtime", "-L\(core.developerPath.path.str)/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator", "-L/usr/lib/swift", "-Xlinker", "-add_ast_path", "-Xlinker", "\(srcRoot.str)/build/ProjectName.build/Debug-iphonesimulator/AppTarget.build/Objects-normal/\(results.runDestinationTargetArchitecture)/AppTarget.swiftmodule", "-Xlinker", "-alias", "-Xlinker", "_main", "-Xlinker", "___debug_main_executable_dylib_entry_point", "-Xlinker", "-no_adhoc_codesign", "-o", "\(srcRoot.str)/build/Debug-iphonesimulator/AppTarget.app/AppTarget.debug.dylib"])
618+
XCTAssertEqualSequences(linkerCommandLine, ["\(core.developerPath.path.str)/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang", "-Xlinker", "-reproducible", "-target", "\(results.runDestinationTargetArchitecture)-apple-ios\(core.loadSDK(.iOSSimulator).defaultDeploymentTarget)-simulator", "-dynamiclib", "-isysroot", core.loadSDK(.iOSSimulator).path.str, "-Os", "-L\(srcRoot.str)/build/EagerLinkingTBDs/Debug-iphonesimulator", "-L\(srcRoot.str)/build/Debug-iphonesimulator", "-F\(srcRoot.str)/build/EagerLinkingTBDs/Debug-iphonesimulator", "-F\(srcRoot.str)/build/Debug-iphonesimulator", "-filelist", "\(srcRoot.str)/build/ProjectName.build/Debug-iphonesimulator/AppTarget.build/Objects-normal/\(results.runDestinationTargetArchitecture)/AppTarget.LinkFileList", "-install_name", "@rpath/AppTarget.debug.dylib", "-Xlinker", "-dead_strip", "-Xlinker", "-object_path_lto", "-Xlinker", "\(srcRoot.str)/build/ProjectName.build/Debug-iphonesimulator/AppTarget.build/Objects-normal/\(results.runDestinationTargetArchitecture)/AppTarget_lto.o", "-rdynamic", "-Xlinker", "-objc_abi_version", "-Xlinker", "2", "-Xlinker", "-dependency_info", "-Xlinker", "\(srcRoot.str)/build/ProjectName.build/Debug-iphonesimulator/AppTarget.build/Objects-normal/\(results.runDestinationTargetArchitecture)/AppTarget_dependency_info.dat", "-fobjc-link-runtime", "-L\(core.developerPath.path.str)/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator", "-L/usr/lib/swift", "-Xlinker", "-add_ast_path", "-Xlinker", "\(srcRoot.str)/build/ProjectName.build/Debug-iphonesimulator/AppTarget.build/Objects-normal/\(results.runDestinationTargetArchitecture)/AppTarget.swiftmodule", "-Xlinker", "-alias", "-Xlinker", "_main", "-Xlinker", "___debug_main_executable_dylib_entry_point", "-Xlinker", "-no_adhoc_codesign", "-o", "\(srcRoot.str)/build/Debug-iphonesimulator/AppTarget.app/AppTarget.debug.dylib"])
619619
}
620620
}
621621
}

Tests/SWBTaskConstructionTests/XCFrameworkTaskConstructionTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ fileprivate struct XCFrameworkTaskConstructionTests: CoreBasedTests {
215215
// There needs to be a strong dependency on the XCFramework processing.
216216
results.checkTaskFollows(task, antecedent: try #require(processSupportXCFrameworkTask))
217217

218-
task.checkCommandLine(["clang", "-Xlinker", "-reproducible", "-target", "x86_64-apple-macos\(core.loadSDK(.macOS).defaultDeploymentTarget)", "-isysroot", core.loadSDK(.macOS).path.str, "-Os", "-L\(SRCROOT)/build/EagerLinkingTBDs/Debug", "-L\(SRCROOT)/build/Debug", "-F\(SRCROOT)/build/EagerLinkingTBDs/Debug", "-F\(SRCROOT)/build/Debug", "-filelist", "\(SRCROOT)/build/aProject.build/Debug/App.build/Objects-normal/x86_64/App.LinkFileList", "-dead_strip", "-Xlinker", "-object_path_lto", "-Xlinker", "\(SRCROOT)/build/aProject.build/Debug/App.build/Objects-normal/x86_64/App_lto.o", "-Xlinker", "-dependency_info", "-Xlinker", "\(SRCROOT)/build/aProject.build/Debug/App.build/Objects-normal/x86_64/App_dependency_info.dat", "-framework", "Support", "-Xlinker", "-no_adhoc_codesign", "-o", "\(SRCROOT)/build/Debug/App.app/Contents/MacOS/App"])
218+
task.checkCommandLine(["clang", "-Xlinker", "-reproducible", "-target", "x86_64-apple-macos\(core.loadSDK(.macOS).defaultDeploymentTarget)", "-isysroot", core.loadSDK(.macOS).path.str, "-Os", "-L\(SRCROOT)/build/EagerLinkingTBDs/Debug", "-L\(SRCROOT)/build/Debug", "-F\(SRCROOT)/build/EagerLinkingTBDs/Debug", "-F\(SRCROOT)/build/Debug", "-filelist", "\(SRCROOT)/build/aProject.build/Debug/App.build/Objects-normal/x86_64/App.LinkFileList", "-Xlinker", "-dead_strip", "-Xlinker", "-object_path_lto", "-Xlinker", "\(SRCROOT)/build/aProject.build/Debug/App.build/Objects-normal/x86_64/App_lto.o", "-Xlinker", "-dependency_info", "-Xlinker", "\(SRCROOT)/build/aProject.build/Debug/App.build/Objects-normal/x86_64/App_dependency_info.dat", "-framework", "Support", "-Xlinker", "-no_adhoc_codesign", "-o", "\(SRCROOT)/build/Debug/App.app/Contents/MacOS/App"])
219219
}
220220
}
221221

@@ -252,7 +252,7 @@ fileprivate struct XCFrameworkTaskConstructionTests: CoreBasedTests {
252252
// There needs to be a strong dependency on the XCFramework processing.
253253
results.checkTaskFollows(task, antecedent: try #require(processSupportXCFrameworkTask))
254254

255-
task.checkCommandLine(["clang", "-Xlinker", "-reproducible", "-target", "x86_64-apple-driverkit\(core.loadSDK(.driverKit).defaultDeploymentTarget)", "-isysroot", core.loadSDK(.driverKit).path.str, "-Os", "-L\(SRCROOT)/build/EagerLinkingTBDs/Debug-driverkit", "-L\(SRCROOT)/build/Debug-driverkit", "-F\(SRCROOT)/build/EagerLinkingTBDs/Debug-driverkit", "-F\(SRCROOT)/build/Debug-driverkit", "-filelist", "\(SRCROOT)/build/aProject.build/Debug-driverkit/Driver.build/Objects-normal/x86_64/Driver.LinkFileList", "-dead_strip", "-Xlinker", "-object_path_lto", "-Xlinker", "\(SRCROOT)/build/aProject.build/Debug-driverkit/Driver.build/Objects-normal/x86_64/Driver_lto.o", "-Xlinker", "-dependency_info", "-Xlinker", "\(SRCROOT)/build/aProject.build/Debug-driverkit/Driver.build/Objects-normal/x86_64/Driver_dependency_info.dat", "-framework", "Support", "-Xlinker", "-no_adhoc_codesign", "-o", "\(SRCROOT)/build/Debug-driverkit/Driver.dext/Driver"])
255+
task.checkCommandLine(["clang", "-Xlinker", "-reproducible", "-target", "x86_64-apple-driverkit\(core.loadSDK(.driverKit).defaultDeploymentTarget)", "-isysroot", core.loadSDK(.driverKit).path.str, "-Os", "-L\(SRCROOT)/build/EagerLinkingTBDs/Debug-driverkit", "-L\(SRCROOT)/build/Debug-driverkit", "-F\(SRCROOT)/build/EagerLinkingTBDs/Debug-driverkit", "-F\(SRCROOT)/build/Debug-driverkit", "-filelist", "\(SRCROOT)/build/aProject.build/Debug-driverkit/Driver.build/Objects-normal/x86_64/Driver.LinkFileList", "-Xlinker", "-dead_strip", "-Xlinker", "-object_path_lto", "-Xlinker", "\(SRCROOT)/build/aProject.build/Debug-driverkit/Driver.build/Objects-normal/x86_64/Driver_lto.o", "-Xlinker", "-dependency_info", "-Xlinker", "\(SRCROOT)/build/aProject.build/Debug-driverkit/Driver.build/Objects-normal/x86_64/Driver_dependency_info.dat", "-framework", "Support", "-Xlinker", "-no_adhoc_codesign", "-o", "\(SRCROOT)/build/Debug-driverkit/Driver.dext/Driver"])
256256
}
257257
}
258258

@@ -999,7 +999,7 @@ fileprivate struct XCFrameworkTaskConstructionTests: CoreBasedTests {
999999
results.checkTaskFollows(task, antecedent: try #require(processSupportXCFrameworkTask))
10001000
results.checkTaskFollows(task, antecedent: try #require(processExtrasXCFrameworkTask))
10011001

1002-
task.checkCommandLine(["clang", "-Xlinker", "-reproducible", "-target", "arm64-apple-ios\(core.loadSDK(.iOS).defaultDeploymentTarget)", "-isysroot", core.loadSDK(.iOS).path.str, "-Os", "-L\(SRCROOT)/build/EagerLinkingTBDs/Debug-iphoneos", "-L\(SRCROOT)/build/Debug-iphoneos", "-F\(SRCROOT)/build/EagerLinkingTBDs/Debug-iphoneos", "-F\(SRCROOT)/build/Debug-iphoneos", "-filelist", "\(SRCROOT)/build/aProject.build/Debug-iphoneos/App.build/Objects-normal/arm64/App.LinkFileList", "-dead_strip", "-Xlinker", "-object_path_lto", "-Xlinker", "\(SRCROOT)/build/aProject.build/Debug-iphoneos/App.build/Objects-normal/arm64/App_lto.o", "-Xlinker", "-dependency_info", "-Xlinker", "\(SRCROOT)/build/aProject.build/Debug-iphoneos/App.build/Objects-normal/arm64/App_dependency_info.dat", "-framework", "Support", "-framework", "Extras", "-Xlinker", "-no_adhoc_codesign", "-o", "\(SRCROOT)/build/Debug-iphoneos/App.app/App"])
1002+
task.checkCommandLine(["clang", "-Xlinker", "-reproducible", "-target", "arm64-apple-ios\(core.loadSDK(.iOS).defaultDeploymentTarget)", "-isysroot", core.loadSDK(.iOS).path.str, "-Os", "-L\(SRCROOT)/build/EagerLinkingTBDs/Debug-iphoneos", "-L\(SRCROOT)/build/Debug-iphoneos", "-F\(SRCROOT)/build/EagerLinkingTBDs/Debug-iphoneos", "-F\(SRCROOT)/build/Debug-iphoneos", "-filelist", "\(SRCROOT)/build/aProject.build/Debug-iphoneos/App.build/Objects-normal/arm64/App.LinkFileList", "-Xlinker", "-dead_strip", "-Xlinker", "-object_path_lto", "-Xlinker", "\(SRCROOT)/build/aProject.build/Debug-iphoneos/App.build/Objects-normal/arm64/App_lto.o", "-Xlinker", "-dependency_info", "-Xlinker", "\(SRCROOT)/build/aProject.build/Debug-iphoneos/App.build/Objects-normal/arm64/App_dependency_info.dat", "-framework", "Support", "-framework", "Extras", "-Xlinker", "-no_adhoc_codesign", "-o", "\(SRCROOT)/build/Debug-iphoneos/App.app/App"])
10031003
}
10041004
}
10051005
}

Tests/SwiftBuildTests/GeneratePreviewInfoTests.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ fileprivate struct GeneratePreviewInfoTests: CoreBasedTests {
228228
"\(tmpDir.str)/Test/build/Test.build/Debug-iphoneos/App.build/Objects-normal/\(activeRunDestination.targetArchitecture)/App.LinkFileList",
229229
"-install_name",
230230
"@rpath/App.debug.dylib",
231+
"-Xlinker",
231232
"-dead_strip",
232233
"-Xlinker",
233234
"-object_path_lto",
@@ -518,6 +519,7 @@ fileprivate struct GeneratePreviewInfoTests: CoreBasedTests {
518519
"-F\(tmpDir.str)/Test/build/Debug-iphoneos",
519520
"-filelist",
520521
"\(tmpDir.str)/Test/build/Test.build/Debug-iphoneos/CApplication.build/Objects-normal/arm64/CApplication.LinkFileList",
522+
"-Xlinker",
521523
"-dead_strip",
522524
"-Xlinker", "-object_path_lto", "-Xlinker", "\(tmpDir.str)/Test/build/Test.build/Debug-iphoneos/CApplication.build/Objects-normal/arm64/CApplication_lto.o",
523525
"-Xlinker", "-dependency_info",

0 commit comments

Comments
 (0)