Skip to content

Commit db4ce1f

Browse files
authored
Merge pull request #26614 from compnerd/incremental-force-autolink-symbol
Driver: loosen restrictions for `-force-autolink-symbol`
2 parents bd3643a + 1d84cb6 commit db4ce1f

File tree

5 files changed

+33
-10
lines changed

5 files changed

+33
-10
lines changed

lib/Driver/Driver.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,14 +206,18 @@ static void validateSearchPathArgs(DiagnosticEngine &diags,
206206
}
207207

208208
static void validateAutolinkingArgs(DiagnosticEngine &diags,
209-
const ArgList &args) {
209+
const ArgList &args,
210+
const llvm::Triple &T) {
210211
auto *forceLoadArg = args.getLastArg(options::OPT_autolink_force_load);
211212
if (!forceLoadArg)
212213
return;
213214
auto *incrementalArg = args.getLastArg(options::OPT_incremental);
214215
if (!incrementalArg)
215216
return;
216217

218+
if (T.supportsCOMDAT())
219+
return;
220+
217221
// Note: -incremental can itself be overridden by other arguments later
218222
// on, but since -autolink-force-load is a rare and not-really-recommended
219223
// option it's not worth modeling that complexity here (or moving the
@@ -223,14 +227,15 @@ static void validateAutolinkingArgs(DiagnosticEngine &diags,
223227
}
224228

225229
/// Perform miscellaneous early validation of arguments.
226-
static void validateArgs(DiagnosticEngine &diags, const ArgList &args) {
230+
static void validateArgs(DiagnosticEngine &diags, const ArgList &args,
231+
const llvm::Triple &T) {
227232
validateBridgingHeaderArgs(diags, args);
228233
validateWarningControlArgs(diags, args);
229234
validateProfilingArgs(diags, args);
230235
validateDebugInfoArgs(diags, args);
231236
validateCompilationConditionArgs(diags, args);
232237
validateSearchPathArgs(diags, args);
233-
validateAutolinkingArgs(diags, args);
238+
validateAutolinkingArgs(diags, args, T);
234239
}
235240

236241
std::unique_ptr<ToolChain>
@@ -783,7 +788,7 @@ Driver::buildCompilation(const ToolChain &TC,
783788
std::unique_ptr<DerivedArgList> TranslatedArgList(
784789
translateInputAndPathArgs(*ArgList, workingDirectory));
785790

786-
validateArgs(Diags, *TranslatedArgList);
791+
validateArgs(Diags, *TranslatedArgList, TC.getTriple());
787792

788793
// Perform toolchain specific args validation.
789794
TC.validateArguments(Diags, *TranslatedArgList);

lib/IRGen/IRGenModule.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1184,14 +1184,17 @@ void IRGenModule::emitAutolinkInfo() {
11841184
}
11851185

11861186
if (!IRGen.Opts.ForceLoadSymbolName.empty() &&
1187-
isFirstObjectFileInModule(*this)) {
1187+
(Triple.supportsCOMDAT() || isFirstObjectFileInModule(*this))) {
11881188
llvm::SmallString<64> buf;
11891189
encodeForceLoadSymbolName(buf, IRGen.Opts.ForceLoadSymbolName);
11901190
auto ForceImportThunk =
11911191
llvm::Function::Create(llvm::FunctionType::get(VoidTy, false),
11921192
llvm::GlobalValue::ExternalLinkage, buf,
11931193
&Module);
11941194
ApplyIRLinkage(IRLinkage::ExternalExport).to(ForceImportThunk);
1195+
if (Triple.supportsCOMDAT())
1196+
if (auto *GO = cast<llvm::GlobalObject>(ForceImportThunk))
1197+
GO->setComdat(Module.getOrInsertComdat(ForceImportThunk->getName()));
11951198

11961199
auto BB = llvm::BasicBlock::Create(getLLVMContext(), "", ForceImportThunk);
11971200
llvm::IRBuilder<> IRB(BB);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: %swiftc_driver -incremental -autolink-force-load %s 2>&1 | %FileCheck -check-prefix=AUTOLINK_FORCE_LOAD %s
2+
// RUN: %swiftc_driver -autolink-force-load -incremental %s 2>&1 | %FileCheck -check-prefix=AUTOLINK_FORCE_LOAD %s
3+
4+
// MACHO targets do not support COMDAT
5+
// UNSUPPORTED: OS=macosx
6+
// UNSUPPORTED: OS=tvos
7+
// UNSUPPORTED: OS=watchos
8+
// UNSUPPORTED: OS=ios
9+
10+
// AUTOLINK_FORCE_LOAD-NOT: error: '-autolink-force-load' is not supported with '-incremental'
11+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// RUN: not %swiftc_driver -incremental -autolink-force-load %s 2>&1 | %FileCheck -check-prefix=AUTOLINK_FORCE_LOAD %s
2+
// RUN: not %swiftc_driver -autolink-force-load -incremental %s 2>&1 | %FileCheck -check-prefix=AUTOLINK_FORCE_LOAD %s
3+
4+
// MACHO targets do not support COMDAT
5+
// REQUIRES-ANY: OS=macosx, OS=tvos, OS=watchos, OS=ios
6+
7+
// AUTOLINK_FORCE_LOAD: error: '-autolink-force-load' is not supported with '-incremental'
8+

test/Driver/options.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,6 @@
101101
// ASSUME_SINGLE_THREADED: swift
102102
// ASSUME_SINGLE_THREADED: -frontend {{.*}} -assume-single-threaded
103103

104-
// RUN: not %swiftc_driver -incremental -autolink-force-load %s 2>&1 | %FileCheck -check-prefix=AUTOLINK_FORCE_LOAD %s
105-
// RUN: not %swiftc_driver -autolink-force-load -incremental %s 2>&1 | %FileCheck -check-prefix=AUTOLINK_FORCE_LOAD %s
106-
// AUTOLINK_FORCE_LOAD: error: '-autolink-force-load' is not supported with '-incremental'
107-
108104
// RUN: %swift_driver -### -g -debug-info-format=codeview %s | %FileCheck -check-prefix DEBUG_INFO_FORMAT_CODEVIEW %s
109105
// RUN: %swift_driver -### -g -debug-info-format=dwarf %s | %FileCheck -check-prefix DEBUG_INFO_FORMAT_DWARF %s
110106
// RUN: %swiftc_driver -### -g -debug-info-format=codeview %s | %FileCheck -check-prefix DEBUG_INFO_FORMAT_CODEVIEW %s
@@ -132,4 +128,4 @@
132128
// RUN: %swiftc_driver -F %t/test.framework/ %s 2>&1 | %FileCheck -check-prefix SEARCH_PATH_INCLUDES_FRAMEWORK_EXTENSION %s
133129
// RUN: %swift_driver -Fsystem %t/test.framework/ %s 2>&1 | %FileCheck -check-prefix SEARCH_PATH_INCLUDES_FRAMEWORK_EXTENSION %s
134130
// RUN: %swiftc_driver -Fsystem %t/test.framework/ %s 2>&1 | %FileCheck -check-prefix SEARCH_PATH_INCLUDES_FRAMEWORK_EXTENSION %s
135-
// SEARCH_PATH_INCLUDES_FRAMEWORK_EXTENSION: warning: framework search path ends in ".framework"
131+
// SEARCH_PATH_INCLUDES_FRAMEWORK_EXTENSION: warning: framework search path ends in ".framework"

0 commit comments

Comments
 (0)