X-Git-Url: https://git.saurik.com/apple/ld64.git/blobdiff_plain/a645023da60d22e86be13f7b4d97adeff8bc6665..7f09b9353af9897bf18933788d6a59c152c29edd:/src/ld/passes/stubs/stub_x86_64.hpp?ds=sidebyside diff --git a/src/ld/passes/stubs/stub_x86_64.hpp b/src/ld/passes/stubs/stub_x86_64.hpp index e74b37d..5031dbc 100644 --- a/src/ld/passes/stubs/stub_x86_64.hpp +++ b/src/ld/passes/stubs/stub_x86_64.hpp @@ -1,6 +1,6 @@ /* -*- mode: C++; c-basic-offset: 4; tab-width: 4 -*- * - * Copyright (c) 2009 Apple Inc. All rights reserved. + * Copyright (c) 2009-2012 Apple Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -39,8 +39,6 @@ public: { pass.addAtom(*this); } virtual const ld::File* file() const { return NULL; } - virtual bool translationUnitSource(const char** dir, const char** nm) const - { return false; } virtual const char* name() const { return "fast binder pointer"; } virtual uint64_t size() const { return 8; } virtual uint64_t objectAddress() const { return 0; } @@ -66,8 +64,6 @@ public: symbolTableNotIn, false, false, false, ld::Atom::Alignment(3)) { pass.addAtom(*this); } virtual const ld::File* file() const { return NULL; } - virtual bool translationUnitSource(const char** dir, const char** nm) const - { return false; } virtual const char* name() const { return "image cache pointer"; } virtual uint64_t size() const { return 8; } virtual uint64_t objectAddress() const { return 0; } @@ -101,8 +97,6 @@ public: { pass.addAtom(*this); } virtual ld::File* file() const { return NULL; } - virtual bool translationUnitSource(const char** dir, const char** nm) const - { return false; } virtual const char* name() const { return "helper helper"; } virtual uint64_t size() const { return 16; } virtual uint64_t objectAddress() const { return 0; } @@ -163,8 +157,6 @@ public: _fixup3(6, ld::Fixup::k1of1, ld::Fixup::kindStoreTargetAddressX86BranchPCRel32, helperHelper(pass)) { } virtual const ld::File* file() const { return _stubTo.file(); } - virtual bool translationUnitSource(const char** dir, const char** nm) const - { return false; } virtual const char* name() const { return _stubTo.name(); } virtual uint64_t size() const { return 10; } virtual uint64_t objectAddress() const { return 0; } @@ -215,8 +207,6 @@ public: _fixup3(32, ld::Fixup::k1of1, ld::Fixup::kindStoreTargetAddressX86PCRel32, lazyPointer) { } virtual const ld::File* file() const { return _stubTo.file(); } - virtual bool translationUnitSource(const char** dir, const char** nm) const - { return false; } virtual const char* name() const { return _stubTo.name(); } virtual uint64_t size() const { return 36; } virtual uint64_t objectAddress() const { return 0; } @@ -298,8 +288,6 @@ public: } virtual const ld::File* file() const { return _stubTo.file(); } - virtual bool translationUnitSource(const char** dir, const char** ) const - { return false; } virtual const char* name() const { return _stubTo.name(); } virtual uint64_t size() const { return 8; } virtual uint64_t objectAddress() const { return 0; } @@ -333,8 +321,6 @@ public: _fixup(2, ld::Fixup::k1of1, ld::Fixup::kindStoreTargetAddressX86PCRel32, &_lazyPointer) { pass.addAtom(*this); } virtual const ld::File* file() const { return _stubTo.file(); } - virtual bool translationUnitSource(const char** dir, const char** ) const - { return false; } virtual const char* name() const { return _stubTo.name(); } virtual uint64_t size() const { return 6; } virtual uint64_t objectAddress() const { return 0; } @@ -362,5 +348,74 @@ ld::Section StubAtom::_s_section("__TEXT", "__stubs", ld::Section::typeStub); + +class NonLazyPointerAtom : public ld::Atom { +public: + NonLazyPointerAtom(ld::passes::stubs::Pass& pass, const ld::Atom& stubTo) + : ld::Atom(_s_section, ld::Atom::definitionRegular, + ld::Atom::combineNever, ld::Atom::scopeLinkageUnit, ld::Atom::typeNonLazyPointer, + symbolTableNotIn, false, false, false, ld::Atom::Alignment(3)), + _stubTo(stubTo), + _fixup1(0, ld::Fixup::k1of1, ld::Fixup::kindStoreTargetAddressLittleEndian64, &stubTo) { + pass.addAtom(*this); + } + + virtual const ld::File* file() const { return _stubTo.file(); } + virtual const char* name() const { return _stubTo.name(); } + virtual uint64_t size() const { return 8; } + virtual uint64_t objectAddress() const { return 0; } + virtual void copyRawContent(uint8_t buffer[]) const { } + virtual void setScope(Scope) { } + virtual ld::Fixup::iterator fixupsBegin() const { return (ld::Fixup*)&_fixup1; } + virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup1)[1]; } + +private: + const ld::Atom& _stubTo; + ld::Fixup _fixup1; + + static ld::Section _s_section; +}; + +ld::Section NonLazyPointerAtom::_s_section("__DATA", "__got", ld::Section::typeNonLazyPointer); + + + +class KextStubAtom : public ld::Atom { +public: + KextStubAtom(ld::passes::stubs::Pass& pass, const ld::Atom& stubTo) + : ld::Atom(_s_section, ld::Atom::definitionRegular, ld::Atom::combineNever, + ld::Atom::scopeLinkageUnit, ld::Atom::typeStub, + symbolTableNotIn, false, false, false, ld::Atom::Alignment(1)), + _stubTo(stubTo), + _nonLazyPointer(pass, stubTo), + _fixup(2, ld::Fixup::k1of1, ld::Fixup::kindStoreTargetAddressX86PCRel32, &_nonLazyPointer) { pass.addAtom(*this); } + + virtual const ld::File* file() const { return _stubTo.file(); } + virtual const char* name() const { return _stubTo.name(); } + virtual uint64_t size() const { return 6; } + virtual uint64_t objectAddress() const { return 0; } + virtual void copyRawContent(uint8_t buffer[]) const { + buffer[0] = 0xFF; // jmp *foo$non_lazy_pointer(%rip) + buffer[1] = 0x25; + buffer[2] = 0x00; + buffer[3] = 0x00; + buffer[4] = 0x00; + buffer[5] = 0x00; + } + virtual void setScope(Scope) { } + virtual ld::Fixup::iterator fixupsBegin() const { return &_fixup; } + virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup)[1]; } + +private: + const ld::Atom& _stubTo; + NonLazyPointerAtom _nonLazyPointer; + mutable ld::Fixup _fixup; + + static ld::Section _s_section; +}; + +ld::Section KextStubAtom::_s_section("__TEXT", "__stubs", ld::Section::typeStub); + + } // namespace x86_64