Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,18 @@ static void validateSearchPathArgs(DiagnosticEngine &diags,
}

static void validateAutolinkingArgs(DiagnosticEngine &diags,
const ArgList &args) {
const ArgList &args,
const llvm::Triple &T) {
auto *forceLoadArg = args.getLastArg(options::OPT_autolink_force_load);
if (!forceLoadArg)
return;
auto *incrementalArg = args.getLastArg(options::OPT_incremental);
if (!incrementalArg)
return;

if (T.supportsCOMDAT())
return;

// Note: -incremental can itself be overridden by other arguments later
// on, but since -autolink-force-load is a rare and not-really-recommended
// option it's not worth modeling that complexity here (or moving the
Expand All @@ -223,14 +227,15 @@ static void validateAutolinkingArgs(DiagnosticEngine &diags,
}

/// Perform miscellaneous early validation of arguments.
static void validateArgs(DiagnosticEngine &diags, const ArgList &args) {
static void validateArgs(DiagnosticEngine &diags, const ArgList &args,
const llvm::Triple &T) {
validateBridgingHeaderArgs(diags, args);
validateWarningControlArgs(diags, args);
validateProfilingArgs(diags, args);
validateDebugInfoArgs(diags, args);
validateCompilationConditionArgs(diags, args);
validateSearchPathArgs(diags, args);
validateAutolinkingArgs(diags, args);
validateAutolinkingArgs(diags, args, T);
}

std::unique_ptr<ToolChain>
Expand Down Expand Up @@ -783,7 +788,7 @@ Driver::buildCompilation(const ToolChain &TC,
std::unique_ptr<DerivedArgList> TranslatedArgList(
translateInputAndPathArgs(*ArgList, workingDirectory));

validateArgs(Diags, *TranslatedArgList);
validateArgs(Diags, *TranslatedArgList, TC.getTriple());

// Perform toolchain specific args validation.
TC.validateArguments(Diags, *TranslatedArgList);
Expand Down
5 changes: 4 additions & 1 deletion lib/IRGen/IRGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1184,14 +1184,17 @@ void IRGenModule::emitAutolinkInfo() {
}

if (!IRGen.Opts.ForceLoadSymbolName.empty() &&
isFirstObjectFileInModule(*this)) {
(Triple.supportsCOMDAT() || isFirstObjectFileInModule(*this))) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't we add this whole thing in the first place because we were using a COMMON global variable on Mach-O and that didn't work on Windows? Can't we go back to that on non-COMDAT platforms? (See #15647.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that is exactly what I did in #26635 (thanks to @rjmccall kicking my memory back into place!)

llvm::SmallString<64> buf;
encodeForceLoadSymbolName(buf, IRGen.Opts.ForceLoadSymbolName);
auto ForceImportThunk =
llvm::Function::Create(llvm::FunctionType::get(VoidTy, false),
llvm::GlobalValue::ExternalLinkage, buf,
&Module);
ApplyIRLinkage(IRLinkage::ExternalExport).to(ForceImportThunk);
if (Triple.supportsCOMDAT())
if (auto *GO = cast<llvm::GlobalObject>(ForceImportThunk))
GO->setComdat(Module.getOrInsertComdat(ForceImportThunk->getName()));

auto BB = llvm::BasicBlock::Create(getLLVMContext(), "", ForceImportThunk);
llvm::IRBuilder<> IRB(BB);
Expand Down
11 changes: 11 additions & 0 deletions test/Driver/autolink-force-load-comdat.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// RUN: %swiftc_driver -incremental -autolink-force-load %s 2>&1 | %FileCheck -check-prefix=AUTOLINK_FORCE_LOAD %s
// RUN: %swiftc_driver -autolink-force-load -incremental %s 2>&1 | %FileCheck -check-prefix=AUTOLINK_FORCE_LOAD %s

// MACHO targets do not support COMDAT
// UNSUPPORTED: OS=macosx
// UNSUPPORTED: OS=tvos
// UNSUPPORTED: OS=watchos
// UNSUPPORTED: OS=ios

// AUTOLINK_FORCE_LOAD-NOT: error: '-autolink-force-load' is not supported with '-incremental'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For negative checks, it's best not to include the exact text of a diagnostic, because we tweak that sometimes.


8 changes: 8 additions & 0 deletions test/Driver/autolink-force-load-no-comdat.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// RUN: not %swiftc_driver -incremental -autolink-force-load %s 2>&1 | %FileCheck -check-prefix=AUTOLINK_FORCE_LOAD %s
// RUN: not %swiftc_driver -autolink-force-load -incremental %s 2>&1 | %FileCheck -check-prefix=AUTOLINK_FORCE_LOAD %s
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no real reason to put this in a separate test file; since you're just testing the driver behavior, you can use -### and an explicit triple to check for the error cases.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, yes, this is driver, not IRGen. My mistake. Either way, #26635 will remove the file.


// MACHO targets do not support COMDAT
// REQUIRES-ANY: OS=macosx, OS=tvos, OS=watchos, OS=ios

// AUTOLINK_FORCE_LOAD: error: '-autolink-force-load' is not supported with '-incremental'

6 changes: 1 addition & 5 deletions test/Driver/options.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,6 @@
// ASSUME_SINGLE_THREADED: swift
// ASSUME_SINGLE_THREADED: -frontend {{.*}} -assume-single-threaded

// RUN: not %swiftc_driver -incremental -autolink-force-load %s 2>&1 | %FileCheck -check-prefix=AUTOLINK_FORCE_LOAD %s
// RUN: not %swiftc_driver -autolink-force-load -incremental %s 2>&1 | %FileCheck -check-prefix=AUTOLINK_FORCE_LOAD %s
// AUTOLINK_FORCE_LOAD: error: '-autolink-force-load' is not supported with '-incremental'

// RUN: %swift_driver -### -g -debug-info-format=codeview %s | %FileCheck -check-prefix DEBUG_INFO_FORMAT_CODEVIEW %s
// RUN: %swift_driver -### -g -debug-info-format=dwarf %s | %FileCheck -check-prefix DEBUG_INFO_FORMAT_DWARF %s
// RUN: %swiftc_driver -### -g -debug-info-format=codeview %s | %FileCheck -check-prefix DEBUG_INFO_FORMAT_CODEVIEW %s
Expand Down Expand Up @@ -132,4 +128,4 @@
// RUN: %swiftc_driver -F %t/test.framework/ %s 2>&1 | %FileCheck -check-prefix SEARCH_PATH_INCLUDES_FRAMEWORK_EXTENSION %s
// RUN: %swift_driver -Fsystem %t/test.framework/ %s 2>&1 | %FileCheck -check-prefix SEARCH_PATH_INCLUDES_FRAMEWORK_EXTENSION %s
// RUN: %swiftc_driver -Fsystem %t/test.framework/ %s 2>&1 | %FileCheck -check-prefix SEARCH_PATH_INCLUDES_FRAMEWORK_EXTENSION %s
// SEARCH_PATH_INCLUDES_FRAMEWORK_EXTENSION: warning: framework search path ends in ".framework"
// SEARCH_PATH_INCLUDES_FRAMEWORK_EXTENSION: warning: framework search path ends in ".framework"