[Embedded] Identify more places to emit symbols even with deferred code generation

Deferred code generation only produces symbols when they are needed.
Expand this out to cover more of the cases where we need them:
* @c/@_cdecl with and without @implementation
* @_expose(Cxx) and @_expose(Wasm)
* @_section and @_used
* (already present) the main entry point

Part of the Embedded Swift linkage model. Also fixes #74328 /
rdar://147207945 along the way.
This commit is contained in:
Doug Gregor
2025-10-03 15:25:53 -07:00
parent 67c7fbc87b
commit cc519a09d0
8 changed files with 169 additions and 0 deletions

View File

@@ -1069,6 +1069,18 @@ SILFunction::isPossiblyUsedExternally() const {
if (markedAsUsed())
return true;
// If this function is exposed to a foreign language, it can be used
// externally (by that language).
if (auto decl = getDeclRef().getDecl()) {
if (SILDeclRef::declExposedToForeignLanguage(decl))
return true;
}
// If this function was explicitly placed in a section or given a WebAssembly
// export, it can be used externally.
if (!Section.empty() || !WasmExportName.empty())
return true;
if (shouldBePreservedForDebugger())
return true;