[llvm-branch-commits] [lld] 601f0fb - [lld/mac] Set ordinal on dynamic undefined symbols in symbol table
Nico Weber via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Dec 15 11:45:00 PST 2020
Author: Nico Weber
Date: 2020-12-15T14:39:36-05:00
New Revision: 601f0fb8465b9a8a22015f959261c66ec98878a4
URL: https://github.com/llvm/llvm-project/commit/601f0fb8465b9a8a22015f959261c66ec98878a4
DIFF: https://github.com/llvm/llvm-project/commit/601f0fb8465b9a8a22015f959261c66ec98878a4.diff
LOG: [lld/mac] Set ordinal on dynamic undefined symbols in symbol table
This lets `nm -m` print "(from libfoo)" in its output, which is more
accessible than dumping the bind table.
See https://reviews.llvm.org/D57190#2455761 for the somewhat
surprising `AltEntry` that appears in symtab.s.
Differential Revision: https://reviews.llvm.org/D93318
Added:
Modified:
lld/MachO/SyntheticSections.cpp
lld/test/MachO/dylink.s
lld/test/MachO/symtab.s
Removed:
################################################################################
diff --git a/lld/MachO/SyntheticSections.cpp b/lld/MachO/SyntheticSections.cpp
index 808d3594bfad..c2c121005899 100644
--- a/lld/MachO/SyntheticSections.cpp
+++ b/lld/MachO/SyntheticSections.cpp
@@ -753,6 +753,10 @@ void SymtabSection::writeTo(uint8_t *buf) const {
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;
}
diff --git a/lld/test/MachO/dylink.s b/lld/test/MachO/dylink.s
index 2a8e19d966d6..a727b7539397 100644
--- a/lld/test/MachO/dylink.s
+++ b/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.
diff --git a/lld/test/MachO/symtab.s b/lld/test/MachO/symtab.s
index a4dce665acb4..2fe550a330f1 100644
--- a/lld/test/MachO/symtab.s
+++ b/lld/test/MachO/symtab.s
@@ -62,7 +62,7 @@
# CHECK-NEXT: Type: Undef (0x0)
# CHECK-NEXT: Section: (0x0)
# CHECK-NEXT: RefType: UndefinedNonLazy (0x0)
-# CHECK-NEXT: Flags [ (0x0)
+# CHECK-NEXT: Flags [ (0x100)
# CHECK-NEXT: ]
# CHECK-NEXT: Value: 0x0
# CHECK-NEXT: }
@@ -71,7 +71,8 @@
# CHECK-NEXT: Type: Undef (0x0)
# CHECK-NEXT: Section: (0x0)
# CHECK-NEXT: RefType: UndefinedNonLazy (0x0)
-# CHECK-NEXT: Flags [ (0x0)
+# CHECK-NEXT: Flags [ (0x200)
+# CHECK-NEXT: AltEntry (0x200)
# CHECK-NEXT: ]
# CHECK-NEXT: Value: 0x0
# CHECK-NEXT: }
More information about the llvm-branch-commits
mailing list