summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShantonu Sen <ssen@apple.com>2009-09-22 00:49:12 +0000
committerShantonu Sen <ssen@apple.com>2009-09-22 00:49:12 +0000
commitb4c3b6f8a2d3481bac6b0e9b4240fa0c99412d10 (patch)
treeecfc1c923f3e6991c75264d5a8e9edd2d394e492
parent92a6cf5b64bb661c8b67825a4a5583eb01807633 (diff)
downloadcompiler-rt-b4c3b6f8a2d3481bac6b0e9b4240fa0c99412d10.tar.gz
compiler-rt-b4c3b6f8a2d3481bac6b0e9b4240fa0c99412d10.tar.bz2
compiler-rt-b4c3b6f8a2d3481bac6b0e9b4240fa0c99412d10.tar.xz
1) Remove cmake-specific #define usage from the exported
Block.h/Block_private.h headers, since clients won't know what to set. These are moved into runtime.c as appropriate 2) Use cmake checks for CAS builtins, instead of guessing based on GCC #defines (which aren't set by clang and llvm-gcc anyway) 3) "#pragma mark" isn't supported by FSF gcc, so "#if 0" it out. It should still show up in IDEs that support it 4) Fix some compiler warnings. GCC 4.3.3 seems super strict about %p. function pointers can't be cast to void * either. 5) Avoid a warning for apple_versioning.c that "ISO C does not allow empty files" git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@82504 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--BlocksRuntime/Block.h15
-rw-r--r--BlocksRuntime/Block_private.h13
-rw-r--r--BlocksRuntime/CMakeLists.txt5
-rw-r--r--BlocksRuntime/runtime.c58
-rw-r--r--CMakeLists.txt7
-rw-r--r--ConfigureChecks.cmake22
-rw-r--r--config.h.cmake12
-rw-r--r--lib/apple_versioning.c5
8 files changed, 83 insertions, 54 deletions
diff --git a/BlocksRuntime/Block.h b/BlocksRuntime/Block.h
index 477040c7..2f2920a5 100644
--- a/BlocksRuntime/Block.h
+++ b/BlocksRuntime/Block.h
@@ -22,8 +22,8 @@
*
*/
-#ifndef _Block_H_
-#define _Block_H_
+#ifndef _BLOCK_H_
+#define _BLOCK_H_
#if !defined(BLOCK_EXPORT)
# if defined(__cplusplus)
@@ -33,14 +33,7 @@
# endif
#endif
-#include <config.h>
-
-#if defined( HAVE_AVAILABILITY_MACROS_H ) && defined( HAVE_TARGET_CONDITIONALS_H )
-#include <AvailabilityMacros.h>
-#include <TargetConditionals.h>
-#endif /* HAVE_AVAILABILITY_MACROS_H and HAVE_TARGET_CONDITIONALS_H. */
-
-#if __cplusplus
+#if defined(__cplusplus)
extern "C" {
#endif
@@ -53,7 +46,7 @@ BLOCK_EXPORT void *_Block_copy(const void *aBlock);
/* Lose the reference, and if heap based and last reference, recover the memory. */
BLOCK_EXPORT void _Block_release(const void *aBlock);
-#if __cplusplus
+#if defined(__cplusplus)
}
#endif
diff --git a/BlocksRuntime/Block_private.h b/BlocksRuntime/Block_private.h
index e5ea8c00..f7cad030 100644
--- a/BlocksRuntime/Block_private.h
+++ b/BlocksRuntime/Block_private.h
@@ -33,16 +33,9 @@
# endif
#endif
-#include <config.h>
-
-#if defined( HAVE_AVAILABILITY_MACROS_H ) && defined( HAVE_TARGET_CONDITIONALS_H )
-#include <AvailabilityMacros.h>
-#include <TargetConditionals.h>
-#endif /* HAVE_AVAILABILITY_MACROS_H and HAVE_TARGET_CONDITIONALS_H. */
-
#include <stdbool.h>
-#if __cplusplus
+#if defined(__cplusplus)
extern "C" {
#endif
@@ -171,9 +164,9 @@ struct Block_basic {
};
-#if __cplusplus
+#if defined(__cplusplus)
}
#endif
-#endif
+#endif /* _BLOCK_PRIVATE_H_ */
diff --git a/BlocksRuntime/CMakeLists.txt b/BlocksRuntime/CMakeLists.txt
index 33ab7e55..46b8993f 100644
--- a/BlocksRuntime/CMakeLists.txt
+++ b/BlocksRuntime/CMakeLists.txt
@@ -6,3 +6,8 @@ SET( SRCS
)
ADD_LIBRARY( ${PROJECT_NAME} SHARED ${SRCS})
+SET_TARGET_PROPERTIES( ${PROJECT_NAME} PROPERTIES
+ INSTALL_NAME_DIR ${CMAKE_INSTALL_PREFIX}/lib )
+
+INSTALL( TARGETS ${PROJECT_NAME} DESTINATION lib )
+INSTALL( FILES Block.h Block_private.h DESTINATION include )
diff --git a/BlocksRuntime/runtime.c b/BlocksRuntime/runtime.c
index bd079bef..dedb6eb0 100644
--- a/BlocksRuntime/runtime.c
+++ b/BlocksRuntime/runtime.c
@@ -27,10 +27,23 @@
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
+#include <stdbool.h>
-#if TARGET_OS_MAC
+#include "config.h"
+
+#ifdef HAVE_AVAILABILITY_MACROS_H
+#include <AvailabilityMacros.h>
+#endif
+
+#ifdef HAVE_TARGET_CONDITIONALS_H
+#include <TargetConditionals.h>
+#endif
+
+#if defined(HAVE_OSATOMIC_COMPARE_AND_SWAP_INT) && defined(HAVE_OSATOMIC_COMPARE_AND_SWAP_LONG)
+#ifdef HAVE_LIBKERN_OSATOMIC_H
#include <libkern/OSAtomic.h>
-#elif TARGET_OS_WIN32
+#endif
+#elif defined(__WIN32__)
#define _CRT_SECURE_NO_WARNINGS 1
#include <windows.h>
static __inline bool OSAtomicCompareAndSwapLong(long oldl, long newl, long volatile *dst)
@@ -50,8 +63,7 @@ static __inline bool OSAtomicCompareAndSwapInt(int oldi, int newi, int volatile
* a 64-bit system, make sure we have an 8-byte atomic function
* available.
*/
-#elif __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 && \
- ((__SIZEOF_LONG__ != 8) || __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8)
+#elif defined(HAVE_SYNC_BOOL_COMPARE_AND_SWAP_INT) && defined(HAVE_SYNC_BOOL_COMPARE_AND_SWAP_LONG)
static __inline bool OSAtomicCompareAndSwapLong(long oldl, long newl, long volatile *dst)
{
return __sync_bool_compare_and_swap(dst, oldl, newl);
@@ -61,6 +73,8 @@ static __inline bool OSAtomicCompareAndSwapInt(int oldi, int newi, int volatile
{
return __sync_bool_compare_and_swap(dst, oldi, newi);
}
+#else
+#error unknown atomic compare-and-swap primitive
#endif
@@ -143,7 +157,7 @@ static int latching_decr_int(int *where) {
/***********************
GC support stub routines
************************/
-#if !TARGET_OS_WIN32
+#if 0
#pragma mark GC Support Routines
#endif
@@ -171,11 +185,7 @@ static void _Block_release_object_default(const void *ptr) {
}
static void _Block_assign_weak_default(const void *ptr, void *dest) {
-#if !TARGET_OS_WIN32
- *(long *)dest = (long)ptr;
-#else
*(void **)dest = (void *)ptr;
-#endif
}
static void _Block_memmove_default(void *dst, void *src, unsigned long size) {
@@ -260,7 +270,7 @@ void _Block_use_RR( void (*retain)(const void *),
Internal Support routines for copying
********************************************************************************/
-#if !TARGET_OS_WIN32
+#if 0
#pragma mark Copy/Release support
#endif
@@ -429,7 +439,7 @@ static void _Block_byref_release(const void *arg) {
*
***********************************************************/
-#if !TARGET_OS_WIN32
+#if 0
#pragma mark SPI/API
#endif
@@ -460,7 +470,7 @@ void _Block_release(void *arg) {
;
}
else {
- printf("Block_release called upon a stack Block: %p, ignored\n", aBlock);
+ printf("Block_release called upon a stack Block: %p, ignored\n", (void *)aBlock);
}
}
@@ -498,7 +508,7 @@ unsigned long int Block_size(void *arg) {
}
-#if !TARGET_OS_WIN32
+#if 0
#pragma mark Compiler SPI entry points
#endif
@@ -595,7 +605,7 @@ void _Block_object_dispose(const void *object, const int flags) {
/*******************
Debugging support
********************/
-#if !TARGET_OS_WIN32
+#if 0
#pragma mark Debugging
#endif
@@ -612,7 +622,7 @@ const char *_Block_dump(const void *block) {
printf("Block compiled by obsolete compiler, please recompile source for this Block\n");
exit(1);
}
- cp += sprintf(cp, "^%p (new layout) =\n", closure);
+ cp += sprintf(cp, "^%p (new layout) =\n", (void *)closure);
if (closure->isa == NULL) {
cp += sprintf(cp, "isa: NULL\n");
}
@@ -632,7 +642,7 @@ const char *_Block_dump(const void *block) {
cp += sprintf(cp, "isa: finalizing Block\n");
}
else {
- cp += sprintf(cp, "isa?: %p\n", closure->isa);
+ cp += sprintf(cp, "isa?: %p\n", (void *)closure->isa);
}
cp += sprintf(cp, "flags:");
if (closure->flags & BLOCK_HAS_DESCRIPTOR) {
@@ -651,16 +661,16 @@ const char *_Block_dump(const void *block) {
cp += sprintf(cp, " HASCTOR");
}
cp += sprintf(cp, "\nrefcount: %u\n", closure->flags & BLOCK_REFCOUNT_MASK);
- cp += sprintf(cp, "invoke: %p\n", closure->invoke);
+ cp += sprintf(cp, "invoke: %#lx\n", (uintptr_t)closure->invoke);
{
struct Block_descriptor *dp = closure->descriptor;
- cp += sprintf(cp, "descriptor: %p\n", dp);
+ cp += sprintf(cp, "descriptor: %p\n", (void *)dp);
cp += sprintf(cp, "descriptor->reserved: %lu\n", dp->reserved);
cp += sprintf(cp, "descriptor->size: %lu\n", dp->size);
if (closure->flags & BLOCK_HAS_COPY_DISPOSE) {
- cp += sprintf(cp, "descriptor->copy helper: %p\n", dp->copy);
- cp += sprintf(cp, "descriptor->dispose helper: %p\n", dp->dispose);
+ cp += sprintf(cp, "descriptor->copy helper: %#lx\n", (uintptr_t)dp->copy);
+ cp += sprintf(cp, "descriptor->dispose helper: %#lx\n", (uintptr_t)dp->dispose);
}
}
return buffer;
@@ -670,13 +680,13 @@ const char *_Block_dump(const void *block) {
const char *_Block_byref_dump(struct Block_byref *src) {
static char buffer[256];
char *cp = buffer;
- cp += sprintf(cp, "byref data block %p contents:\n", src);
- cp += sprintf(cp, " forwarding: %p\n", src->forwarding);
+ cp += sprintf(cp, "byref data block %p contents:\n", (void *)src);
+ cp += sprintf(cp, " forwarding: %p\n", (void *)src->forwarding);
cp += sprintf(cp, " flags: 0x%x\n", src->flags);
cp += sprintf(cp, " size: %d\n", src->size);
if (src->flags & BLOCK_HAS_COPY_DISPOSE) {
- cp += sprintf(cp, " copy helper: %p\n", src->byref_keep);
- cp += sprintf(cp, " dispose helper: %p\n", src->byref_destroy);
+ cp += sprintf(cp, " copy helper: %#lx\n", (uintptr_t)src->byref_keep);
+ cp += sprintf(cp, " dispose helper: %#lx\n", (uintptr_t)src->byref_destroy);
}
return buffer;
}
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 165422eb..064fde0a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -26,13 +26,6 @@ INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_BINARY_DIR}
)
-install(DIRECTORY include
- DESTINATION .
- PATTERN ".svn" EXCLUDE
- PATTERN "*.cmake" EXCLUDE
- PATTERN "*.in" EXCLUDE
- )
-
SET( Achitectures
i386 x86_64 ppc arm
)
diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake
index 0516d7fc..b72a390a 100644
--- a/ConfigureChecks.cmake
+++ b/ConfigureChecks.cmake
@@ -1,5 +1,7 @@
INCLUDE( CheckIncludeFile )
INCLUDE( CheckFunctionExists )
+INCLUDE( CheckSymbolExists )
+INCLUDE( CheckCSourceCompiles )
SET( PACKAGE ${PACKAGE_NAME} )
SET( VERSION ${PACKAGE_VERSION} )
@@ -11,6 +13,26 @@ SET( SOURCEDIR ${CMAKE_SOURCE_DIR} )
CHECK_INCLUDE_FILE( sys/byteorder.h HAVE_SYS_BYTEORDER_H )
CHECK_INCLUDE_FILE( AvailabilityMacros.h HAVE_AVAILABILITY_MACROS_H )
CHECK_INCLUDE_FILE( TargetConditionals.h HAVE_TARGET_CONDITIONALS_H )
+CHECK_INCLUDE_FILE( libkern/OSAtomic.h HAVE_LIBKERN_OSATOMIC_H )
# FUNCTIONS
CHECK_FUNCTION_EXISTS( sysconf HAVE_SYSCONF )
+CHECK_SYMBOL_EXISTS( OSAtomicCompareAndSwapInt libkern/OSAtomic.h HAVE_OSATOMIC_COMPARE_AND_SWAP_INT )
+CHECK_SYMBOL_EXISTS( OSAtomicCompareAndSwapLong libkern/OSAtomic.h HAVE_OSATOMIC_COMPARE_AND_SWAP_LONG )
+
+# BUILTIN
+CHECK_C_SOURCE_COMPILES( "
+volatile int a;
+int main(int argc, char *argv[]) {
+ (void)__sync_bool_compare_and_swap(&a, 1, 2);
+ return 0;
+}
+" HAVE_SYNC_BOOL_COMPARE_AND_SWAP_INT )
+
+CHECK_C_SOURCE_COMPILES( "
+volatile long a;
+int main(int argc, char *argv[]) {
+ (void)__sync_bool_compare_and_swap(&a, 1, 2);
+ return 0;
+}
+" HAVE_SYNC_BOOL_COMPARE_AND_SWAP_LONG )
diff --git a/config.h.cmake b/config.h.cmake
index ac72ee2d..307e2778 100644
--- a/config.h.cmake
+++ b/config.h.cmake
@@ -1,2 +1,12 @@
#cmakedefine HAVE_SYS_BYTEORDER_H ${HAVE_SYS_BYTEORDER}
-#cmakedefine __Apple__ ${CMAKE_HOST_APPLE}
+#cmakedefine HAVE_AVAILABILITY_MACROS_H ${HAVE_AVAILABILITY_MACROS_H}
+#cmakedefine HAVE_TARGET_CONDITIONALS_H ${HAVE_TARGET_CONDITIONALS_H}
+#cmakedefine HAVE_LIBKERN_OSATOMIC_H ${HAVE_LIBKERN_OSATOMIC_H}
+
+#cmakedefine HAVE_SYSCONF ${HAVE_SYSCONF}
+
+#cmakedefine HAVE_OSATOMIC_COMPARE_AND_SWAP_INT ${HAVE_OSATOMIC_COMPARE_AND_SWAP_INT}
+#cmakedefine HAVE_OSATOMIC_COMPARE_AND_SWAP_LONG ${HAVE_OSATOMIC_COMPARE_AND_SWAP_LONG}
+
+#cmakedefine HAVE_SYNC_BOOL_COMPARE_AND_SWAP_INT ${HAVE_SYNC_BOOL_COMPARE_AND_SWAP_INT}
+#cmakedefine HAVE_SYNC_BOOL_COMPARE_AND_SWAP_LONG ${HAVE_SYNC_BOOL_COMPARE_AND_SWAP_LONG}
diff --git a/lib/apple_versioning.c b/lib/apple_versioning.c
index f64d306d..0360026b 100644
--- a/lib/apple_versioning.c
+++ b/lib/apple_versioning.c
@@ -143,5 +143,8 @@ NOT_HERE_BEFORE_10_6(__gcc_qsub)
NOT_HERE_BEFORE_10_6(__trampoline_setup)
#endif /* __ppc__ */
+#else /* !__APPLE__ */
-#endif /* __APPLE__*/
+extern int avoid_empty_file;
+
+#endif /* !__APPLE__*/