]> git.saurik.com Git - apple/dyld.git/commitdiff
dyld-46.12.tar.gz mac-os-x-10410ppc mac-os-x-10410x86 mac-os-x-1049ppc mac-os-x-1049x86 v46.12
authorApple <opensource@apple.com>
Tue, 27 Mar 2007 05:59:27 +0000 (05:59 +0000)
committerApple <opensource@apple.com>
Tue, 27 Mar 2007 05:59:27 +0000 (05:59 +0000)
src/ImageLoaderMachO.cpp
src/dyld.cpp
src/dyldStartup.s
src/glue.c
unit-tests/test-cases/flat-prebound/bar.c
unit-tests/test-cases/flat-prebound/foo.c
unit-tests/test-cases/flat-prebound/main.c
unit-tests/test-cases/flat-private-extern/Makefile [new file with mode: 0644]
unit-tests/test-cases/flat-private-extern/bar.c [new file with mode: 0644]
unit-tests/test-cases/flat-private-extern/foo.c [new file with mode: 0644]
unit-tests/test-cases/flat-private-extern/main.c [new file with mode: 0644]

index ed7c64569f7b762720077bd45f75422c7c89b71f..418805b30d8fafeaac958008fd0167c197698e99 100644 (file)
@@ -1397,12 +1397,16 @@ void ImageLoaderMachO::doRebase(const LinkContext& context)
                                                otherRelocsPPC(locationToFix, sreloc->r_type, reloc->r_address, slide);
                                                break;
                #endif
-               #if __ppc__ || __ppc64__
+               #if __ppc__ 
                                        case PPC_RELOC_PB_LA_PTR:
                                                // do nothing
                                                break;
-               #endif
-               #if __i386__
+               #elif __ppc64__
+                                       case PPC_RELOC_PB_LA_PTR:
+                                               // these should never exist in ppc64, but the first ld64 had a bug and created them
+                                               *locationToFix = sreloc->r_value + slide;
+                                               break;
+               #elif __i386__
                                        case GENERIC_RELOC_PB_LA_PTR:
                                                // do nothing
                                                break;
