[lld] r215602 - [mach-o] Fix stub generation to work for dylibs and bundles
Nick Kledzik
kledzik at apple.com
Wed Aug 13 16:31:07 PDT 2014
Author: kledzik
Date: Wed Aug 13 18:31:07 2014
New Revision: 215602
URL: http://llvm.org/viewvc/llvm-project?rev=215602&view=rev
Log:
[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.
Added:
lld/trunk/test/mach-o/Inputs/libSystem.yaml
Modified:
lld/trunk/lib/ReaderWriter/MachO/ExecutableAtoms.hpp
lld/trunk/lib/ReaderWriter/MachO/WriterMachO.cpp
lld/trunk/test/mach-o/arm-interworking-movw.yaml
lld/trunk/test/mach-o/arm-interworking.yaml
lld/trunk/test/mach-o/dylib-install-names.yaml
lld/trunk/test/mach-o/sectalign.yaml
Modified: lld/trunk/lib/ReaderWriter/MachO/ExecutableAtoms.hpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/ExecutableAtoms.hpp?rev=215602&r1=215601&r2=215602&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/ExecutableAtoms.hpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/ExecutableAtoms.hpp Wed Aug 13 18:31:07 2014
@@ -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
Modified: lld/trunk/lib/ReaderWriter/MachO/WriterMachO.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/WriterMachO.cpp?rev=215602&r1=215601&r2=215602&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/WriterMachO.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/WriterMachO.cpp Wed Aug 13 18:31:07 2014
@@ -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:
Added: lld/trunk/test/mach-o/Inputs/libSystem.yaml
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/mach-o/Inputs/libSystem.yaml?rev=215602&view=auto
==============================================================================
--- lld/trunk/test/mach-o/Inputs/libSystem.yaml (added)
+++ lld/trunk/test/mach-o/Inputs/libSystem.yaml Wed Aug 13 18:31:07 2014
@@ -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
+
+...
Modified: lld/trunk/test/mach-o/arm-interworking-movw.yaml
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/mach-o/arm-interworking-movw.yaml?rev=215602&r1=215601&r2=215602&view=diff
==============================================================================
--- lld/trunk/test/mach-o/arm-interworking-movw.yaml (original)
+++ lld/trunk/test/mach-o/arm-interworking-movw.yaml Wed Aug 13 18:31:07 2014
@@ -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
#
Modified: lld/trunk/test/mach-o/arm-interworking.yaml
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/mach-o/arm-interworking.yaml?rev=215602&r1=215601&r2=215602&view=diff
==============================================================================
--- lld/trunk/test/mach-o/arm-interworking.yaml (original)
+++ lld/trunk/test/mach-o/arm-interworking.yaml Wed Aug 13 18:31:07 2014
@@ -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.
Modified: lld/trunk/test/mach-o/dylib-install-names.yaml
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/mach-o/dylib-install-names.yaml?rev=215602&r1=215601&r2=215602&view=diff
==============================================================================
--- lld/trunk/test/mach-o/dylib-install-names.yaml (original)
+++ lld/trunk/test/mach-o/dylib-install-names.yaml Wed Aug 13 18:31:07 2014
@@ -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
Modified: lld/trunk/test/mach-o/sectalign.yaml
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/mach-o/sectalign.yaml?rev=215602&r1=215601&r2=215602&view=diff
==============================================================================
--- lld/trunk/test/mach-o/sectalign.yaml (original)
+++ lld/trunk/test/mach-o/sectalign.yaml Wed Aug 13 18:31:07 2014
@@ -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.
More information about the llvm-commits
mailing list