From 2de2b37bffe2c6933059776506986e1e112036db Mon Sep 17 00:00:00 2001 From: Apple Date: Tue, 27 Mar 2007 05:59:27 +0000 Subject: [PATCH] dyld-46.12.tar.gz --- src/ImageLoaderMachO.cpp | 28 ++++++----- src/dyld.cpp | 4 -- src/dyldStartup.s | 2 +- src/glue.c | 12 +++++ unit-tests/test-cases/flat-prebound/bar.c | 4 ++ unit-tests/test-cases/flat-prebound/foo.c | 22 ++++++++- unit-tests/test-cases/flat-prebound/main.c | 15 +++--- .../test-cases/flat-private-extern/Makefile | 43 +++++++++++++++++ .../test-cases/flat-private-extern/bar.c | 29 +++++++++++ .../test-cases/flat-private-extern/foo.c | 29 +++++++++++ .../test-cases/flat-private-extern/main.c | 48 +++++++++++++++++++ 11 files changed, 212 insertions(+), 24 deletions(-) create mode 100644 unit-tests/test-cases/flat-private-extern/Makefile create mode 100644 unit-tests/test-cases/flat-private-extern/bar.c create mode 100644 unit-tests/test-cases/flat-private-extern/foo.c create mode 100644 unit-tests/test-cases/flat-private-extern/main.c diff --git a/src/ImageLoaderMachO.cpp b/src/ImageLoaderMachO.cpp index ed7c645..418805b 100644 --- a/src/ImageLoaderMachO.cpp +++ b/src/ImageLoaderMachO.cpp @@ -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; diff --git a/src/dyld.cpp b/src/dyld.cpp index 3fc6ac5..4d875e4 100644 --- a/src/dyld.cpp +++ b/src/dyld.cpp @@ -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 } } } diff --git a/src/dyldStartup.s b/src/dyldStartup.s index 6601cab..2afa8d4 100644 --- a/src/dyldStartup.s +++ b/src/dyldStartup.s @@ -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 diff --git a/src/glue.c b/src/glue.c index 1cd36ff..f44e198 100644 --- a/src/glue.c +++ b/src/glue.c @@ -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 diff --git a/unit-tests/test-cases/flat-prebound/bar.c b/unit-tests/test-cases/flat-prebound/bar.c index 4bf747a..e12bfce 100644 --- a/unit-tests/test-cases/flat-prebound/bar.c +++ b/unit-tests/test-cases/flat-prebound/bar.c @@ -21,8 +21,12 @@ * @APPLE_LICENSE_HEADER_END@ */ +#include int bar() { return 1; } + +int barVar = 1; +int barVar2 = 1; diff --git a/unit-tests/test-cases/flat-prebound/foo.c b/unit-tests/test-cases/flat-prebound/foo.c index 5f951e8..f47a91a 100644 --- a/unit-tests/test-cases/flat-prebound/foo.c +++ b/unit-tests/test-cases/flat-prebound/foo.c @@ -20,10 +20,28 @@ * * @APPLE_LICENSE_HEADER_END@ */ +#include 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; } diff --git a/unit-tests/test-cases/flat-prebound/main.c b/unit-tests/test-cases/flat-prebound/main.c index b43924f..54862f4 100644 --- a/unit-tests/test-cases/flat-prebound/main.c +++ b/unit-tests/test-cases/flat-prebound/main.c @@ -23,26 +23,29 @@ #include // fprintf(), NULL #include // exit(), EXIT_SUCCESS #include - +#include #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 index 0000000..c68be00 --- /dev/null +++ b/unit-tests/test-cases/flat-private-extern/Makefile @@ -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 index 0000000..0b13569 --- /dev/null +++ b/unit-tests/test-cases/flat-private-extern/bar.c @@ -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 index 0000000..ed6fc9b --- /dev/null +++ b/unit-tests/test-cases/flat-private-extern/foo.c @@ -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 index 0000000..6505066 --- /dev/null +++ b/unit-tests/test-cases/flat-private-extern/main.c @@ -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 // fprintf(), NULL +#include // exit(), EXIT_SUCCESS +#include + +#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; +} -- 2.45.2