[lld] r260271 - Use __nl_symbol_ptr instead of __got in the stubs pass on x86 archs.

Pete Cooper via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 9 12:11:18 PST 2016


Author: pete
Date: Tue Feb  9 14:11:17 2016
New Revision: 260271

URL: http://llvm.org/viewvc/llvm-project?rev=260271&view=rev
Log:
Use __nl_symbol_ptr instead of __got in the stubs pass on x86 archs.

The non lazy atoms generated in the stubs pass use an image cache to
hold all of the pointers.  On arm archs, this is the __got section,
but on x86 archs it should be __nl_symbol_ptr.

rdar://problem/24572729

Modified:
    lld/trunk/include/lld/Core/DefinedAtom.h
    lld/trunk/lib/Core/DefinedAtom.cpp
    lld/trunk/lib/ReaderWriter/MachO/ArchHandler.h
    lld/trunk/lib/ReaderWriter/MachO/ArchHandler_arm.cpp
    lld/trunk/lib/ReaderWriter/MachO/ArchHandler_arm64.cpp
    lld/trunk/lib/ReaderWriter/MachO/ArchHandler_x86.cpp
    lld/trunk/lib/ReaderWriter/MachO/ArchHandler_x86_64.cpp
    lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp
    lld/trunk/lib/ReaderWriter/MachO/StubsPass.cpp
    lld/trunk/test/mach-o/lazy-bind-x86_64.yaml

Modified: lld/trunk/include/lld/Core/DefinedAtom.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/DefinedAtom.h?rev=260271&r1=260270&r2=260271&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/DefinedAtom.h (original)
+++ lld/trunk/include/lld/Core/DefinedAtom.h Tue Feb  9 14:11:17 2016
@@ -129,6 +129,7 @@ public:
     typeObjC1Class,         // ObjC1 class [Darwin]
     typeLazyPointer,        // pointer through which a stub jumps
     typeLazyDylibPointer,   // pointer through which a stub jumps [Darwin]
+    typeNonLazyPointer,     // pointer to external symbol
     typeCFString,           // NS/CFString object [Darwin]
     typeGOT,                // pointer to external symbol
     typeInitializerPtr,     // pointer to initializer function

Modified: lld/trunk/lib/Core/DefinedAtom.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Core/DefinedAtom.cpp?rev=260271&r1=260270&r2=260271&view=diff
==============================================================================
--- lld/trunk/lib/Core/DefinedAtom.cpp (original)
+++ lld/trunk/lib/Core/DefinedAtom.cpp Tue Feb  9 14:11:17 2016
@@ -54,6 +54,7 @@ DefinedAtom::ContentPermissions DefinedA
   case typeObjC1Class:
   case typeLazyPointer:
   case typeLazyDylibPointer:
+  case typeNonLazyPointer:
   case typeThunkTLV:
   case typeRWNote:
     return permRW_;

Modified: lld/trunk/lib/ReaderWriter/MachO/ArchHandler.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/ArchHandler.h?rev=260271&r1=260270&r2=260271&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/ArchHandler.h (original)
+++ lld/trunk/lib/ReaderWriter/MachO/ArchHandler.h Tue Feb  9 14:11:17 2016
@@ -255,6 +255,8 @@ public:
     ReferenceInfo   stubHelperReferenceToImm;
     ReferenceInfo   stubHelperReferenceToHelperCommon;
 
+    DefinedAtom::ContentType stubHelperImageCacheContentType;
+
     uint32_t        stubHelperCommonSize;
     uint8_t         stubHelperCommonAlignment;
     uint8_t         stubHelperCommonBytes[36];

Modified: lld/trunk/lib/ReaderWriter/MachO/ArchHandler_arm.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/ArchHandler_arm.cpp?rev=260271&r1=260270&r2=260271&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/ArchHandler_arm.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/ArchHandler_arm.cpp Tue Feb  9 14:11:17 2016
@@ -260,6 +260,9 @@ const ArchHandler::StubInfo ArchHandler_
   { Reference::KindArch::ARM, lazyImmediateLocation, 8, 0 },
   { Reference::KindArch::ARM, arm_b24, 4, 0 },
 
+  // Stub helper image cache content type
+  DefinedAtom::typeGOT,
+
   // Stub Helper-Common size and code
   36,
   // Stub helper alignment

Modified: lld/trunk/lib/ReaderWriter/MachO/ArchHandler_arm64.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/ArchHandler_arm64.cpp?rev=260271&r1=260270&r2=260271&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/ArchHandler_arm64.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/ArchHandler_arm64.cpp Tue Feb  9 14:11:17 2016
@@ -283,6 +283,9 @@ const ArchHandler::StubInfo ArchHandler_
   { Reference::KindArch::AArch64, lazyImmediateLocation, 8, 0 },
   { Reference::KindArch::AArch64, branch26, 4, 0 },
 
+  // Stub helper image cache content type
+  DefinedAtom::typeGOT,
+
   // Stub Helper-Common size and code
   24,
   // Stub helper alignment

