[lld] r248217 - [LLD][MachO] Fix a FIXME: Subtract base address from atom address when building

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 21 15:06:03 PDT 2015


Author: lhames
Date: Mon Sep 21 17:06:02 2015
New Revision: 248217

URL: http://llvm.org/viewvc/llvm-project?rev=248217&view=rev
Log:
[LLD][MachO] Fix a FIXME: Subtract base address from atom address when building
export trie.

Added:
    lld/trunk/test/mach-o/executable-exports.yaml
      - copied, changed from r248205, lld/trunk/test/mach-o/dylib-exports.yaml
Removed:
    lld/trunk/test/mach-o/dylib-exports.yaml
Modified:
    lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp
    lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp

Modified: lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp?rev=248217&r1=248216&r2=248217&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp Mon Sep 21 17:06:02 2015
@@ -195,6 +195,9 @@ void MachOLinkingContext::configure(Head
       _pageZeroSize = 0x1000;
     }
 
+    // Initial base address is __PAGEZERO size.
+    _baseAddress = _pageZeroSize;
+
     // Make PIE by default when targetting newer OSs.
     switch (os) {
       case OS::macOSX:

Modified: lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp?rev=248217&r1=248216&r2=248217&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp Mon Sep 21 17:06:02 2015
@@ -1162,7 +1162,7 @@ void Util::addExportInfo(const lld::File
       }
       Export exprt;
       exprt.name = atom->name();
-      exprt.offset = _atomToAddress[atom];   // FIXME: subtract base address
+      exprt.offset = _atomToAddress[atom] - _ctx.baseAddress();
       exprt.kind = EXPORT_SYMBOL_FLAGS_KIND_REGULAR;
       if (atom->merge() == DefinedAtom::mergeAsWeak)
         exprt.flags = EXPORT_SYMBOL_FLAGS_WEAK_DEFINITION;

Removed: lld/trunk/test/mach-o/dylib-exports.yaml
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/mach-o/dylib-exports.yaml?rev=248216&view=auto
==============================================================================
--- lld/trunk/test/mach-o/dylib-exports.yaml (original)
+++ lld/trunk/test/mach-o/dylib-exports.yaml (removed)
@@ -1,41 +0,0 @@
-# RUN: lld -flavor darwin -arch x86_64 -macosx_version_min 10.8 -dylib \
-# RUN:      %s %p/Inputs/libSystem.yaml -o %t  && \
-# RUN: llvm-objdump -exports-trie %t | FileCheck %s
-#
-#
-# Tests that exports trie builds properly.
-#
-
---- !mach-o
-arch:            x86_64
-file-type:       MH_OBJECT
-flags:           [ MH_SUBSECTIONS_VIA_SYMBOLS ]
-sections:
-  - segment:         __TEXT
-    section:         __text
-    type:            S_REGULAR
-    attributes:      [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ]
-    address:         0x0000000000000000
-    content:         [ 0xC3, 0xC3, 0xC3 ]
-global-symbols:
-  - name:            _myHidden
-    type:            N_SECT
-    scope:           [ N_EXT, N_PEXT ]
-    sect:            1
-    value:           0x0000000000000000
-  - name:            _myRegular
-    type:            N_SECT
-    scope:           [ N_EXT ]
-    sect:            1
-    value:           0x0000000000000001
-  - name:            _myWeak
-    type:            N_SECT
-    scope:           [ N_EXT ]
-    sect:            1
-    desc:            [ N_WEAK_DEF ]
-    value:           0x0000000000000002
-...
-
-# CHECK-NOT:  _myHidden
-# CHECK:      _myRegular
-# CHECK:      _myWeak [weak_def]

Copied: lld/trunk/test/mach-o/executable-exports.yaml (from r248205, lld/trunk/test/mach-o/dylib-exports.yaml)
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/mach-o/executable-exports.yaml?p2=lld/trunk/test/mach-o/executable-exports.yaml&p1=lld/trunk/test/mach-o/dylib-exports.yaml&r1=248205&r2=248217&rev=248217&view=diff
==============================================================================
--- lld/trunk/test/mach-o/dylib-exports.yaml (original)
+++ lld/trunk/test/mach-o/executable-exports.yaml Mon Sep 21 17:06:02 2015
@@ -1,4 +1,4 @@
-# RUN: lld -flavor darwin -arch x86_64 -macosx_version_min 10.8 -dylib \
+# RUN: lld -flavor darwin -arch x86_64 -macosx_version_min 10.8 \
 # RUN:      %s %p/Inputs/libSystem.yaml -o %t  && \
 # RUN: llvm-objdump -exports-trie %t | FileCheck %s
 #
@@ -16,7 +16,7 @@ sections:
     type:            S_REGULAR
     attributes:      [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ]
     address:         0x0000000000000000
-    content:         [ 0xC3, 0xC3, 0xC3 ]
+    content:         [ 0xC3, 0xC3, 0xC3, 0xC3 ]
 global-symbols:
   - name:            _myHidden
     type:            N_SECT
@@ -34,8 +34,13 @@ global-symbols:
     sect:            1
     desc:            [ N_WEAK_DEF ]
     value:           0x0000000000000002
+  - name:            _main
+    type:            N_SECT
+    scope:           [ N_EXT ]
+    sect:            1
+    value:           0x0000000000000003
 ...
 
 # CHECK-NOT:  _myHidden
-# CHECK:      _myRegular
-# CHECK:      _myWeak [weak_def]
+# CHECK:      0x00000FFD  _myRegular
+# CHECK:      0x00000FFE  _myWeak [weak_def]




More information about the llvm-commits mailing list