瀏覽代碼

[runtime] fix warnings on linux (gcc 8.3.0) (#18479)

* [aot] fix warnings on linux (gcc 8.3.0)

Fixes these warnings:
```
aot-compiler.c: In function ‘emit_trampolines’:
aot-compiler.c:7675:28: warning: ‘_e’ directive writing 2 bytes into a region of size between 1 and 256 [-Wformat-overflow=]
    sprintf (end_symbol, "%s_e", symbol);
                            ^~
aot-compiler.c:7675:4: note: ‘sprintf’ output between 3 and 258 bytes into a destination of size 256
    sprintf (end_symbol, "%s_e", symbol);
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
At top level:
aot-compiler.c:753:1: warning: ‘link_shared_library’ defined but not used [-Wunused-function]
 link_shared_library (MonoAotCompile *acfg)
 ^~~~~~~~~~~~~~~~~~~
aot-compiler.c:558:1: warning: ‘mangle_symbol_alloc’ defined but not used [-Wunused-function]
 mangle_symbol_alloc (const char * symbol)
 ^~~~~~~~~~~~~~~~~~~
aot-compiler.c:535:1: warning: ‘mangle_symbol’ defined but not used [-Wunused-function]
 mangle_symbol (const char * symbol, char * mangled_symbol, gsize length)
 ^~~~~~~~~~~~~~~~~~~
```

* [amd64] fix warnings on linux (gcc 8.3.0)

Fixes this warning:
```
tramp-amd64.c: In function ‘mono_arch_create_generic_trampoline’:
tramp-amd64.c:242:65: warning: variable ‘ex_offset’ set but not used [-Wunused-but-set-variable]
  int i, lmf_offset, offset, res_offset, arg_offset, rax_offset, ex_offset, tramp_offset, ctx_offset, saved_regs_offset;
                                                                 ^~~~~~~~~
```

* [lldb] fix warnings on linux (gcc 8.3.0)

Fixes these warnings:
```
lldb.c:243:1: warning: ‘buffer_add_buffer’ defined but not used [-Wunused-function]
 buffer_add_buffer (Buffer *buf, Buffer *data)
 ^~~~~~~~~~~~~~~~~
lldb.c:215:1: warning: ‘buffer_add_id’ defined but not used [-Wunused-function]
 buffer_add_id (Buffer *buf, int id)
 ^~~~~~~~~~~~~
lldb.c:208:1: warning: ‘buffer_add_long’ defined but not used [-Wunused-function]
 buffer_add_long (Buffer *buf, guint64 l)
 ^~~~~~~~~~~~~~~
lldb.c:188:1: warning: ‘buffer_add_short’ defined but not used [-Wunused-function]
 buffer_add_short (Buffer *buf, guint32 val)
 ^~~~~~~~~~~~~~~~

```

* [interp] fix warnings on linux (gcc 8.3.0)

Fixes these warnings:
```
interp/interp.c:3425:1: warning: ‘g_error_xsx’ defined but not used [-Wunused-function]
 g_error_xsx (const char *format, int x1, const char *s, int x2)
 ^~~~~~~~~~~
  CC       interp/libmono_ee_interp_la-mintops.lo
  CC       interp/libmono_ee_interp_la-transform.lo
  CCLD     libmono-ee-interp.la
ar: `u' modifier ignored since `D' is the default (see `U')
  CC       libmono_dbg_la-debugger-agent.lo
  CC       libmono_dbg_la-debugger-state-machine.lo
  CC       libmono_dbg_la-debugger-engine.lo
  CCLD     libmono-dbg.la
ar: `u' modifier ignored since `D' is the default (see `U')
  CCLD     mono-sgen
  AR       libmain.a
ar: `u' modifier ignored since `D' is the default (see `U')
  CC       interp/libmaintest_a-whitebox.o
In file included from interp/whitebox.c:3:
interp/transform.h:163:12: warning: ‘stack_type’ defined but not used [-Wunused-variable]
 static int stack_type [] = {
            ^~~~~~~~~~
interp/transform.h:155:20: warning: ‘stack_type_string’ defined but not used [-Wunused-variable]
 static const char *stack_type_string [] = { "I4", "I8", "R4", "R8", "O ", "VT", "MP", "F " };
                    ^~~~~~~~~~~~~~~~~

```

* [thread state] fix warnings on linux (gcc 8.3.0)

Fixes these warnings:
```
  CC       libmonoutils_la-mono-threads-state-machine.lo
mono-threads-state-machine.c:33:1: warning: ‘get_thread_no_safepoints’ defined but not used [-Wunused-function]
 get_thread_no_safepoints (int thread_state)
 ^~~~~~~~~~~~~~~~~~~~~~~~
mono-threads-state-machine.c:26:1: warning: ‘get_thread_suspend_count’ defined but not used [-Wunused-function]
 get_thread_suspend_count (int thread_state)
 ^~~~~~~~~~~~~~~~~~~~~~~~
```

* [domain] fix warnings on linux (gcc 8.3.0)

Fixes these warnings:
```
appdomain.c:2415:1: warning: ‘get_app_context_base_directory’ defined but not used [-Wunused-function]
 get_app_context_base_directory (MonoError *error)
 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  CC       libmonoruntimesgen_la-assembly-load-context.lo
  CC       libmonoruntimesgen_la-domain.lo
domain.c:135:1: warning: ‘mono_domain_alcs_lock’ declared ‘static’ but never defined [-Wunused-function]
 mono_domain_alcs_lock (MonoDomain *domain);
 ^~~~~~~~~~~~~~~~~~~~~
domain.c:138:1: warning: ‘mono_domain_alcs_unlock’ declared ‘static’ but never defined [-Wunused-function]
 mono_domain_alcs_unlock (MonoDomain *domain);
 ^~~~~~~~~~~~~~~~~~~~~~~
domain.c:2129:1: warning: ‘mono_alc_free’ defined but not used [-Wunused-function]
 mono_alc_free (MonoAssemblyLoadContext *alc)
 ^~~~~~~~~~~~~
domain.c:2108:1: warning: ‘mono_domain_create_default_alc’ defined but not used [-Wunused-function]
 mono_domain_create_default_alc (MonoDomain *domain)
 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
domain.c:2084:1: warning: ‘create_alc’ defined but not used [-Wunused-function]
 create_alc (MonoDomain *domain, gboolean is_default)
 ^~~~~~~~~~

```

* [native library] fix warnings on linux (gcc 8.3.0)

Fixes this warning:
```
  CC       libmonoruntimesgen_la-native-library.lo
native-library.c:295:1: warning: ‘mono_loader_register_module_locking’ defined but not used [-Wunused-function]
 mono_loader_register_module_locking (const char *name, MonoDl *module)
 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```

* [sample] fix warnings on linux (gcc 8.3.0)

Fixes this warning:
```
  CC       libtestlib_la-test-mono-embed.lo
In file included from test-mono-embed.c:7:
../../samples/embed/teste.c:20:1: warning: function declaration isn’t a prototype [-Wstrict-prototypes]
 gimme () {
 ^~~~~

```

* fix for checked builds
Bernhard Urban-Forster 5 年之前
父節點
當前提交
b4c506c304

+ 4 - 0
mono/metadata/appdomain.c

@@ -154,7 +154,9 @@ static MonoLoadFunc load_function = NULL;
 
 /* Lazy class loading functions */
 static GENERATE_GET_CLASS_WITH_CACHE (assembly, "System.Reflection", "Assembly");
+#ifdef ENABLE_NETCORE
 static GENERATE_GET_CLASS_WITH_CACHE (app_context, "System", "AppContext");
+#endif
 
 GENERATE_GET_CLASS_WITH_CACHE (appdomain, MONO_APPDOMAIN_CLASS_NAME_SPACE, MONO_APPDOMAIN_CLASS_NAME);
 GENERATE_GET_CLASS_WITH_CACHE (appdomain_setup, MONO_APPDOMAIN_SETUP_CLASS_NAME_SPACE, MONO_APPDOMAIN_SETUP_CLASS_NAME);
@@ -2411,6 +2413,7 @@ real_load (gchar **search_path, const gchar *culture, const gchar *name, const M
 	return result;
 }
 
+#ifdef ENABLE_NETCORE
 static char *
 get_app_context_base_directory (MonoError *error)
 {
@@ -2431,6 +2434,7 @@ get_app_context_base_directory (MonoError *error)
 
 	HANDLE_FUNCTION_RETURN_VAL (base_dir);
 }
+#endif
 
 /*
  * Try loading the assembly from ApplicationBase and PrivateBinPath 

+ 6 - 10
mono/metadata/domain.c

@@ -131,6 +131,7 @@ get_runtime_by_version (const char *version);
 static void
 mono_domain_alcs_destroy (MonoDomain *domain);
 
+#ifdef ENABLE_NETCORE
 static void
 mono_domain_alcs_lock (MonoDomain *domain);
 
@@ -139,6 +140,7 @@ mono_domain_alcs_unlock (MonoDomain *domain);
 
 static void
 mono_domain_create_default_alc (MonoDomain *domain);
+#endif
 
 static LockFreeMempool*
 lock_free_mempool_new (void)
@@ -2080,10 +2082,10 @@ mono_domain_alcs_unlock (MonoDomain *domain)
 #endif
 
 
+#ifdef ENABLE_NETCORE
 static MonoAssemblyLoadContext *
 create_alc (MonoDomain *domain, gboolean is_default)
 {
-#ifdef ENABLE_NETCORE
 	MonoAssemblyLoadContext *alc = NULL;
 
 	mono_domain_alcs_lock (domain);
@@ -2099,22 +2101,18 @@ create_alc (MonoDomain *domain, gboolean is_default)
 leave:
 	mono_domain_alcs_unlock (domain);
 	return alc;
-#else
-	return NULL;
-#endif
 }
+#endif
 
+#ifdef ENABLE_NETCORE
 void
 mono_domain_create_default_alc (MonoDomain *domain)
 {
-#ifdef ENABLE_NETCORE
 	if (domain->default_alc)
 		return;
 	create_alc (domain, TRUE);
-#endif
 }
 
-#ifdef ENABLE_NETCORE
 MonoAssemblyLoadContext *
 mono_domain_create_individual_alc (MonoDomain *domain, uint32_t this_gchandle, gboolean collectible, MonoError *error)
 {
@@ -2123,16 +2121,14 @@ mono_domain_create_individual_alc (MonoDomain *domain, uint32_t this_gchandle, g
 	alc->gchandle = this_gchandle;
 	return alc;
 }
-#endif
 
 static void
 mono_alc_free (MonoAssemblyLoadContext *alc)
 {
-#ifdef ENABLE_NETCORE
 	mono_alc_cleanup (alc);
 	g_free (alc);
-#endif
 }
+#endif
 
 void
 mono_domain_alcs_destroy (MonoDomain *domain)

+ 2 - 0
mono/metadata/native-library.c

@@ -291,6 +291,7 @@ mono_loader_register_module (const char *name, MonoDl *module)
 	mono_global_loader_data_unlock ();
 }
 
+#ifdef ENABLE_NETCORE
 static MonoDl *
 mono_loader_register_module_locking (const char *name, MonoDl *module)
 {
@@ -317,6 +318,7 @@ exit:
 
 	return result;
 }
+#endif
 
 static void
 remove_cached_module (gpointer key, gpointer value, gpointer user_data)

+ 5 - 9
mono/mini/aot-compiler.c

@@ -531,6 +531,7 @@ report_loader_error (MonoAotCompile *acfg, MonoError *error, gboolean fatal, con
 
 #define MAX_SYMBOL_SIZE 256
 
+#if defined(TARGET_WIN32) && defined(TARGET_X86)
 static const char *
 mangle_symbol (const char * symbol, char * mangled_symbol, gsize length)
 {
@@ -540,15 +541,11 @@ mangle_symbol (const char * symbol, char * mangled_symbol, gsize length)
 	g_assert (NULL != mangled_symbol);
 	g_assert (0 != length);
 
-#if defined(TARGET_WIN32) && defined(TARGET_X86)
 	if (symbol && '_' != symbol [0]) {
 		needed_size = g_snprintf (mangled_symbol, length, "_%s", symbol);
 	} else {
 		needed_size = g_snprintf (mangled_symbol, length, "%s", symbol);
 	}
-#else
-	needed_size = g_snprintf (mangled_symbol, length, "%s", symbol);
-#endif
 
 	g_assert (0 <= needed_size && needed_size < length);
 	return mangled_symbol;
@@ -559,17 +556,14 @@ mangle_symbol_alloc (const char * symbol)
 {
 	g_assert (NULL != symbol);
 
-#if defined(TARGET_WIN32) && defined(TARGET_X86)
 	if (symbol && '_' != symbol [0]) {
 		return g_strdup_printf ("_%s", symbol);
 	}
 	else {
 		return g_strdup_printf ("%s", symbol);
 	}
-#else
-	return g_strdup_printf ("%s", symbol);
-#endif
 }
+#endif
 
 static void
 emit_section_change (MonoAotCompile *acfg, const char *section_name, int subsection_index)
@@ -749,11 +743,13 @@ emit_global_inner (MonoAotCompile *acfg, const char *name, gboolean func)
 
 #endif
 
+#ifdef TARGET_WIN32_MSVC
 static gboolean
 link_shared_library (MonoAotCompile *acfg)
 {
 	return !acfg->aot_opts.static_link && !acfg->aot_opts.asm_only;
 }
+#endif
 
 static gboolean
 add_to_global_symbol_table (MonoAotCompile *acfg)
@@ -7472,7 +7468,7 @@ static void
 emit_trampolines (MonoAotCompile *acfg)
 {
 	char symbol [MAX_SYMBOL_SIZE];
-	char end_symbol [MAX_SYMBOL_SIZE];
+	char end_symbol [MAX_SYMBOL_SIZE + 2];
 	int i, tramp_got_offset;
 	int ntype;
 #ifdef MONO_ARCH_HAVE_FULL_AOT_TRAMPOLINES

+ 2 - 0
mono/mini/interp/interp.c

@@ -3421,11 +3421,13 @@ g_warning_ds (const char *format, int d, const char *s)
 	g_warning (format, d, s);
 }
 
+#if !USE_COMPUTED_GOTO
 static void
 g_error_xsx (const char *format, int x1, const char *s, int x2)
 {
 	g_error (format, x1, s, x2);
 }
+#endif
 
 static MONO_ALWAYS_INLINE void
 method_entry (ThreadContext *context, InterpFrame *frame, gboolean *out_tracing, MonoException **out_ex)

+ 16 - 0
mono/mini/interp/transform.c

@@ -164,6 +164,22 @@ static const MagicIntrinsic int_cmpop[] = {
 	{ "op_LessThanOrEqual", {MINT_CLE_P, MINT_CLE_UN_P, MINT_CLE_FP}}
 };
 
+static const char *stack_type_string [] = { "I4", "I8", "R4", "R8", "O ", "VT", "MP", "F " };
+
+static int stack_type [] = {
+	STACK_TYPE_I4, /*I1*/
+	STACK_TYPE_I4, /*U1*/
+	STACK_TYPE_I4, /*I2*/
+	STACK_TYPE_I4, /*U2*/
+	STACK_TYPE_I4, /*I4*/
+	STACK_TYPE_I8, /*I8*/
+	STACK_TYPE_R4, /*R4*/
+	STACK_TYPE_R8, /*R8*/
+	STACK_TYPE_O,  /*O*/
+	STACK_TYPE_MP, /*P*/
+	STACK_TYPE_VT
+};
+
 static gboolean generate_code (TransformData *td, MonoMethod *method, MonoMethodHeader *header, MonoGenericContext *generic_context, MonoError *error);
 
 static InterpInst*

+ 0 - 16
mono/mini/interp/transform.h

@@ -152,28 +152,12 @@ typedef struct
 #define STACK_TYPE_MP 6
 #define STACK_TYPE_F  7
 
-static const char *stack_type_string [] = { "I4", "I8", "R4", "R8", "O ", "VT", "MP", "F " };
-
 #if SIZEOF_VOID_P == 8
 #define STACK_TYPE_I STACK_TYPE_I8
 #else
 #define STACK_TYPE_I STACK_TYPE_I4
 #endif
 
-static int stack_type [] = {
-	STACK_TYPE_I4, /*I1*/
-	STACK_TYPE_I4, /*U1*/
-	STACK_TYPE_I4, /*I2*/
-	STACK_TYPE_I4, /*U2*/
-	STACK_TYPE_I4, /*I4*/
-	STACK_TYPE_I8, /*I8*/
-	STACK_TYPE_R4, /*R4*/
-	STACK_TYPE_R8, /*R8*/
-	STACK_TYPE_O,  /*O*/
-	STACK_TYPE_MP, /*P*/
-	STACK_TYPE_VT
-};
-
 /* test exports for white box testing */
 void
 mono_test_interp_cprop (TransformData *td);

+ 0 - 28
mono/mini/lldb.c

@@ -184,15 +184,6 @@ buffer_add_byte (Buffer *buf, guint8 val)
 	buf->p++;
 }
 
-static void
-buffer_add_short (Buffer *buf, guint32 val)
-{
-	buffer_make_room (buf, 2);
-	buf->p [0] = (val >> 8) & 0xff;
-	buf->p [1] = (val >> 0) & 0xff;
-	buf->p += 2;
-}
-
 static void
 buffer_add_int (Buffer *buf, guint32 val)
 {
@@ -204,19 +195,6 @@ buffer_add_int (Buffer *buf, guint32 val)
 	buf->p += 4;
 }
 
-static void
-buffer_add_long (Buffer *buf, guint64 l)
-{
-	buffer_add_int (buf, (l >> 32) & 0xffffffff);
-	buffer_add_int (buf, (l >> 0) & 0xffffffff);
-}
-
-static void
-buffer_add_id (Buffer *buf, int id)
-{
-	buffer_add_int (buf, (guint64)id);
-}
-
 static void
 buffer_add_data (Buffer *buf, guint8 *data, int len)
 {
@@ -239,12 +217,6 @@ buffer_add_string (Buffer *buf, const char *str)
 	}
 }
 
-static void
-buffer_add_buffer (Buffer *buf, Buffer *data)
-{
-	buffer_add_data (buf, data->buf, buffer_len (data));
-}
-
 static void
 buffer_free (Buffer *buf)
 {

+ 2 - 2
mono/mini/tramp-amd64.c

@@ -239,7 +239,7 @@ mono_arch_create_generic_trampoline (MonoTrampolineType tramp_type, MonoTrampInf
 {
 	const char *tramp_name;
 	guint8 *buf, *code, *tramp, *br [2], *r11_save_code, *after_r11_save_code, *br_ex_check;
-	int i, lmf_offset, offset, res_offset, arg_offset, rax_offset, ex_offset, tramp_offset, ctx_offset, saved_regs_offset;
+	int i, lmf_offset, offset, res_offset, arg_offset, rax_offset, tramp_offset, ctx_offset, saved_regs_offset;
 	int r11_save_offset, saved_fpregs_offset, rbp_offset, framesize, orig_rsp_to_rbp_offset, cfa_offset;
 	gboolean has_caller;
 	GSList *unwind_ops = NULL;
@@ -260,8 +260,8 @@ mono_arch_create_generic_trampoline (MonoTrampolineType tramp_type, MonoTrampInf
 	offset += sizeof (target_mgreg_t);
 	rax_offset = -offset;
 
+	/* ex_offset */
 	offset += sizeof (target_mgreg_t);
-	ex_offset = -offset;
 
 	offset += sizeof (target_mgreg_t);
 	r11_save_offset = -offset;

+ 1 - 0
mono/utils/mono-threads-debug.h

@@ -36,6 +36,7 @@
 #if 1
 #define THREADS_STATE_MACHINE_DEBUG(...)
 #else
+#define THREADS_STATE_MACHINE_DEBUG_ENABLED
 #define THREADS_STATE_MACHINE_DEBUG MOSTLY_ASYNC_SAFE_PRINTF
 #endif
 

+ 4 - 0
mono/utils/mono-threads-state-machine.c

@@ -22,19 +22,23 @@ get_thread_state (int thread_state)
 	return state.state;
 }
 
+#if defined (THREADS_STATE_MACHINE_DEBUG_ENABLED) || defined (ENABLE_CHECKED_BUILD_THREAD)
 static int
 get_thread_suspend_count (int thread_state)
 {
 	const MonoThreadStateMachine state = {thread_state};
 	return state.suspend_count;
 }
+#endif
 
+#ifdef THREADS_STATE_MACHINE_DEBUG_ENABLED
 static gboolean
 get_thread_no_safepoints (int thread_state)
 {
 	const MonoThreadStateMachine state = {thread_state};
 	return state.no_safepoints;
 }
+#endif
 
 static MonoThreadStateMachine
 build_thread_state (int thread_state, int suspend_count, gboolean no_safepoints)

+ 1 - 1
samples/embed/teste.c

@@ -17,7 +17,7 @@
  */
 
 static MonoString*
-gimme () {
+gimme (void) {
 	return mono_string_new (mono_domain_get (), "All your monos are belong to us!");
 }