Skip to content

Commit 577a70a

Browse files
authored
Fix gcc warnings during mono linux-x64 build (#60675)
* Fix gcc warnings during mono linux-x64 build main with Debug configuration: 822 warnings - http://sprunge.us/2GzrDE PR with Debug configuration: 3 warnings related to deprecated sys/sysctl.h includes - http://sprunge.us/JuyA3K after fixing Debug warnings, there were 13 additional warnings in Release configuration: http://sprunge.us/PJCivP PR with Release configuration: (same) 3 warnings - http://sprunge.us/NwKHNE * Address CR feedback
1 parent 594f32e commit 577a70a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+173
-192
lines changed

src/coreclr/pal/src/thread/process.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2148,7 +2148,7 @@ GetProcessIdDisambiguationKey(DWORD processId, UINT64 *disambiguationKey)
21482148

21492149
// All the format specifiers for the fields in the stat file are provided by 'man proc'.
21502150
int sscanfRet = sscanf_s(scanStartPosition,
2151-
"%*c %*d %*d %*d %*d %*d %*u %*lu %*lu %*lu %*lu %*lu %*lu %*ld %*ld %*ld %*ld %*ld %*ld %llu \n",
2151+
"%*c %*d %*d %*d %*d %*d %*u %*u %*u %*u %*u %*u %*u %*d %*d %*d %*d %*d %*d %llu \n",
21522152
&starttime);
21532153

21542154
if (sscanfRet != 1)

src/libraries/Native/Unix/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ if (CLR_CMAKE_TARGET_OSX OR CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS
104104
add_definitions(-D__APPLE_USE_RFC_3542)
105105
endif ()
106106

107-
if (CLR_CMAKE_TARGET_LINUX)
107+
if (CLR_CMAKE_TARGET_LINUX OR CLR_CMAKE_TARGET_ANDROID)
108108
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_GNU_SOURCE")
109109
endif ()
110110

src/libraries/Native/Unix/System.Globalization.Native/pal_collation.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ static UChar* s_breakIteratorRules = NULL;
542542
// We are customizing the break iterator to exclude the CRxLF rule which don't allow breaking between CR and LF.
543543
// The general rules syntax explained in the doc https://unicode-org.github.io/icu/userguide/boundaryanalysis/break-rules.html.
544544
// The ICU latest rules definition exist here https://github.com/unicode-org/icu/blob/main/icu4c/source/data/brkitr/rules/char.txt.
545-
static UBreakIterator* CreateCustomizedBreakIterator()
545+
static UBreakIterator* CreateCustomizedBreakIterator(void)
546546
{
547547
static UChar emptyString[1];
548548
UBreakIterator* breaker;
@@ -815,6 +815,7 @@ static int32_t GetSearchIteratorUsingCollator(
815815
if (!U_SUCCESS(err))
816816
{
817817
int32_t r;
818+
(void)r;
818819
r = RestoreSearchHandle(pSortHandle, *pSearchIterator, options);
819820
assert(r && "restoring search handle shouldn't fail.");
820821
return -1;
@@ -824,6 +825,7 @@ static int32_t GetSearchIteratorUsingCollator(
824825
if (!U_SUCCESS(err))
825826
{
826827
int32_t r;
828+
(void)r;
827829
r = RestoreSearchHandle(pSortHandle, *pSearchIterator, options);
828830
assert(r && "restoring search handle shouldn't fail.");
829831
return -1;

src/libraries/Native/Unix/System.Globalization.Native/pal_icushim.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ static int FindICULibs(const char* versionPrefix, char* symbolName, char* symbol
368368

369369
#endif
370370

371-
static void ValidateICUDataCanLoad()
371+
static void ValidateICUDataCanLoad(void)
372372
{
373373
UVersionInfo version;
374374
UErrorCode err = U_ZERO_ERROR;

src/mono/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,6 @@ endif()
754754
######################################
755755
# EXTRACT VERSION
756756
######################################
757-
include("${CMAKE_CURRENT_SOURCE_DIR}/../../eng/native/configurepaths.cmake")
758757
include_directories(${CLR_ARTIFACTS_OBJ_DIR})
759758
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
760759
if(NOT EXISTS "${VERSION_HEADER_PATH}")

src/mono/cmake/config.h.in

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -510,14 +510,11 @@
510510
/* Define to 1 if you have the `strerror_r' function. */
511511
#cmakedefine HAVE_STRERROR_R 1
512512

513-
/* Define to 1 if strerror_r returns char *. */
514-
#cmakedefine STRERROR_R_CHAR_P 1
515-
516513
/* Have GLIBC_BEFORE_2_3_4_SCHED_SETAFFINITY */
517514
#cmakedefine GLIBC_BEFORE_2_3_4_SCHED_SETAFFINITY 1
518515

519516
/* GLIBC has CPU_COUNT macro in sched.h */
520-
#cmakedefine GLIBC_HAS_CPU_COUNT 1
517+
#cmakedefine HAVE_GNU_CPU_COUNT
521518

522519
/* Have large file support */
523520
#cmakedefine HAVE_LARGE_FILE_SUPPORT 1
@@ -712,6 +709,8 @@
712709
/* The size of `size_t', as computed by sizeof. */
713710
#define SIZEOF_SIZE_T @SIZEOF_SIZE_T@
714711

712+
#cmakedefine01 HAVE_GNU_STRERROR_R
713+
715714
/* Define to 1 if the system has the type `struct sockaddr'. */
716715
#cmakedefine HAVE_STRUCT_SOCKADDR 1
717716

src/mono/cmake/configure.cmake

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ include(CheckTypeSize)
66
include(CheckStructHasMember)
77
include(CheckSymbolExists)
88
include(CheckCCompilerFlag)
9+
include(CheckCSourceCompiles)
910

1011
# Apple platforms like macOS/iOS allow targeting older operating system versions with a single SDK,
1112
# the mere presence of a symbol in the SDK doesn't tell us whether the deployment target really supports it.
@@ -124,21 +125,44 @@ check_type_size("long" SIZEOF_LONG)
124125
check_type_size("long long" SIZEOF_LONG_LONG)
125126
check_type_size("size_t" SIZEOF_SIZE_T)
126127

128+
if (HOST_LINUX OR HOST_ANDROID)
129+
set(CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
130+
endif()
131+
132+
check_c_source_compiles(
133+
"
134+
#include <string.h>
135+
int main(void)
136+
{
137+
char buffer[1];
138+
char c = *strerror_r(0, buffer, 0);
139+
return 0;
140+
}
141+
"
142+
HAVE_GNU_STRERROR_R)
143+
144+
check_c_source_compiles(
145+
"
146+
#include <sched.h>
147+
int main(void)
148+
{
149+
CPU_COUNT((void *) 0);
150+
return 0;
151+
}
152+
"
153+
HAVE_GNU_CPU_COUNT)
154+
155+
if (HOST_LINUX OR HOST_ANDROID)
156+
set(CMAKE_REQUIRED_DEFINITIONS)
157+
endif()
158+
127159
# ICONV
128160
set(ICONV_LIB)
129161
find_library(LIBICONV_FOUND iconv)
130162
if(NOT LIBICONV_FOUND STREQUAL "LIBICONV_FOUND-NOTFOUND")
131163
set(ICONV_LIB "iconv")
132164
endif()
133165

134-
file(WRITE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/test.c
135-
"#include <sched.h>\n"
136-
"void main () { CPU_COUNT((void *) 0); }\n"
137-
)
138-
try_compile(GLIBC_HAS_CPU_COUNT ${CMAKE_BINARY_DIR}/CMakeTmp SOURCES "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/test.c"
139-
COMPILE_DEFINITIONS "-D_GNU_SOURCE")
140-
141-
142166
if(HOST_WIN32)
143167
# checking for this doesn't work for some reason, hardcode result
144168
set(HAVE_WINTERNL_H 1)

src/mono/cmake/defines-todo.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
#option (MAJOR_IN_MKDEV "Define to 1 if `major', `minor', and `makedev' are declared in <mkdev.h>.")
66
#option (MAJOR_IN_SYSMACROS "Define to 1 if `major', `minor', and `makedev' are declared in <sysmacros.h>.")
7-
#option (STRERROR_R_CHAR_P "Define to 1 if strerror_r returns char *.")
87
#option (HAVE_LIBICONV "Define to 1 if you have the `iconv' library (-liconv).")
98
#option (ANDROID_UNIFIED_HEADERS "Whether Android NDK unified headers are used")
109
#option (MONO_DL_NEED_USCORE "Does dlsym require leading underscore.")

src/mono/mono/component/debugger-agent.c

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2541,7 +2541,6 @@ try_process_suspend (void *the_tls, MonoContext *ctx, gboolean from_breakpoint)
25412541
static void
25422542
suspend_vm (void)
25432543
{
2544-
gboolean tp_suspend = FALSE;
25452544
mono_loader_lock ();
25462545

25472546
mono_coop_mutex_lock (&suspend_mutex);
@@ -2557,12 +2556,6 @@ suspend_vm (void)
25572556
}
25582557

25592558
mono_coop_mutex_unlock (&suspend_mutex);
2560-
2561-
if (suspend_count == 1)
2562-
/*
2563-
* Suspend creation of new threadpool threads, since they cannot run
2564-
*/
2565-
tp_suspend = TRUE;
25662559
mono_loader_unlock ();
25672560
}
25682561

@@ -2576,7 +2569,6 @@ static void
25762569
resume_vm (void)
25772570
{
25782571
g_assert (is_debugger_thread ());
2579-
gboolean tp_resume = FALSE;
25802572

25812573
mono_loader_lock ();
25822574

@@ -2599,8 +2591,6 @@ resume_vm (void)
25992591
mono_coop_mutex_unlock (&suspend_mutex);
26002592
//g_assert (err == 0);
26012593

2602-
if (suspend_count == 0)
2603-
tp_resume = TRUE;
26042594
mono_loader_unlock ();
26052595
}
26062596

@@ -5257,15 +5247,15 @@ decode_vtype (MonoType *t, MonoDomain *domain, gpointer void_addr, gpointer void
52575247
{
52585248
guint8 *addr = (guint8*)void_addr;
52595249
guint8 *buf = (guint8*)void_buf;
5260-
gboolean is_enum;
52615250
MonoClass *klass;
52625251
MonoClassField *f;
52635252
int nfields;
52645253
gpointer iter = NULL;
52655254
MonoDomain *d;
52665255
ErrorCode err;
52675256

5268-
is_enum = decode_byte (buf, &buf, limit);
5257+
/* is_enum, ignored */
5258+
decode_byte (buf, &buf, limit);
52695259
if (CHECK_PROTOCOL_VERSION(2, 61))
52705260
decode_byte (buf, &buf, limit);
52715261
klass = decode_typeid (buf, &buf, limit, &d, &err);
@@ -5487,7 +5477,6 @@ decode_value_internal (MonoType *t, int type, MonoDomain *domain, guint8 *addr,
54875477
} else if (type == MONO_TYPE_VALUETYPE) {
54885478
ERROR_DECL (error);
54895479
guint8 *buf2;
5490-
gboolean is_enum;
54915480
MonoClass *klass;
54925481
MonoDomain *d;
54935482
guint8 *vtype_buf;
@@ -5499,7 +5488,7 @@ decode_value_internal (MonoType *t, int type, MonoDomain *domain, guint8 *addr,
54995488
* Same as the beginning of the handle_vtype case above.
55005489
*/
55015490
buf2 = buf;
5502-
is_enum = decode_byte (buf, &buf, limit);
5491+
decode_byte (buf, &buf, limit);
55035492
decode_byte (buf, &buf, limit); //ignore is boxed
55045493
klass = decode_typeid (buf, &buf, limit, &d, &err);
55055494
if (err != ERR_NONE)
@@ -8927,7 +8916,7 @@ thread_commands (int command, guint8 *p, guint8 *end, Buffer *buf)
89278916

89288917
for (int i = 0; i < tls->frame_count; i++)
89298918
{
8930-
PRINT_DEBUG_MSG(1, "[dbg] Searching Context [%d] - [%lld] - [%lld]\n", i, (uint64_t) MONO_CONTEXT_GET_SP (&tls->frames [i]->ctx), sp_received);
8919+
PRINT_DEBUG_MSG(1, "[dbg] Searching Context [%d] - [%" PRIu64 "] - [%" PRId64 "]\n", i, (uint64_t) MONO_CONTEXT_GET_SP (&tls->frames [i]->ctx), sp_received);
89318920
if (sp_received == (uint64_t)MONO_CONTEXT_GET_SP (&tls->frames [i]->ctx)) {
89328921
buffer_add_int(buf, i);
89338922
break;
@@ -9625,8 +9614,6 @@ object_commands (int command, guint8 *p, guint8 *end, Buffer *buf)
96259614
buffer_add_typeid (buf, obj->vtable->domain, mono_class_from_mono_type_internal (((MonoReflectionType*)obj->vtable->type)->type));
96269615
break;
96279616
case CMD_OBJECT_REF_GET_VALUES_ICORDBG: {
9628-
gpointer iter;
9629-
iter = NULL;
96309617
len = 1;
96319618
MonoClass *dummy_class;
96329619
int field_token = decode_int (p, &p, end);

src/mono/mono/component/debugger-engine.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -715,16 +715,16 @@ ss_req_acquire (MonoInternalThread *thread)
715715
for (i = 0; i < the_ss_reqs->len; ++i) {
716716
SingleStepReq *current_req = (SingleStepReq *)g_ptr_array_index (the_ss_reqs, i);
717717
if (current_req->thread == thread) {
718-
current_req->refcount ++;
718+
current_req->refcount ++;
719719
req = current_req;
720720
}
721721
}
722722
dbg_unlock ();
723723
return req;
724724
}
725725

726-
static int
727-
ss_req_count ()
726+
static int
727+
ss_req_count (void)
728728
{
729729
return the_ss_reqs->len;
730730
}

src/mono/mono/component/event_pipe.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <eventpipe/ep-event-instance.h>
1212
#include <eventpipe/ep-session.h>
1313

14+
extern void ep_rt_mono_component_init (void);
1415
static bool _event_pipe_component_inited = false;
1516

1617
struct _EventPipeProviderConfigurationNative {
@@ -287,7 +288,6 @@ MonoComponentEventPipe *
287288
mono_component_event_pipe_init (void)
288289
{
289290
if (!_event_pipe_component_inited) {
290-
extern void ep_rt_mono_component_init (void);
291291
ep_rt_mono_component_init ();
292292
_event_pipe_component_inited = true;
293293
}

src/mono/mono/component/hot_reload.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ hot_reload_effective_table_slow (const MonoTableInfo **t, int *idx)
801801
return;
802802

803803
GList *list = info->delta_image;
804-
MonoImage *dmeta;
804+
MonoImage *dmeta = NULL;
805805
int ridx;
806806
MonoTableInfo *table;
807807
int g = 0;

src/mono/mono/eglib/gmarkup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ parse_name (const char *p, const char *end, char **value)
193193

194194
l = (int)(p - start);
195195
*value = g_malloc (l + 1);
196-
if (*value == NULL)
196+
if (*value == NULL || l <= 0)
197197
return end;
198198
strncpy (*value, start, l);
199199
(*value) [l] = 0;

src/mono/mono/eglib/gstr.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,11 @@ g_strerror (gint errnum)
249249
size_t buff_len = sizeof (tmp_buff);
250250
buff [0] = 0;
251251

252-
#ifndef STRERROR_R_CHAR_P
252+
#if HAVE_GNU_STRERROR_R
253+
buff = strerror_r (errnum, buff, buff_len);
254+
if (!error_messages [errnum])
255+
error_messages [errnum] = g_strdup (buff);
256+
#else /* HAVE_GNU_STRERROR_R */
253257
int r;
254258
while ((r = strerror_r (errnum, buff, buff_len - 1))) {
255259
if (r != ERANGE) {
@@ -261,17 +265,13 @@ g_strerror (gint errnum)
261265
else
262266
buff = g_realloc (buff, buff_len * 2);
263267
buff_len *= 2;
264-
//Spec is not clean on whether size argument includes space for null terminator or not
268+
//Spec is not clean on whether size argument includes space for null terminator or not
265269
}
266270
if (!error_messages [errnum])
267271
error_messages [errnum] = g_strdup (buff);
268272
if (buff != tmp_buff)
269273
g_free (buff);
270-
#else /* STRERROR_R_CHAR_P */
271-
buff = strerror_r (errnum, buff, buff_len);
272-
if (!error_messages [errnum])
273-
error_messages [errnum] = g_strdup (buff);
274-
#endif /* STRERROR_R_CHAR_P */
274+
#endif /* HAVE_GNU_STRERROR_R */
275275

276276
#else /* HAVE_STRERROR_R */
277277
if (!error_messages [errnum])

src/mono/mono/eventpipe/ds-rt-mono.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ ipc_get_process_id_disambiguation_key (
158158

159159
// All the format specifiers for the fields in the stat file are provided by 'man proc'.
160160
int result_sscanf = sscanf (scan_start_position,
161-
"%*c %*d %*d %*d %*d %*d %*u %*lu %*lu %*lu %*lu %*lu %*lu %*ld %*ld %*ld %*ld %*ld %*ld %llu \n",
161+
"%*c %*d %*d %*d %*d %*d %*u %*u %*u %*u %*u %*u %*u %*d %*d %*d %*d %*d %*d %llu \n",
162162
&start_time);
163163

164164
if (result_sscanf != 1) {

src/mono/mono/eventpipe/ep-rt-mono.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
#include <runtime_version.h>
3131
#include <clretwallmain.h>
3232

33+
extern void InitProvidersAndEvents (void);
34+
3335
// EventPipe rt init state.
3436
gboolean _ep_rt_mono_initialized;
3537

@@ -1826,7 +1828,6 @@ profiler_eventpipe_thread_exited (
18261828
MonoProfiler *prof,
18271829
uintptr_t tid)
18281830
{
1829-
void ep_rt_mono_thread_exited (void);
18301831
ep_rt_mono_thread_exited ();
18311832
}
18321833

@@ -2414,7 +2415,6 @@ ep_rt_mono_os_environment_get_utf16 (ep_rt_env_array_utf16_t *env_array)
24142415
void
24152416
ep_rt_mono_init_providers_and_events (void)
24162417
{
2417-
extern void InitProvidersAndEvents (void);
24182418
InitProvidersAndEvents ();
24192419
}
24202420

0 commit comments

Comments
 (0)