@@ -10,9 +10,6 @@ namespace installapi {
10
10
11
11
// / Metadata stored about a mapping of a declaration to a symbol.
12
12
struct DylibVerifier ::SymbolContext {
13
- // Name to use for printing in diagnostics.
14
- std::string PrettyPrintName{" " };
15
-
16
13
// Name to use for all querying and verification
17
14
// purposes.
18
15
std::string SymbolName{" " };
@@ -30,11 +27,35 @@ struct DylibVerifier::SymbolContext {
30
27
bool Inlined = false ;
31
28
};
32
29
33
- static std::string
34
- getAnnotatedName (const Record *R, EncodeKind Kind, StringRef Name,
35
- bool ValidSourceLoc = true ,
36
- ObjCIFSymbolKind ObjCIF = ObjCIFSymbolKind::None) {
37
- assert (!Name.empty () && " Need symbol name for printing" );
30
+ static bool isCppMangled (StringRef Name) {
31
+ // InstallAPI currently only supports itanium manglings.
32
+ return (Name.starts_with (" _Z" ) || Name.starts_with (" __Z" ) ||
33
+ Name.starts_with (" ___Z" ));
34
+ }
35
+
36
+ static std::string demangle (StringRef Name) {
37
+ // InstallAPI currently only supports itanium manglings.
38
+ if (!isCppMangled (Name))
39
+ return Name.str ();
40
+ char *Result = llvm::itaniumDemangle (Name);
41
+ if (!Result)
42
+ return Name.str ();
43
+
44
+ std::string Demangled (Result);
45
+ free (Result);
46
+ return Demangled;
47
+ }
48
+
49
+ std::string DylibVerifier::getAnnotatedName (const Record *R,
50
+ SymbolContext &SymCtx,
51
+ bool ValidSourceLoc) {
52
+ assert (!SymCtx.SymbolName .empty () && " Expected symbol name" );
53
+
54
+ const StringRef SymbolName = SymCtx.SymbolName ;
55
+ std::string PrettyName =
56
+ (Demangle && (SymCtx.Kind == EncodeKind::GlobalSymbol))
57
+ ? demangle (SymbolName)
58
+ : SymbolName.str ();
38
59
39
60
std::string Annotation;
40
61
if (R->isWeakDefined ())
@@ -45,58 +66,47 @@ getAnnotatedName(const Record *R, EncodeKind Kind, StringRef Name,
45
66
Annotation += " (tlv) " ;
46
67
47
68
// Check if symbol represents only part of a @interface declaration.
48
- const bool IsAnnotatedObjCClass = ((ObjCIF != ObjCIFSymbolKind::None) &&
49
- (ObjCIF <= ObjCIFSymbolKind::EHType));
69
+ const bool IsAnnotatedObjCClass =
70
+ ((SymCtx.ObjCIFKind != ObjCIFSymbolKind::None) &&
71
+ (SymCtx.ObjCIFKind <= ObjCIFSymbolKind::EHType));
50
72
51
73
if (IsAnnotatedObjCClass) {
52
- if (ObjCIF == ObjCIFSymbolKind::EHType)
74
+ if (SymCtx. ObjCIFKind == ObjCIFSymbolKind::EHType)
53
75
Annotation += " Exception Type of " ;
54
- if (ObjCIF == ObjCIFSymbolKind::MetaClass)
76
+ if (SymCtx. ObjCIFKind == ObjCIFSymbolKind::MetaClass)
55
77
Annotation += " Metaclass of " ;
56
- if (ObjCIF == ObjCIFSymbolKind::Class)
78
+ if (SymCtx. ObjCIFKind == ObjCIFSymbolKind::Class)
57
79
Annotation += " Class of " ;
58
80
}
59
81
60
82
// Only print symbol type prefix or leading "_" if there is no source location
61
83
// tied to it. This can only ever happen when the location has to come from
62
84
// debug info.
63
85
if (ValidSourceLoc) {
64
- if ((Kind == EncodeKind::GlobalSymbol) && Name.starts_with (" _" ))
65
- return Annotation + Name.drop_front (1 ).str ();
66
- return Annotation + Name.str ();
86
+ StringRef PrettyNameRef (PrettyName);
87
+ if ((SymCtx.Kind == EncodeKind::GlobalSymbol) &&
88
+ !isCppMangled (SymbolName) && PrettyNameRef.starts_with (" _" ))
89
+ return Annotation + PrettyNameRef.drop_front (1 ).str ();
90
+ return Annotation + PrettyName;
67
91
}
68
92
69
93
if (IsAnnotatedObjCClass)
70
- return Annotation + Name. str () ;
94
+ return Annotation + PrettyName ;
71
95
72
- switch (Kind) {
96
+ switch (SymCtx. Kind ) {
73
97
case EncodeKind::GlobalSymbol:
74
- return Annotation + Name. str () ;
98
+ return Annotation + PrettyName ;
75
99
case EncodeKind::ObjectiveCInstanceVariable:
76
- return Annotation + " (ObjC IVar) " + Name. str () ;
100
+ return Annotation + " (ObjC IVar) " + PrettyName ;
77
101
case EncodeKind::ObjectiveCClass:
78
- return Annotation + " (ObjC Class) " + Name. str () ;
102
+ return Annotation + " (ObjC Class) " + PrettyName ;
79
103
case EncodeKind::ObjectiveCClassEHType:
80
- return Annotation + " (ObjC Class EH) " + Name. str () ;
104
+ return Annotation + " (ObjC Class EH) " + PrettyName ;
81
105
}
82
106
83
107
llvm_unreachable (" unexpected case for EncodeKind" );
84
108
}
85
109
86
- static std::string demangle (StringRef Name) {
87
- // InstallAPI currently only supports itanium manglings.
88
- if (!(Name.starts_with (" _Z" ) || Name.starts_with (" __Z" ) ||
89
- Name.starts_with (" ___Z" )))
90
- return Name.str ();
91
- char *Result = llvm::itaniumDemangle (Name);
92
- if (!Result)
93
- return Name.str ();
94
-
95
- std::string Demangled (Result);
96
- free (Result);
97
- return Demangled;
98
- }
99
-
100
110
static DylibVerifier::Result updateResult (const DylibVerifier::Result Prev,
101
111
const DylibVerifier::Result Curr) {
102
112
if (Prev == Curr)
@@ -193,19 +203,18 @@ bool DylibVerifier::compareObjCInterfaceSymbols(const Record *R,
193
203
// The decl represents a complete ObjCInterface, but the symbols in the
194
204
// dylib do not. Determine which symbol is missing. To keep older projects
195
205
// building, treat this as a warning.
196
- if (!DR->isExportedSymbol (ObjCIFSymbolKind::Class))
206
+ if (!DR->isExportedSymbol (ObjCIFSymbolKind::Class)) {
207
+ SymCtx.ObjCIFKind = ObjCIFSymbolKind::Class;
197
208
PrintDiagnostic (DR->getLinkageForSymbol (ObjCIFSymbolKind::Class), R,
198
- getAnnotatedName (R, SymCtx.Kind , SymCtx.PrettyPrintName ,
199
- /* ValidSourceLoc=*/ true ,
200
- ObjCIFSymbolKind::Class),
209
+ getAnnotatedName (R, SymCtx),
201
210
/* PrintAsWarning=*/ true );
202
-
203
- if (!DR->isExportedSymbol (ObjCIFSymbolKind::MetaClass))
211
+ }
212
+ if (!DR->isExportedSymbol (ObjCIFSymbolKind::MetaClass)) {
213
+ SymCtx.ObjCIFKind = ObjCIFSymbolKind::MetaClass;
204
214
PrintDiagnostic (DR->getLinkageForSymbol (ObjCIFSymbolKind::MetaClass), R,
205
- getAnnotatedName (R, SymCtx.Kind , SymCtx.PrettyPrintName ,
206
- /* ValidSourceLoc=*/ true ,
207
- ObjCIFSymbolKind::MetaClass),
215
+ getAnnotatedName (R, SymCtx),
208
216
/* PrintAsWarning=*/ true );
217
+ }
209
218
return true ;
210
219
}
211
220
@@ -221,7 +230,7 @@ bool DylibVerifier::compareObjCInterfaceSymbols(const Record *R,
221
230
// At this point that means there was not a matching class symbol
222
231
// to represent the one discovered as a declaration.
223
232
PrintDiagnostic (DR->getLinkageForSymbol (SymCtx.ObjCIFKind ), R,
224
- SymCtx.PrettyPrintName );
233
+ SymCtx.SymbolName );
225
234
return false ;
226
235
}
227
236
@@ -234,15 +243,15 @@ DylibVerifier::Result DylibVerifier::compareVisibility(const Record *R,
234
243
Ctx.emitDiag ([&]() {
235
244
Ctx.Diag ->Report (SymCtx.FA ->D ->getLocation (),
236
245
diag::err_library_missing_symbol)
237
- << SymCtx. PrettyPrintName ;
246
+ << getAnnotatedName (R, SymCtx) ;
238
247
});
239
248
return Result::Invalid;
240
249
}
241
250
if (DR->isInternal ()) {
242
251
Ctx.emitDiag ([&]() {
243
252
Ctx.Diag ->Report (SymCtx.FA ->D ->getLocation (),
244
253
diag::err_library_hidden_symbol)
245
- << SymCtx. PrettyPrintName ;
254
+ << getAnnotatedName (R, SymCtx) ;
246
255
});
247
256
return Result::Invalid;
248
257
}
@@ -269,7 +278,7 @@ DylibVerifier::Result DylibVerifier::compareVisibility(const Record *R,
269
278
}
270
279
Ctx.emitDiag ([&]() {
271
280
Ctx.Diag ->Report (SymCtx.FA ->D ->getLocation (), ID)
272
- << SymCtx. PrettyPrintName ;
281
+ << getAnnotatedName (R, SymCtx) ;
273
282
});
274
283
return Outcome;
275
284
}
@@ -293,14 +302,14 @@ DylibVerifier::Result DylibVerifier::compareAvailability(const Record *R,
293
302
Ctx.emitDiag ([&]() {
294
303
Ctx.Diag ->Report (SymCtx.FA ->D ->getLocation (),
295
304
diag::warn_header_availability_mismatch)
296
- << SymCtx. PrettyPrintName << IsDeclAvailable << IsDeclAvailable;
305
+ << getAnnotatedName (R, SymCtx) << IsDeclAvailable << IsDeclAvailable;
297
306
});
298
307
return Result::Ignore;
299
308
case VerificationMode::Pedantic:
300
309
Ctx.emitDiag ([&]() {
301
310
Ctx.Diag ->Report (SymCtx.FA ->D ->getLocation (),
302
311
diag::err_header_availability_mismatch)
303
- << SymCtx. PrettyPrintName << IsDeclAvailable << IsDeclAvailable;
312
+ << getAnnotatedName (R, SymCtx) << IsDeclAvailable << IsDeclAvailable;
304
313
});
305
314
return Result::Invalid;
306
315
case VerificationMode::ErrorsOnly:
@@ -313,23 +322,19 @@ DylibVerifier::Result DylibVerifier::compareAvailability(const Record *R,
313
322
314
323
bool DylibVerifier::compareSymbolFlags (const Record *R, SymbolContext &SymCtx,
315
324
const Record *DR) {
316
- std::string DisplayName =
317
- Demangle ? demangle (DR->getName ()) : DR->getName ().str ();
318
-
319
325
if (DR->isThreadLocalValue () && !R->isThreadLocalValue ()) {
320
326
Ctx.emitDiag ([&]() {
321
327
Ctx.Diag ->Report (SymCtx.FA ->D ->getLocation (),
322
328
diag::err_dylib_symbol_flags_mismatch)
323
- << getAnnotatedName (DR, SymCtx.Kind , DisplayName)
324
- << DR->isThreadLocalValue ();
329
+ << getAnnotatedName (DR, SymCtx) << DR->isThreadLocalValue ();
325
330
});
326
331
return false ;
327
332
}
328
333
if (!DR->isThreadLocalValue () && R->isThreadLocalValue ()) {
329
334
Ctx.emitDiag ([&]() {
330
335
SymCtx.FA ->D ->getLocation (),
331
336
Ctx.Diag ->Report (diag::err_header_symbol_flags_mismatch)
332
- << SymCtx. PrettyPrintName << R->isThreadLocalValue ();
337
+ << getAnnotatedName (DR, SymCtx) << R->isThreadLocalValue ();
333
338
});
334
339
return false ;
335
340
}
@@ -338,16 +343,15 @@ bool DylibVerifier::compareSymbolFlags(const Record *R, SymbolContext &SymCtx,
338
343
Ctx.emitDiag ([&]() {
339
344
Ctx.Diag ->Report (SymCtx.FA ->D ->getLocation (),
340
345
diag::err_dylib_symbol_flags_mismatch)
341
- << getAnnotatedName (DR, SymCtx.Kind , DisplayName)
342
- << R->isWeakDefined ();
346
+ << getAnnotatedName (DR, SymCtx) << R->isWeakDefined ();
343
347
});
344
348
return false ;
345
349
}
346
350
if (!DR->isWeakDefined () && R->isWeakDefined ()) {
347
351
Ctx.emitDiag ([&]() {
348
352
Ctx.Diag ->Report (SymCtx.FA ->D ->getLocation (),
349
353
diag::err_header_symbol_flags_mismatch)
350
- << SymCtx. PrettyPrintName << R->isWeakDefined ();
354
+ << getAnnotatedName (R, SymCtx) << R->isWeakDefined ();
351
355
});
352
356
return false ;
353
357
}
@@ -457,10 +461,7 @@ DylibVerifier::Result DylibVerifier::verify(ObjCIVarRecord *R,
457
461
458
462
std::string FullName =
459
463
ObjCIVarRecord::createScopedName (SuperClass, R->getName ());
460
- SymbolContext SymCtx{
461
- getAnnotatedName (R, EncodeKind::ObjectiveCInstanceVariable,
462
- Demangle ? demangle (FullName) : FullName),
463
- FullName, EncodeKind::ObjectiveCInstanceVariable, FA};
464
+ SymbolContext SymCtx{FullName, EncodeKind::ObjectiveCInstanceVariable, FA};
464
465
return verifyImpl (R, SymCtx);
465
466
}
466
467
@@ -485,11 +486,8 @@ DylibVerifier::Result DylibVerifier::verify(ObjCInterfaceRecord *R,
485
486
SymCtx.SymbolName = R->getName ();
486
487
SymCtx.ObjCIFKind = assignObjCIFSymbolKind (R);
487
488
488
- std::string DisplayName =
489
- Demangle ? demangle (SymCtx.SymbolName ) : SymCtx.SymbolName ;
490
489
SymCtx.Kind = R->hasExceptionAttribute () ? EncodeKind::ObjectiveCClassEHType
491
490
: EncodeKind::ObjectiveCClass;
492
- SymCtx.PrettyPrintName = getAnnotatedName (R, SymCtx.Kind , DisplayName);
493
491
SymCtx.FA = FA;
494
492
495
493
return verifyImpl (R, SymCtx);
@@ -504,8 +502,6 @@ DylibVerifier::Result DylibVerifier::verify(GlobalRecord *R,
504
502
SimpleSymbol Sym = parseSymbol (R->getName ());
505
503
SymbolContext SymCtx;
506
504
SymCtx.SymbolName = Sym.Name ;
507
- SymCtx.PrettyPrintName =
508
- getAnnotatedName (R, Sym.Kind , Demangle ? demangle (Sym.Name ) : Sym.Name );
509
505
SymCtx.Kind = Sym.Kind ;
510
506
SymCtx.FA = FA;
511
507
SymCtx.Inlined = R->isInlined ();
0 commit comments