Skip to content

Commit f4101c4

Browse files
authored
Merge pull request swiftlang#79233 from compnerd/startfiles
Driver: support `-nostartfiles` in the C++ driver
2 parents 8463e2a + ef39af0 commit f4101c4

File tree

4 files changed

+25
-19
lines changed

4 files changed

+25
-19
lines changed

include/swift/Option/Options.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2116,7 +2116,7 @@ def digester_mode:
21162116
def nostartfiles:
21172117
Flag<["-"], "nostartfiles">,
21182118
Flags<[FrontendOption, DoesNotAffectIncrementalBuild, NoInteractiveOption,
2119-
HelpHidden, NewDriverOnlyOption]>,
2119+
HelpHidden]>,
21202120
HelpText<"Do not link in the Swift language startup routines">;
21212121

21222122
def gcc_toolchain: Separate<["-"], "gcc-toolchain">,

lib/Driver/UnixToolChains.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -266,11 +266,13 @@ toolchains::GenericUnix::constructInvocation(const DynamicLinkJobAction &job,
266266
getResourceDirPath(SharedResourceDirPath, context.Args,
267267
/*Shared=*/!(staticExecutable || staticStdlib));
268268

269-
SmallString<128> swiftrtPath = SharedResourceDirPath;
270-
llvm::sys::path::append(swiftrtPath,
271-
swift::getMajorArchitectureName(getTriple()));
272-
llvm::sys::path::append(swiftrtPath, "swiftrt.o");
273-
Arguments.push_back(context.Args.MakeArgString(swiftrtPath));
269+
if (!context.Args.hasArg(options::OPT_nostartfiles)) {
270+
SmallString<128> swiftrtPath = SharedResourceDirPath;
271+
llvm::sys::path::append(swiftrtPath,
272+
swift::getMajorArchitectureName(getTriple()));
273+
llvm::sys::path::append(swiftrtPath, "swiftrt.o");
274+
Arguments.push_back(context.Args.MakeArgString(swiftrtPath));
275+
}
274276

275277
addPrimaryInputsOfType(Arguments, context.Inputs, context.Args,
276278
file_types::TY_Object);

lib/Driver/WebAssemblyToolChains.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,13 @@ toolchains::WebAssembly::constructInvocation(const DynamicLinkJobAction &job,
116116
SmallString<128> SharedResourceDirPath;
117117
getResourceDirPath(SharedResourceDirPath, context.Args, /*Shared=*/false);
118118

119-
SmallString<128> swiftrtPath = SharedResourceDirPath;
120-
llvm::sys::path::append(swiftrtPath,
121-
swift::getMajorArchitectureName(getTriple()));
122-
llvm::sys::path::append(swiftrtPath, "swiftrt.o");
123-
Arguments.push_back(context.Args.MakeArgString(swiftrtPath));
119+
if (!context.Args.hasArg(options::OPT_nostartfiles)) {
120+
SmallString<128> swiftrtPath = SharedResourceDirPath;
121+
llvm::sys::path::append(swiftrtPath,
122+
swift::getMajorArchitectureName(getTriple()));
123+
llvm::sys::path::append(swiftrtPath, "swiftrt.o");
124+
Arguments.push_back(context.Args.MakeArgString(swiftrtPath));
125+
}
124126

125127
addPrimaryInputsOfType(Arguments, context.Inputs, context.Args,
126128
file_types::TY_Object);

lib/Driver/WindowsToolChains.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,16 @@ toolchains::Windows::constructInvocation(const DynamicLinkJobAction &job,
144144
getTriple().getArchName()));
145145
}
146146

147-
SmallString<128> SharedResourceDirPath;
148-
getResourceDirPath(SharedResourceDirPath, context.Args, /*Shared=*/true);
149-
150-
SmallString<128> swiftrtPath = SharedResourceDirPath;
151-
llvm::sys::path::append(swiftrtPath,
152-
swift::getMajorArchitectureName(getTriple()));
153-
llvm::sys::path::append(swiftrtPath, "swiftrt.obj");
154-
Arguments.push_back(context.Args.MakeArgString(swiftrtPath));
147+
if (!context.Args.hasArg(options::OPT_nostartfiles)) {
148+
SmallString<128> SharedResourceDirPath;
149+
getResourceDirPath(SharedResourceDirPath, context.Args, /*Shared=*/true);
150+
151+
SmallString<128> swiftrtPath = SharedResourceDirPath;
152+
llvm::sys::path::append(swiftrtPath,
153+
swift::getMajorArchitectureName(getTriple()));
154+
llvm::sys::path::append(swiftrtPath, "swiftrt.obj");
155+
Arguments.push_back(context.Args.MakeArgString(swiftrtPath));
156+
}
155157

156158
addPrimaryInputsOfType(Arguments, context.Inputs, context.Args,
157159
file_types::TY_Object);

0 commit comments

Comments
 (0)