From 42109667d4b080bbc8091235c036ed418d369d13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20P=C3=B6chtrager?= Date: Sun, 15 Mar 2015 22:21:16 +0100 Subject: [PATCH] * linux ppc/ppc64 & arm/arm64/aarch64 port (compiles now - everything else is *untested*) other changes: * rename 'machochecker' to 'machocheck' * get rid of duplicate $CFLAGS * fix a typo in the ios toolchain README * package.sh: remove the autom4te.cache directory --- README.md | 20 +-- cctools/as/i386/Makefile.am | 2 +- cctools/as/write_object.c | 6 + cctools/configure.ac | 30 +++- cctools/include/foreign/arm | 1 + cctools/include/foreign/libkern/OSAtomic.h | 5 +- .../include/foreign/libkern/arm/OSByteOrder.h | 130 ++++++++++++++++++ .../foreign/libkern/arm/_OSByteOrder.h | 91 ++++++++++++ cctools/include/foreign/mach/arm | 1 + cctools/include/foreign/mach/ppc/vm_types.h | 9 +- cctools/include/foreign/ppc/_types.h | 17 ++- cctools/include/foreign/ppc/endian.h | 8 ++ cctools/include/stuff/bytesex.h | 5 + cctools/ld64/src/3rd/helper.c | 117 ++++++++++------ cctools/ld64/src/ld/InputFiles.cpp | 6 +- cctools/ld64/src/other/Makefile.am | 4 +- cctools/libstuff/bytesex.c | 5 + cctools/libstuff/macosx_deployment_target.c | 4 + cctools/libstuff/ofile.c | 5 + cctools/libstuff/swap_headers.c | 5 + package.sh | 1 + usage_examples/ios_toolchain/README | 2 +- 22 files changed, 408 insertions(+), 66 deletions(-) create mode 120000 cctools/include/foreign/arm create mode 100644 cctools/include/foreign/libkern/arm/OSByteOrder.h create mode 100644 cctools/include/foreign/libkern/arm/_OSByteOrder.h create mode 120000 cctools/include/foreign/mach/arm diff --git a/README.md b/README.md index 2c791b9..e68a12b 100644 --- a/README.md +++ b/README.md @@ -5,14 +5,18 @@ Originally ported by [cjacker](http://ios-toolchain-based-on-clang-for-linux.goo ## SUPPORTED HOSTS ## -Linux -FreeBSD -NetBSD -OpenBSD -DragonFlyBSD -Windows (Cygwin) -Mac OS X -iOS +** SUPPORTED OPERATING SYSTEMS: ** + +Linux, FreeBSD, NetBSD, OpenBSD, DragonFlyBSD, +Windows (Cygwin), Mac OS X and iOS + +** SUPPORTED HOST ARCHITECTURES: ** + +x86, x86_64 + +Untested, but compiles: + +arm, aarch64, ppc, ppc64 ## SUPPORTED TARGETS ## diff --git a/cctools/as/i386/Makefile.am b/cctools/as/i386/Makefile.am index 4be3a79..18be3aa 100644 --- a/cctools/as/i386/Makefile.am +++ b/cctools/as/i386/Makefile.am @@ -3,7 +3,7 @@ libexec_PROGRAMS = i386-as i386_as_LDADD = \ $(top_srcdir)/libstuff/libstuff.la -i386_as_CFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/include/foreign -I$(top_srcdir)/libstuff -I$(top_srcdir)/as $(WARNINGS) $(LTO_DEF) -DNeXT_MOD -DASLIBEXECDIR="\"$(ASLIBEXECDIR)/\"" -D__DARWIN_UNIX03 -DI386 -Di486 -Di586 -Di686 $(ENDIAN_FLAG) +i386_as_CFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/include/foreign -I$(top_srcdir)/libstuff -I$(top_srcdir)/as $(WARNINGS) $(LTO_DEF) -DNeXT_MOD -DASLIBEXECDIR="\"$(ASLIBEXECDIR)/\"" -D__DARWIN_UNIX03 -DI386 -Di486 -Di586 -Di686 -UPPC $(ENDIAN_FLAG) i386_as_SOURCES = ../app.c ../as.c ../atof-generic.c ../atof-ieee.c ../expr.c ../fixes.c ../flonum-const.c \ ../flonum-copy.c ../flonum-mult.c ../frags.c ../hash.c ../hex-value.c ../input-file.c \ diff --git a/cctools/as/write_object.c b/cctools/as/write_object.c index a751dae..ed4ca76 100644 --- a/cctools/as/write_object.c +++ b/cctools/as/write_object.c @@ -75,11 +75,17 @@ #define RELOC_PAIR SPARC_RELOC_PAIR #endif #if defined(M68K) || defined(I386) +#undef RELOC_SECTDIFF /* cctools-port: need to undef these to avoid warnings */ +#undef RELOC_LOCAL_SECTDIFF +#undef RELOC_PAIR #define RELOC_SECTDIFF GENERIC_RELOC_SECTDIFF #define RELOC_LOCAL_SECTDIFF GENERIC_RELOC_LOCAL_SECTDIFF #define RELOC_PAIR GENERIC_RELOC_PAIR #endif #ifdef ARM +#undef RELOC_SECTDIFF /* cctools-port: need to undef these to avoid warnings */ +#undef RELOC_LOCAL_SECTDIFF +#undef RELOC_PAIR #define RELOC_SECTDIFF ARM_RELOC_SECTDIFF #define RELOC_LOCAL_SECTDIFF ARM_RELOC_SECTDIFF #define RELOC_PAIR ARM_RELOC_PAIR diff --git a/cctools/configure.ac b/cctools/configure.ac index fcc9c39..2c1dc55 100644 --- a/cctools/configure.ac +++ b/cctools/configure.ac @@ -93,7 +93,7 @@ case "`$CC --version`" in WARNINGS="$WARNINGS -Wno-unused-but-set-variable -Wno-deprecated -Wno-deprecated-declarations" WARNINGS="$WARNINGS -Wno-char-subscripts -Wno-strict-aliasing" OBJCWARNINGS="-Wall" - CFLAGS="$CFLAGS -std=gnu99 $CFLAGS -D__private_extern__= " + CFLAGS="$CFLAGS -std=gnu99 -D__private_extern__=" CXXFLAGS="$CXXFLAGS -D__private_extern__=" ;; esac @@ -112,6 +112,21 @@ case "`$CXX --version`" in ;; esac +case $target_cpu in + powerpc) + EXTRAFLAGS="$EXTRAFLAGS -D__ppc__" + ;; + powerpc64*) + EXTRAFLAGS="$EXTRAFLAGS -D__ppc__ -D__ppc64__" + ;; + arm64*|aarch64) + EXTRAFLAGS="$EXTRAFLAGS -D__arm64__" + ;; + arm*) + EXTRAFLAGS="$EXTRAFLAGS -D__arm__" + ;; +esac + if test "x$EXTRAFLAGS" != "x"; then CFLAGS="$CFLAGS $EXTRAFLAGS" OBJCFLAGS="$OBJCFLAGS $EXTRAFLAGS" @@ -162,13 +177,14 @@ fi AC_CHECK_HEADERS([uuid/uuid.h], [], [AC_MSG_ERROR([*** uuid.h not found, please install uuid dev packages according to your system])]) + #for libstuff emulated.c case $target_cpu in powerpc) AC_DEFINE(EMULATED_HOST_CPU_TYPE, 18, [Emulated CPU type]) AC_DEFINE(EMULATED_HOST_CPU_SUBTYPE, 100, [Emulated CPU subtype]) ;; - powerpc64) + powerpc64*) AC_DEFINE(EMULATED_HOST_CPU_TYPE, 16777234, [Emulated CPU type]) AC_DEFINE(EMULATED_HOST_CPU_SUBTYPE, 0, [Emulated CPU subtype]) ;; @@ -180,7 +196,7 @@ case $target_cpu in AC_DEFINE(EMULATED_HOST_CPU_TYPE, 16777223, [Emulated CPU type]) AC_DEFINE(EMULATED_HOST_CPU_SUBTYPE, 3, [Emulated CPU subtype]) ;; - arm64*) + arm64*|aarch64) AC_DEFINE(EMULATED_HOST_CPU_TYPE, 16777228, [Emulated CPU type]) AC_DEFINE(EMULATED_HOST_CPU_SUBTYPE, 0, [Emulated CPU subtype]) ;; @@ -203,7 +219,7 @@ AC_SUBST([ASLIBEXECDIR], ['${libexecdir}/as']) # set PROGRAM PREFIX if test "$target_alias"; then -AC_SUBST([PROGRAM_PREFIX], ['${target_alias}-']) + AC_SUBST([PROGRAM_PREFIX], ['${target_alias}-']) fi AC_CHECK_LIB([dl],[dlopen],[DL_LIB=-ldl]) @@ -213,8 +229,8 @@ AC_CHECK_LIB([pthread],[pthread_create],[PTHREAD_FLAGS=-pthread]) AC_SUBST(PTHREAD_FLAGS) if test "x$isdarwin" = "xno"; then -AC_CHECK_LIB([uuid],[uuid_generate_random],[UUID_LIB=-luuid],[exit 1]) -AC_SUBST(UUID_LIB) + AC_CHECK_LIB([uuid],[uuid_generate_random],[UUID_LIB=-luuid],[exit 1]) + AC_SUBST(UUID_LIB) fi AC_CHECK_LIB([execinfo],[backtrace],[DL_LIB=-lexecinfo]) @@ -238,7 +254,7 @@ AC_SUBST(CXXABI_LIB) ORIGLDFLAGS=$LDFLAGS LDFLAGS="$LDFLAGS -Wl,-rpath,/usr/local/lib,--enable-new-dtags" -AC_MSG_CHECKING([if -Wl,-rpath,,--enable-new-dtags is supported]) +AC_MSG_CHECKING([if -Wl,-rptah,,--enable-new-dtags is supported]) AC_LINK_IFELSE( [AC_LANG_SOURCE([[int main(){}]])], [rpathlink=yes diff --git a/cctools/include/foreign/arm b/cctools/include/foreign/arm new file mode 120000 index 0000000..536b5a3 --- /dev/null +++ b/cctools/include/foreign/arm @@ -0,0 +1 @@ +i386/ \ No newline at end of file diff --git a/cctools/include/foreign/libkern/OSAtomic.h b/cctools/include/foreign/libkern/OSAtomic.h index 5624290..5b28da5 100644 --- a/cctools/include/foreign/libkern/OSAtomic.h +++ b/cctools/include/foreign/libkern/OSAtomic.h @@ -82,7 +82,8 @@ __inline static int32_t OSAtomicDecrement32Barrier( volatile int32_t *__theValue ) { return OSAtomicAdd32Barrier( -1, __theValue); } -#if defined(__ppc64__) || defined(__i386__) || defined(__x86_64__) || defined(__arm__) || defined(__arm64__) +/* cctools-port: added defined(__ppc__) || */ +#if defined(__ppc__) || defined(__ppc64__) || defined(__i386__) || defined(__x86_64__) || defined(__arm__) || defined(__arm64__) int64_t OSAtomicAdd64( int64_t __theAmount, volatile int64_t *__theValue ); int64_t OSAtomicAdd64Barrier( int64_t __theAmount, volatile int64_t *__theValue ); @@ -101,7 +102,7 @@ __inline static int64_t OSAtomicDecrement64Barrier( volatile int64_t *__theValue ) { return OSAtomicAdd64Barrier( -1, __theValue); } -#endif /* defined(__ppc64__) || defined(__i386__) || defined(__x86_64__) || defined(__arm__) || defined(__arm64__) */ +#endif /* defined(__ppc__) || defined(__ppc64__) || defined(__i386__) || defined(__x86_64__) || defined(__arm__) || defined(__arm64__) */ /* Boolean functions (and, or, xor.) These come in four versions for each operation: diff --git a/cctools/include/foreign/libkern/arm/OSByteOrder.h b/cctools/include/foreign/libkern/arm/OSByteOrder.h new file mode 100644 index 0000000..fb49739 --- /dev/null +++ b/cctools/include/foreign/libkern/arm/OSByteOrder.h @@ -0,0 +1,130 @@ +#ifndef _OS_OSBYTEORDERARM_H +#define _OS_OSBYTEORDERARM_H + +#include + +#ifndef OS_INLINE +#define OS_INLINE static __inline__ +#endif + +OS_INLINE +uint16_t _OSSwapInt16(uint16_t data) +{ + return __builtin_bswap16(data); +} + +OS_INLINE +uint32_t _OSSwapInt32(uint32_t data) +{ + return __builtin_bswap32(data); +} + +OS_INLINE +uint64_t _OSSwapInt64(uint64_t data) +{ + return __builtin_bswap64(data); +} + +/* + * Copyright (c) 1999-2006 Apple Computer, Inc. All rights reserved. + * + * @APPLE_OSREFERENCE_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. The rights granted to you under the License + * may not be used to create, or enable the creation or redistribution of, + * unlawful or unlicensed copies of an Apple operating system, or to + * circumvent, violate, or enable the circumvention or violation of, any + * terms of an Apple operating system software license agreement. + * + * 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_OSREFERENCE_LICENSE_HEADER_END@ + */ + +OS_INLINE +uint16_t +OSReadSwapInt16( + const volatile void * base, + uintptr_t byteOffset +) +{ + uint16_t result; + + result = *(volatile uint16_t *)((uintptr_t)base + byteOffset); + return _OSSwapInt16(result); +} + +OS_INLINE +uint32_t +OSReadSwapInt32( + const volatile void * base, + uintptr_t byteOffset +) +{ + uint32_t result; + + result = *(volatile uint32_t *)((uintptr_t)base + byteOffset); + return _OSSwapInt32(result); +} + +OS_INLINE +uint64_t +OSReadSwapInt64( + const volatile void * base, + uintptr_t byteOffset +) +{ + uint64_t result; + + result = *(volatile uint64_t *)((uintptr_t)base + byteOffset); + return _OSSwapInt64(result); +} + +/* Functions for byte reversed stores. */ + +OS_INLINE +void +OSWriteSwapInt16( + volatile void * base, + uintptr_t byteOffset, + uint16_t data +) +{ + *(volatile uint16_t *)((uintptr_t)base + byteOffset) = _OSSwapInt16(data); +} + +OS_INLINE +void +OSWriteSwapInt32( + volatile void * base, + uintptr_t byteOffset, + uint32_t data +) +{ + *(volatile uint32_t *)((uintptr_t)base + byteOffset) = _OSSwapInt32(data); +} + +OS_INLINE +void +OSWriteSwapInt64( + volatile void * base, + uintptr_t byteOffset, + uint64_t data +) +{ + *(volatile uint64_t *)((uintptr_t)base + byteOffset) = _OSSwapInt64(data); +} + +#endif /* ! _OS_OSBYTEORDERARM_H */ diff --git a/cctools/include/foreign/libkern/arm/_OSByteOrder.h b/cctools/include/foreign/libkern/arm/_OSByteOrder.h new file mode 100644 index 0000000..69a4fbb --- /dev/null +++ b/cctools/include/foreign/libkern/arm/_OSByteOrder.h @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2006 Apple Computer, Inc. All rights reserved. + * + * @APPLE_OSREFERENCE_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. The rights granted to you under the License + * may not be used to create, or enable the creation or redistribution of, + * unlawful or unlicensed copies of an Apple operating system, or to + * circumvent, violate, or enable the circumvention or violation of, any + * terms of an Apple operating system software license agreement. + * + * 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_OSREFERENCE_LICENSE_HEADER_END@ + */ + +#ifndef _OS__OSBYTEORDER_H +#define _OS__OSBYTEORDER_H + +/* + * This header is normally included from . However, + * also includes this in the case of little-endian + * architectures, so that we can map OSByteOrder routines to the hton* and ntoh* + * macros. This results in the asymmetry below; we only include + * for little-endian architectures. + */ + +#include + +/* Macros for swapping constant values in the preprocessing stage. */ +#define __DARWIN_OSSwapConstInt16(x) \ + ((__uint16_t)((((__uint16_t)(x) & 0xff00) >> 8) | \ + (((__uint16_t)(x) & 0x00ff) << 8))) + +#define __DARWIN_OSSwapConstInt32(x) \ + ((__uint32_t)((((__uint32_t)(x) & 0xff000000) >> 24) | \ + (((__uint32_t)(x) & 0x00ff0000) >> 8) | \ + (((__uint32_t)(x) & 0x0000ff00) << 8) | \ + (((__uint32_t)(x) & 0x000000ff) << 24))) + +#define __DARWIN_OSSwapConstInt64(x) \ + ((__uint64_t)((((__uint64_t)(x) & 0xff00000000000000ULL) >> 56) | \ + (((__uint64_t)(x) & 0x00ff000000000000ULL) >> 40) | \ + (((__uint64_t)(x) & 0x0000ff0000000000ULL) >> 24) | \ + (((__uint64_t)(x) & 0x000000ff00000000ULL) >> 8) | \ + (((__uint64_t)(x) & 0x00000000ff000000ULL) << 8) | \ + (((__uint64_t)(x) & 0x0000000000ff0000ULL) << 24) | \ + (((__uint64_t)(x) & 0x000000000000ff00ULL) << 40) | \ + (((__uint64_t)(x) & 0x00000000000000ffULL) << 56))) + +#if defined(__GNUC__) + + +#if defined (__arm__) || defined(__arm64__) +#include +#endif + + +#define __DARWIN_OSSwapInt16(x) \ + ((__uint16_t)(__builtin_constant_p(x) ? __DARWIN_OSSwapConstInt16(x) : _OSSwapInt16(x))) + +#define __DARWIN_OSSwapInt32(x) \ + (__builtin_constant_p(x) ? __DARWIN_OSSwapConstInt32(x) : _OSSwapInt32(x)) + +#define __DARWIN_OSSwapInt64(x) \ + (__builtin_constant_p(x) ? __DARWIN_OSSwapConstInt64(x) : _OSSwapInt64(x)) + +#else /* ! __GNUC__ */ + + +#define __DARWIN_OSSwapInt16(x) _OSSwapInt16(x) + +#define __DARWIN_OSSwapInt32(x) _OSSwapInt32(x) + +#define __DARWIN_OSSwapInt64(x) _OSSwapInt64(x) + +#endif /* __GNUC__ */ + +#endif /* ! _OS__OSBYTEORDER_H */ diff --git a/cctools/include/foreign/mach/arm b/cctools/include/foreign/mach/arm new file mode 120000 index 0000000..536b5a3 --- /dev/null +++ b/cctools/include/foreign/mach/arm @@ -0,0 +1 @@ +i386/ \ No newline at end of file diff --git a/cctools/include/foreign/mach/ppc/vm_types.h b/cctools/include/foreign/mach/ppc/vm_types.h index 3d04ddd..9e6ee79 100644 --- a/cctools/include/foreign/mach/ppc/vm_types.h +++ b/cctools/include/foreign/mach/ppc/vm_types.h @@ -93,7 +93,14 @@ typedef __darwin_natural_t natural_t; typedef int integer_t; -#if defined(__ppc__) +/* + * cctools-port: Added !defined(__ppc64__) because of: + * $ clang -target powerpc64le-linux-gnu -dM -E - < /dev/null | grep ppc + * #define __ppc64__ 1 + * #define __ppc__ 1 + */ + +#if defined(__ppc__) && !defined(__ppc64__) /* * For 32-bit PowerPC ABIs, the scalable types were diff --git a/cctools/include/foreign/ppc/_types.h b/cctools/include/foreign/ppc/_types.h index 4b78559..99db647 100644 --- a/cctools/include/foreign/ppc/_types.h +++ b/cctools/include/foreign/ppc/_types.h @@ -43,8 +43,19 @@ typedef short __int16_t; typedef unsigned short __uint16_t; typedef int __int32_t; typedef unsigned int __uint32_t; -typedef long long __int64_t; -typedef unsigned long long __uint64_t; + +#ifdef __INT64_TYPE__ +typedef __INT64_TYPE__ __int64_t; +typedef unsigned __INT64_TYPE__ __uint64_t; +#else +#if __SIZEOF_POINTER__ == 8 && !defined(__CYGWIN__) +typedef long int __int64_t; +typedef unsigned long int __uint64_t; +#else +typedef long long int __int64_t; +typedef unsigned long long int __uint64_t; +#endif +#endif typedef long __darwin_intptr_t; typedef unsigned int __darwin_natural_t; @@ -73,12 +84,14 @@ typedef int __darwin_ct_rune_t; /* ct_rune_t */ * mbstate_t is an opaque object to keep conversion state, during multibyte * stream conversions. The content must not be referenced by user programs. */ +#if defined(__APPLE__) typedef union { char __mbstate8[128]; long long _mbstateL; /* for alignment */ } __mbstate_t; typedef __mbstate_t __darwin_mbstate_t; /* mbstate_t */ +#endif #if defined(__GNUC__) && defined(__PTRDIFF_TYPE__) typedef __PTRDIFF_TYPE__ __darwin_ptrdiff_t; /* ptr1 - ptr2 */ diff --git a/cctools/include/foreign/ppc/endian.h b/cctools/include/foreign/ppc/endian.h index c6929f1..029f5a1 100644 --- a/cctools/include/foreign/ppc/endian.h +++ b/cctools/include/foreign/ppc/endian.h @@ -112,13 +112,21 @@ #if defined(KERNEL) || (!defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)) +// cctools-port +#undef LITTLE_ENDIAN +#undef BIG_ENDIAN +#undef PDP_ENDIAN +#undef BYTE_ORDER + #define LITTLE_ENDIAN __DARWIN_LITTLE_ENDIAN #define BIG_ENDIAN __DARWIN_BIG_ENDIAN #define PDP_ENDIAN __DARWIN_PDP_ENDIAN #define BYTE_ORDER __DARWIN_BYTE_ORDER +#if defined(__has_include) && __has_include() /* cctools-port */ #include +#endif #endif /* defined(KERNEL) || (!defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)) */ #endif /* !_PPC_ENDIAN_H_ */ diff --git a/cctools/include/stuff/bytesex.h b/cctools/include/stuff/bytesex.h index c6bc071..23ecc7f 100644 --- a/cctools/include/stuff/bytesex.h +++ b/cctools/include/stuff/bytesex.h @@ -50,6 +50,11 @@ #include #include #include +/* cctools-port: need to undef these to avoid warnings */ +#undef MACHINE_THREAD_STATE +#undef MACHINE_THREAD_STATE_COUNT +#undef THREAD_STATE_NONE +#undef VALID_THREAD_STATE_FLAVOR #include #include #include diff --git a/cctools/ld64/src/3rd/helper.c b/cctools/ld64/src/3rd/helper.c index 717deec..b492c29 100644 --- a/cctools/ld64/src/3rd/helper.c +++ b/cctools/ld64/src/3rd/helper.c @@ -38,28 +38,28 @@ void __assert_rtn(const char *func, const char *file, int line, const char *msg) int _NSGetExecutablePath(char *path, unsigned int *size) { #ifdef __FreeBSD__ - int mib[4]; - mib[0] = CTL_KERN; - mib[1] = KERN_PROC; - mib[2] = KERN_PROC_PATHNAME; - mib[3] = -1; - size_t cb = *size; - if (sysctl(mib, 4, path, &cb, NULL, 0) != 0) - return -1; - *size = cb; - return 0; -#else - int bufsize = *size; - int ret_size; - ret_size = readlink("/proc/self/exe", path, bufsize-1); - if (ret_size != -1) - { + int mib[4]; + mib[0] = CTL_KERN; + mib[1] = KERN_PROC; + mib[2] = KERN_PROC_PATHNAME; + mib[3] = -1; + size_t cb = *size; + if (sysctl(mib, 4, path, &cb, NULL, 0) != 0) + return -1; + *size = cb; + return 0; + #else + int bufsize = *size; + int ret_size; + ret_size = readlink("/proc/self/exe", path, bufsize-1); + if (ret_size != -1) + { *size = ret_size; path[ret_size]=0; return 0; - } - else - return -1; + } + else + return -1; #endif } @@ -70,36 +70,71 @@ int _dyld_find_unwind_sections(void* i, struct dyld_unwind_sections* sec) mach_port_t mach_host_self(void) { - return 0; + return 0; } kern_return_t host_statistics ( host_t host_priv, host_flavor_t flavor, host_info_t host_info_out, mach_msg_type_number_t *host_info_outCnt) { - return ENOTSUP; + return ENOTSUP; } -uint64_t mach_absolute_time(void) { - uint64_t t = 0; - struct timeval tv; - if (gettimeofday(&tv,NULL)) return t; - t = ((uint64_t)tv.tv_sec << 32) | tv.tv_usec; - return t; -} - -kern_return_t mach_timebase_info( mach_timebase_info_t info) { - info->numer = 1; - info->denom = 1; - return 0; -} - -int32_t OSAtomicAdd32( int32_t theAmount, volatile int32_t *theValue ) +uint64_t mach_absolute_time(void) { - __sync_fetch_and_add(theValue, theAmount); - return *theValue; + uint64_t t = 0; + struct timeval tv; + if (gettimeofday(&tv,NULL)) return t; + t = ((uint64_t)tv.tv_sec << 32) | tv.tv_usec; + return t; } -int64_t OSAtomicAdd64(int64_t theAmount, volatile int64_t *theValue) { - __sync_fetch_and_add(theValue, theAmount); - return *theValue; + +kern_return_t mach_timebase_info( mach_timebase_info_t info) +{ + info->numer = 1; + info->denom = 1; + return 0; +} + +#if defined(__ppc__) && !defined(__ppc64__) + +/* + * __sync_fetch_and_add_8 is missing on ppc 32-bit for some reason. + */ + +#include +static pthread_mutex_t lock; + +__attribute__((constructor (101))) +static void init_mutex() { pthread_mutex_init(&lock, NULL); } + +int64_t __clang_does_not_like_redeclaring_sync_fetch_and_add_8( + volatile int64_t *ptr, int64_t value, ...) +{ + pthread_mutex_lock(&lock); + *ptr = value; + pthread_mutex_unlock(&lock); + return *ptr; +} + +asm +( + ".global __sync_fetch_and_add_8\n" + ".weak __sync_fetch_and_add_8\n" + ".type __sync_fetch_and_add_8, @function\n" + "__sync_fetch_and_add_8:\n" + "b __clang_does_not_like_redeclaring_sync_fetch_and_add_8\n" + ".size __sync_fetch_and_add_8, .-__sync_fetch_and_add_8" +); + +#endif /* __ppc__ && !__ppc64__ */ + +int32_t OSAtomicAdd32(int32_t __theAmount, volatile int32_t *__theValue) +{ + return __sync_fetch_and_add(__theValue, __theAmount); +} + +int64_t OSAtomicAdd64(int64_t __theAmount, volatile int64_t *__theValue) +{ + return __sync_fetch_and_add(__theValue, __theAmount); } #endif /* __APPLE__ */ diff --git a/cctools/ld64/src/ld/InputFiles.cpp b/cctools/ld64/src/ld/InputFiles.cpp index a5c0ec9..c5dda60 100644 --- a/cctools/ld64/src/ld/InputFiles.cpp +++ b/cctools/ld64/src/ld/InputFiles.cpp @@ -813,9 +813,13 @@ void InputFiles::inferArchitecture(Options& opts, const char** archName) opts.setArchitecture(CPU_TYPE_I386, CPU_SUBTYPE_X86_ALL); #elif __x86_64__ opts.setArchitecture(CPU_TYPE_X86_64, CPU_SUBTYPE_X86_64_ALL); +#elif __ppc__ // ld64-port + opts.setArchitecture(CPU_TYPE_POWERPC, CPU_SUBTYPE_POWERPC_ALL); +#elif __ppc64__ // ld64-port + opts.setArchitecture(CPU_TYPE_POWERPC64, CPU_SUBTYPE_POWERPC_ALL); #elif __arm__ opts.setArchitecture(CPU_TYPE_ARM, CPU_SUBTYPE_ARM_V6); -#elif __arm64__ +#elif __arm64__ // ld64-port opts.setArchitecture(CPU_TYPE_ARM, CPU_SUBTYPE_ARM64_ALL); #else #error unknown default architecture diff --git a/cctools/ld64/src/other/Makefile.am b/cctools/ld64/src/other/Makefile.am index 41c5b92..1df63d3 100644 --- a/cctools/ld64/src/other/Makefile.am +++ b/cctools/ld64/src/other/Makefile.am @@ -2,7 +2,7 @@ bin_PROGRAMS = \ dyldinfo \ ObjectDump \ unwinddump \ - machochecker + machocheck AM_CXXFLAGS = \ -D__DARWIN_UNIX03 \ @@ -34,7 +34,7 @@ AM_CFLAGS = \ -I$(top_srcdir)/ld64/src/ld/passes unwinddump_SOURCES = unwinddump.cpp -machochecker_SOURCES = machochecker.cpp +machocheck_SOURCES = machochecker.cpp ObjectDump_SOURCES = \ ObjectDump.cpp \ $(top_srcdir)/ld64/src/ld/debugline.c diff --git a/cctools/libstuff/bytesex.c b/cctools/libstuff/bytesex.c index 27e7169..5b3d4e0 100644 --- a/cctools/libstuff/bytesex.c +++ b/cctools/libstuff/bytesex.c @@ -200,6 +200,11 @@ #include #include #include +/* cctools-port: need to undef these to avoid warnings */ +#undef MACHINE_THREAD_STATE +#undef MACHINE_THREAD_STATE_COUNT +#undef THREAD_STATE_NONE +#undef VALID_THREAD_STATE_FLAVOR #include #include #include diff --git a/cctools/libstuff/macosx_deployment_target.c b/cctools/libstuff/macosx_deployment_target.c index 0fc2790..f8cd0f6 100644 --- a/cctools/libstuff/macosx_deployment_target.c +++ b/cctools/libstuff/macosx_deployment_target.c @@ -112,11 +112,15 @@ use_default: /* * The default value is the version of the running OS. */ +#ifdef __APPLE__ osversion_name[0] = CTL_KERN; osversion_name[1] = KERN_OSRELEASE; osversion_len = sizeof(osversion) - 1; if(sysctl(osversion_name, 2, osversion, &osversion_len, NULL, 0) == -1) system_error("sysctl for kern.osversion failed"); +#else + memcpy(osversion, "10.5", 5); /* cctools-port: claim we are on 10.5 */ +#endif /* * Now parse this out. It is expected to be of the form "x.y.z" where diff --git a/cctools/libstuff/ofile.c b/cctools/libstuff/ofile.c index 8c80b05..11079e6 100644 --- a/cctools/libstuff/ofile.c +++ b/cctools/libstuff/ofile.c @@ -60,6 +60,11 @@ #include #include #include +/* cctools-port: need to undef these to avoid warnings */ +#undef MACHINE_THREAD_STATE +#undef MACHINE_THREAD_STATE_COUNT +#undef THREAD_STATE_NONE +#undef VALID_THREAD_STATE_FLAVOR #include #include #include diff --git a/cctools/libstuff/swap_headers.c b/cctools/libstuff/swap_headers.c index 76959d5..b18b91c 100644 --- a/cctools/libstuff/swap_headers.c +++ b/cctools/libstuff/swap_headers.c @@ -40,6 +40,11 @@ #include #include #include +/* cctools-port: need to undef these to avoid warnings */ +#undef MACHINE_THREAD_STATE +#undef MACHINE_THREAD_STATE_COUNT +#undef THREAD_STATE_NONE +#undef VALID_THREAD_STATE_FLAVOR #include #include "stuff/bool.h" #include "stuff/bytesex.h" diff --git a/package.sh b/package.sh index 61d7c4d..1503891 100755 --- a/package.sh +++ b/package.sh @@ -24,6 +24,7 @@ rm -f package.sh rm -f .gitignore pushd cctools &>/dev/null ./autogen.sh +rm -rf autom4te.cache popd &>/dev/null popd &>/dev/null diff --git a/usage_examples/ios_toolchain/README b/usage_examples/ios_toolchain/README index f1b8252..583cd13 100644 --- a/usage_examples/ios_toolchain/README +++ b/usage_examples/ios_toolchain/README @@ -6,7 +6,7 @@ USAGE: ./build.sh /path/to/sdk.tar.* -Target CPU should be one of arm6, armv7, armv7s and arm64. +Target CPU should be one of armv6, armv7, armv7s and arm64. This will build an iOS toolchain prefixed with arm-apple-darwin11-*