diff --git a/compiler-include/stdatomic.h b/compiler-include/stdatomic.h new file mode 100644 index 000000000..e03798766 --- /dev/null +++ b/compiler-include/stdatomic.h @@ -0,0 +1,190 @@ +/*===---- stdatomic.h - Standard header for atomic types and operations -----=== + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + *===-----------------------------------------------------------------------=== + */ + +#ifndef __CLANG_STDATOMIC_H +#define __CLANG_STDATOMIC_H + +/* If we're hosted, fall back to the system's stdatomic.h. FreeBSD, for + * example, already has a Clang-compatible stdatomic.h header. + */ +#if __STDC_HOSTED__ && __has_include_next() +# include_next +#else + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* 7.17.1 Introduction */ + +#define ATOMIC_BOOL_LOCK_FREE __GCC_ATOMIC_BOOL_LOCK_FREE +#define ATOMIC_CHAR_LOCK_FREE __GCC_ATOMIC_CHAR_LOCK_FREE +#define ATOMIC_CHAR16_T_LOCK_FREE __GCC_ATOMIC_CHAR16_T_LOCK_FREE +#define ATOMIC_CHAR32_T_LOCK_FREE __GCC_ATOMIC_CHAR32_T_LOCK_FREE +#define ATOMIC_WCHAR_T_LOCK_FREE __GCC_ATOMIC_WCHAR_T_LOCK_FREE +#define ATOMIC_SHORT_T_LOCK_FREE __GCC_ATOMIC_SHORT_T_LOCK_FREE +#define ATOMIC_INT_T_LOCK_FREE __GCC_ATOMIC_INT_T_LOCK_FREE +#define ATOMIC_LONG_T_LOCK_FREE __GCC_ATOMIC_LONG_T_LOCK_FREE +#define ATOMIC_LLONG_T_LOCK_FREE __GCC_ATOMIC_LLONG_T_LOCK_FREE +#define ATOMIC_POINTER_T_LOCK_FREE __GCC_ATOMIC_POINTER_T_LOCK_FREE + +/* 7.17.2 Initialization */ + +#define ATOMIC_VAR_INIT(value) (value) +#define atomic_init __c11_atomic_init + +/* 7.17.3 Order and consistency */ + +typedef enum memory_order { + memory_order_relaxed = __ATOMIC_RELAXED, + memory_order_consume = __ATOMIC_CONSUME, + memory_order_acquire = __ATOMIC_ACQUIRE, + memory_order_release = __ATOMIC_RELEASE, + memory_order_acq_rel = __ATOMIC_ACQ_REL, + memory_order_seq_cst = __ATOMIC_SEQ_CST +} memory_order; + +#define kill_dependency(y) (y) + +/* 7.17.4 Fences */ + +/* These should be provided by the libc implementation. */ +void atomic_thread_fence(memory_order); +void atomic_signal_fence(memory_order); + +#define atomic_thread_fence(order) __c11_atomic_thread_fence(order) +#define atomic_signal_fence(order) __c11_atomic_signal_fence(order) + +/* 7.17.5 Lock-free property */ + +#define atomic_is_lock_free(obj) __c11_atomic_is_lock_free(sizeof(*(obj))) + +/* 7.17.6 Atomic integer types */ + +#ifdef __cplusplus +typedef _Atomic(bool) atomic_bool; +#else +typedef _Atomic(_Bool) atomic_bool; +#endif +typedef _Atomic(char) atomic_char; +typedef _Atomic(signed char) atomic_schar; +typedef _Atomic(unsigned char) atomic_uchar; +typedef _Atomic(short) atomic_short; +typedef _Atomic(unsigned short) atomic_ushort; +typedef _Atomic(int) atomic_int; +typedef _Atomic(unsigned int) atomic_uint; +typedef _Atomic(long) atomic_long; +typedef _Atomic(unsigned long) atomic_ulong; +typedef _Atomic(long long) atomic_llong; +typedef _Atomic(unsigned long long) atomic_ullong; +typedef _Atomic(uint_least16_t) atomic_char16_t; +typedef _Atomic(uint_least32_t) atomic_char32_t; +typedef _Atomic(wchar_t) atomic_wchar_t; +typedef _Atomic(int_least8_t) atomic_int_least8_t; +typedef _Atomic(uint_least8_t) atomic_uint_least8_t; +typedef _Atomic(int_least16_t) atomic_int_least16_t; +typedef _Atomic(uint_least16_t) atomic_uint_least16_t; +typedef _Atomic(int_least32_t) atomic_int_least32_t; +typedef _Atomic(uint_least32_t) atomic_uint_least32_t; +typedef _Atomic(int_least64_t) atomic_int_least64_t; +typedef _Atomic(uint_least64_t) atomic_uint_least64_t; +typedef _Atomic(int_fast8_t) atomic_int_fast8_t; +typedef _Atomic(uint_fast8_t) atomic_uint_fast8_t; +typedef _Atomic(int_fast16_t) atomic_int_fast16_t; +typedef _Atomic(uint_fast16_t) atomic_uint_fast16_t; +typedef _Atomic(int_fast32_t) atomic_int_fast32_t; +typedef _Atomic(uint_fast32_t) atomic_uint_fast32_t; +typedef _Atomic(int_fast64_t) atomic_int_fast64_t; +typedef _Atomic(uint_fast64_t) atomic_uint_fast64_t; +typedef _Atomic(intptr_t) atomic_intptr_t; +typedef _Atomic(uintptr_t) atomic_uintptr_t; +typedef _Atomic(size_t) atomic_size_t; +typedef _Atomic(ptrdiff_t) atomic_ptrdiff_t; +typedef _Atomic(intmax_t) atomic_intmax_t; +typedef _Atomic(uintmax_t) atomic_uintmax_t; + +/* 7.17.7 Operations on atomic types */ + +#define atomic_store(object, desired) __c11_atomic_store(object, desired, __ATOMIC_SEQ_CST) +#define atomic_store_explicit __c11_atomic_store + +#define atomic_load(object) __c11_atomic_load(object, __ATOMIC_SEQ_CST) +#define atomic_load_explicit __c11_atomic_load + +#define atomic_exchange(object, desired) __c11_atomic_exchange(object, desired, __ATOMIC_SEQ_CST) +#define atomic_exchange_explicit __c11_atomic_exchange + +#define atomic_compare_exchange_strong(object, expected, desired) __c11_atomic_compare_exchange_strong(object, expected, desired, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST) +#define atomic_compare_exchange_strong_explicit __c11_atomic_compare_exchange_strong + +#define atomic_compare_exchange_weak(object, expected, desired) __c11_atomic_compare_exchange_weak(object, expected, desired, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST) +#define atomic_compare_exchange_weak_explicit __c11_atomic_compare_exchange_weak + +#define atomic_fetch_add(object, operand) __c11_atomic_fetch_add(object, operand, __ATOMIC_SEQ_CST) +#define atomic_fetch_add_explicit __c11_atomic_fetch_add + +#define atomic_fetch_sub(object, operand) __c11_atomic_fetch_sub(object, operand, __ATOMIC_SEQ_CST) +#define atomic_fetch_sub_explicit __c11_atomic_fetch_sub + +#define atomic_fetch_or(object, operand) __c11_atomic_fetch_or(object, operand, __ATOMIC_SEQ_CST) +#define atomic_fetch_or_explicit __c11_atomic_fetch_or + +#define atomic_fetch_xor(object, operand) __c11_atomic_fetch_xor(object, operand, __ATOMIC_SEQ_CST) +#define atomic_fetch_xor_explicit __c11_atomic_fetch_xor + +#define atomic_fetch_and(object, operand) __c11_atomic_fetch_and(object, operand, __ATOMIC_SEQ_CST) +#define atomic_fetch_and_explicit __c11_atomic_fetch_and + +/* 7.17.8 Atomic flag type and operations */ + +typedef struct atomic_flag { atomic_bool _Value; } atomic_flag; + +#define ATOMIC_FLAG_INIT { 0 } + +/* These should be provided by the libc implementation. */ +#ifdef __cplusplus +bool atomic_flag_test_and_set(volatile atomic_flag *); +bool atomic_flag_test_and_set_explicit(volatile atomic_flag *, memory_order); +#else +_Bool atomic_flag_test_and_set(volatile atomic_flag *); +_Bool atomic_flag_test_and_set_explicit(volatile atomic_flag *, memory_order); +#endif +void atomic_flag_clear(volatile atomic_flag *); +void atomic_flag_clear_explicit(volatile atomic_flag *, memory_order); + +#define atomic_flag_test_and_set(object) __c11_atomic_exchange(&(object)->_Value, 1, __ATOMIC_SEQ_CST) +#define atomic_flag_test_and_set_explicit(object, order) __c11_atomic_exchange(&(object)->_Value, 1, order) + +#define atomic_flag_clear(object) __c11_atomic_store(&(object)->_Value, 0, __ATOMIC_SEQ_CST) +#define atomic_flag_clear_explicit(object, order) __c11_atomic_store(&(object)->_Value, 0, order) + +#ifdef __cplusplus +} +#endif + +#endif /* __STDC_HOSTED__ */ +#endif /* __CLANG_STDATOMIC_H */ + diff --git a/src/duct/src/CMakeLists.txt b/src/duct/src/CMakeLists.txt index 92b99bdf1..0f28057c9 100644 --- a/src/duct/src/CMakeLists.txt +++ b/src/duct/src/CMakeLists.txt @@ -10,9 +10,17 @@ add_definitions(-D__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__=1080) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -nostdinc -D__DARWIN_UNIX03 -fPIC -w") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -nostdlib -Wl,-flat_namespace -Wl,-undefined,suppress") -set(DYLIB_INSTALL_NAME "/usr/lib/system/libsystem_duct.dylib") -add_darling_library(system_duct SHARED commpage.c libnotify.c numcpus.c +SET(duct_sources + commpage.c libnotify.c numcpus.c CRGetCrashLogMessage.c acl.c bootstrap.c dyld.c dns_sd.c sa_dst_compare.c asl.c) +set(DYLIB_INSTALL_NAME "/usr/lib/system/libsystem_duct.dylib") +add_darling_library(system_duct SHARED ${duct_sources}) + +set(CMAKE_AR "${CMAKE_BINARY_DIR}/src/external/cctools-port/cctools/ar/x86_64-apple-darwin11-ar") +set(CMAKE_RANLIB "${CMAKE_BINARY_DIR}/src/external/cctools-port/cctools/misc/ranlib") +add_library(system_duct_static STATIC ${duct_sources}) +add_dependencies(system_duct_static ranlib x86_64-apple-darwin11-ar) + install(TARGETS system_duct DESTINATION ${CMAKE_INSTALL_LIBDIR}/darling) diff --git a/src/dyld-apple/CMakeLists.txt b/src/dyld-apple/CMakeLists.txt index 0cd07243a..e49fa060a 100644 --- a/src/dyld-apple/CMakeLists.txt +++ b/src/dyld-apple/CMakeLists.txt @@ -60,11 +60,13 @@ add_darling_executable(system_loader src/dyldExceptions.c src/glue.c src/dyldStartup.S + src/stub_binding_helper.S + src/start_glue.S ) #use_ld64(system_loader) set_target_properties(system_loader PROPERTIES OUTPUT_NAME "dyld") -set_property(TARGET system_loader APPEND_STRING PROPERTY LINK_FLAGS " -dylinker") -target_link_libraries(system_loader crt1.10.6.o libc_static system_blocks_static unwind_static system_kernel_static) +set_property(TARGET system_loader APPEND_STRING PROPERTY LINK_FLAGS " -Wl,-dylinker -Wl,-dead_strip -nostdlib -Wl,-e,__dyld_start") +target_link_libraries(system_loader libc_static system_blocks_static unwind_static system_kernel_static system_m_static cxxabi_static keymgr_static compiler_rt_static system_duct_static) install(TARGETS system_dyld DESTINATION ${CMAKE_INSTALL_LIBDIR}/darling) diff --git a/src/dyld-apple/src/dyld.cpp b/src/dyld-apple/src/dyld.cpp index 21bb23161..1e44461d9 100644 --- a/src/dyld-apple/src/dyld.cpp +++ b/src/dyld-apple/src/dyld.cpp @@ -5329,7 +5329,7 @@ static void loadInsertedDylib(const char* path) static void configureProcessRestrictions(const macho_header* mainExecutableMH) { uint32_t flags; -#if TARGET_IPHONE_SIMULATOR +#if TARGET_IPHONE_SIMULATOR || defined(DARLING) sEnvMode = envAll; gLinkContext.requireCodeSignature = true; #elif __IPHONE_OS_VERSION_MIN_REQUIRED diff --git a/src/external/bash b/src/external/bash index 48e2e2ab5..a2e8ce549 160000 --- a/src/external/bash +++ b/src/external/bash @@ -1 +1 @@ -Subproject commit 48e2e2ab5bab6f3cadac2a4ba94be53399b3a356 +Subproject commit a2e8ce5490be207d15bf4d1f448f6a5ea26c55db diff --git a/src/external/file_cmds b/src/external/file_cmds index a21e201e1..c52b1adb3 160000 --- a/src/external/file_cmds +++ b/src/external/file_cmds @@ -1 +1 @@ -Subproject commit a21e201e12749c9e1fc92e96ce84b04856b9d93d +Subproject commit c52b1adb3c753d9c7fafb168853bf4d1b29fa6cc diff --git a/src/external/openssh b/src/external/openssh index e690b9291..b7051b7fd 160000 --- a/src/external/openssh +++ b/src/external/openssh @@ -1 +1 @@ -Subproject commit e690b9291787daaff47366853814cab390bf2432 +Subproject commit b7051b7fd82af6c3425b76a535b8230568a86044 diff --git a/src/external/security b/src/external/security index 9aa282894..9a6e079f1 160000 --- a/src/external/security +++ b/src/external/security @@ -1 +1 @@ -Subproject commit 9aa2828946570894aa042122e351856205f45d12 +Subproject commit 9a6e079f1c8dfc0b33b97c2349265821df888867 diff --git a/src/kernel/CMakeLists.txt b/src/kernel/CMakeLists.txt index c70dd48c3..fb8c19307 100644 --- a/src/kernel/CMakeLists.txt +++ b/src/kernel/CMakeLists.txt @@ -34,7 +34,7 @@ target_link_libraries(system_kernel system_duct) add_library(system_kernel_static STATIC $ #$ - $ + $ ${extra_objs} $) diff --git a/src/kernel/emulation/linux/CMakeLists.txt b/src/kernel/emulation/linux/CMakeLists.txt index d1ecbefd6..1a812a9f0 100644 --- a/src/kernel/emulation/linux/CMakeLists.txt +++ b/src/kernel/emulation/linux/CMakeLists.txt @@ -28,7 +28,7 @@ set(emulation_sources unistd/fdatasync.c unistd/dup.c unistd/dup2.c - unistd/exit.c + unistd/_exit.c unistd/close.c unistd/fchdir.c unistd/fchown.c @@ -168,6 +168,7 @@ set(emulation_sources ext/sched_yield.c ext/syslog.c ext/futex.c + ext/mremap.c bsdthread/bsdthread_register.c bsdthread/bsdthread_create.c bsdthread/bsdthread_terminate.c @@ -214,3 +215,6 @@ set_source_files_properties(misc/sysctl.c PROPERTIES COMPILE_FLAGS "-I${DARLING_TOP_DIRECTORY}/platform-include -I${DARLING_TOP_DIRECTORY}/kernel-include") add_library(emulation OBJECT ${emulation_sources}) +add_library(emulation_dyld OBJECT ${emulation_sources}) +set_target_properties(emulation_dyld PROPERTIES COMPILE_FLAGS "-ffunction-sections -DVARIANT_DYLD") + diff --git a/src/kernel/emulation/linux/bsdthread/bsdthread_create.c b/src/kernel/emulation/linux/bsdthread/bsdthread_create.c index 1128a8fc3..c6b46d50b 100644 --- a/src/kernel/emulation/linux/bsdthread/bsdthread_create.c +++ b/src/kernel/emulation/linux/bsdthread/bsdthread_create.c @@ -7,6 +7,7 @@ #include #include "../../../../../platform-include/sys/mman.h" #include "../../../../libdyld/threads.h" +#include "../../../../../platform-include/sys/errno.h" #include "../mman/mman.h" #include "../simple.h" @@ -26,6 +27,7 @@ extern void *memset(void *s, int c, size_t n); long sys_bsdthread_create(void* thread_start, void* arg, void** stack, void* pthread, uint32_t flags) { +#ifndef VARIANT_DYLD // dyld doesn't create threads int ret; unsigned long stacksize = 0; @@ -51,6 +53,9 @@ long sys_bsdthread_create(void* thread_start, void* arg, return errno_linux_to_bsd(ret); return pthread; +#else + return -ENOSYS; +#endif } void* thread_stack_allocate(unsigned long stacksize) diff --git a/src/kernel/emulation/linux/bsdthread/bsdthread_register.c b/src/kernel/emulation/linux/bsdthread/bsdthread_register.c index 55c7fafe4..73ceb4f2a 100644 --- a/src/kernel/emulation/linux/bsdthread/bsdthread_register.c +++ b/src/kernel/emulation/linux/bsdthread/bsdthread_register.c @@ -1,6 +1,7 @@ #include "bsdthread_register.h" #include "../base.h" #include "../errno.h" +#include "../../../../../platform-include/sys/errno.h" #include int pthread_obj_size; diff --git a/src/kernel/emulation/linux/bsdthread/bsdthread_terminate.c b/src/kernel/emulation/linux/bsdthread/bsdthread_terminate.c index 7953ac1f0..1a6d5783f 100644 --- a/src/kernel/emulation/linux/bsdthread/bsdthread_terminate.c +++ b/src/kernel/emulation/linux/bsdthread/bsdthread_terminate.c @@ -2,6 +2,7 @@ #include "bsdthread_register.h" #include "../base.h" #include "../errno.h" +#include "../../../../../platform-include/sys/errno.h" #include #include #include @@ -16,6 +17,7 @@ int semaphore_signal_trap(int signal_name); long sys_bsdthread_terminate(void* stackaddr, unsigned long freesize, int port, int join_sem) { +#ifndef VARIANT_DYLD #ifdef BSDTHREAD_WRAP_LINUX_PTHREAD // Implemented in libdyld extern int __darling_thread_terminate(void* stackaddr, @@ -28,6 +30,9 @@ long sys_bsdthread_terminate(void* stackaddr, unsigned long freesize, int port, return bsdthread_terminate_trap((uintptr_t) stackaddr, freesize, port, join_sem); #endif +#else + return -ENOSYS; +#endif } diff --git a/src/kernel/emulation/linux/bsdthread/workq_kernreturn.c b/src/kernel/emulation/linux/bsdthread/workq_kernreturn.c index 884ccb56c..739df6ae9 100644 --- a/src/kernel/emulation/linux/bsdthread/workq_kernreturn.c +++ b/src/kernel/emulation/linux/bsdthread/workq_kernreturn.c @@ -49,6 +49,7 @@ static void list_remove(struct parked_thread* head, struct parked_thread* item); long sys_workq_kernreturn(int options, void* item, int affinity, int prio) { +#ifndef VARIANT_DYLD // item is only used with WQOPS_QUEUE_ADD switch (options) { @@ -189,6 +190,9 @@ wakeup: default: return -ENOTSUP; } +#else + return -ENOSYS; +#endif } static int sem_down(int* sem, int timeout) diff --git a/src/kernel/emulation/linux/ext/mremap.c b/src/kernel/emulation/linux/ext/mremap.c new file mode 100644 index 000000000..f4f1a6083 --- /dev/null +++ b/src/kernel/emulation/linux/ext/mremap.c @@ -0,0 +1,22 @@ +#include "mremap.h" +#include "../errno.h" +#include "../base.h" +#include + +extern long cerror(int __err); + +VISIBLE +int __linux_mremap(void* old_addr, unsigned long old_size, unsigned long new_size, int flags, void* new_address) +{ + int rv; + + rv = LINUX_SYSCALL(__NR_mremap, old_addr, old_size, new_size, flags, new_address); + if (rv < 0) + { + cerror(errno_linux_to_bsd(rv)); + return -1; + } + + return rv; +} + diff --git a/src/kernel/emulation/linux/ext/mremap.h b/src/kernel/emulation/linux/ext/mremap.h new file mode 100644 index 000000000..9acd003eb --- /dev/null +++ b/src/kernel/emulation/linux/ext/mremap.h @@ -0,0 +1,7 @@ +#ifndef EXT_MREMAP_H +#define EXT_MREMAP_H + +int __linux_mremap(void* old_addr, unsigned long old_size, unsigned long new_size, int flags, void* new_address); + +#endif + diff --git a/src/kernel/emulation/linux/misc/sysctl.c b/src/kernel/emulation/linux/misc/sysctl.c index ded019ba8..edfd8cb08 100644 --- a/src/kernel/emulation/linux/misc/sysctl.c +++ b/src/kernel/emulation/linux/misc/sysctl.c @@ -208,8 +208,10 @@ long sys_sysctl(int* name, unsigned int nlen, void* old, case KERN_OSTYPE: { const char* s = NULL; +#ifndef VARIANT_DYLD if (version_conf_sect != NULL) s = iniconfig_valmap_get(version_conf_sect, "sysname"); +#endif if (s == NULL) s = lu.sysname; @@ -222,8 +224,10 @@ long sys_sysctl(int* name, unsigned int nlen, void* old, case KERN_OSRELEASE: { const char* s = NULL; +#ifndef VARIANT_DYLD if (version_conf_sect != NULL) s = iniconfig_valmap_get(version_conf_sect, "release"); +#endif if (s == NULL) s = lu.release; @@ -233,8 +237,10 @@ long sys_sysctl(int* name, unsigned int nlen, void* old, case KERN_VERSION: { const char* s = NULL; +#ifndef VARIANT_DYLD if (version_conf_sect != NULL) s = iniconfig_valmap_get(version_conf_sect, "version"); +#endif if (s == NULL) s = lu.version; @@ -252,6 +258,7 @@ long sys_sysctl(int* name, unsigned int nlen, void* old, static void need_uname(void) { +#ifndef VARIANT_DYLD // Cache __linux_uname results if (!lu.sysname[0]) { @@ -260,6 +267,7 @@ static void need_uname(void) if (version_conf != NULL) version_conf_sect = iniconfig_getsection(version_conf, "uname"); } +#endif } extern unsigned long strlcpy(char* dst, const char* src, unsigned long size); diff --git a/src/kernel/emulation/linux/signal/sig_restorer.S b/src/kernel/emulation/linux/signal/sig_restorer.S index 3d66927a4..4d3230dfa 100644 --- a/src/kernel/emulation/linux/signal/sig_restorer.S +++ b/src/kernel/emulation/linux/signal/sig_restorer.S @@ -1,15 +1,15 @@ .text -.globl sig_restorer -.private_extern sig_restorer +.globl _sig_restorer +.private_extern _sig_restorer #ifdef __x86_64__ -sig_restorer: +_sig_restorer: movl $15, %eax syscall #elif defined(__i386__) -sig_restorer: +_sig_restorer: movl $173, %eax int $0x80 #endif diff --git a/src/kernel/libsyscall/sys_x86-64/___gettimeofday.S b/src/kernel/libsyscall/sys_x86-64/___gettimeofday.S index 27cf08850..b8b538c19 100644 --- a/src/kernel/libsyscall/sys_x86-64/___gettimeofday.S +++ b/src/kernel/libsyscall/sys_x86-64/___gettimeofday.S @@ -30,10 +30,6 @@ #include "SYS.h" -#ifdef DARLING -# define ___gettimeofday __gettimeofday -#endif - #if defined(__i386__) /* diff --git a/src/kernel/mach_server/client/mach_traps.c b/src/kernel/mach_server/client/mach_traps.c index 84165943d..36264a29f 100644 --- a/src/kernel/mach_server/client/mach_traps.c +++ b/src/kernel/mach_server/client/mach_traps.c @@ -246,7 +246,7 @@ kern_return_t _kernelrpc_mach_vm_map_trap( if (!(flags & VM_FLAGS_ANYWHERE)) posix_flags |= MAP_FIXED; if ((flags >> 24) == VM_MEMORY_REALLOC) - addr = mremap(((char*)*address) - 0x1000, 0x1000, 0x1000 + size, 0); + addr = __linux_mremap(((char*)*address) - 0x1000, 0x1000, 0x1000 + size, 0); else addr = mmap(*address, size, prot, posix_flags, -1, 0); diff --git a/src/keymgr/CMakeLists.txt b/src/keymgr/CMakeLists.txt index 04efa1326..2ed503252 100644 --- a/src/keymgr/CMakeLists.txt +++ b/src/keymgr/CMakeLists.txt @@ -20,4 +20,9 @@ set(DYLIB_INSTALL_NAME "/usr/lib/system/libkeymgr.dylib") add_darling_library(keymgr SHARED ${keymgr_sources}) target_link_libraries(keymgr PRIVATE system_c system_dyld) +set(CMAKE_AR "${CMAKE_BINARY_DIR}/src/external/cctools-port/cctools/ar/x86_64-apple-darwin11-ar") +set(CMAKE_RANLIB "${CMAKE_BINARY_DIR}/src/external/cctools-port/cctools/misc/ranlib") +add_library(keymgr_static STATIC ${keymgr_sources}) +add_dependencies(keymgr_static ranlib x86_64-apple-darwin11-ar) + install(TARGETS keymgr DESTINATION ${CMAKE_INSTALL_LIBDIR}/darling) diff --git a/src/libc/CMakeLists.txt b/src/libc/CMakeLists.txt index 290fd1ecf..da541e3c8 100644 --- a/src/libc/CMakeLists.txt +++ b/src/libc/CMakeLists.txt @@ -154,11 +154,17 @@ add_library(libc_static STATIC $ $ $ + $ $ + $ + $ + $ + $ $ $ platform/OSAtomic.c) add_dependencies(libc_static ranlib x86_64-apple-darwin11-ar) +set_target_properties(libc_static PROPERTIES COMPILE_FLAGS "-ffunction-sections") # TODO: see ./xcodescripts/variants.xcconfig diff --git a/src/libc/gdtoa/FreeBSD/glue.c b/src/libc/gdtoa/FreeBSD/glue.c index 0db1914f4..25b58fdb3 100644 --- a/src/libc/gdtoa/FreeBSD/glue.c +++ b/src/libc/gdtoa/FreeBSD/glue.c @@ -7,4 +7,5 @@ #include "spinlock.h" +__attribute__ ((visibility ("visible"))) spinlock_t __gdtoa_locks[2]; diff --git a/src/libc/gen/CMakeLists.txt b/src/libc/gen/CMakeLists.txt index 5d98a89c3..c5705b778 100644 --- a/src/libc/gen/CMakeLists.txt +++ b/src/libc/gen/CMakeLists.txt @@ -237,7 +237,9 @@ SET_TARGET_PROPERTIES(libc-gen_pre1050 PROPERTIES COMPILE_FLAGS "-DBUILDING_VARI # DYLD variants # *** -add_library(libc-gen_dyld OBJECT _simple.c FreeBSD/arc4random.c FreeBSD/closedir.c dirfd.c FreeBSD/getcwd.c FreeBSD/getpagesize.c nanosleep.c FreeBSD/opendir.c FreeBSD/readdir.c FreeBSD/scandir.c FreeBSD/sysctl.c FreeBSD/sysctlbyname.c FreeBSD/telldir.c FreeBSD/usleep.c) +add_library(libc-gen_dyld OBJECT _simple.c FreeBSD/arc4random.c FreeBSD/closedir.c dirfd.c FreeBSD/getcwd.c FreeBSD/getpagesize.c nanosleep.c FreeBSD/opendir.c + FreeBSD/readdir.c FreeBSD/scandir.c FreeBSD/sysctl.c FreeBSD/sysctlbyname.c FreeBSD/telldir.c FreeBSD/usleep.c FreeBSD/sysconf.c + FreeBSD/isatty.c FreeBSD/termios.c FreeBSD/getprogname.c errlst.c platfunc.c) SET_TARGET_PROPERTIES(libc-gen_dyld PROPERTIES COMPILE_FLAGS "-UBUILDING_VARIANT -DVARIANT_DYLD -DVARIANT_CANCELABLE -DVARIANT_DARWINEXTSN") diff --git a/src/libc/pthreads/CMakeLists.txt b/src/libc/pthreads/CMakeLists.txt index bca8bc4a7..b53a19757 100644 --- a/src/libc/pthreads/CMakeLists.txt +++ b/src/libc/pthreads/CMakeLists.txt @@ -43,5 +43,5 @@ SET_TARGET_PROPERTIES(libc-pthreads_legacy PROPERTIES COMPILE_FLAGS "-DBUILDING_ # DYLD variant -add_library(libc-pthreads_dyld OBJECT pthread.c pthread_mutex.c pthread_tsd.c) +add_library(libc-pthreads_dyld OBJECT pthread.c pthread_mutex.c pthread_tsd.c pthread_cond.c pthread_cancelable.c) SET_TARGET_PROPERTIES(libc-pthreads_dyld PROPERTIES COMPILE_FLAGS "-UBUILDING_VARIANT -DVARIANT_DYLD -DVARIANT_CANCELABLE -DVARIANT_DARWINEXTSN") diff --git a/src/libc/pthreads/pthread.c b/src/libc/pthreads/pthread.c index cf784d3db..b94314d8f 100644 --- a/src/libc/pthreads/pthread.c +++ b/src/libc/pthreads/pthread.c @@ -258,9 +258,15 @@ void pthread_workqueue_atfork_prepare(void); void pthread_workqueue_atfork_parent(void); void pthread_workqueue_atfork_child(void); +#ifndef VARIANT_DYLD extern void dispatch_atfork_prepare(void); extern void dispatch_atfork_parent(void); extern void dispatch_atfork_child(void); +#else +#define dispatch_atfork_prepare() +#define dispatch_atfork_parent() +#define dispatch_atfork_child() +#endif /* workq_kernreturn commands */ #define WQOPS_QUEUE_ADD 1 diff --git a/src/libc/pthreads/pthread_cancelable.c b/src/libc/pthreads/pthread_cancelable.c index e18918014..aa51be5ac 100644 --- a/src/libc/pthreads/pthread_cancelable.c +++ b/src/libc/pthreads/pthread_cancelable.c @@ -79,7 +79,7 @@ extern int __sigwait(const sigset_t *set, int *sig); #ifdef VARIANT_CANCELABLE extern int __semwait_signal(int cond_sem, int mutex_sem, int timeout, int relative, __int64_t tv_sec, __int32_t tv_nsec); #else -extern int __semwait_signal(int cond_sem, int mutex_sem, int timeout, int relative, __int64_t tv_sec, __int32_t tv_nsec) __asm__("__semwait_signal_nocancel"); +extern int __semwait_signal(int cond_sem, int mutex_sem, int timeout, int relative, __int64_t tv_sec, __int32_t tv_nsec) __asm__("___semwait_signal_nocancel"); #endif /* diff --git a/src/libc/stdlib/CMakeLists.txt b/src/libc/stdlib/CMakeLists.txt index 05ad6fa3e..1e10b8e24 100644 --- a/src/libc/stdlib/CMakeLists.txt +++ b/src/libc/stdlib/CMakeLists.txt @@ -101,6 +101,6 @@ add_library(libc-stdlib_extsn OBJECT ${stdlib-extsn_sources}) SET_TARGET_PROPERTIES(libc-stdlib_extsn PROPERTIES COMPILE_DEFINITIONS "BUILDING_VARIANT;VARIANT_DARWINEXTSN") # DYLD variant -add_library(libc-stdlib_dyld OBJECT FreeBSD/atexit.c FreeBSD/exit.c FreeBSD/heapsort.c FreeBSD/merge.c FreeBSD/qsort.c FreeBSD/reallocf.c FreeBSD/realpath.c FreeBSD/strtoul.c) +add_library(libc-stdlib_dyld OBJECT FreeBSD/atexit.c FreeBSD/exit.c FreeBSD/heapsort.c FreeBSD/merge.c FreeBSD/qsort.c FreeBSD/reallocf.c FreeBSD/realpath.c FreeBSD/strtoul.c FreeBSD/strtol.c FreeBSD/getenv.c FreeBSD/exit.c) SET_TARGET_PROPERTIES(libc-stdlib_dyld PROPERTIES COMPILE_FLAGS "-UBUILDING_VARIANT -DVARIANT_DYLD -DVARIANT_CANCELABLE -DVARIANT_DARWINEXTSN") diff --git a/src/libc/string/CMakeLists.txt b/src/libc/string/CMakeLists.txt index 49f0a082c..a727407ba 100644 --- a/src/libc/string/CMakeLists.txt +++ b/src/libc/string/CMakeLists.txt @@ -96,6 +96,7 @@ add_library(libc-string_legacy OBJECT ${string-legacy_sources}) SET_TARGET_PROPERTIES(libc-string_legacy PROPERTIES COMPILE_DEFINITIONS "BUILDING_VARIANT;VARIANT_LEGACY") # DYLD variant -add_library(libc-string_dyld OBJECT strcat.c FreeBSD/strchr.c strcpy.c FreeBSD/strdup.c strlcat.c strlcpy.c FreeBSD/strncmp.c FreeBSD/strnlen.c FreeBSD/strrchr.c FreeBSD/strstr.c FreeBSD/strtok.c) +add_library(libc-string_dyld OBJECT strcat.c FreeBSD/strchr.c strcpy.c FreeBSD/strdup.c strlcat.c strlcpy.c FreeBSD/strncmp.c FreeBSD/strnlen.c FreeBSD/strrchr.c FreeBSD/strstr.c FreeBSD/strtok.c + FreeBSD/memchr.c FreeBSD/memcmp.c FreeBSD/memcpy.c FreeBSD/wcscpy.c FreeBSD/wcslen.c FreeBSD/wcsncmp.c FreeBSD/wcsncpy.c FreeBSD/strerror.c) SET_TARGET_PROPERTIES(libc-string_dyld PROPERTIES COMPILE_FLAGS "-UBUILDING_VARIANT -DVARIANT_DYLD -DVARIANT_CANCELABLE -DVARIANT_DARWINEXTSN") diff --git a/src/libc/sys/CMakeLists.txt b/src/libc/sys/CMakeLists.txt index ca1ff8c47..a23840f82 100644 --- a/src/libc/sys/CMakeLists.txt +++ b/src/libc/sys/CMakeLists.txt @@ -48,6 +48,6 @@ set(sys-noinode64_sources statx_np.c) add_library(libc-sys_noinode64 OBJECT ${sys-noinode64_sources}) SET_TARGET_PROPERTIES(libc-sys_noinode64 PROPERTIES COMPILE_FLAGS "-U__DARWIN_UNIX03 -U__DARWIN_64_BIT_INO_T -DVARIANT_INODE32 -DBUILDING_VARIANT -D_DARWIN_NO_64_BIT_INODE") -add_library(libc-sys_dyld OBJECT gettimeofday.c) +add_library(libc-sys_dyld OBJECT gettimeofday.c crt_externs.c) SET_TARGET_PROPERTIES(libc-sys_dyld PROPERTIES COMPILE_FLAGS "-UBUILDING_VARIANT -DVARIANT_DYLD -DVARIANT_CANCELABLE -DVARIANT_DARWINEXTSN") diff --git a/src/libc/x86_64/CMakeLists.txt b/src/libc/x86_64/CMakeLists.txt index c9f99b570..69e75ab2b 100644 --- a/src/libc/x86_64/CMakeLists.txt +++ b/src/libc/x86_64/CMakeLists.txt @@ -96,16 +96,22 @@ add_library(libc-hwplat_dyld OBJECT pthreads/pthread_self.S pthreads/pthread_getspecific.S pthreads/preempt.S + pthreads/thread_start.S + pthreads/start_wqthread.S string/__bzero.S string/bcopy_sse3x.S string/bcopy_sse42.S + string/bcopy.c string/bzero_sse2.S + string/bzero_sse42.S + string/bzero.c string/ffs.S string/longcopy_sse3x.S string/strcmp.S string/strlen.S string/strncpy.S string/memmove.c + string/memcpy.c sys/OSAtomic.S sys/atomic.c sys/spinlocks.c diff --git a/src/libm/CMakeLists.txt b/src/libm/CMakeLists.txt index 3cfd891d6..1713ccb12 100644 --- a/src/libm/CMakeLists.txt +++ b/src/libm/CMakeLists.txt @@ -160,3 +160,7 @@ set_property(TARGET system_m APPEND_STRING PROPERTY LINK_FLAGS install(TARGETS system_m DESTINATION ${CMAKE_INSTALL_LIBDIR}/darling) +set(CMAKE_AR "${CMAKE_BINARY_DIR}/src/external/cctools-port/cctools/ar/x86_64-apple-darwin11-ar") +set(CMAKE_RANLIB "${CMAKE_BINARY_DIR}/src/external/cctools-port/cctools/misc/ranlib") +add_library(system_m_static STATIC ${libm_sources} $) +add_dependencies(system_m_static ranlib x86_64-apple-darwin11-ar)