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

llvm-svn: 260271
This commit is contained in:
Pete Cooper 2016-02-09 20:11:17 +00:00
parent a951e8ece7
commit e8d9df4ea5
10 changed files with 30 additions and 5 deletions

View 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

View 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_;

View File

@ -255,6 +255,8 @@ public:
ReferenceInfo stubHelperReferenceToImm;
ReferenceInfo stubHelperReferenceToHelperCommon;
DefinedAtom::ContentType stubHelperImageCacheContentType;
uint32_t stubHelperCommonSize;
uint8_t stubHelperCommonAlignment;
uint8_t stubHelperCommonBytes[36];

View 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

View 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

View 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

View 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

View 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,

View 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(

View 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