Skip to content

Commit 7835c57

Browse files
[WASM] Enable stdlib thin CMO for driver and autolink
1 parent b889bcf commit 7835c57

File tree

8 files changed

+28
-1
lines changed

8 files changed

+28
-1
lines changed

include/swift/AST/IRGenOptions.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,9 @@ class IRGenOptions {
238238
/// Frameworks that we should not autolink against.
239239
SmallVector<std::string, 1> DisableAutolinkFrameworks;
240240

241+
/// Disable autolinking swiftCore for stdlib thin CMO
242+
unsigned DisableAutolinkStdlib : 1;
243+
241244
/// Print the LLVM inline tree at the end of the LLVM pass pipeline.
242245
unsigned PrintInlineTree : 1;
243246

@@ -351,6 +354,7 @@ class IRGenOptions {
351354
DisableLLVMOptzns(false), DisableSwiftSpecificLLVMOptzns(false),
352355
DisableLLVMSLPVectorizer(false), Playground(false),
353356
EmitStackPromotionChecks(false), FunctionSections(false),
357+
DisableAutolinkStdlib(false),
354358
PrintInlineTree(false), EmbedMode(IRGenEmbedMode::None),
355359
LLVMLTOKind(IRGenLLVMLTOKind::None), HasValueNamesSetting(false),
356360
ValueNames(false), EnableReflectionMetadata(true),

include/swift/Option/Options.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,10 @@ def no_stdlib_rpath: Flag<["-"], "no-stdlib-rpath">,
713713
Flags<[HelpHidden,DoesNotAffectIncrementalBuild]>,
714714
HelpText<"Don't add any rpath entries.">;
715715

716+
def no_stdlib_link: Flag<["-"], "no-stdlib-link">,
717+
Flags<[FrontendOption, DoesNotAffectIncrementalBuild]>,
718+
HelpText<"Don't link stdlib.">;
719+
716720
def static_executable : Flag<["-"], "static-executable">,
717721
HelpText<"Statically link the executable">;
718722
def no_static_executable : Flag<["-"], "no-static-executable">,

lib/Driver/ToolChains.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ void ToolChain::addCommonFrontendArgs(const OutputInfo &OI,
304304
}
305305

306306
addLTOArgs(OI, arguments);
307+
inputArgs.AddLastArg(arguments, options::OPT_no_stdlib_link);
307308

308309
// -g implies -enable-anonymous-context-mangled-names, because the extra
309310
// metadata aids debugging.

lib/Driver/WebAssemblyToolChains.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,12 @@ toolchains::WebAssembly::constructInvocation(const DynamicLinkJobAction &job,
163163
llvm::report_fatal_error(linkFile + " not found");
164164
}
165165

166+
if (context.Args.hasArg(options::OPT_no_stdlib_link)) {
167+
Arguments.push_back("-lswiftStandaloneRuntime");
168+
} else {
169+
Arguments.push_back("-lswiftCore");
170+
}
171+
166172
// Explicitly pass the target to the linker
167173
Arguments.push_back(
168174
context.Args.MakeArgString("--target=" + getTriple().str()));

lib/Frontend/CompilerInvocation.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1553,6 +1553,10 @@ static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args,
15531553
A->getAsString(Args), A->getValue());
15541554
}
15551555

1556+
if (Args.hasArg(OPT_no_stdlib_link)) {
1557+
Opts.DisableAutolinkStdlib = true;
1558+
}
1559+
15561560
if (const Arg *A = Args.getLastArg(options::OPT_sanitize_coverage_EQ)) {
15571561
Opts.SanitizeCoverage =
15581562
parseSanitizerCoverageArgValue(A, Triple, Diags, Opts.Sanitizers);

lib/IRGen/IRGenModule.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,6 +1220,8 @@ void IRGenModule::addLinkLibrary(const LinkLibrary &linkLib) {
12201220

12211221
switch (linkLib.getKind()) {
12221222
case LibraryKind::Library: {
1223+
if (linkLib.getName() == "swiftCore" && IRGen.Opts.DisableAutolinkStdlib)
1224+
return;
12231225
AutolinkEntries.emplace_back(linkLib);
12241226
break;
12251227
}

stdlib/public/runtime/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,13 @@ add_swift_target_library(swiftRuntime OBJECT_LIBRARY
152152
SWIFT_COMPILE_FLAGS ${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS}
153153
INSTALL_IN_COMPONENT never_install)
154154

155+
156+
add_swift_target_library(swiftStandaloneRuntime STATIC IS_STDLIB
157+
INCORPORATE_OBJECT_LIBRARIES
158+
swiftRuntime swiftLLVMSupport swiftDemangling swiftStdlibStubs
159+
INSTALL_IN_COMPONENT
160+
stdlib)
161+
155162
set(ELFISH_SDKS)
156163
set(COFF_SDKS)
157164
set(WASM_SDKS)

utils/webassembly/static-executable-args.lnk

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
-static
2-
-lswiftCore
32
-lswiftSwiftOnoneSupport
43
-lswiftWasiPthread
54
-licuuc

0 commit comments

Comments
 (0)