@@ -1725,8 +1725,8 @@ void IRGenModule::emitVTableStubs() {
1725
1725
1726
1726
static IRLinkage
1727
1727
getIRLinkage (const UniversalLinkageInfo &info, SILLinkage linkage,
1728
- ForDefinition_t isDefinition,
1729
- bool isWeakImported ) {
1728
+ ForDefinition_t isDefinition, bool isWeakImported,
1729
+ bool isKnownLocal = false ) {
1730
1730
#define RESULT (LINKAGE, VISIBILITY, DLL_STORAGE ) \
1731
1731
IRLinkage{llvm::GlobalValue::LINKAGE##Linkage, \
1732
1732
llvm::GlobalValue::VISIBILITY##Visibility, \
@@ -1766,7 +1766,8 @@ getIRLinkage(const UniversalLinkageInfo &info, SILLinkage linkage,
1766
1766
case SILLinkage::Private: {
1767
1767
if (info.forcePublicDecls () && !isDefinition)
1768
1768
return getIRLinkage (info, SILLinkage::PublicExternal, isDefinition,
1769
- isWeakImported);
1769
+ isWeakImported, isKnownLocal);
1770
+
1770
1771
auto linkage = info.needLinkerToMergeDuplicateSymbols ()
1771
1772
? llvm::GlobalValue::LinkOnceODRLinkage
1772
1773
: llvm::GlobalValue::InternalLinkage;
@@ -1782,7 +1783,10 @@ getIRLinkage(const UniversalLinkageInfo &info, SILLinkage linkage,
1782
1783
1783
1784
auto linkage = isWeakImported ? llvm::GlobalValue::ExternalWeakLinkage
1784
1785
: llvm::GlobalValue::ExternalLinkage;
1785
- return {linkage, llvm::GlobalValue::DefaultVisibility, ImportedStorage};
1786
+ return {linkage, llvm::GlobalValue::DefaultVisibility,
1787
+ isKnownLocal
1788
+ ? llvm::GlobalValue::DefaultStorageClass
1789
+ : ImportedStorage};
1786
1790
}
1787
1791
1788
1792
case SILLinkage::HiddenExternal:
@@ -1791,8 +1795,10 @@ getIRLinkage(const UniversalLinkageInfo &info, SILLinkage linkage,
1791
1795
return RESULT (AvailableExternally, Hidden, Default);
1792
1796
1793
1797
return {llvm::GlobalValue::ExternalLinkage,
1794
- llvm::GlobalValue::DefaultVisibility, ImportedStorage};
1795
-
1798
+ llvm::GlobalValue::DefaultVisibility,
1799
+ isKnownLocal
1800
+ ? llvm::GlobalValue::DefaultStorageClass
1801
+ : ImportedStorage};
1796
1802
}
1797
1803
1798
1804
llvm_unreachable (" bad SIL linkage" );
@@ -1807,9 +1813,15 @@ void irgen::updateLinkageForDefinition(IRGenModule &IGM,
1807
1813
// entire linkage computation.
1808
1814
UniversalLinkageInfo linkInfo (IGM);
1809
1815
bool weakImported = entity.isWeakImported (IGM.getSwiftModule ());
1816
+
1817
+ bool isKnownLocal = entity.isAlwaysSharedLinkage ();
1818
+ if (const auto *DC = entity.getDeclContextForEmission ())
1819
+ if (const auto *MD = DC->getParentModule ())
1820
+ isKnownLocal = IGM.getSwiftModule () == MD;
1821
+
1810
1822
auto IRL =
1811
1823
getIRLinkage (linkInfo, entity.getLinkage (ForDefinition),
1812
- ForDefinition, weakImported);
1824
+ ForDefinition, weakImported, isKnownLocal );
1813
1825
ApplyIRLinkage (IRL).to (global);
1814
1826
1815
1827
// Everything externally visible is considered used in Swift.
@@ -1834,21 +1846,16 @@ LinkInfo LinkInfo::get(const UniversalLinkageInfo &linkInfo,
1834
1846
const LinkEntity &entity,
1835
1847
ForDefinition_t isDefinition) {
1836
1848
LinkInfo result;
1837
- // FIXME: For anything in the standard library, we assume is locally defined.
1838
- // The only two ways imported interfaces are currently created is via a shims
1839
- // interface where the ClangImporter will correctly give us the proper DLL
1840
- // storage for the declaration. Otherwise, it is from a `@_silgen_name`
1841
- // attributed declaration, which we explicitly handle elsewhere. So, in the
1842
- // case of a standard library build, just assume everything is locally
1843
- // defined. Ideally, we would integrate the linkage calculation properly to
1844
- // avoid this special casing.
1845
- ForDefinition_t isStdlibOrDefinition =
1846
- ForDefinition_t (swiftModule->isStdlibModule () || isDefinition);
1849
+
1850
+ bool isKnownLocal = entity.isAlwaysSharedLinkage ();
1851
+ if (const auto *DC = entity.getDeclContextForEmission ())
1852
+ if (const auto *MD = DC->getParentModule ())
1853
+ isKnownLocal = MD == swiftModule;
1847
1854
1848
1855
entity.mangle (result.Name );
1849
1856
bool weakImported = entity.isWeakImported (swiftModule);
1850
- result.IRL = getIRLinkage (linkInfo, entity.getLinkage (isStdlibOrDefinition ),
1851
- isDefinition, weakImported);
1857
+ result.IRL = getIRLinkage (linkInfo, entity.getLinkage (isDefinition ),
1858
+ isDefinition, weakImported, isKnownLocal );
1852
1859
result.ForDefinition = isDefinition;
1853
1860
return result;
1854
1861
}
0 commit comments