[mach-o] Add support for parsing of weak-def symbols
authorNick Kledzik <kledzik@apple.com>
Wed, 28 May 2014 02:04:45 +0000 (02:04 +0000)
committerNick Kledzik <kledzik@apple.com>
Wed, 28 May 2014 02:04:45 +0000 (02:04 +0000)
llvm-svn: 209707

lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp
lld/test/mach-o/parse-data.yaml
lld/test/mach-o/parse-function.yaml

index 05180c8..4a8d4b7 100644 (file)
@@ -91,9 +91,11 @@ static void processSymbol(const NormalizedFile &normalizedFile, MachOFile &file,
     file.addZeroFillDefinedAtom(sym.name, atomScope(sym.scope), size, copyRefs);
   } else {
     ArrayRef<uint8_t> atomContent = section.content.slice(offset, size);
+    DefinedAtom::Merge m = DefinedAtom::mergeNo;
+    if (sym.desc & N_WEAK_DEF)
+      m = DefinedAtom::mergeAsWeak;
     file.addDefinedAtom(sym.name, atomScope(sym.scope),
-                        atomTypeFromSection(section), DefinedAtom::mergeNo,
-                        atomContent, copyRefs);
+                        atomTypeFromSection(section), m, atomContent, copyRefs);
   }
 }
 
index d280750..a854317 100644 (file)
@@ -26,19 +26,19 @@ sections:
     address:         0x0000000000000000
     content:         [ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
                        0x11, 0x12, 0x13, 0x14, 0x21, 0x22, 0x23, 0x24,
-                       0x31, 0x32, 0x33, 0x34 ]
+                       0x31, 0x32, 0x33, 0x34, 0x41, 0x42, 0x43, 0x44 ]
   - segment:         __DATA
     section:         __bss
     type:            S_ZEROFILL
     attributes:      [  ]
     alignment:       2
-    address:         0x0000000000000014
+    address:         0x0000000000000018
     size:            4
 local-symbols:
   - name:            _s1
     type:            N_SECT
     sect:            2
-    value:           0x0000000000000014
+    value:           0x0000000000000018
   - name:            _s2
     type:            N_SECT
     sect:            1
@@ -59,6 +59,12 @@ global-symbols:
     scope:           [ N_EXT ]
     sect:            1
     value:           0x000000000000000C
+  - name:            _cWeak
+    type:            N_SECT
+    scope:           [ N_EXT ]
+    sect:            1
+    desc:            [ N_WEAK_DEF ]
+    value:           0x0000000000000014
 ...
 
 # CHECK: defined-atoms:
@@ -79,5 +85,10 @@ global-symbols:
 # CHECK:     scope:           global
 # CHECK:     content:         [ 21, 22, 23, 24 ]
 
+# CHECK:   - name:            _cWeak
+# CHECK:     scope:           global
+# CHECK:     content:         [ 41, 42, 43, 44 ]
+# CHECK:     merge:           as-weak
+
 # CHECK:   - name:            _s2
 # CHECK:     content:         [ 31, 32, 33, 34 ]
index 729ae39..44eba84 100644 (file)
@@ -1,6 +1,6 @@
 # RUN: lld -flavor darwin -arch x86_64 -r -print_atoms %s -o %t  | FileCheck %s
 #
-# Test parsing of scope of functions.
+# Test parsing of mach-o functions.
 #
 
 --- !mach-o
@@ -16,29 +16,51 @@ sections:
     attributes:      [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ]
     alignment:       4
     address:         0x0000000000000000
-    content:         [ 0xC3, 0xC3, 0xC3 ]
+    content:         [ 0xC3, 0xC3, 0xC3, 0xC3, 0xC3 ]
 local-symbols:
   - name:            _myStatic
     type:            N_SECT
     sect:            1
-    value:           0x0000000000000002
+    value:           0x0000000000000005
 global-symbols:
   - name:            _myGlobal
     type:            N_SECT
     scope:           [ N_EXT ]
     sect:            1
     value:           0x0000000000000000
+  - name:            _myGlobalWeak
+    type:            N_SECT
+    scope:           [ N_EXT ]
+    sect:            1
+    desc:            [ N_WEAK_DEF ]
+    value:           0x0000000000000001
   - name:            _myHidden
     type:            N_SECT
     scope:           [ N_EXT, N_PEXT ]
     sect:            1
-    value:           0x0000000000000001
+    value:           0x0000000000000002
+  - name:            _myHiddenWeak
+    type:            N_SECT
+    scope:           [ N_EXT, N_PEXT ]
+    sect:            1
+    desc:            [ N_WEAK_DEF ]
+    value:           0x0000000000000003
 ...
 
 # CHECK:      name:   _myGlobal
 # CHECK:      scope:  global
+
+# CHECK:      name:   _myGlobalWeak
+# CHECK:      scope:  global
+# CHECK:      merge:  as-weak
+
 # CHECK:      name:   _myHidden
 # CHECK:      scope:  hidden
+
+# CHECK:      name:   _myHiddenWeak
+# CHECK:      scope:  hidden
+# CHECK:      merge:  as-weak
+
 # CHECK:      name:   _myStatic
 # CHECK-NOT:   scope:  global
 # CHECK-NOT:   scope:  hidden