@@ -1752,6 +1756,12 @@ uintptr_t ImageLoaderMachO::resolveUndefined(const LinkContext& context, const s
 
        if ( context.bindFlat || !twoLevel ) {
                // flat lookup
+               if ( ((undefinedSymbol->n_type & N_PEXT) != 0) && ((undefinedSymbol->n_type & N_TYPE) == N_SECT) ) {
+                       // is a multi-module private_extern internal reference that the linker did not optimize away
+                       uintptr_t addr = undefinedSymbol->n_value + this->fSlide;
+                       *foundIn = this;
+                       return addr;
+               }
                const Symbol* sym;
                if ( context.flatExportFinder(symbolName, &sym, foundIn) )
                        return (*foundIn)->getExportedSymbolAddress(sym);
@@ -1762,13 +1772,6 @@ uintptr_t ImageLoaderMachO::resolveUndefined(const LinkContext& context, const s
                        if ( sym != NULL )
                                return (*foundIn)->getExportedSymbolAddress(sym);
                }
-               if ( ((undefinedSymbol->n_type & N_PEXT) != 0) || ((undefinedSymbol->n_type & N_TYPE) == N_SECT) ) {
-                       // could be a multi-module private_extern internal reference
-                       // the static linker squirrels away the target address in n_value
-                       uintptr_t addr = undefinedSymbol->n_value + this->fSlide;
-                       *foundIn = this;
-                       return addr;
-               }
                if ( (undefinedSymbol->n_desc & N_WEAK_REF) != 0 ) {
                        // definition can't be found anywhere
                        // if reference is weak_import, then it is ok, just return 0
@@ -2326,7 +2329,10 @@ void ImageLoaderMachO::setupLazyPointerHandler(const LinkContext& context)
 bool ImageLoaderMachO::usablePrebinding(const LinkContext& context) const
 {
        // if prebound and loaded at prebound address, and all libraries are same as when this was prebound, then no need to bind
-       if ( this->isPrebindable() && this->allDependentLibrariesAsWhenPreBound() && (this->getSlide() == 0) ) {
+       if ( this->isPrebindable() 
+               && (this->getSlide() == 0) 
+               && this->usesTwoLevelNameSpace()
+               && this->allDependentLibrariesAsWhenPreBound() ) {
                // allow environment variables to disable prebinding
                if ( context.bindFlat )
                        return false;
index 3fc6ac544ee081ba48018d514c4ad04e4e0cfaab..4d875e4896c3fbfa9b1a563d24fffdefa5b55298 100644 (file)
@@ -1054,7 +1054,6 @@ static bool fatFindRunsOnAllCPUs(cpu_type_t cpu, const fat_header* fh, uint64_t*
                                                return true;
                                        }
                                        break;
-#ifdef CPU_TYPE_X86_64
                                case CPU_TYPE_X86_64:
                                        if ( (cpu_subtype_t)OSSwapBigToHostInt32(archs[i].cpusubtype) == CPU_SUBTYPE_X86_64_ALL ) {
                                                *offset = OSSwapBigToHostInt32(archs[i].offset);
@@ -1062,7 +1061,6 @@ static bool fatFindRunsOnAllCPUs(cpu_type_t cpu, const fat_header* fh, uint64_t*
                                                return true;
                                        }
                                        break;
-#endif
                        }
                }
        }
@@ -1142,12 +1140,10 @@ bool isCompatibleMachO(const uint8_t* firstPage)
                                        if ( mh->cpusubtype == CPU_SUBTYPE_I386_ALL ) 
                                                return true;
                                        break;                                  
-#ifdef CPU_TYPE_X86_64
                                case CPU_TYPE_X86_64:
                                        if ( mh->cpusubtype == CPU_SUBTYPE_X86_64_ALL ) 
                                                return true;
                                        break;          
-#endif
                        }
                }
        }
index 6601cab606ea30ab1bd57009c3b689f0fd3fbc1c..2afa8d43e651a3592caa378e7a6a45006f97e3a2 100644 (file)
@@ -164,9 +164,9 @@ __dyld_start:
        addq    $16,%rsp        # remove the mh argument, and debugger end frame marker
        movq    $0,%rbp         # restore ebp back to zero
        jmp     *%rax           # jump to the entry point
-       
 #endif /* __x86_64__ */
 
+
 #if __ppc__ || __ppc64__
 #include <architecture/ppc/mode_independent_asm.h>
 
index 1cd36ff000934883883b15c2c24619a8231dea1c..f44e198d36cbf281040b9547f495a204d1ef1982 100644 (file)
@@ -132,6 +132,18 @@ struct tm* localtime(const time_t* t)
        return (struct tm*)NULL;
 }
 
+struct tm* localtime_r(const time_t* t, struct tm *result)
+{
+       return result;
+}
+
+time_t mktime(struct tm *timeptr)
+{
+       return 0;
+}
+
+
+
 
 /*
  * On ppc64, the C++ runtime references strftime & wcsftime, but they
index 4bf747a8ecd9f051cb42b99a3063738916932fa9..e12bfce1e134b6a966da21ebf7240be5a88ba47c 100644 (file)
  * @APPLE_LICENSE_HEADER_END@
  */
 
+#include <stdbool.h>
 
 int bar()
 {
        return 1;
 }
+
+int barVar  = 1;
+int barVar2 = 1;
index 5f951e814885573b4b09e713d3acf8e157671016..f47a91afe8af15a749390842bd0a1a75e5aeef21 100644 (file)
  * 
  * @APPLE_LICENSE_HEADER_END@
  */
+#include <stdbool.h>
 
 extern int bar();
+extern int barVar;
+extern int barVar2;
 
-int foo()
+int* myBarVar = &barVar;
+
+
+bool foo()
 {
-       return bar();
+       // test non-lazy pointer
+       if ( barVar2 != 0 )
+               return false;
+
+       // test external relocation
+       if ( *myBarVar != 0 )
+               return false;
+       
+       // test lazy pointer
+       if ( bar() != 0 )
+               return false;
+               
+       return true;
 }
