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;
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);
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
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;
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);
return true;
}
break;
-#endif
}
}
}
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
}
}
}
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>
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
* @APPLE_LICENSE_HEADER_END@
*/
+#include <stdbool.h>
int bar()
{
return 1;
}
+
+int barVar = 1;
+int barVar2 = 1;
*
* @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;
}
#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;
+
--- /dev/null
+##
+# 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
+
--- /dev/null
+/*
+ * 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;
+}
--- /dev/null
+/*
+ * 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();
+}
--- /dev/null
+/*
+ * 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;
+}