[lld] r215598 - [mach-o] set ordinal in n_desc for undefined symbols
Nick Kledzik
kledzik at apple.com
Wed Aug 13 16:11:43 PDT 2014
Author: kledzik
Date: Wed Aug 13 18:11:42 2014
New Revision: 215598
URL: http://llvm.org/viewvc/llvm-project?rev=215598&view=rev
Log:
[mach-o] set ordinal in n_desc for undefined symbols
Mach-o uses "two-level namespace" where each undefined symbols is associated
with a specific dylib. This means at runtime the loader (dyld) does need to
search all loaded dylibs for that symbol but rather just the one specified.
Now that llvm-nm -m prints out that info, properly set that info, and test
it in the hello world test cases.
Modified:
lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp
lld/trunk/test/mach-o/hello-world-armv6.yaml
lld/trunk/test/mach-o/hello-world-armv7.yaml
lld/trunk/test/mach-o/hello-world-x86.yaml
lld/trunk/test/mach-o/hello-world-x86_64.yaml
Modified: lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp?rev=215598&r1=215597&r2=215598&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp Wed Aug 13 18:11:42 2014
@@ -761,11 +761,16 @@ void Util::addSymbols(const lld::File &a
const uint32_t start = file.globalSymbols.size() + file.localSymbols.size();
for (AtomAndIndex &ai : undefs) {
Symbol sym;
+ uint16_t desc = 0;
+ if (!rMode) {
+ uint8_t ordinal = dylibOrdinal(dyn_cast<SharedLibraryAtom>(ai.atom));
+ llvm::MachO::SET_LIBRARY_ORDINAL(desc, ordinal);
+ }
sym.name = ai.atom->name();
sym.type = N_UNDF;
sym.scope = N_EXT;
sym.sect = 0;
- sym.desc = 0;
+ sym.desc = desc;
sym.value = 0;
_atomToSymbolIndex[ai.atom] = file.undefinedSymbols.size() + start;
file.undefinedSymbols.push_back(sym);
Modified: lld/trunk/test/mach-o/hello-world-armv6.yaml
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/mach-o/hello-world-armv6.yaml?rev=215598&r1=215597&r2=215598&view=diff
==============================================================================
--- lld/trunk/test/mach-o/hello-world-armv6.yaml (original)
+++ lld/trunk/test/mach-o/hello-world-armv6.yaml Wed Aug 13 18:11:42 2014
@@ -1,5 +1,5 @@
# RUN: lld -flavor darwin -arch armv6 -ios_version_min 7.0 %s -o %t && \
-# RUN: llvm-nm %t | FileCheck %s
+# RUN: llvm-nm -m %t | FileCheck %s
#
# Test that armv6 (arm) hello-world can be linked into a mach-o executable
#
@@ -85,6 +85,6 @@ global-symbols:
...
-# CHECK: {{[0-9a-f]+}} T _main
-# CHECK: U _printf
-# CHECK: U dyld_stub_binder
+# CHECK: {{[0-9a-f]+}} (__TEXT,__text) external _main
+# CHECK: (undefined) external _printf (from libSystem)
+# CHECK: (undefined) external dyld_stub_binder (from libSystem)
Modified: lld/trunk/test/mach-o/hello-world-armv7.yaml
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/mach-o/hello-world-armv7.yaml?rev=215598&r1=215597&r2=215598&view=diff
==============================================================================
--- lld/trunk/test/mach-o/hello-world-armv7.yaml (original)
+++ lld/trunk/test/mach-o/hello-world-armv7.yaml Wed Aug 13 18:11:42 2014
@@ -1,5 +1,5 @@
# RUN: lld -flavor darwin -arch armv7 -ios_version_min 7.0 %s -o %t && \
-# RUN: llvm-nm %t | FileCheck %s
+# RUN: llvm-nm -m -n %t | FileCheck %s
#
# Test that armv7 (thumb) hello-world can be linked into a mach-o executable
#
@@ -98,6 +98,6 @@ global-symbols:
...
-# CHECK: {{[0-9a-f]+}} T _main
-# CHECK: U _printf
-# CHECK: U dyld_stub_binder
+# CHECK: {{[0-9a-f]+}} (__TEXT,__text) external [Thumb] _main
+# CHECK: (undefined) external _printf (from libSystem)
+# CHECK: (undefined) external dyld_stub_binder (from libSystem)
Modified: lld/trunk/test/mach-o/hello-world-x86.yaml
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/mach-o/hello-world-x86.yaml?rev=215598&r1=215597&r2=215598&view=diff
==============================================================================
--- lld/trunk/test/mach-o/hello-world-x86.yaml (original)
+++ lld/trunk/test/mach-o/hello-world-x86.yaml Wed Aug 13 18:11:42 2014
@@ -1,5 +1,5 @@
# RUN: lld -flavor darwin -arch i386 -macosx_version_min 10.8 %s -o %t && \
-# RUN: llvm-nm %t | FileCheck %s
+# RUN: llvm-nm -m %t | FileCheck %s
#
# Test that i386 hello-world can be linked into a mach-o executable
#
@@ -83,6 +83,6 @@ global-symbols:
...
-# CHECK: {{[0-9a-f]+}} T _main
-# CHECK: U _printf
-# CHECK: U dyld_stub_binder
+# CHECK: {{[0-9a-f]+}} (__TEXT,__text) external _main
+# CHECK: (undefined) external _printf (from libSystem)
+# CHECK: (undefined) external dyld_stub_binder (from libSystem)
Modified: lld/trunk/test/mach-o/hello-world-x86_64.yaml
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/mach-o/hello-world-x86_64.yaml?rev=215598&r1=215597&r2=215598&view=diff
==============================================================================
--- lld/trunk/test/mach-o/hello-world-x86_64.yaml (original)
+++ lld/trunk/test/mach-o/hello-world-x86_64.yaml Wed Aug 13 18:11:42 2014
@@ -1,5 +1,5 @@
# RUN: lld -flavor darwin -arch x86_64 -macosx_version_min 10.8 %s -o %t && \
-# RUN: llvm-nm %t | FileCheck %s
+# RUN: llvm-nm -m -n %t | FileCheck %s
#
# Test that x86_64 hello-world can be linked into a mach-o executable
#
@@ -138,7 +138,7 @@ global-symbols:
...
-# CHECK: U ___stdoutp
-# CHECK: U _fprintf
-# CHECK: {{[0-9a-f]+}} T _main
-# CHECK: U dyld_stub_binder
+# CHECK: {{[0-9a-f]+}} (__TEXT,__text) external _main
+# CHECK: (undefined) external ___stdoutp (from libSystem)
+# CHECK: (undefined) external _fprintf (from libSystem)
+# CHECK: (undefined) external dyld_stub_binder (from libSystem)
More information about the llvm-commits
mailing list