@@ -309,13 +309,43 @@ void SymbolTable::scanVersionScript() {
309
309
310
310
// Then, assign versions to "*". In GNU linkers they have lower priority than
311
311
// other wildcards.
312
+ bool globalAsteriskFound = false ;
313
+ bool localAsteriskFound = false ;
314
+ bool asteriskReported = false ;
315
+ auto assignAsterisk = [&](SymbolVersion &pat, VersionDefinition *ver,
316
+ bool isLocal) {
317
+ // Avoid issuing a warning if both '--retain-symbol-file' and a version
318
+ // script with `global: *` are used.
319
+ //
320
+ // '--retain-symbol-file' adds a "*" pattern to
321
+ // 'config->versionDefinitions[VER_NDX_LOCAL].nonLocalPatterns', see
322
+ // 'readConfigs()' in 'Driver.cpp'. Note that it is not '.localPatterns',
323
+ // and may seem counterintuitive, but still works as expected. Here we can
324
+ // exploit that and skip analyzing the pattern added for this option.
325
+ if (!asteriskReported && (isLocal || ver->id > VER_NDX_LOCAL)) {
326
+ if ((isLocal && globalAsteriskFound) ||
327
+ (!isLocal && localAsteriskFound)) {
328
+ warn (" wildcard pattern '*' is used for both 'local' and 'global' "
329
+ " scopes in version script" );
330
+ asteriskReported = true ;
331
+ } else if (!isLocal && globalAsteriskFound) {
332
+ warn (" wildcard pattern '*' is used for multiple version definitions in "
333
+ " version script" );
334
+ asteriskReported = true ;
335
+ } else {
336
+ localAsteriskFound = isLocal;
337
+ globalAsteriskFound = !isLocal;
338
+ }
339
+ }
340
+ assignWildcard (pat, isLocal ? VER_NDX_LOCAL : ver->id , ver->name );
341
+ };
312
342
for (VersionDefinition &v : llvm::reverse (ctx.arg .versionDefinitions )) {
313
343
for (SymbolVersion &pat : v.nonLocalPatterns )
314
344
if (pat.hasWildcard && pat.name == " *" )
315
- assignWildcard (pat, v. id , v. name );
345
+ assignAsterisk (pat, &v, false );
316
346
for (SymbolVersion &pat : v.localPatterns )
317
347
if (pat.hasWildcard && pat.name == " *" )
318
- assignWildcard (pat, VER_NDX_LOCAL, v. name );
348
+ assignAsterisk (pat, &v, true );
319
349
}
320
350
321
351
// Symbol themselves might know their versions because symbols
0 commit comments