diff --git a/include/swift/AST/DiagnosticsDriver.def b/include/swift/AST/DiagnosticsDriver.def index 291af950315ca..9b9e90bdbbd07 100644 --- a/include/swift/AST/DiagnosticsDriver.def +++ b/include/swift/AST/DiagnosticsDriver.def @@ -140,9 +140,6 @@ ERROR(error_input_changed_during_build,none, ERROR(error_conflicting_options, none, "conflicting options '%0' and '%1'", (StringRef, StringRef)) -ERROR(error_option_not_supported, none, - "'%0' is not supported with '%1'", - (StringRef, StringRef)) WARNING(warn_ignore_embed_bitcode, none, "ignoring -embed-bitcode since no object file is being generated", ()) diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp index 9dd28b9075367..a1348fe2c688f 100644 --- a/lib/Driver/Driver.cpp +++ b/lib/Driver/Driver.cpp @@ -205,27 +205,6 @@ static void validateSearchPathArgs(DiagnosticEngine &diags, } } -static void validateAutolinkingArgs(DiagnosticEngine &diags, - 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 - // check somewhere else). - diags.diagnose(SourceLoc(), diag::error_option_not_supported, - forceLoadArg->getSpelling(), incrementalArg->getSpelling()); -} - /// Perform miscellaneous early validation of arguments. static void validateArgs(DiagnosticEngine &diags, const ArgList &args, const llvm::Triple &T) { @@ -235,7 +214,6 @@ static void validateArgs(DiagnosticEngine &diags, const ArgList &args, validateDebugInfoArgs(diags, args); validateCompilationConditionArgs(diags, args); validateSearchPathArgs(diags, args); - validateAutolinkingArgs(diags, args, T); } std::unique_ptr diff --git a/lib/IRGen/IRGenModule.cpp b/lib/IRGen/IRGenModule.cpp index ebe565371ee50..85b5482a6080b 100644 --- a/lib/IRGen/IRGenModule.cpp +++ b/lib/IRGen/IRGenModule.cpp @@ -47,6 +47,7 @@ #include "llvm/ADT/PointerUnion.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/MD5.h" +#include "llvm/Transforms/Utils/ModuleUtils.h" #include "ConformanceDescription.h" #include "GenEnum.h" @@ -1105,23 +1106,6 @@ static bool replaceModuleFlagsEntry(llvm::LLVMContext &Ctx, llvm_unreachable("Could not replace old linker options entry?"); } -/// Returns true if the object file generated by \p IGM will be the "first" -/// object file in the module. This lets us determine where to put a symbol -/// that must be unique. -static bool isFirstObjectFileInModule(IRGenModule &IGM) { - if (IGM.getSILModule().isWholeModule()) - return IGM.IRGen.getPrimaryIGM() == &IGM; - - const DeclContext *DC = IGM.getSILModule().getAssociatedContext(); - if (!DC) - return false; - - assert(!isa(DC) && "that would be a whole module build"); - assert(isa(DC) && "compiling something smaller than a file?"); - ModuleDecl *containingModule = cast(DC)->getParentModule(); - return containingModule->getFiles().front() == DC; -} - void IRGenModule::emitAutolinkInfo() { // Collect the linker options already in the module (from ClangCodeGen). // FIXME: This constant should be vended by LLVM somewhere. @@ -1183,8 +1167,7 @@ void IRGenModule::emitAutolinkInfo() { addUsedGlobal(var); } - if (!IRGen.Opts.ForceLoadSymbolName.empty() && - (Triple.supportsCOMDAT() || isFirstObjectFileInModule(*this))) { + if (!IRGen.Opts.ForceLoadSymbolName.empty()) { llvm::SmallString<64> buf; encodeForceLoadSymbolName(buf, IRGen.Opts.ForceLoadSymbolName); auto ForceImportThunk = @@ -1192,9 +1175,13 @@ void IRGenModule::emitAutolinkInfo() { llvm::GlobalValue::ExternalLinkage, buf, &Module); ApplyIRLinkage(IRLinkage::ExternalExport).to(ForceImportThunk); - if (Triple.supportsCOMDAT()) + if (Triple.supportsCOMDAT()) { if (auto *GO = cast(ForceImportThunk)) GO->setComdat(Module.getOrInsertComdat(ForceImportThunk->getName())); + } else { + ForceImportThunk->setLinkage(llvm::GlobalValue::LinkageTypes::LinkOnceODRLinkage); + llvm::appendToCompilerUsed(Module, {ForceImportThunk}); + } auto BB = llvm::BasicBlock::Create(getLLVMContext(), "", ForceImportThunk); llvm::IRBuilder<> IRB(BB); diff --git a/test/Driver/autolink-force-load-comdat.swift b/test/Driver/autolink-force-load-comdat.swift deleted file mode 100644 index 4870a5f12a132..0000000000000 --- a/test/Driver/autolink-force-load-comdat.swift +++ /dev/null @@ -1,11 +0,0 @@ -// 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' - diff --git a/test/Driver/autolink-force-load-no-comdat.swift b/test/Driver/autolink-force-load-no-comdat.swift deleted file mode 100644 index c4dc53a473410..0000000000000 --- a/test/Driver/autolink-force-load-no-comdat.swift +++ /dev/null @@ -1,8 +0,0 @@ -// 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 - -// 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' - diff --git a/test/IRGen/autolink-force-link.swift b/test/IRGen/autolink-force-link.swift index a90730717e4dd..28ecbc529cbcb 100644 --- a/test/IRGen/autolink-force-link.swift +++ b/test/IRGen/autolink-force-link.swift @@ -3,16 +3,15 @@ // RUN: %swift -disable-legacy-type-info -target x86_64-apple-macosx10.9 -parse-stdlib -autolink-force-load -module-name TEST -module-link-name TEST -emit-ir %s %S/../Inputs/empty.swift | %FileCheck -check-prefix=CHECK-WMO %s // CHECK-WMO: source_filename = "-" -// CHECK-WMO: define void @"_swift_FORCE_LOAD_$_TEST"() +// CHECK-WMO: define linkonce_odr void @"_swift_FORCE_LOAD_$_TEST"() // CHECK-WMO-NOT: source_filename // RUN: %swift -disable-legacy-type-info -target x86_64-apple-macosx10.9 -parse-stdlib -autolink-force-load -module-name TEST -module-link-name TEST -emit-ir -num-threads 1 %s %S/../Inputs/empty.swift | %FileCheck -check-prefix=CHECK-WMO-THREADED %s // CHECK-WMO-THREADED: source_filename = "-" -// CHECK-WMO-THREADED: define void @"_swift_FORCE_LOAD_$_TEST"() +// CHECK-WMO-THREADED: define linkonce_odr void @"_swift_FORCE_LOAD_$_TEST"() // CHECK-WMO-THREADED: source_filename = "-" -// CHECK-WMO-THREADED-NOT: _swift_FORCE_LOAD_$_TEST // CHECK-WMO-THREADED-NOT: source_filename @@ -20,10 +19,10 @@ // RUN: %swift -disable-legacy-type-info -target x86_64-apple-macosx10.9 -parse-stdlib -autolink-force-load -module-name TEST -module-link-name TEST -emit-ir %S/../Inputs/empty.swift -primary-file %s | %FileCheck -check-prefix=CHECK-SINGLE-FILE-SECOND %s // CHECK-SINGLE-FILE-FIRST: source_filename = "-" -// CHECK-SINGLE-FILE-FIRST: define void @"_swift_FORCE_LOAD_$_TEST"() +// CHECK-SINGLE-FILE-FIRST: define linkonce_odr void @"_swift_FORCE_LOAD_$_TEST"() // CHECK-SINGLE-FILE-FIRST-NOT: source_filename // CHECK-SINGLE-FILE-SECOND: source_filename = "-" -// CHECK-SINGLE-FILE-SECOND-NOT: _swift_FORCE_LOAD_$_TEST +// CHECK-SINGLE-FILE-SECOND: define linkonce_odr void @"_swift_FORCE_LOAD_$_TEST"() // CHECK-SINGLE-FILE-SECOND-NOT: source_filename diff --git a/test/Serialization/autolinking.swift b/test/Serialization/autolinking.swift index 864bd8db62caf..8b02048d68e52 100644 --- a/test/Serialization/autolinking.swift +++ b/test/Serialization/autolinking.swift @@ -40,10 +40,10 @@ import someModule // NO-FORCE-LOAD-NOT: FORCE_LOAD // NO-FORCE-LOAD-NOT -lmodule // NO-FORCE-LOAD-NOT -lmagic -// FORCE-LOAD: define{{( dllexport)?}} void @"_swift_FORCE_LOAD_$_module"() {{(comdat )?}}{ +// FORCE-LOAD: define{{( dllexport| linkonce_odr)?}} void @"_swift_FORCE_LOAD_$_module"() {{(comdat )?}}{ // FORCE-LOAD: ret void // FORCE-LOAD: } -// FORCE-LOAD-HEX: define{{( dllexport)?}} void @"_swift_FORCE_LOAD_$306d6f64756c65"() {{(comdat )?}}{ +// FORCE-LOAD-HEX: define{{( dllexport| linkonce_odr)?}} void @"_swift_FORCE_LOAD_$306d6f64756c65"() {{(comdat )?}}{ // FORCE-LOAD-HEX: ret void // FORCE-LOAD-HEX: }