23
23
#include " swift/AST/ParameterList.h"
24
24
#include " swift/AST/PropertyWrappers.h"
25
25
#include " swift/Basic/LLVM.h"
26
+ #include " swift/ClangImporter/ClangImporter.h"
26
27
#include " swift/IRGen/IRGenPublic.h"
27
28
#include " swift/IRGen/Linking.h"
28
29
#include " swift/SIL/FormalLinkage.h"
32
33
#include " swift/SIL/SILWitnessTable.h"
33
34
#include " swift/SIL/SILWitnessVisitor.h"
34
35
#include " swift/SIL/TypeLowering.h"
36
+ #include " clang/Basic/TargetInfo.h"
35
37
#include " llvm/ADT/StringSet.h"
38
+ #include " llvm/IR/Mangler.h"
36
39
#include " llvm/Support/Error.h"
37
40
#include " llvm/Support/YAMLTraits.h"
38
41
#include " llvm/TextAPI/MachO/InterfaceFile.h"
@@ -52,10 +55,15 @@ static bool isGlobalOrStaticVar(VarDecl *VD) {
52
55
}
53
56
54
57
void TBDGenVisitor::addSymbol (StringRef name, SymbolKind kind) {
55
- Symbols.addSymbol (kind, name, Archs);
58
+ // The linker expects to see mangled symbol names in TBD files, so make sure
59
+ // to mangle before inserting the symbol.
60
+ SmallString<32 > mangled;
61
+ llvm::Mangler::getNameWithPrefix (mangled, name, DataLayout);
62
+
63
+ Symbols.addSymbol (kind, mangled, Archs);
56
64
57
65
if (StringSymbols && kind == SymbolKind::GlobalSymbol) {
58
- auto isNewValue = StringSymbols->insert (name ).second ;
66
+ auto isNewValue = StringSymbols->insert (mangled ).second ;
59
67
(void )isNewValue;
60
68
assert (isNewValue && " symbol appears twice" );
61
69
}
@@ -640,7 +648,10 @@ static void enumeratePublicSymbolsAndWrite(ModuleDecl *M, FileUnit *singleFile,
640
648
file.addArch (arch);
641
649
file.setPlatform (getPlatformKind (target));
642
650
643
- TBDGenVisitor visitor (file, arch, symbols, linkInfo, M, opts);
651
+ auto *clang = static_cast <ClangImporter *>(ctx.getClangModuleLoader ());
652
+ TBDGenVisitor visitor (file, arch, symbols,
653
+ clang->getTargetInfo ().getDataLayout (),
654
+ linkInfo, M, opts);
644
655
645
656
auto visitFile = [&](FileUnit *file) {
646
657
if (file == M->getFiles ()[0 ]) {
0 commit comments