[PATCH] D93318: [lld/mac] Set ordinal on dynamic undefined symbols in symbol table

Nico Weber via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 15 10:40:29 PST 2020


thakis created this revision.
thakis added a reviewer: lld-macho.
thakis requested review of this revision.

This lets `nm -m` print "(from libfoo)" in its output, which is more
accessible than dumping the bind table.


https://reviews.llvm.org/D93318

Files:
  lld/MachO/SyntheticSections.cpp
  lld/test/MachO/dylink.s


Index: lld/test/MachO/dylink.s
===================================================================
--- lld/test/MachO/dylink.s
+++ lld/test/MachO/dylink.s
@@ -38,6 +38,12 @@
 # CHECK-DAG: __DATA       __data 0x{{0*}}[[#%x, DATA_ADDR + 8]]                       pointer 8   libhello   _hello_its_me
 # CHECK-DAG: __DATA       __data 0x{{0*}}[[#%x, DATA_ADDR + 16]]                      pointer -15 libgoodbye _goodbye_world
 
+# RUN: llvm-nm -m %t/dylink | FileCheck --check-prefix=NM %s
+
+# NM-DAG: _goodbye_world (from libgoodbye)
+# NM-DAG: _hello_its_me (from libhello)
+# NM-DAG: _hello_world (from libhello)
+
 # RUN: llvm-objdump --macho --all-headers %t/dylink | FileCheck %s \
 # RUN:   --check-prefix=LOAD --implicit-check-not LC_LOAD_DYLIB
 ## Check that we don't create duplicate LC_LOAD_DYLIBs.
Index: lld/MachO/SyntheticSections.cpp
===================================================================
--- lld/MachO/SyntheticSections.cpp
+++ lld/MachO/SyntheticSections.cpp
@@ -753,6 +753,10 @@
         nList->n_value = defined->getVA();
       }
       nList->n_desc |= defined->isWeakDef() ? MachO::N_WEAK_DEF : 0;
+    } else if (auto *dysym = dyn_cast<DylibSymbol>(entry.sym)) {
+      uint16_t n_desc = nList->n_desc;
+      MachO::SET_LIBRARY_ORDINAL(n_desc, dysym->file->ordinal);
+      nList->n_desc = n_desc;
     }
     ++nList;
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D93318.311963.patch
Type: text/x-patch
Size: 1359 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201215/7fe452fd/attachment.bin>


More information about the llvm-commits mailing list