Skip to content

Commit e83403c

Browse files
authored
Merge pull request #84161 from DougGregor/remove-mergeable-symbols
2 parents 43fa4a4 + 66a730b commit e83403c

20 files changed

+73
-50
lines changed

include/swift/AST/IRGenOptions.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -498,8 +498,6 @@ class IRGenOptions {
498498
/// Internalize symbols (static library) - do not export any public symbols.
499499
unsigned InternalizeSymbols : 1;
500500

501-
unsigned MergeableSymbols : 1;
502-
503501
/// Emit a section with references to class_ro_t* in generic class patterns.
504502
unsigned EmitGenericRODatas : 1;
505503

@@ -645,7 +643,7 @@ class IRGenOptions {
645643
WitnessMethodElimination(false), ConditionalRuntimeRecords(false),
646644
AnnotateCondFailMessage(false),
647645
InternalizeAtLink(false), InternalizeSymbols(false),
648-
MergeableSymbols(false), EmitGenericRODatas(true),
646+
EmitGenericRODatas(true),
649647
NoPreallocatedInstantiationCaches(false),
650648
DisableReadonlyStaticObjects(false), CollocatedMetadataFunctions(false),
651649
ColocateTypeDescriptors(true), UseRelativeProtocolWitnessTables(false),

include/swift/IRGen/Linking.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,10 @@ class UniversalLinkageInfo {
5757
/// be promoted to public external. Used by the LLDB expression evaluator.
5858
bool ForcePublicDecls;
5959

60-
/// When true, allows duplicate external and hidden declarations by marking
61-
/// them as linkonce / weak.
62-
bool MergeableSymbols;
63-
6460
explicit UniversalLinkageInfo(IRGenModule &IGM);
6561

6662
UniversalLinkageInfo(const llvm::Triple &triple, bool hasMultipleIGMs,
67-
bool forcePublicDecls, bool isStaticLibrary,
68-
bool mergeableSymbols);
63+
bool forcePublicDecls, bool isStaticLibrary);
6964

7065
/// In case of multiple llvm modules (in multi-threaded compilation) all
7166
/// private decls must be visible from other files.

include/swift/SIL/SILGlobalVariable.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@ class SILGlobalVariable
5151

5252
/// The SIL module that the global variable belongs to.
5353
SILModule &Module;
54-
54+
55+
/// The module that defines this global variable. This member should only be
56+
/// when a global variable is deserialized to be emitted into another module.
57+
ModuleDecl *ParentModule = nullptr;
58+
5559
/// The mangled name of the variable, which will be propagated to the
5660
/// binary. A pointer into the module's lookup table.
5761
StringRef Name;
@@ -120,6 +124,15 @@ class SILGlobalVariable
120124

121125
SILModule &getModule() const { return Module; }
122126

127+
/// Returns the module that defines this function.
128+
ModuleDecl *getParentModule() const;
129+
130+
/// Sets \c ParentModule as fallback if \c DeclCtxt is not available to
131+
/// provide the parent module.
132+
void setParentModule(ModuleDecl *module) {
133+
ParentModule = module;
134+
}
135+
123136
SILType getLoweredType() const { return LoweredType; }
124137
CanSILFunctionType getLoweredFunctionType() const {
125138
return LoweredType.castTo<SILFunctionType>();

lib/Frontend/CompilerInvocation.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3766,10 +3766,6 @@ static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args,
37663766

37673767
Opts.InternalizeSymbols = FrontendOpts.Static;
37683768

3769-
if (Args.hasArg(OPT_mergeable_symbols)) {
3770-
Opts.MergeableSymbols = true;
3771-
}
3772-
37733769
if (Args.hasArg(OPT_disable_preallocated_instantiation_caches)) {
37743770
Opts.NoPreallocatedInstantiationCaches = true;
37753771
}
@@ -3906,6 +3902,10 @@ static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args,
39063902

39073903
Opts.DebugCallsiteInfo |= Args.hasArg(OPT_debug_callsite_info);
39083904

3905+
if (Args.hasArg(OPT_mergeable_symbols))
3906+
Diags.diagnose(SourceLoc(), diag::warn_flag_deprecated,
3907+
"-mergeable-symbols");
3908+
39093909
return false;
39103910
}
39113911

lib/IRGen/GenDecl.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2332,8 +2332,6 @@ getIRLinkage(StringRef name, const UniversalLinkageInfo &info,
23322332

23332333
if (hasNonUniqueDefinition)
23342334
linkage = llvm::GlobalValue::WeakODRLinkage;
2335-
else if (info.MergeableSymbols)
2336-
linkage = llvm::GlobalValue::WeakODRLinkage;
23372335

23382336
return {linkage, PublicDefinitionVisibility,
23392337
info.Internalize ? llvm::GlobalValue::DefaultStorageClass
@@ -2352,8 +2350,6 @@ getIRLinkage(StringRef name, const UniversalLinkageInfo &info,
23522350
case SILLinkage::Hidden:
23532351
if (hasNonUniqueDefinition)
23542352
return RESULT(WeakODR, Hidden, Default);
2355-
if (info.MergeableSymbols)
2356-
return RESULT(WeakODR, Hidden, Default);
23572353

23582354
return RESULT(External, Hidden, Default);
23592355

lib/IRGen/Linking.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,19 +82,16 @@ bool swift::irgen::useDllStorage(const llvm::Triple &triple) {
8282
UniversalLinkageInfo::UniversalLinkageInfo(IRGenModule &IGM)
8383
: UniversalLinkageInfo(IGM.Triple, IGM.IRGen.hasMultipleIGMs(),
8484
IGM.IRGen.Opts.ForcePublicLinkage,
85-
IGM.IRGen.Opts.InternalizeSymbols,
86-
IGM.IRGen.Opts.MergeableSymbols) {}
85+
IGM.IRGen.Opts.InternalizeSymbols) {}
8786

8887
UniversalLinkageInfo::UniversalLinkageInfo(const llvm::Triple &triple,
8988
bool hasMultipleIGMs,
9089
bool forcePublicDecls,
91-
bool isStaticLibrary,
92-
bool mergeableSymbols)
90+
bool isStaticLibrary)
9391
: IsELFObject(triple.isOSBinFormatELF()),
9492
IsMSVCEnvironment(triple.isWindowsMSVCEnvironment()),
9593
UseDLLStorage(useDllStorage(triple)), Internalize(isStaticLibrary),
96-
HasMultipleIGMs(hasMultipleIGMs), ForcePublicDecls(forcePublicDecls),
97-
MergeableSymbols(mergeableSymbols) {}
94+
HasMultipleIGMs(hasMultipleIGMs), ForcePublicDecls(forcePublicDecls) {}
9895

9996
LinkEntity LinkEntity::forSILGlobalVariable(SILGlobalVariable *G,
10097
IRGenModule &IGM) {

lib/IRGen/TBDGenVisitor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ class TBDGenVisitor : public IRSymbolVisitor {
124124
APIRecorder &recorder)
125125
: DataLayoutDescription(dataLayoutString),
126126
UniversalLinkInfo(target, opts.HasMultipleIGMs, /*forcePublic*/ false,
127-
/*static=*/false, /*mergeableSymbols*/false),
127+
/*static=*/false),
128128
SwiftModule(swiftModule), Opts(opts), recorder(recorder),
129129
previousInstallNameMap(parsePreviousModuleInstallNameMap()) {}
130130

lib/SIL/IR/SILGlobalVariable.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ SILGlobalVariable *SILGlobalVariable::create(SILModule &M, SILLinkage linkage,
4343
return var;
4444
}
4545

46+
ModuleDecl *SILGlobalVariable::getParentModule() const {
47+
return ParentModule ? ParentModule : getModule().getSwiftModule();
48+
}
49+
4650
static bool isGlobalLet(SILModule &mod, VarDecl *decl, SILType type) {
4751
if (!decl)
4852
return false;
@@ -92,11 +96,22 @@ bool SILGlobalVariable::isPossiblyUsedExternally() const {
9296
}
9397

9498
bool SILGlobalVariable::hasNonUniqueDefinition() const {
95-
auto decl = getDecl();
96-
if (!decl)
99+
// Non-uniqueness is a property of the Embedded linkage model.
100+
auto &ctx = getModule().getASTContext();
101+
if (!ctx.LangOpts.hasFeature(Feature::Embedded))
97102
return false;
98103

99-
return SILDeclRef::declHasNonUniqueDefinition(decl);
104+
// If this is for a declaration, ask it.
105+
if (auto decl = getDecl()) {
106+
return SILDeclRef::declHasNonUniqueDefinition(decl);
107+
}
108+
109+
// If this variable is from a different module than the one we are emitting
110+
// code for, then it must have a non-unique definition.
111+
if (getParentModule() != getModule().getSwiftModule())
112+
return true;
113+
114+
return false;
100115
}
101116

102117
bool SILGlobalVariable::shouldBePreservedForDebugger() const {

lib/SILGen/SILGenGlobalVariable.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,6 @@ void SILGenModule::emitGlobalInitialization(PatternBindingDecl *pd,
231231
auto onceSILTy
232232
= SILType::getPrimitiveObjectType(onceTy->getCanonicalType());
233233

234-
// TODO: include the module in the onceToken's name mangling.
235-
// Then we can make it fragile.
236234
auto onceToken = SILGlobalVariable::create(M, SILLinkage::Private,
237235
IsNotSerialized,
238236
onceTokenBuffer, onceSILTy);

lib/Serialization/DeserializeSIL.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4078,9 +4078,11 @@ SILGlobalVariable *SILDeserializer::readGlobalVar(StringRef Name) {
40784078

40794079
TypeID TyID;
40804080
DeclID dID;
4081+
ModuleID parentModuleID;
40814082
unsigned rawLinkage, serializedKind, IsDeclaration, IsLet, IsUsed;
40824083
SILGlobalVarLayout::readRecord(scratch, rawLinkage, serializedKind,
4083-
IsDeclaration, IsLet, IsUsed, TyID, dID);
4084+
IsDeclaration, IsLet, IsUsed, TyID, dID,
4085+
parentModuleID);
40844086
if (TyID == 0) {
40854087
LLVM_DEBUG(llvm::dbgs() << "SILGlobalVariable typeID is 0.\n");
40864088
return nullptr;
@@ -4115,6 +4117,9 @@ SILGlobalVariable *SILDeserializer::readGlobalVar(StringRef Name) {
41154117
globalVarOrOffset.set(v, true /*isFullyDeserialized*/);
41164118
v->setDeclaration(IsDeclaration);
41174119

4120+
if (parentModuleID)
4121+
v->setParentModule(MF->getModule(parentModuleID));
4122+
41184123
if (Callback)
41194124
Callback->didDeserialize(MF->getAssociatedModule(), v);
41204125

0 commit comments

Comments
 (0)