[mono] Fix warnings on OSX, re-enable -Werror on CI with CMake (#44747)
authorRyan Lucia <rylucia@microsoft.com>
Thu, 26 Nov 2020 08:18:02 +0000 (03:18 -0500)
committerGitHub <noreply@github.com>
Thu, 26 Nov 2020 08:18:02 +0000 (03:18 -0500)
* Ifdef out removed icalls on netcore

* Fix format string for cross builds

desc here is based on the pointer size of the target, whereas void* is based on the host

* Re-enable -WError on CI for OSX and Wasm

This got lost in the CMake transition

* Improve ep_rt_thread_id_t handling.

* Make types_str local to mono_fdhandle_insert

* Fix OSX build error.

* Align os thread id to uint64_t.

* Update src/mono/mono/sgen/sgen-descriptor.c

Co-authored-by: Aleksey Kliger (λgeek) <akliger@gmail.com>
* Update src/mono/mono/sgen/sgen-descriptor.c

Co-authored-by: Aleksey Kliger (λgeek) <akliger@gmail.com>
* Update src/mono/mono/sgen/sgen-descriptor.c

Co-authored-by: Aleksey Kliger (λgeek) <akliger@gmail.com>
* Revert "Make types_str local to mono_fdhandle_insert"

This reverts commit 04f56efcb8e9d33dca12f831f9c05591c649678c.

* Put types_str under appropriate ifdef

* Disable Werror on wasm

Co-authored-by: lateralusX <lateralusx.github@gmail.com>
Co-authored-by: Aleksey Kliger (λgeek) <akliger@gmail.com>
Co-authored-by: Alexander Köplinger <alex.koeplinger@outlook.com>
17 files changed:
src/mono/mono.proj
src/mono/mono/eventpipe/ep-rt-mono.h
src/mono/mono/eventpipe/ep-rt-types-mono.h
src/mono/mono/metadata/fdhandle.c
src/mono/mono/metadata/icall.c
src/mono/mono/sgen/sgen-descriptor.c
src/native/eventpipe/ds-server.c
src/native/eventpipe/ep-buffer-manager.c
src/native/eventpipe/ep-buffer.c
src/native/eventpipe/ep-config.c
src/native/eventpipe/ep-event-instance.c
src/native/eventpipe/ep-json-file.c
src/native/eventpipe/ep-rt.h
src/native/eventpipe/ep-sample-profiler.c
src/native/eventpipe/ep-session.c
src/native/eventpipe/ep-thread.c
src/native/eventpipe/ep-thread.h

index afde59e..bc0e097 100644 (file)
     <PackageReference Include="$(MicrosoftNETCoreRuntimeICUTransportPackage)" PrivateAssets="all" Version="$(MicrosoftNETCoreRuntimeICUTransportVersion)" GeneratePathProperty="true" />
   </ItemGroup>
 
+  <!-- CI specific build options -->    
+  <ItemGroup Condition="'$(ContinuousIntegrationBuild)' == 'true' and ('$(TargetsOSX)' == 'true')">
+    <_MonoCMakeArgs Include="-DENABLE_WERROR=1"/>
+  </ItemGroup>
+
   <!-- Sanity checks -->
   <Target Name="CheckEnv">
     <Error Condition="'$(TargetstvOS)' == 'true' and '$(Platform)' != 'x64' and '$(Platform)' != 'arm64'" Text="Error: Invalid platform for $(TargetOS): $(Platform)." />
index a70bb11..6cc6636 100644 (file)
@@ -313,7 +313,6 @@ prefix_name ## _rt_ ## type_name ## _ ## func_name
 
 typedef MonoThreadStart ep_rt_thread_start_func;
 typedef mono_thread_start_return_t ep_rt_thread_start_func_return_t;
-typedef MonoNativeThreadId ep_rt_thread_id_t;
 
 typedef EventPipeThreadHolder * (*ep_rt_thread_holder_alloc_func)(void);
 typedef void (*ep_rt_thread_holder_free_func)(EventPipeThreadHolder *thread_holder);
@@ -1376,13 +1375,13 @@ ep_rt_processors_get_count (void)
 
 static
 inline
-size_t
+ep_rt_thread_id_t
 ep_rt_current_thread_get_id (void)
 {
 #ifdef EP_RT_MONO_USE_STATIC_RUNTIME
-       return MONO_NATIVE_THREAD_ID_TO_UINT (mono_native_thread_id_get ());
+       return mono_native_thread_id_get ();
 #else
-       return MONO_NATIVE_THREAD_ID_TO_UINT (ep_rt_mono_func_table_get ()->ep_rt_mono_native_thread_id_get ());
+       return ep_rt_mono_func_table_get ()->ep_rt_mono_native_thread_id_get ();
 #endif
 }
 
@@ -1848,10 +1847,26 @@ ep_rt_thread_get_handle (void)
 
 static
 inline
-size_t
+ep_rt_thread_id_t
 ep_rt_thread_get_id (ep_rt_thread_handle_t thread_handle)
 {
-       return MONO_NATIVE_THREAD_ID_TO_UINT (mono_thread_info_get_tid (thread_handle));
+       return mono_thread_info_get_tid (thread_handle);
+}
+
+static
+inline
+uint64_t
+ep_rt_thread_id_t_to_uint64_t (ep_rt_thread_id_t thread_id)
+{
+       return (uint64_t)MONO_NATIVE_THREAD_ID_TO_UINT (thread_id);
+}
+
+static
+inline
+ep_rt_thread_id_t
+ep_rt_uint64_t_to_thread_id_t (uint64_t thread_id)
+{
+       return MONO_UINT_TO_NATIVE_THREAD_ID (thread_id);
 }
 
 static
index 916c737..8fde364 100644 (file)
@@ -134,5 +134,7 @@ typedef struct _rt_mono_event_internal_t ep_rt_wait_event_handle_t;
 typedef struct _rt_mono_lock_internal_t ep_rt_lock_handle_t;
 typedef ep_rt_lock_handle_t ep_rt_spin_lock_handle_t;
 
+typedef MonoNativeThreadId ep_rt_thread_id_t;
+
 #endif /* ENABLE_PERFTRACING */
 #endif /* __EVENTPIPE_RT_TYPES_MONO_H__ */
index 39e531b..fd41505 100644 (file)
@@ -8,6 +8,7 @@ static MonoCoopMutex fds_mutex;
 static MonoFDHandleCallback fds_callback[MONO_FDTYPE_COUNT];
 static mono_lazy_init_t fds_init = MONO_LAZY_INIT_STATUS_NOT_INITIALIZED;
 
+#ifndef DISABLE_ASSERT_MESSAGES
 static const gchar *types_str[] = {
        "File",
        "Console",
@@ -15,6 +16,7 @@ static const gchar *types_str[] = {
        "Socket",
        NULL
 };
+#endif
 
 static void
 fds_remove (gpointer data)
index 727889b..77f8c05 100644 (file)
@@ -6061,7 +6061,6 @@ ves_icall_RuntimeType_get_core_clr_security_level (MonoReflectionTypeHandle rfie
        return_val_if_nok (error, -1);
        return mono_security_core_clr_class_level (klass);
 }
-#endif
 
 int
 ves_icall_RuntimeFieldInfo_get_core_clr_security_level (MonoReflectionFieldHandle rfield, MonoError *error)
@@ -6076,6 +6075,7 @@ ves_icall_RuntimeMethodInfo_get_core_clr_security_level (MonoReflectionMethodHan
        MonoMethod *method = MONO_HANDLE_GETVAL (rfield, method);
        return mono_security_core_clr_method_level (method, TRUE);
 }
+#endif
 
 MonoStringHandle
 ves_icall_System_Reflection_RuntimeAssembly_get_fullname (MonoReflectionAssemblyHandle assembly, MonoError *error)
@@ -6818,11 +6818,13 @@ mono_icall_module_get_hinstance (MonoImage *image)
 }
 #endif /* HOST_WIN32 */
 
+#ifndef ENABLE_NETCORE
 gpointer
 ves_icall_System_Reflection_RuntimeModule_GetHINSTANCE (MonoImage *image, MonoError *error)
 {
        return mono_icall_module_get_hinstance (image);
 }
+#endif
 
 void
 ves_icall_System_Reflection_RuntimeModule_GetPEKind (MonoImage *image, gint32 *pe_kind, gint32 *machine, MonoError *error)
index a959d2e..df72b4e 100644 (file)
@@ -129,7 +129,7 @@ mono_gc_make_descr_for_object (gsize *bitmap, int numbits, size_t obj_size)
        }
 
        if (first_set < 0) {
-               SGEN_LOG (6, "Ptrfree descriptor %p, size: %ld", (void*)desc, (long)stored_size);
+               SGEN_LOG (6, "Ptrfree descriptor %" PRIu64 ", size: %zu", (uint64_t)desc, stored_size);
                if (stored_size <= MAX_RUNLEN_OBJECT_SIZE && stored_size <= SGEN_MAX_SMALL_OBJ_SIZE)
                        return DESC_TYPE_SMALL_PTRFREE | stored_size;
                return DESC_TYPE_COMPLEX_PTRFREE;
@@ -142,7 +142,7 @@ mono_gc_make_descr_for_object (gsize *bitmap, int numbits, size_t obj_size)
        /* we know the 2-word header is ptr-free */
        if (last_set < BITMAP_NUM_BITS + OBJECT_HEADER_WORDS && stored_size <= SGEN_MAX_SMALL_OBJ_SIZE) {
                desc = DESC_TYPE_BITMAP | ((*bitmap >> OBJECT_HEADER_WORDS) << LOW_TYPE_BITS);
-               SGEN_LOG (6, "Largebitmap descriptor %p, size: %ld, last set: %d", (void*)desc, (long)stored_size, last_set);
+               SGEN_LOG (6, "Largebitmap descriptor %" PRIu64 ", size: %zu, last set: %d", (uint64_t)desc, stored_size, last_set);
                return desc;
        }
 
@@ -153,7 +153,7 @@ mono_gc_make_descr_for_object (gsize *bitmap, int numbits, size_t obj_size)
                 */
                if (first_set < 256 && num_set < 256 && (first_set + num_set == last_set + 1)) {
                        desc = DESC_TYPE_RUN_LENGTH | stored_size | (first_set << 16) | (num_set << 24);
-                       SGEN_LOG (6, "Runlen descriptor %p, size: %ld, first set: %d, num set: %d", (void*)desc, (long)stored_size, first_set, num_set);
+                       SGEN_LOG (6, "Runlen descriptor %" PRIu64 ", size: %zu, first set: %d, num set: %d", (uint64_t)desc, stored_size, first_set, num_set);
                        return desc;
                }
        }