Modified: lld/trunk/lib/ReaderWriter/MachO/ArchHandler_x86.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/ArchHandler_x86.cpp?rev=260271&r1=260270&r2=260271&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/ArchHandler_x86.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/ArchHandler_x86.cpp Tue Feb  9 14:11:17 2016
@@ -216,6 +216,9 @@ const ArchHandler::StubInfo ArchHandler_
   { Reference::KindArch::x86, lazyImmediateLocation, 1, 0 },
   { Reference::KindArch::x86, branch32, 6, 0 },
 
+  // Stub helper image cache content type
+  DefinedAtom::typeNonLazyPointer,
+
   // Stub Helper-Common size and code
   12,
   // Stub helper alignment

Modified: lld/trunk/lib/ReaderWriter/MachO/ArchHandler_x86_64.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/ArchHandler_x86_64.cpp?rev=260271&r1=260270&r2=260271&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/ArchHandler_x86_64.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/ArchHandler_x86_64.cpp Tue Feb  9 14:11:17 2016
@@ -284,6 +284,9 @@ const ArchHandler::StubInfo ArchHandler_
   { Reference::KindArch::x86_64, lazyImmediateLocation, 1, 0 },
   { Reference::KindArch::x86_64, branch32, 6, 0 },
 
+  // Stub helper image cache content type
+  DefinedAtom::typeNonLazyPointer,
+
   // Stub Helper-Common size and code
   16,
   // Stub helper alignment

Modified: lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp?rev=260271&r1=260270&r2=260271&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp Tue Feb  9 14:11:17 2016
@@ -283,6 +283,8 @@ const MachOFinalSectionFromAtomType sect
                                                           typeTerminatorPtr),
   ENTRY("__DATA", "__got",            S_NON_LAZY_SYMBOL_POINTERS,
                                                           typeGOT),
+  ENTRY("__DATA", "__nl_symbol_ptr",  S_NON_LAZY_SYMBOL_POINTERS,
+                                                          typeNonLazyPointer),
   ENTRY("__DATA", "__thread_vars",    S_THREAD_LOCAL_VARIABLES,
                                                           typeThunkTLV),
   ENTRY("__DATA", "__thread_data",    S_THREAD_LOCAL_REGULAR,

Modified: lld/trunk/lib/ReaderWriter/MachO/StubsPass.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/StubsPass.cpp?rev=260271&r1=260270&r2=260271&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/StubsPass.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/StubsPass.cpp Tue Feb  9 14:11:17 2016
@@ -68,11 +68,11 @@ private:
 //
 class NonLazyPointerAtom : public SimpleDefinedAtom {
 public:
-  NonLazyPointerAtom(const File &file, bool is64)
-    : SimpleDefinedAtom(file), _is64(is64) { }
+  NonLazyPointerAtom(const File &file, bool is64, ContentType contentType)
+    : SimpleDefinedAtom(file), _is64(is64), _contentType(contentType) { }
 
   ContentType contentType() const override {
-    return DefinedAtom::typeGOT;
+    return _contentType;
   }
 
   Alignment alignment() const override {
@@ -95,6 +95,7 @@ public:
 
 private:
   const bool _is64;
+  const ContentType _contentType;
 };
 
 //
@@ -239,9 +240,11 @@ public:
     SimpleDefinedAtom *helperCommonAtom =
         new (_file.allocator()) StubHelperCommonAtom(_file, _stubInfo);
     SimpleDefinedAtom *helperCacheNLPAtom =
-        new (_file.allocator()) NonLazyPointerAtom(_file, _ctx.is64Bit());
+        new (_file.allocator()) NonLazyPointerAtom(_file, _ctx.is64Bit(),
+                                    _stubInfo.stubHelperImageCacheContentType);
     SimpleDefinedAtom *helperBinderNLPAtom =
-        new (_file.allocator()) NonLazyPointerAtom(_file, _ctx.is64Bit());
+        new (_file.allocator()) NonLazyPointerAtom(_file, _ctx.is64Bit(),
+                                    _stubInfo.stubHelperImageCacheContentType);
     addReference(helperCommonAtom, _stubInfo.stubHelperCommonReferenceToCache,
                  helperCacheNLPAtom);
     addOptReference(

Modified: lld/trunk/test/mach-o/lazy-bind-x86_64.yaml
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/mach-o/lazy-bind-x86_64.yaml?rev=260271&r1=260270&r2=260271&view=diff
==============================================================================
--- lld/trunk/test/mach-o/lazy-bind-x86_64.yaml (original)
+++ lld/trunk/test/mach-o/lazy-bind-x86_64.yaml Tue Feb  9 14:11:17 2016
@@ -91,6 +91,10 @@ undefined-symbols:
 # CHECK-DYLIBS-NEXT:     offset
 # CHECK-DYLIBS-NEXT:      align 2^2 (4)
 
+# Make sure the __nl_symbol_ptr section is used instea of __got as this is x86_64
+# CHECK-DYLIBS:   sectname __nl_symbol_ptr
+# CHECK-DYLIBS-NEXT:    segname __DATA
+
 # CHECK-DYLIBS:           cmd LC_LOAD_DYLIB
 # CHECK-DYLIBS:          name /usr/lib/libbar.dylib (offset 24)
 # CHECK-DYLIBS:       current version 2.3.0




More information about the llvm-commits mailing list