diff options
| author | Nick Kledzik <kledzik@apple.com> | 2014-08-13 23:31:07 +0000 |
|---|---|---|
| committer | Nick Kledzik <kledzik@apple.com> | 2014-08-13 23:31:07 +0000 |
| commit | ebf09360ec66ed380f491774461aa94cfeb51c8e (patch) | |
| tree | 4bb9b3ccceec20f0742067a6aeb21cc5d6297019 | |
| parent | 9b1e0a83b1daae262884c075d282c8e03047b3f1 (diff) | |
| download | bcm5719-llvm-ebf09360ec66ed380f491774461aa94cfeb51c8e.tar.gz bcm5719-llvm-ebf09360ec66ed380f491774461aa94cfeb51c8e.zip | |
[mach-o] Fix stub generation to work for dylibs and bundles
Split up the CRuntimeFile into one part for output types that need an entry
point and another part for output types that use stubs.
Add file 'test/mach-o/Inputs/libSystem.yaml' for use by test cases that
use -dylib and therefore may now need the helper symbol in libSystem.dylib.
llvm-svn: 215602
| -rw-r--r-- | lld/lib/ReaderWriter/MachO/ExecutableAtoms.hpp | 42 | ||||
| -rw-r--r-- | lld/lib/ReaderWriter/MachO/WriterMachO.cpp | 11 | ||||
| -rw-r--r-- | lld/test/mach-o/Inputs/libSystem.yaml | 13 | ||||
| -rw-r--r-- | lld/test/mach-o/arm-interworking-movw.yaml | 4 | ||||
| -rw-r--r-- | lld/test/mach-o/arm-interworking.yaml | 3 | ||||
| -rw-r--r-- | lld/test/mach-o/dylib-install-names.yaml | 9 | ||||
| -rw-r--r-- | lld/test/mach-o/sectalign.yaml | 3 |
7 files changed, 59 insertions, 26 deletions
diff --git a/lld/lib/ReaderWriter/MachO/ExecutableAtoms.hpp b/lld/lib/ReaderWriter/MachO/ExecutableAtoms.hpp index e12b881047c..f0788fa3da1 100644 --- a/lld/lib/ReaderWriter/MachO/ExecutableAtoms.hpp +++ b/lld/lib/ReaderWriter/MachO/ExecutableAtoms.hpp @@ -25,30 +25,42 @@ namespace mach_o { // -// CRuntimeFile adds an UndefinedAtom for "_main" so that the Resolving +// CEntryFile adds an UndefinedAtom for "_main" so that the Resolving // phase will fail if "_main" is undefined. // -class CRuntimeFile : public SimpleFile { +class CEntryFile : public SimpleFile { public: - CRuntimeFile(const MachOLinkingContext &context) - : SimpleFile("C runtime"), - _undefMain(*this, context.entrySymbolName()), - _undefBinder(*this, context.binderSymbolName()) { - // only main executables need _main - if (context.outputMachOType() == llvm::MachO::MH_EXECUTE) { - this->addAtom(_undefMain); - } - // only dynamic binaries use stubs - if (context.needsStubsPass()) { - this->addAtom(_undefBinder); - } - } + CEntryFile(const MachOLinkingContext &context) + : SimpleFile("C entry"), + _undefMain(*this, context.entrySymbolName()) { + this->addAtom(_undefMain); + } private: SimpleUndefinedAtom _undefMain; +}; + + +// +// StubHelperFile adds an UndefinedAtom for "dyld_stub_binder" so that +// the Resolveing phase will fail if "dyld_stub_binder" is undefined. +// +class StubHelperFile : public SimpleFile { +public: + StubHelperFile(const MachOLinkingContext &context) + : SimpleFile("stub runtime"), + _undefBinder(*this, context.binderSymbolName()) { + this->addAtom(_undefBinder); + } + +private: SimpleUndefinedAtom _undefBinder; }; + + + + } // namespace mach_o } // namespace lld diff --git a/lld/lib/ReaderWriter/MachO/WriterMachO.cpp b/lld/lib/ReaderWriter/MachO/WriterMachO.cpp index f76bfffbca9..17102df6349 100644 --- a/lld/lib/ReaderWriter/MachO/WriterMachO.cpp +++ b/lld/lib/ReaderWriter/MachO/WriterMachO.cpp @@ -46,10 +46,13 @@ public: } bool createImplicitFiles(std::vector<std::unique_ptr<File> > &r) override { - if (_context.outputMachOType() == llvm::MachO::MH_EXECUTE) { - // When building main executables, add _main as required entry point. - r.emplace_back(new CRuntimeFile(_context)); - } + // When building main executables, add _main as required entry point. + if (_context.outputTypeHasEntry()) + r.emplace_back(new CEntryFile(_context)); + // If this can link with dylibs, need helper function (dyld_stub_binder). + if (_context.needsStubsPass()) + r.emplace_back(new StubHelperFile(_context)); + return true; } private: diff --git a/lld/test/mach-o/Inputs/libSystem.yaml b/lld/test/mach-o/Inputs/libSystem.yaml new file mode 100644 index 00000000000..2a7f46381dc --- /dev/null +++ b/lld/test/mach-o/Inputs/libSystem.yaml @@ -0,0 +1,13 @@ +# +# For use by test cases that create dynamic output types which may needs stubs +# and therefore will need a dylib definition of dyld_stub_binder. +# + +--- +shared-library-atoms: + - name: dyld_stub_binder + load-name: /usr/lib/libSystem.B.dylib + type: code + size: 0 + +... diff --git a/lld/test/mach-o/arm-interworking-movw.yaml b/lld/test/mach-o/arm-interworking-movw.yaml index d291513df0f..1d61b6257f3 100644 --- a/lld/test/mach-o/arm-interworking-movw.yaml +++ b/lld/test/mach-o/arm-interworking-movw.yaml @@ -1,7 +1,7 @@ # REQUIRES: arm # RUN: lld -flavor darwin -arch armv7 -r -print_atoms %s -o %t | FileCheck %s \ -# RUN: && lld -flavor darwin -arch armv7 -dylib -print_atoms \ -# RUN: -sectalign __TEXT __text 0x1000 %t -o %t2 | FileCheck %s \ +# RUN: && lld -flavor darwin -arch armv7 -dylib -print_atoms %t -o %t2 \ +# RUN: %p/Inputs/libSystem.yaml -sectalign __TEXT __text 0x1000 | FileCheck %s \ # RUN: && llvm-objdump -d -macho -triple=armv7-apple-ios %t2 | FileCheck -check-prefix=ACODE %s \ # RUN: && llvm-objdump -d -macho -triple=thumbv7-apple-ios %t2 | FileCheck -check-prefix=TCODE %s # diff --git a/lld/test/mach-o/arm-interworking.yaml b/lld/test/mach-o/arm-interworking.yaml index 59e311f91b2..156c5ff8d2a 100644 --- a/lld/test/mach-o/arm-interworking.yaml +++ b/lld/test/mach-o/arm-interworking.yaml @@ -1,5 +1,6 @@ # RUN: lld -flavor darwin -arch armv7 -r -print_atoms %s -o %t | FileCheck %s \ -# RUN: && lld -flavor darwin -arch armv7 -dylib -print_atoms %t -o %t2 | FileCheck %s \ +# RUN: && lld -flavor darwin -arch armv7 -dylib -print_atoms \ +# RUN: %p/Inputs/libSystem.yaml %t -o %t2 | FileCheck %s \ # RUN: && macho-dump --dump-section-data %t2 | FileCheck -check-prefix=CODE %s # # Test thumb and arm branches round trip through -r. diff --git a/lld/test/mach-o/dylib-install-names.yaml b/lld/test/mach-o/dylib-install-names.yaml index 2ee361e59bc..cdfe59178d2 100644 --- a/lld/test/mach-o/dylib-install-names.yaml +++ b/lld/test/mach-o/dylib-install-names.yaml @@ -1,12 +1,15 @@ # Check we accept -install_name correctly: -# RUN: lld -flavor darwin -arch x86_64 -install_name libwibble.dylib -dylib %s -o %t.dylib +# RUN: lld -flavor darwin -arch x86_64 -install_name libwibble.dylib -dylib \ +# RUN: %p/Inputs/libSystem.yaml %s -o %t.dylib # RUN: macho-dump %t.dylib | FileCheck %s --check-prefix=CHECK-BINARY-WRITE # Check we read LC_ID_DYLIB correctly: -# RUN: lld -flavor darwin -arch x86_64 %p/Inputs/use-dylib-install-names.yaml %t.dylib -r -print_atoms | FileCheck %s --check-prefix=CHECK-BINARY-READ +# RUN: lld -flavor darwin -arch x86_64 %p/Inputs/use-dylib-install-names.yaml \ +# RUN: %t.dylib -r -print_atoms | FileCheck %s --check-prefix=CHECK-BINARY-READ # Check we default the install-name to the output file: -# RUN: lld -flavor darwin -arch x86_64 -dylib %s -o libwibble.dylib +# RUN: lld -flavor darwin -arch x86_64 -dylib %s -o libwibble.dylib \ +# RUN: %p/Inputs/libSystem.yaml # RUN: macho-dump libwibble.dylib | FileCheck %s --check-prefix=CHECK-BINARY-WRITE # RUN: rm -f libwibble.dylib diff --git a/lld/test/mach-o/sectalign.yaml b/lld/test/mach-o/sectalign.yaml index 7e2ad97ef4e..3556a5ecbcf 100644 --- a/lld/test/mach-o/sectalign.yaml +++ b/lld/test/mach-o/sectalign.yaml @@ -1,5 +1,6 @@ # RUN: lld -flavor darwin -arch x86_64 -macosx_version_min 10.8 %s -dylib \ -# RUN: -sectalign __DATA __custom 0x800 -sectalign __TEXT __text 0x400 -o %t \ +# RUN: -sectalign __DATA __custom 0x800 -sectalign __TEXT __text 0x400 \ +# RUN: %p/Inputs/libSystem.yaml -o %t \ # RUN: && llvm-readobj -sections %t | FileCheck %s # # Test -sectalign option on __text and a custom section. |