index b43924f4e877e1f9eb6f0fc423507143dfc06531..54862f4acb689e14f5ce7ea0bf2a5f0a229db810 100644 (file)
 #include <stdio.h>  // fprintf(), NULL
 #include <stdlib.h> // exit(), EXIT_SUCCESS
 #include <dlfcn.h>
-
+#include <stdbool.h>
 #include "test.h" // PASS(), FAIL(), XPASS(), XFAIL()
 
 // foo() internally calls bar()
 // libfoo.dylib is build flat and prebound to libbar.dylib
 // but the bar in this main executable should override the prebound bar
-
-extern int foo();
+extern bool foo();
 
 int main()
 {
-       if ( foo() != 0 )
-               FAIL("flat-prebound found wrong bar");
-       else
+       if ( foo() )
                PASS("flat-prebound");
+       else
+               FAIL("flat-prebound found wrong bar");
 
        return EXIT_SUCCESS;
 }
 
+
 int bar()
 {
        return 0;
 }
+int barVar = 0;
+int barVar2 = 0;
+
diff --git a/unit-tests/test-cases/flat-private-extern/Makefile b/unit-tests/test-cases/flat-private-extern/Makefile
new file mode 100644 (file)
index 0000000..c68be00
--- /dev/null
@@ -0,0 +1,43 @@
+##
+# Copyright (c) 2006 Apple Computer, Inc. All rights reserved.
+#
+# @APPLE_LICENSE_HEADER_START@
+# 
+# This file contains Original Code and/or Modifications of Original Code
+# as defined in and that are subject to the Apple Public Source License
+# Version 2.0 (the 'License'). You may not use this file except in
+# compliance with the License. Please obtain a copy of the License at
+# http://www.opensource.apple.com/apsl/ and read it before using this
+# file.
+# 
+# The Original Code and all software distributed under the License are
+# distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+# EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+# INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+# Please see the License for the specific language governing rights and
+# limitations under the License.
+# 
+# @APPLE_LICENSE_HEADER_END@
+##
+TESTROOT = ../..
+include ${TESTROOT}/include/common.makefile
+
+run: all
+       ./main
+
+all: main 
+
+main : main.c libfoobar.dylib
+       ${CC} ${CCFLAGS} -I${TESTROOT}/include -o main main.c libfoobar.dylib 
+
+
+libfoobar.dylib : foo.c bar.c
+       ${CC} ${CCFLAGS} -dynamiclib foo.c bar.c -o libfoobar.dylib -flat_namespace 
+
+
+
+
+clean:
+       ${RM} ${RMFLAGS} *~ main libfoobar.dylib
+
diff --git a/unit-tests/test-cases/flat-private-extern/bar.c b/unit-tests/test-cases/flat-private-extern/bar.c
new file mode 100644 (file)
index 0000000..0b13569
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2006 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ * 
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ * 
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ * 
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+int bar() __attribute__((visibility("hidden")));
+
+int bar()
+{
+       return 1;
+}
diff --git a/unit-tests/test-cases/flat-private-extern/foo.c b/unit-tests/test-cases/flat-private-extern/foo.c
new file mode 100644 (file)
index 0000000..ed6fc9b
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2006 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ * 
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ * 
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ * 
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+extern int bar();
+
+int foo()
+{
+       return bar();
+}
diff --git a/unit-tests/test-cases/flat-private-extern/main.c b/unit-tests/test-cases/flat-private-extern/main.c
new file mode 100644 (file)
index 0000000..6505066
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ * 
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ * 
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ * 
+ * @APPLE_LICENSE_HEADER_END@
+ */
+#include <stdio.h>  // fprintf(), NULL
+#include <stdlib.h> // exit(), EXIT_SUCCESS
+#include <dlfcn.h>
+
+#include "test.h" // PASS(), FAIL(), XPASS(), XFAIL()
+
+// foo() internally calls bar()
+// libfoobar.dylib is build flat with bar() that is private_extern
+// The bar() in the main executable should not override the one in libfoobar
+
+extern int foo();
+
+int main()
+{
+       if ( foo() == 0 )
+               FAIL("flat-private-extern found wrong bar");
+       else
+               PASS("flat-private-extern");
+
+       return EXIT_SUCCESS;
+}
+
+int bar()
+{
+       return 0;
+}