Skip to content

Commit 590f502

Browse files
authored
Merge pull request #576 from swiftlang/owenv/dead-strip
Fixup cross platform specs handling of DEAD_CODE_STRIPPING
2 parents 1b2d827 + 18fcc44 commit 590f502

File tree

6 files changed

+98
-2
lines changed

6 files changed

+98
-2
lines changed

Sources/SWBGenericUnixPlatform/Specs/UnixLd.xcspec

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,16 @@
102102
};
103103
Condition = "$(ALTERNATE_LINKER) == gold";
104104
},
105+
{
106+
Name = "DEAD_CODE_STRIPPING";
107+
Type = Boolean;
108+
DefaultValue = NO;
109+
Condition = "$(MACH_O_TYPE) != mh_object";
110+
CommandLineArgs = {
111+
YES = ("-Xlinker", "--gc-sections");
112+
NO = ();
113+
};
114+
},
105115
{
106116
// Frameworks are Mac specific
107117
Name = "SYSTEM_FRAMEWORK_SEARCH_PATHS";

Sources/SWBQNXPlatform/Specs/QNXLd.xcspec

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@
9696
};
9797
Condition = "$(ALTERNATE_LINKER) == gold";
9898
},
99+
{
100+
Name = "DEAD_CODE_STRIPPING";
101+
Type = Boolean;
102+
Condition = "NO";
103+
},
99104
{
100105
// Frameworks are Mac specific
101106
Name = "SYSTEM_FRAMEWORK_SEARCH_PATHS";

Sources/SWBUniversalPlatform/Specs/Ld.xcspec

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,10 @@
459459
Type = Boolean;
460460
DefaultValue = NO;
461461
Condition = "$(MACH_O_TYPE) != mh_object";
462-
CommandLineFlag = "-dead_strip";
462+
CommandLineArgs = {
463+
YES = ("-dead_strip");
464+
NO = ();
465+
};
463466
},
464467
{
465468
Name = "BUNDLE_LOADER";

Sources/SWBWebAssemblyPlatform/Specs/WasmLd.xcspec

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,16 @@
6464
NO = ();
6565
};
6666
},
67+
{
68+
Name = "DEAD_CODE_STRIPPING";
69+
Type = Boolean;
70+
DefaultValue = NO;
71+
Condition = "$(MACH_O_TYPE) != mh_object";
72+
CommandLineArgs = {
73+
YES = ("-Xlinker", "--gc-sections");
74+
NO = ();
75+
};
76+
},
6777
{
6878
// Frameworks are Mac specific
6979
Name = "SYSTEM_FRAMEWORK_SEARCH_PATHS";

Sources/SWBWindowsPlatform/Specs/WindowsLd.xcspec

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,16 @@
102102
Type = String;
103103
Condition = "NO";
104104
},
105+
{
106+
Name = "DEAD_CODE_STRIPPING";
107+
Type = Boolean;
108+
DefaultValue = NO;
109+
Condition = "$(MACH_O_TYPE) != mh_object";
110+
CommandLineArgs = {
111+
YES = ("-Xlinker", "/OPT:REF");
112+
NO = ();
113+
};
114+
},
105115
{
106116
// No such concept
107117
Name = "LD_RUNPATH_SEARCH_PATHS";

Tests/SWBTaskConstructionTests/TaskConstructionTests.swift

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
import struct Foundation.Data
13+
import Foundation
1414

1515
import Testing
1616

@@ -8657,6 +8657,64 @@ fileprivate struct TaskConstructionTests: CoreBasedTests {
86578657
}
86588658
}
86598659

8660+
@Test(.requireSDKs(.host))
8661+
func crossPlatformDeadCodeStripping() async throws {
8662+
try await withTemporaryDirectory { tmpDir in
8663+
let testProject = TestProject(
8664+
"aProject",
8665+
sourceRoot: tmpDir,
8666+
groupTree: TestGroup(
8667+
"SomeFiles", path: "Sources",
8668+
children: [
8669+
TestFile("SourceFile.c"),
8670+
]),
8671+
buildConfigurations: [
8672+
TestBuildConfiguration("Debug", buildSettings: [
8673+
"DEAD_CODE_STRIPPING": "YES",
8674+
"ONLY_ACTIVE_ARCH": "YES"
8675+
])
8676+
],
8677+
targets: [
8678+
TestStandardTarget(
8679+
"Library",
8680+
type: .dynamicLibrary,
8681+
buildConfigurations: [
8682+
TestBuildConfiguration("Debug")
8683+
],
8684+
buildPhases: [
8685+
TestSourcesBuildPhase([
8686+
"SourceFile.c",
8687+
])
8688+
]
8689+
)]
8690+
)
8691+
8692+
let fs = PseudoFS()
8693+
8694+
let core = try await getCore()
8695+
let tester = try TaskConstructionTester(core, testProject)
8696+
8697+
try await tester.checkBuild(BuildParameters(configuration: "Debug", overrides: [:]), runDestination: .host, fs: fs) { results in
8698+
try results.checkTask(.matchRuleType("Ld")) { task in
8699+
switch try ProcessInfo.processInfo.hostOperatingSystem() {
8700+
case .macOS:
8701+
task.checkCommandLineContains(["-dead_strip"])
8702+
task.checkCommandLineDoesNotContain("--gc-sections")
8703+
task.checkCommandLineDoesNotContain("/OPT:REF")
8704+
case .windows:
8705+
task.checkCommandLineDoesNotContain("-dead_strip")
8706+
task.checkCommandLineDoesNotContain("--gc-sections")
8707+
task.checkCommandLineContains(["/OPT:REF"])
8708+
default:
8709+
task.checkCommandLineDoesNotContain("-dead_strip")
8710+
task.checkCommandLineContains(["--gc-sections"])
8711+
task.checkCommandLineDoesNotContain("/OPT:REF")
8712+
}
8713+
}
8714+
}
8715+
}
8716+
}
8717+
86608718
@Test(.requireSDKs(.macOS))
86618719
func warningSuppression() async throws {
86628720
try await withTemporaryDirectory { tmpDir in

0 commit comments

Comments
 (0)