[lld] [lld][elf] Warn if '*' pattern is used multiple times in version scripts (PR #102669)

Igor Kudrin via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 18 20:21:53 PDT 2024


================
@@ -309,13 +309,43 @@ void SymbolTable::scanVersionScript() {
 
   // Then, assign versions to "*". In GNU linkers they have lower priority than
   // other wildcards.
+  bool globalAsteriskFound = false;
+  bool localAsteriskFound = false;
+  bool asteriskReported = false;
+  auto assignAsterisk = [&](SymbolVersion &pat, VersionDefinition *ver,
+                            bool isLocal) {
+    // Avoid issuing a warning if both '--retain-symbol-file' and a version
+    // script with `global: *` are used.
+    //
+    // '--retain-symbol-file' adds a "*" pattern to
+    // 'config->versionDefinitions[VER_NDX_LOCAL].nonLocalPatterns', see
+    // 'readConfigs()' in 'Driver.cpp'. Note that it is not '.localPatterns',
+    // and may seem counterintuitive, but still works as expected. Here we can
+    // exploit that and skip analyzing the pattern added for this option.
+    if (!asteriskReported && (isLocal || ver->id > VER_NDX_LOCAL)) {
+      if ((isLocal && globalAsteriskFound) ||
+          (!isLocal && localAsteriskFound)) {
+        warn("wildcard pattern '*' is used for both 'local' and 'global' "
+             "scopes in version script");
+        asteriskReported = true;
+      } else if (!isLocal && globalAsteriskFound) {
+        warn("wildcard pattern '*' is used for multiple version definitions in "
+             "version script");
+        asteriskReported = true;
+      } else {
+        localAsteriskFound = isLocal;
+        globalAsteriskFound = !isLocal;
+      }
+    }
+    assignWildcard(pat, isLocal ? VER_NDX_LOCAL : ver->id, ver->name);
----------------
igorkudrin wrote:

Fixed in #112323, thanks.

https://github.com/llvm/llvm-project/pull/102669


More information about the llvm-commits mailing list