From adc577574f3d8697833d2e6ec3ce2c8915607e46 Mon Sep 17 00:00:00 2001 From: David Grove Date: Fri, 12 Aug 2016 11:41:45 -0400 Subject: [PATCH 1/3] fixes for compilation/linking problems on linux --- src/Makefile.am | 3 ++- src/init.c | 2 +- src/queue.c | 4 ++++ src/shims/linux_stubs.h | 2 -- src/voucher.c | 2 ++ src/voucher_internal.h | 2 ++ 6 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index 31e8c5080..670178fcf 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -87,10 +87,11 @@ if BUILD_OWN_BLOCKS_RUNTIME libdispatch_la_SOURCES+= BlocksRuntime/data.c BlocksRuntime/runtime.c CBLOCKS_FLAGS+= -I$(top_srcdir)/src/BlocksRuntime CXXBLOCKS_FLAGS+= -I$(top_srcdir)/src/BlocksRuntime +BLOCKS_RUNTIME_LIBS=-ldl endif libdispatch_la_LDFLAGS=-avoid-version -libdispatch_la_LIBADD=$(KQUEUE_LIBS) $(PTHREAD_WORKQUEUE_LIBS) $(BSD_OVERLAY_LIBS) +libdispatch_la_LIBADD=$(KQUEUE_LIBS) $(PTHREAD_WORKQUEUE_LIBS) $(BSD_OVERLAY_LIBS) $(BLOCKS_RUNTIME_LIBS) if HAVE_DARWIN_LD libdispatch_la_LDFLAGS+=-Wl,-compatibility_version,1 \ diff --git a/src/init.c b/src/init.c index 45cbff3bf..87be596f2 100644 --- a/src/init.c +++ b/src/init.c @@ -1197,7 +1197,7 @@ dispatch_source_type_readwrite_init(dispatch_source_t ds, dispatch_queue_t q DISPATCH_UNUSED) { ds->ds_is_level = true; -#ifdef HAVE_DECL_NOTE_LOWAT +#if HAVE_DECL_NOTE_LOWAT // bypass kernel check for device kqueue support rdar://19004921 ds->ds_dkev->dk_kevent.fflags = NOTE_LOWAT; #endif diff --git a/src/queue.c b/src/queue.c index 58c545b17..5d79b2c6c 100644 --- a/src/queue.c +++ b/src/queue.c @@ -2734,12 +2734,16 @@ _dispatch_block_create_with_voucher_and_priority(dispatch_block_flags_t flags, bool assign = (flags & DISPATCH_BLOCK_ASSIGN_CURRENT); if (assign && !(flags & DISPATCH_BLOCK_HAS_VOUCHER)) { +#if OS_VOUCHER_ACTIVITY_SPI voucher = VOUCHER_CURRENT; +#endif flags |= DISPATCH_BLOCK_HAS_VOUCHER; } +#if OS_VOUCHER_ACTIVITY_SPI if (voucher == VOUCHER_CURRENT) { voucher = _voucher_get(); } +#endif if (assign && !(flags & DISPATCH_BLOCK_HAS_PRIORITY)) { pri = _dispatch_priority_propagate(); flags |= DISPATCH_BLOCK_HAS_PRIORITY; diff --git a/src/shims/linux_stubs.h b/src/shims/linux_stubs.h index e13304906..0c12e8272 100644 --- a/src/shims/linux_stubs.h +++ b/src/shims/linux_stubs.h @@ -47,8 +47,6 @@ typedef uint32_t voucher_activity_trace_id_t; typedef uint32_t voucher_activity_id_t; -typedef uint32_t _voucher_activity_buffer_hook_t;; - typedef uint32_t voucher_activity_flag_t; typedef struct { } mach_msg_header_t; diff --git a/src/voucher.c b/src/voucher.c index 94a293427..ee04e3b19 100644 --- a/src/voucher.c +++ b/src/voucher.c @@ -1560,6 +1560,7 @@ _voucher_init(void) { } +#if OS_VOUCHER_ACTIVITY_SPI void* voucher_activity_get_metadata_buffer(size_t *length) { @@ -1631,6 +1632,7 @@ voucher_activity_initialize_4libtrace(voucher_activity_hooks_t hooks) { (void)hooks; } +#endif // OS_VOUCHER_ACTIVITY_SPI size_t _voucher_debug(voucher_t v, char* buf, size_t bufsiz) diff --git a/src/voucher_internal.h b/src/voucher_internal.h index 3aa1a6579..b34ad4643 100644 --- a/src/voucher_internal.h +++ b/src/voucher_internal.h @@ -90,8 +90,10 @@ voucher_get_mach_voucher(voucher_t voucher); void _voucher_init(void); void _voucher_atfork_child(void); void _voucher_activity_debug_channel_init(void); +#if OS_VOUCHER_ACTIVITY_SPI void _voucher_activity_swap(firehose_activity_id_t old_id, firehose_activity_id_t new_id); +#endif void _voucher_xref_dispose(voucher_t voucher); void _voucher_dispose(voucher_t voucher); size_t _voucher_debug(voucher_t v, char* buf, size_t bufsiz); From 2c9f19e08bec5121a7711cde28c3361b1ad07ec6 Mon Sep 17 00:00:00 2001 From: David Grove Date: Fri, 12 Aug 2016 16:46:22 -0400 Subject: [PATCH 2/3] xcode / autoconf plumbing to select module.modulemap file --- .gitignore | 2 ++ configure.ac | 16 +++++++++++++++- dispatch/Makefile.am | 2 +- dispatch/{ => darwin}/module.modulemap | 0 .../{module.map => generic/module.modulemap} | 0 libdispatch.xcodeproj/project.pbxproj | 4 ++-- private/{ => darwin}/module.modulemap | 0 private/generic/module.modulemap | 11 +++++++++++ src/Makefile.am | 2 +- 9 files changed, 32 insertions(+), 5 deletions(-) rename dispatch/{ => darwin}/module.modulemap (100%) rename dispatch/{module.map => generic/module.modulemap} (100%) rename private/{ => darwin}/module.modulemap (100%) create mode 100644 private/generic/module.modulemap diff --git a/.gitignore b/.gitignore index 1bf54ca69..aa26514c9 100644 --- a/.gitignore +++ b/.gitignore @@ -29,3 +29,5 @@ config configure libtool .dirstamp +/dispatch/module.modulemap +/private/module.modulemap diff --git a/configure.ac b/configure.ac index e3e06ce5b..461659ec5 100644 --- a/configure.ac +++ b/configure.ac @@ -432,6 +432,20 @@ AS_IF([test "x$have_mach" = "xtrue"], [ ]) AM_CONDITIONAL(HAVE_DARWIN_LD, [test "x$dispatch_cv_ld_darwin" == "xyes"]) +# +# symlink platform-specific module.modulemap files +# +AS_CASE([$target_os], + [darwin*], [ dispatch_module_map_os=darwin ], + [ dispatch_module_map_os=generic ] +) +AC_CONFIG_COMMANDS([modulemaps], [ + ln -fs $dispatch_module_map_os/module.modulemap $ac_top_srcdir/dispatch/module.modulemap + ln -fs $dispatch_module_map_os/module.modulemap $ac_top_srcdir/private/module.modulemap + ], + [dispatch_module_map_os="$dispatch_module_map_os"] +) + # # Temporary: some versions of clang do not mark __builtin_trap() as # __attribute__((__noreturn__)). Detect and add if required. @@ -449,6 +463,6 @@ AC_CONFIG_FILES([Makefile dispatch/Makefile man/Makefile os/Makefile private/Mak # # Generate testsuite links # -AC_CONFIG_LINKS([tests/dispatch:$top_srcdir/private tests/leaks-wrapper:tests/leaks-wrapper.sh]) +AC_CONFIG_LINKS([tests/dispatch:$ac_top_srcdir/private tests/leaks-wrapper:tests/leaks-wrapper.sh]) AC_OUTPUT diff --git a/dispatch/Makefile.am b/dispatch/Makefile.am index 53ea5986c..89fd3daf0 100644 --- a/dispatch/Makefile.am +++ b/dispatch/Makefile.am @@ -24,5 +24,5 @@ dispatch_HEADERS= \ time.h if HAVE_SWIFT -dispatch_HEADERS+=module.map +dispatch_HEADERS+=module.modulemap endif diff --git a/dispatch/module.modulemap b/dispatch/darwin/module.modulemap similarity index 100% rename from dispatch/module.modulemap rename to dispatch/darwin/module.modulemap diff --git a/dispatch/module.map b/dispatch/generic/module.modulemap similarity index 100% rename from dispatch/module.map rename to dispatch/generic/module.modulemap diff --git a/libdispatch.xcodeproj/project.pbxproj b/libdispatch.xcodeproj/project.pbxproj index c40d08155..9fe06aa92 100644 --- a/libdispatch.xcodeproj/project.pbxproj +++ b/libdispatch.xcodeproj/project.pbxproj @@ -662,8 +662,8 @@ C01866BD1C5973210040FC07 /* libdispatch.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libdispatch.a; sourceTree = BUILT_PRODUCTS_DIR; }; C01866BE1C59735B0040FC07 /* libdispatch-mp-static.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "libdispatch-mp-static.xcconfig"; sourceTree = ""; }; C01866BF1C5976C90040FC07 /* run-on-install.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = "run-on-install.sh"; sourceTree = ""; }; - C901445E1C73A7FE002638FC /* module.modulemap */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = "sourcecode.module-map"; path = module.modulemap; sourceTree = ""; }; - C90144641C73A845002638FC /* module.modulemap */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = "sourcecode.module-map"; path = module.modulemap; sourceTree = ""; }; + C901445E1C73A7FE002638FC /* module.modulemap */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = "sourcecode.module-map"; name = module.modulemap; path = darwin/module.modulemap; sourceTree = ""; }; + C90144641C73A845002638FC /* module.modulemap */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = "sourcecode.module-map"; name = module.modulemap; path = darwin/module.modulemap; sourceTree = ""; }; C913AC0E143BD34800B78976 /* data_private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = data_private.h; sourceTree = ""; tabWidth = 8; }; C927F35F10FD7F1000C5AB8B /* ddt.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = ddt.xcodeproj; path = tools/ddt/ddt.xcodeproj; sourceTree = ""; }; C96CE17A1CEB851600F4B8E6 /* dispatch_objc.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = dispatch_objc.m; sourceTree = ""; }; diff --git a/private/module.modulemap b/private/darwin/module.modulemap similarity index 100% rename from private/module.modulemap rename to private/darwin/module.modulemap diff --git a/private/generic/module.modulemap b/private/generic/module.modulemap new file mode 100644 index 000000000..62975a59b --- /dev/null +++ b/private/generic/module.modulemap @@ -0,0 +1,11 @@ +module DispatchPrivate [system] [extern_c] { + umbrella header "private.h" + exclude header "mach_private.h" + module * { export * } + export * +} + +module DispatchIntrospectionPrivate [system] [extern_c] { + header "introspection_private.h" + export * +} diff --git a/src/Makefile.am b/src/Makefile.am index 670178fcf..98d36160a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -164,7 +164,7 @@ SWIFT_GEN_FILES= \ $(SWIFT_OBJ_FILES:%=%.~partial.swiftdoc) \ $(SWIFT_OBJ_FILES:%=%.~partial.swiftdeps) -SWIFTC_FLAGS = -Xcc -fmodule-map-file=$(abs_top_srcdir)/dispatch/module.map -I$(abs_top_srcdir) -Xcc -fblocks +SWIFTC_FLAGS = -Xcc -fmodule-map-file=$(abs_top_srcdir)/dispatch/module.modulemap -I$(abs_top_srcdir) -Xcc -fblocks if DISPATCH_ENABLE_OPTIMIZATION SWIFTC_FLAGS+=-O endif From a23ea8cd93cd7eb83acaf695106fa936d842432d Mon Sep 17 00:00:00 2001 From: David Grove Date: Fri, 12 Aug 2016 21:38:44 -0400 Subject: [PATCH 3/3] ensure root_queues are initialized before main thread exits --- src/queue.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/queue.c b/src/queue.c index 5d79b2c6c..0c058be55 100644 --- a/src/queue.c +++ b/src/queue.c @@ -5844,6 +5844,9 @@ _dispatch_main_queue_callback_4CF( void dispatch_main(void) { + dispatch_once_f(&_dispatch_root_queues_pred, NULL, + _dispatch_root_queues_init_once); + #if HAVE_PTHREAD_MAIN_NP if (pthread_main_np()) { #endif