[lld/mac] Comment changes requested on https://reviews.llvm.org/D130725
authorNico Weber <thakis@chromium.org>
Fri, 29 Jul 2022 16:55:04 +0000 (12:55 -0400)
committerNico Weber <thakis@chromium.org>
Fri, 29 Jul 2022 16:55:48 +0000 (12:55 -0400)
No behavior change.

lld/MachO/InputFiles.cpp
lld/test/MachO/special-symbol-ld-previous.s

index 1befdf4..5bd15d6 100644 (file)
@@ -2108,9 +2108,14 @@ void DylibFile::handleLDPreviousSymbol(StringRef name, StringRef originalName) {
     auto *dylib = getSyntheticDylib(installName, newCurrentVersionForSymbol,
                                     newCompatibilityVersion);
 
-    // Just adding the symbol to the symtab works because dylibs contain their
-    // symbols in alphabetical order, guaranteeing $ld$ symbols to precede
-    // normal symbols.
+    // The tbd file usually contains the $ld$previous symbol for an old version,
+    // and then the symbol itself later, for newer deployment targets, like so:
+    //    symbols: [
+    //      '$ld$previous$/Another$$1$3.0$14.0$_zzz$',
+    //      _zzz,
+    //    ]
+    // Since the symbols are sorted, adding them to the symtab in the given
+    // order means the $ld$previous version of _zzz will prevail, as desired.
     dylib->symbols.push_back(symtab->addDylib(
         saver().save(symbolName), dylib, /*isWeakDef=*/false, /*isTlv=*/false));
     return;
index 8cdfb97..eb14316 100644 (file)
 
 ## The remaining cases test handling when a symbol name is part of $ld$previous.
 
-## Case 4: special symbol $ld$previous affects the install name / compatibility version
-## when the specified version 11.0.0 is within the affected range [3.0, 14.0) when a symbol
-## is part of $previous$ if and only if that named symbol is referenced.
-## That is, for $ld$previous$/NewName$$3.0$14.0$_symNam$, if _symNam is
-## referenced, it refers to dylib /NewName if the deployment target is
-## in [3.0, 14.0).
-
+## Case 4: special symbol $ld$previous affects the install name / compatibility version if and only if:
+##   * the specified version 11.0.0 is within the affected range [3.0, 14.0), and
+##   * the symbol name after $previous$ points to a referenced symbol
 # RUN: %lld -o %t/libfoo4_yes.dylib %t/libLDPreviousInstallName-Symbol.tbd %t/ref_ySyy.o -dylib -platform_version macos 11.0.0 11.0.0
 # RUN: llvm-otool -L %t/libfoo4_yes.dylib | FileCheck --check-prefix=CASE4-YES --implicit-check-not=/New %s
 # CASE4-YES: /Old (compatibility version 1.2.3, current version 1.2.3)