Use __nl_symbol_ptr instead of __got in the stubs pass on x86 archs.
authorPete Cooper <peter_cooper@apple.com>
Tue, 9 Feb 2016 20:11:17 +0000 (20:11 +0000)
committerPete Cooper <peter_cooper@apple.com>
Tue, 9 Feb 2016 20:11:17 +0000 (20:11 +0000)
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

llvm-svn: 260271

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

index 56e94e7..8384475 100644 (file)
@@ -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
index 35596e6..09c52f8 100644 (file)
@@ -54,6 +54,7 @@ DefinedAtom::ContentPermissions DefinedAtom::permissions(ContentType type) {
   case typeObjC1Class:
   case typeLazyPointer:
   case typeLazyDylibPointer:
+  case typeNonLazyPointer:
   case typeThunkTLV:
   case typeRWNote:
     return permRW_;
index ed52fbc..379228f 100644 (file)
@@ -255,6 +255,8 @@ public:
     ReferenceInfo   stubHelperReferenceToImm;
     ReferenceInfo   stubHelperReferenceToHelperCommon;
 
+    DefinedAtom::ContentType stubHelperImageCacheContentType;
+
     uint32_t        stubHelperCommonSize;
     uint8_t         stubHelperCommonAlignment;
     uint8_t         stubHelperCommonBytes[36];
index 700f64a..45c696e 100644 (file)
@@ -260,6 +260,9 @@ const ArchHandler::StubInfo ArchHandler_arm::_sStubInfoArmPIC = {
   { 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
index 58daa67..af89e6d 100644 (file)
@@ -283,6 +283,9 @@ const ArchHandler::StubInfo ArchHandler_arm64::_sStubInfo = {
   { 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
index 273c785..15e1963 100644 (file)
@@ -216,6 +216,9 @@ const ArchHandler::StubInfo ArchHandler_x86::_sStubInfo = {
   { 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
index 9951ff9..d3dcbd1 100644 (file)
@@ -284,6 +284,9 @@ const ArchHandler::StubInfo ArchHandler_x86_64::_sStubInfo = {
   { 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
index b34f703..b412a6c 100644 (file)
@@ -283,6 +283,8 @@ const MachOFinalSectionFromAtomType sectsToAtomType[] = {
                                                           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,
index 88eaf30..2e78d5e 100644 (file)
@@ -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(
index 7252205..ee3e227 100644 (file)
@@ -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