index ffc35bb..ac1900c 100644 (file)
@@ -209,7 +209,7 @@ ds_server_init (void)
                ds_rt_auto_trace_init ();
                ds_rt_auto_trace_launch ();
 
-               ep_rt_thread_id_t thread_id = 0;
+               ep_rt_thread_id_t thread_id = ep_rt_uint64_t_to_thread_id_t (0);
 
                if (!ep_rt_thread_create ((void *)server_thread, NULL, EP_THREAD_TYPE_SERVER, (void *)&thread_id)) {
                        // Failed to create IPC thread.
index b767f9b..9c6e9c2 100644 (file)
@@ -1161,7 +1161,7 @@ ep_buffer_manager_write_all_buffers_to_file_v4 (
                        if (buffer_manager->current_event == NULL)
                                break;
 
-                       size_t capture_thread_id = ep_thread_get_os_thread_id (ep_buffer_get_writer_thread (buffer_manager->current_buffer));
+                       uint64_t capture_thread_id = ep_thread_get_os_thread_id (ep_buffer_get_writer_thread (buffer_manager->current_buffer));
 
                        EventPipeBufferList *buffer_list = buffer_manager->current_buffer_list;
 
index 1bf06c8..186eef2 100644 (file)
@@ -110,7 +110,7 @@ ep_buffer_write_event (
                (EventPipeEventInstance *)buffer->current,
                ep_event,
                proc_number,
-               (thread == NULL) ? ep_rt_current_thread_get_id () : ep_rt_thread_get_id (thread),
+               ep_rt_thread_id_t_to_uint64_t((thread == NULL) ? ep_rt_current_thread_get_id () : ep_rt_thread_get_id (thread)),
                data_dest,
                ep_event_payload_get_size (payload),
                (thread == NULL) ? NULL : activity_id,
index d840959..30335b0 100644 (file)
@@ -383,7 +383,7 @@ ep_config_build_event_metadata_event (
        instance = ep_event_metdata_event_alloc (
                config->metadata_event,
                ep_rt_current_processor_get_number (),
-               ep_rt_current_thread_get_id (),
+               ep_rt_thread_id_t_to_uint64_t (ep_rt_current_thread_get_id ()),
                instance_payload,
                instance_payload_size,
                NULL /* pActivityId */,
index d609e7e..d640438 100644 (file)
@@ -208,7 +208,7 @@ ep_event_instance_serialize_to_json_file (
                ep_event_get_event_version (ep_event_instance->ep_event));
 
        if (characters_written > 0 && characters_written < EP_ARRAY_SIZE (buffer))
-               ep_json_file_write_event_data (json_file, ep_event_instance->timestamp, (ep_rt_thread_id_t)(ep_event_instance->thread_id), buffer, &ep_event_instance->stack_contents);
+               ep_json_file_write_event_data (json_file, ep_event_instance->timestamp, ep_rt_uint64_t_to_thread_id_t (ep_event_instance->thread_id), buffer, &ep_event_instance->stack_contents);
 }
 #else
 void
index fe7b929..d2674af 100644 (file)
@@ -9,6 +9,7 @@
 #include "ep.h"
 #include "ep-event-instance.h"
 #include "ep-rt.h"
+#include <inttypes.h>
 
 #ifdef EP_CHECKED_BUILD
 
@@ -134,7 +135,7 @@ ep_json_file_write_event_data (
                        json_file_write_string (json_file, buffer);
        }
 
-       characters_written = ep_rt_utf8_string_snprintf (buffer, EP_ARRAY_SIZE (buffer), "\"Thread (%ld)\"]},", (uint64_t)thread_id);
+       characters_written = ep_rt_utf8_string_snprintf (buffer, EP_ARRAY_SIZE (buffer), "\"Thread (%" PRIu64 ")\"]},", ep_rt_thread_id_t_to_uint64_t (thread_id));
        if (characters_written > 0 && characters_written < EP_ARRAY_SIZE (buffer))
                json_file_write_string (json_file, buffer);
 }
index cbe82dc..52d65e6 100644 (file)
@@ -468,7 +468,7 @@ uint32_t
 ep_rt_processors_get_count (void);
 
 static
-size_t
+ep_rt_thread_id_t
 ep_rt_current_thread_get_id (void);
 
 static
@@ -690,10 +690,18 @@ ep_rt_thread_handle_t
 ep_rt_thread_get_handle (void);
 
 static
-size_t
+ep_rt_thread_id_t
 ep_rt_thread_get_id (ep_rt_thread_handle_t thread_handle);
 
 static
+uint64_t
+ep_rt_thread_id_t_to_uint64_t (ep_rt_thread_id_t thread_id);
+
+static
+ep_rt_thread_id_t
+ep_rt_uint64_t_to_thread_id_t (uint64_t thread_id);
+
+static
 bool
 ep_rt_thread_has_started (ep_rt_thread_handle_t thread_handle);
 
index 0bbea13..615ceea 100644 (file)
@@ -210,7 +210,7 @@ sample_profiler_enable (void)
                if (!ep_rt_wait_event_is_valid (&_thread_shutdown_event))
                        EP_ASSERT (!"Unable to create sample profiler event.");
 
-               ep_rt_thread_id_t thread_id = 0;
+               ep_rt_thread_id_t thread_id = ep_rt_uint64_t_to_thread_id_t (0);
                if (!ep_rt_thread_create (sampling_thread, NULL, EP_THREAD_TYPE_SAMPLING, &thread_id))
                        EP_ASSERT (!"Unable to create sample profiler thread.");
 
index 7221404..02a3bce 100644 (file)
@@ -94,7 +94,7 @@ session_create_ipc_streaming_thread (EventPipeSession *session)
        if (!ep_rt_wait_event_is_valid (&session->rt_thread_shutdown_event))
                EP_ASSERT (!"Unable to create IPC stream flushing thread shutdown event.");
 
-       ep_rt_thread_id_t thread_id = 0;
+       ep_rt_thread_id_t thread_id = ep_rt_uint64_t_to_thread_id_t (0);
        if (!ep_rt_thread_create ((void *)streaming_thread, (void *)session, EP_THREAD_TYPE_SESSION, &thread_id))
                EP_ASSERT (!"Unable to create IPC stream flushing thread.");
 }
index 33e246f..9632ce7 100644 (file)
@@ -35,7 +35,7 @@ ep_thread_alloc (void)
        ep_rt_spin_lock_alloc (&instance->rt_lock);
        ep_raise_error_if_nok (ep_rt_spin_lock_is_valid (&instance->rt_lock));
 
-       instance->os_thread_id = ep_rt_current_thread_get_id ();
+       instance->os_thread_id = ep_rt_thread_id_t_to_uint64_t (ep_rt_current_thread_get_id ());
        memset (instance->session_state, 0, sizeof (instance->session_state));
 
        EP_SPIN_LOCK_ENTER (&_ep_threads_lock, section1)
index d982e33..1f62102 100644 (file)
@@ -37,7 +37,7 @@ struct _EventPipeThread_Internal {
        ep_rt_spin_lock_handle_t rt_lock;
        // This is initialized when the Thread object is first constructed and remains
        // immutable afterwards.
-       size_t os_thread_id;
+       uint64_t os_thread_id;
        // The EventPipeThreadHolder maintains one count while the thread is alive
        // and each session's EventPipeBufferList maintains one count while it
        // exists.
@@ -69,7 +69,7 @@ ep_thread_get_activity_id_cref (ep_rt_thread_activity_id_handle_t activity_id_ha
 EP_DEFINE_GETTER(EventPipeThread *, thread, EventPipeSession *, rundown_session);
 EP_DEFINE_SETTER(EventPipeThread *, thread, EventPipeSession *, rundown_session);
 EP_DEFINE_GETTER_REF(EventPipeThread *, thread, ep_rt_spin_lock_handle_t *, rt_lock);
-EP_DEFINE_GETTER(EventPipeThread *, thread, size_t, os_thread_id);
+EP_DEFINE_GETTER(EventPipeThread *, thread, uint64_t, os_thread_id);
 EP_DEFINE_GETTER_REF(EventPipeThread *, thread, int32_t *, ref_count);
 
 EventPipeThread *