@@ -62,14 +62,15 @@ using namespace swift::tbdgen;
62
62
using namespace llvm ::yaml;
63
63
using StringSet = llvm::StringSet<>;
64
64
using SymbolKind = llvm::MachO::SymbolKind;
65
+ using SymbolFlags = llvm::MachO::SymbolFlags;
65
66
66
67
TBDGenVisitor::TBDGenVisitor (const TBDGenDescriptor &desc,
67
68
APIRecorder &recorder)
68
69
: TBDGenVisitor(desc.getTarget(), desc.getDataLayoutString(),
69
70
desc.getParentModule(), desc.getOptions(), recorder) {}
70
71
71
72
void TBDGenVisitor::addSymbolInternal (StringRef name, SymbolKind kind,
72
- SymbolSource source) {
73
+ SymbolSource source, SymbolFlags flags ) {
73
74
if (!source.isLinkerDirective () && Opts.LinkerDirectivesOnly )
74
75
return ;
75
76
@@ -82,7 +83,7 @@ void TBDGenVisitor::addSymbolInternal(StringRef name, SymbolKind kind,
82
83
}
83
84
#endif
84
85
recorder.addSymbol (name, kind, source,
85
- DeclStack.empty () ? nullptr : DeclStack.back ());
86
+ DeclStack.empty () ? nullptr : DeclStack.back (), flags );
86
87
}
87
88
88
89
static std::vector<OriginallyDefinedInAttr::ActiveVersion>
@@ -341,7 +342,7 @@ void TBDGenVisitor::addLinkerDirectiveSymbolsLdPrevious(StringRef name,
341
342
OS << Ver.Version .getMajor () << " ." << getMinor (Ver.Version .getMinor ()) << " $" ;
342
343
OS << name << " $" ;
343
344
addSymbolInternal (OS.str (), SymbolKind::GlobalSymbol,
344
- SymbolSource::forLinkerDirective ());
345
+ SymbolSource::forLinkerDirective (), SymbolFlags::Data );
345
346
}
346
347
}
347
348
@@ -387,13 +388,13 @@ void TBDGenVisitor::addLinkerDirectiveSymbolsLdHide(StringRef name,
387
388
llvm::raw_svector_ostream OS (Buffer);
388
389
OS << " $ld$hide$os" << CurMaj << " ." << CurMin << " $" << name;
389
390
addSymbolInternal (OS.str (), SymbolKind::GlobalSymbol,
390
- SymbolSource::forLinkerDirective ());
391
+ SymbolSource::forLinkerDirective (), SymbolFlags::Data );
391
392
}
392
393
}
393
394
}
394
395
395
396
void TBDGenVisitor::addSymbol (StringRef name, SymbolSource source,
396
- SymbolKind kind) {
397
+ SymbolFlags flags, SymbolKind kind) {
397
398
// The linker expects to see mangled symbol names in TBD files,
398
399
// except when being passed objective c classes,
399
400
// so make sure to mangle before inserting the symbol.
@@ -406,7 +407,7 @@ void TBDGenVisitor::addSymbol(StringRef name, SymbolSource source,
406
407
llvm::Mangler::getNameWithPrefix (mangled, name, *DataLayout);
407
408
}
408
409
409
- addSymbolInternal (mangled, kind, source);
410
+ addSymbolInternal (mangled, kind, source, flags );
410
411
if (previousInstallNameMap) {
411
412
addLinkerDirectiveSymbolsLdPrevious (mangled, kind);
412
413
} else {
@@ -434,30 +435,33 @@ void TBDGenVisitor::didVisitDecl(Decl *D) {
434
435
}
435
436
436
437
void TBDGenVisitor::addFunction (SILDeclRef declRef) {
437
- addSymbol (declRef.mangle (), SymbolSource::forSILDeclRef (declRef));
438
+ addSymbol (declRef.mangle (), SymbolSource::forSILDeclRef (declRef),
439
+ SymbolFlags::Text);
438
440
}
439
441
440
442
void TBDGenVisitor::addFunction (StringRef name, SILDeclRef declRef) {
441
- addSymbol (name, SymbolSource::forSILDeclRef (declRef));
443
+ addSymbol (name, SymbolSource::forSILDeclRef (declRef), SymbolFlags::Text );
442
444
}
443
445
444
446
void TBDGenVisitor::addGlobalVar (VarDecl *VD) {
445
447
Mangle::ASTMangler mangler;
446
- addSymbol (mangler.mangleEntity (VD), SymbolSource::forGlobal (VD));
448
+ addSymbol (mangler.mangleEntity (VD), SymbolSource::forGlobal (VD),
449
+ SymbolFlags::Data);
447
450
}
448
451
449
452
void TBDGenVisitor::addLinkEntity (LinkEntity entity) {
450
453
auto linkage =
451
454
LinkInfo::get (UniversalLinkInfo, SwiftModule, entity, ForDefinition);
452
455
453
- addSymbol (linkage.getName (), SymbolSource::forIRLinkEntity (entity));
456
+ SymbolFlags flags = entity.isData () ? SymbolFlags::Data : SymbolFlags::Text;
457
+ addSymbol (linkage.getName (), SymbolSource::forIRLinkEntity (entity), flags);
454
458
}
455
459
456
460
void TBDGenVisitor::addObjCInterface (ClassDecl *CD) {
457
461
// FIXME: We ought to have a symbol source for this.
458
462
SmallString<128 > buffer;
459
463
addSymbol (CD->getObjCRuntimeName (buffer), SymbolSource::forUnknown (),
460
- SymbolKind::ObjectiveCClass);
464
+ SymbolFlags::Data, SymbolKind::ObjectiveCClass);
461
465
recorder.addObjCInterface (CD);
462
466
}
463
467
@@ -474,13 +478,14 @@ void TBDGenVisitor::addProtocolWitnessThunk(RootProtocolConformance *C,
474
478
475
479
std::string decorated = Mangler.mangleWitnessThunk (C, requirementDecl);
476
480
// FIXME: We should have a SILDeclRef SymbolSource for this.
477
- addSymbol (decorated, SymbolSource::forUnknown ());
481
+ addSymbol (decorated, SymbolSource::forUnknown (), SymbolFlags::Text );
478
482
479
483
if (requirementDecl->isProtocolRequirement ()) {
480
484
ValueDecl *PWT = C->getWitness (requirementDecl).getDecl ();
481
485
if (const auto *AFD = dyn_cast<AbstractFunctionDecl>(PWT))
482
486
if (AFD->hasAsync ())
483
- addSymbol (decorated + " Tu" , SymbolSource::forUnknown ());
487
+ addSymbol (decorated + " Tu" , SymbolSource::forUnknown (),
488
+ SymbolFlags::Text);
484
489
}
485
490
}
486
491
@@ -489,7 +494,7 @@ void TBDGenVisitor::addFirstFileSymbols() {
489
494
// FIXME: We ought to have a symbol source for this.
490
495
SmallString<32 > buf;
491
496
addSymbol (irgen::encodeForceLoadSymbolName (buf, Opts.ModuleLinkName ),
492
- SymbolSource::forUnknown ());
497
+ SymbolSource::forUnknown (), SymbolFlags::Data );
493
498
}
494
499
}
495
500
@@ -588,7 +593,7 @@ TBDFile GenerateTBDRequest::evaluate(Evaluator &evaluator,
588
593
auto &ctx = M->getASTContext ();
589
594
590
595
llvm::MachO::InterfaceFile file;
591
- file.setFileType (llvm::MachO::FileType::TBD_V4 );
596
+ file.setFileType (llvm::MachO::FileType::TBD_V5 );
592
597
file.setApplicationExtensionSafe (isApplicationExtensionSafe (ctx.LangOpts ));
593
598
file.setInstallName (opts.InstallName );
594
599
file.setTwoLevelNamespace ();
@@ -615,7 +620,9 @@ TBDFile GenerateTBDRequest::evaluate(Evaluator &evaluator,
615
620
}
616
621
617
622
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
+ };
619
626
SimpleAPIRecorder recorder (addSymbol);
620
627
TBDGenVisitor visitor (desc, recorder);
621
628
visitor.visit (desc);
@@ -627,7 +634,7 @@ PublicSymbolsRequest::evaluate(Evaluator &evaluator,
627
634
TBDGenDescriptor desc) const {
628
635
std::vector<std::string> symbols;
629
636
auto addSymbol = [&](StringRef symbol, SymbolKind kind, SymbolSource source,
630
- Decl *decl) {
637
+ Decl *decl, SymbolFlags flags ) {
631
638
if (kind == SymbolKind::GlobalSymbol)
632
639
symbols.push_back (symbol.str ());
633
640
// TextAPI ObjC Class Kinds represents two symbols.
@@ -652,7 +659,7 @@ void swift::writeTBDFile(ModuleDecl *M, llvm::raw_ostream &os,
652
659
auto desc = TBDGenDescriptor::forModule (M, opts);
653
660
auto file = llvm::cantFail (evaluator (GenerateTBDRequest{desc}));
654
661
llvm::cantFail (llvm::MachO::TextAPIWriter::writeToStream (os, file),
655
- " YAML writing should be error-free" );
662
+ " TBD writing should be error-free" );
656
663
}
657
664
658
665
class APIGenRecorder final : public APIRecorder {
@@ -675,7 +682,7 @@ class APIGenRecorder final : public APIRecorder {
675
682
~APIGenRecorder () {}
676
683
677
684
void addSymbol (StringRef symbol, SymbolKind kind, SymbolSource source,
678
- Decl *decl) override {
685
+ Decl *decl, SymbolFlags flags ) override {
679
686
if (kind != SymbolKind::GlobalSymbol)
680
687
return ;
681
688
@@ -879,7 +886,7 @@ SymbolSourceMapRequest::evaluate(Evaluator &evaluator,
879
886
auto *SymbolSources = Ctx.Allocate <SymbolSourceMap>();
880
887
881
888
auto addSymbol = [=](StringRef symbol, SymbolKind kind, SymbolSource source,
882
- Decl *decl) {
889
+ Decl *decl, SymbolFlags flags ) {
883
890
SymbolSources->insert ({symbol, source});
884
891
};
885
892
0 commit comments