@@ -62,14 +62,15 @@ using namespace swift::tbdgen;
6262using namespace llvm ::yaml;
6363using StringSet = llvm::StringSet<>;
6464using SymbolKind = llvm::MachO::SymbolKind;
65+ using SymbolFlags = llvm::MachO::SymbolFlags;
6566
6667TBDGenVisitor::TBDGenVisitor (const TBDGenDescriptor &desc,
6768 APIRecorder &recorder)
6869 : TBDGenVisitor(desc.getTarget(), desc.getDataLayoutString(),
6970 desc.getParentModule(), desc.getOptions(), recorder) {}
7071
7172void TBDGenVisitor::addSymbolInternal (StringRef name, SymbolKind kind,
72- SymbolSource source) {
73+ SymbolSource source, SymbolFlags flags ) {
7374 if (!source.isLinkerDirective () && Opts.LinkerDirectivesOnly )
7475 return ;
7576
@@ -82,7 +83,7 @@ void TBDGenVisitor::addSymbolInternal(StringRef name, SymbolKind kind,
8283 }
8384#endif
8485 recorder.addSymbol (name, kind, source,
85- DeclStack.empty () ? nullptr : DeclStack.back ());
86+ DeclStack.empty () ? nullptr : DeclStack.back (), flags );
8687}
8788
8889static std::vector<OriginallyDefinedInAttr::ActiveVersion>
@@ -341,7 +342,7 @@ void TBDGenVisitor::addLinkerDirectiveSymbolsLdPrevious(StringRef name,
341342 OS << Ver.Version .getMajor () << " ." << getMinor (Ver.Version .getMinor ()) << " $" ;
342343 OS << name << " $" ;
343344 addSymbolInternal (OS.str (), SymbolKind::GlobalSymbol,
344- SymbolSource::forLinkerDirective ());
345+ SymbolSource::forLinkerDirective (), SymbolFlags::Data );
345346 }
346347}
347348
@@ -387,13 +388,13 @@ void TBDGenVisitor::addLinkerDirectiveSymbolsLdHide(StringRef name,
387388 llvm::raw_svector_ostream OS (Buffer);
388389 OS << " $ld$hide$os" << CurMaj << " ." << CurMin << " $" << name;
389390 addSymbolInternal (OS.str (), SymbolKind::GlobalSymbol,
390- SymbolSource::forLinkerDirective ());
391+ SymbolSource::forLinkerDirective (), SymbolFlags::Data );
391392 }
392393 }
393394}
394395
395396void TBDGenVisitor::addSymbol (StringRef name, SymbolSource source,
396- SymbolKind kind) {
397+ SymbolFlags flags, SymbolKind kind) {
397398 // The linker expects to see mangled symbol names in TBD files,
398399 // except when being passed objective c classes,
399400 // so make sure to mangle before inserting the symbol.
@@ -406,7 +407,7 @@ void TBDGenVisitor::addSymbol(StringRef name, SymbolSource source,
406407 llvm::Mangler::getNameWithPrefix (mangled, name, *DataLayout);
407408 }
408409
409- addSymbolInternal (mangled, kind, source);
410+ addSymbolInternal (mangled, kind, source, flags );
410411 if (previousInstallNameMap) {
411412 addLinkerDirectiveSymbolsLdPrevious (mangled, kind);
412413 } else {
@@ -434,30 +435,33 @@ void TBDGenVisitor::didVisitDecl(Decl *D) {
434435}
435436
436437void TBDGenVisitor::addFunction (SILDeclRef declRef) {
437- addSymbol (declRef.mangle (), SymbolSource::forSILDeclRef (declRef));
438+ addSymbol (declRef.mangle (), SymbolSource::forSILDeclRef (declRef),
439+ SymbolFlags::Text);
438440}
439441
440442void TBDGenVisitor::addFunction (StringRef name, SILDeclRef declRef) {
441- addSymbol (name, SymbolSource::forSILDeclRef (declRef));
443+ addSymbol (name, SymbolSource::forSILDeclRef (declRef), SymbolFlags::Text );
442444}
443445
444446void TBDGenVisitor::addGlobalVar (VarDecl *VD) {
445447 Mangle::ASTMangler mangler;
446- addSymbol (mangler.mangleEntity (VD), SymbolSource::forGlobal (VD));
448+ addSymbol (mangler.mangleEntity (VD), SymbolSource::forGlobal (VD),
449+ SymbolFlags::Data);
447450}
448451
449452void TBDGenVisitor::addLinkEntity (LinkEntity entity) {
450453 auto linkage =
451454 LinkInfo::get (UniversalLinkInfo, SwiftModule, entity, ForDefinition);
452455
453- addSymbol (linkage.getName (), SymbolSource::forIRLinkEntity (entity));
456+ SymbolFlags flags = entity.isData () ? SymbolFlags::Data : SymbolFlags::Text;
457+ addSymbol (linkage.getName (), SymbolSource::forIRLinkEntity (entity), flags);
454458}
455459
456460void TBDGenVisitor::addObjCInterface (ClassDecl *CD) {
457461 // FIXME: We ought to have a symbol source for this.
458462 SmallString<128 > buffer;
459463 addSymbol (CD->getObjCRuntimeName (buffer), SymbolSource::forUnknown (),
460- SymbolKind::ObjectiveCClass);
464+ SymbolFlags::Data, SymbolKind::ObjectiveCClass);
461465 recorder.addObjCInterface (CD);
462466}
463467
@@ -474,13 +478,14 @@ void TBDGenVisitor::addProtocolWitnessThunk(RootProtocolConformance *C,
474478
475479 std::string decorated = Mangler.mangleWitnessThunk (C, requirementDecl);
476480 // FIXME: We should have a SILDeclRef SymbolSource for this.
477- addSymbol (decorated, SymbolSource::forUnknown ());
481+ addSymbol (decorated, SymbolSource::forUnknown (), SymbolFlags::Text );
478482
479483 if (requirementDecl->isProtocolRequirement ()) {
480484 ValueDecl *PWT = C->getWitness (requirementDecl).getDecl ();
481485 if (const auto *AFD = dyn_cast<AbstractFunctionDecl>(PWT))
482486 if (AFD->hasAsync ())
483- addSymbol (decorated + " Tu" , SymbolSource::forUnknown ());
487+ addSymbol (decorated + " Tu" , SymbolSource::forUnknown (),
488+ SymbolFlags::Text);
484489 }
485490}
486491
@@ -489,7 +494,7 @@ void TBDGenVisitor::addFirstFileSymbols() {
489494 // FIXME: We ought to have a symbol source for this.
490495 SmallString<32 > buf;
491496 addSymbol (irgen::encodeForceLoadSymbolName (buf, Opts.ModuleLinkName ),
492- SymbolSource::forUnknown ());
497+ SymbolSource::forUnknown (), SymbolFlags::Data );
493498 }
494499}
495500
@@ -588,7 +593,7 @@ TBDFile GenerateTBDRequest::evaluate(Evaluator &evaluator,
588593 auto &ctx = M->getASTContext ();
589594
590595 llvm::MachO::InterfaceFile file;
591- file.setFileType (llvm::MachO::FileType::TBD_V4 );
596+ file.setFileType (llvm::MachO::FileType::TBD_V5 );
592597 file.setApplicationExtensionSafe (isApplicationExtensionSafe (ctx.LangOpts ));
593598 file.setInstallName (opts.InstallName );
594599 file.setTwoLevelNamespace ();
@@ -615,7 +620,9 @@ TBDFile GenerateTBDRequest::evaluate(Evaluator &evaluator,
615620 }
616621
617622 auto addSymbol = [&](StringRef symbol, SymbolKind kind, SymbolSource source,
618- Decl *decl) { file.addSymbol (kind, symbol, targets); };
623+ Decl *decl, SymbolFlags flags) {
624+ file.addSymbol (kind, symbol, targets, flags);
625+ };
619626 SimpleAPIRecorder recorder (addSymbol);
620627 TBDGenVisitor visitor (desc, recorder);
621628 visitor.visit (desc);
@@ -627,7 +634,7 @@ PublicSymbolsRequest::evaluate(Evaluator &evaluator,
627634 TBDGenDescriptor desc) const {
628635 std::vector<std::string> symbols;
629636 auto addSymbol = [&](StringRef symbol, SymbolKind kind, SymbolSource source,
630- Decl *decl) {
637+ Decl *decl, SymbolFlags flags ) {
631638 if (kind == SymbolKind::GlobalSymbol)
632639 symbols.push_back (symbol.str ());
633640 // TextAPI ObjC Class Kinds represents two symbols.
@@ -652,7 +659,7 @@ void swift::writeTBDFile(ModuleDecl *M, llvm::raw_ostream &os,
652659 auto desc = TBDGenDescriptor::forModule (M, opts);
653660 auto file = llvm::cantFail (evaluator (GenerateTBDRequest{desc}));
654661 llvm::cantFail (llvm::MachO::TextAPIWriter::writeToStream (os, file),
655- " YAML writing should be error-free" );
662+ " TBD writing should be error-free" );
656663}
657664
658665class APIGenRecorder final : public APIRecorder {
@@ -675,7 +682,7 @@ class APIGenRecorder final : public APIRecorder {
675682 ~APIGenRecorder () {}
676683
677684 void addSymbol (StringRef symbol, SymbolKind kind, SymbolSource source,
678- Decl *decl) override {
685+ Decl *decl, SymbolFlags flags ) override {
679686 if (kind != SymbolKind::GlobalSymbol)
680687 return ;
681688
@@ -879,7 +886,7 @@ SymbolSourceMapRequest::evaluate(Evaluator &evaluator,
879886 auto *SymbolSources = Ctx.Allocate <SymbolSourceMap>();
880887
881888 auto addSymbol = [=](StringRef symbol, SymbolKind kind, SymbolSource source,
882- Decl *decl) {
889+ Decl *decl, SymbolFlags flags ) {
883890 SymbolSources->insert ({symbol, source});
884891 };
885892
0 commit comments