Skip to content

Commit

Permalink
Fix gcc warnings during mono linux-x64 build (#60675)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
am11 authored Nov 2, 2021
1 parent 594f32e commit 577a70a
Show file tree
Hide file tree
Showing 45 changed files with 173 additions and 192 deletions.
2 changes: 1 addition & 1 deletion src/coreclr/pal/src/thread/process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2148,7 +2148,7 @@ GetProcessIdDisambiguationKey(DWORD processId, UINT64 *disambiguationKey)

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

if (sscanfRet != 1)
Expand Down
2 changes: 1 addition & 1 deletion src/libraries/Native/Unix/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ if (CLR_CMAKE_TARGET_OSX OR CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS
add_definitions(-D__APPLE_USE_RFC_3542)
endif ()

if (CLR_CMAKE_TARGET_LINUX)
if (CLR_CMAKE_TARGET_LINUX OR CLR_CMAKE_TARGET_ANDROID)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_GNU_SOURCE")
endif ()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ static UChar* s_breakIteratorRules = NULL;
// We are customizing the break iterator to exclude the CRxLF rule which don't allow breaking between CR and LF.
// The general rules syntax explained in the doc https://unicode-org.github.io/icu/userguide/boundaryanalysis/break-rules.html.
// The ICU latest rules definition exist here https://github.com/unicode-org/icu/blob/main/icu4c/source/data/brkitr/rules/char.txt.
static UBreakIterator* CreateCustomizedBreakIterator()
static UBreakIterator* CreateCustomizedBreakIterator(void)
{
static UChar emptyString[1];
UBreakIterator* breaker;
Expand Down Expand Up @@ -815,6 +815,7 @@ static int32_t GetSearchIteratorUsingCollator(
if (!U_SUCCESS(err))
{
int32_t r;
(void)r;
r = RestoreSearchHandle(pSortHandle, *pSearchIterator, options);
assert(r && "restoring search handle shouldn't fail.");
return -1;
Expand All @@ -824,6 +825,7 @@ static int32_t GetSearchIteratorUsingCollator(
if (!U_SUCCESS(err))
{
int32_t r;
(void)r;
r = RestoreSearchHandle(pSortHandle, *pSearchIterator, options);
assert(r && "restoring search handle shouldn't fail.");
return -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ static int FindICULibs(const char* versionPrefix, char* symbolName, char* symbol

#endif

static void ValidateICUDataCanLoad()
static void ValidateICUDataCanLoad(void)
{
UVersionInfo version;
UErrorCode err = U_ZERO_ERROR;
Expand Down
1 change: 0 additions & 1 deletion src/mono/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,6 @@ endif()
######################################
# EXTRACT VERSION
######################################
include("${CMAKE_CURRENT_SOURCE_DIR}/../../eng/native/configurepaths.cmake")
include_directories(${CLR_ARTIFACTS_OBJ_DIR})
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
if(NOT EXISTS "${VERSION_HEADER_PATH}")
Expand Down
7 changes: 3 additions & 4 deletions src/mono/cmake/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -510,14 +510,11 @@
/* Define to 1 if you have the `strerror_r' function. */
#cmakedefine HAVE_STRERROR_R 1

/* Define to 1 if strerror_r returns char *. */
#cmakedefine STRERROR_R_CHAR_P 1

/* Have GLIBC_BEFORE_2_3_4_SCHED_SETAFFINITY */
#cmakedefine GLIBC_BEFORE_2_3_4_SCHED_SETAFFINITY 1

/* GLIBC has CPU_COUNT macro in sched.h */
#cmakedefine GLIBC_HAS_CPU_COUNT 1
#cmakedefine HAVE_GNU_CPU_COUNT

/* Have large file support */
#cmakedefine HAVE_LARGE_FILE_SUPPORT 1
Expand Down Expand Up @@ -712,6 +709,8 @@
/* The size of `size_t', as computed by sizeof. */
#define SIZEOF_SIZE_T @SIZEOF_SIZE_T@

#cmakedefine01 HAVE_GNU_STRERROR_R

/* Define to 1 if the system has the type `struct sockaddr'. */
#cmakedefine HAVE_STRUCT_SOCKADDR 1

Expand Down
40 changes: 32 additions & 8 deletions src/mono/cmake/configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ include(CheckTypeSize)
include(CheckStructHasMember)
include(CheckSymbolExists)
include(CheckCCompilerFlag)
include(CheckCSourceCompiles)

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

if (HOST_LINUX OR HOST_ANDROID)
set(CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
endif()

check_c_source_compiles(
"
#include <string.h>
int main(void)
{
char buffer[1];
char c = *strerror_r(0, buffer, 0);
return 0;
}
"
HAVE_GNU_STRERROR_R)

check_c_source_compiles(
"
#include <sched.h>
int main(void)
{
CPU_COUNT((void *) 0);
return 0;
}
"
HAVE_GNU_CPU_COUNT)

if (HOST_LINUX OR HOST_ANDROID)
set(CMAKE_REQUIRED_DEFINITIONS)
endif()

# ICONV
set(ICONV_LIB)
find_library(LIBICONV_FOUND iconv)
if(NOT LIBICONV_FOUND STREQUAL "LIBICONV_FOUND-NOTFOUND")
set(ICONV_LIB "iconv")
endif()

file(WRITE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/test.c
"#include <sched.h>\n"
"void main () { CPU_COUNT((void *) 0); }\n"
)
try_compile(GLIBC_HAS_CPU_COUNT ${CMAKE_BINARY_DIR}/CMakeTmp SOURCES "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/test.c"
COMPILE_DEFINITIONS "-D_GNU_SOURCE")


if(HOST_WIN32)
# checking for this doesn't work for some reason, hardcode result
set(HAVE_WINTERNL_H 1)
Expand Down
1 change: 0 additions & 1 deletion src/mono/cmake/defines-todo.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#option (MAJOR_IN_MKDEV "Define to 1 if `major', `minor', and `makedev' are declared in <mkdev.h>.")
#option (MAJOR_IN_SYSMACROS "Define to 1 if `major', `minor', and `makedev' are declared in <sysmacros.h>.")
#option (STRERROR_R_CHAR_P "Define to 1 if strerror_r returns char *.")
#option (HAVE_LIBICONV "Define to 1 if you have the `iconv' library (-liconv).")
#option (ANDROID_UNIFIED_HEADERS "Whether Android NDK unified headers are used")
#option (MONO_DL_NEED_USCORE "Does dlsym require leading underscore.")
Expand Down
21 changes: 4 additions & 17 deletions src/mono/mono/component/debugger-agent.c
Original file line number Diff line number Diff line change
Expand Up @@ -2541,7 +2541,6 @@ try_process_suspend (void *the_tls, MonoContext *ctx, gboolean from_breakpoint)
static void
suspend_vm (void)
{
gboolean tp_suspend = FALSE;
mono_loader_lock ();

mono_coop_mutex_lock (&suspend_mutex);
Expand All @@ -2557,12 +2556,6 @@ suspend_vm (void)
}

mono_coop_mutex_unlock (&suspend_mutex);

if (suspend_count == 1)
/*
* Suspend creation of new threadpool threads, since they cannot run
*/
tp_suspend = TRUE;
mono_loader_unlock ();
}

Expand All @@ -2576,7 +2569,6 @@ static void
resume_vm (void)
{
g_assert (is_debugger_thread ());
gboolean tp_resume = FALSE;

mono_loader_lock ();

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

if (suspend_count == 0)
tp_resume = TRUE;
mono_loader_unlock ();
}

Expand Down Expand Up @@ -5257,15 +5247,15 @@ decode_vtype (MonoType *t, MonoDomain *domain, gpointer void_addr, gpointer void
{
guint8 *addr = (guint8*)void_addr;
guint8 *buf = (guint8*)void_buf;
gboolean is_enum;
MonoClass *klass;
MonoClassField *f;
int nfields;
gpointer iter = NULL;
MonoDomain *d;
ErrorCode err;

is_enum = decode_byte (buf, &buf, limit);
/* is_enum, ignored */
decode_byte (buf, &buf, limit);
if (CHECK_PROTOCOL_VERSION(2, 61))
decode_byte (buf, &buf, limit);
klass = decode_typeid (buf, &buf, limit, &d, &err);
Expand Down Expand Up @@ -5487,7 +5477,6 @@ decode_value_internal (MonoType *t, int type, MonoDomain *domain, guint8 *addr,
} else if (type == MONO_TYPE_VALUETYPE) {
ERROR_DECL (error);
guint8 *buf2;
gboolean is_enum;
MonoClass *klass;
MonoDomain *d;
guint8 *vtype_buf;
Expand All @@ -5499,7 +5488,7 @@ decode_value_internal (MonoType *t, int type, MonoDomain *domain, guint8 *addr,
* Same as the beginning of the handle_vtype case above.
*/
buf2 = buf;
is_enum = decode_byte (buf, &buf, limit);
decode_byte (buf, &buf, limit);
decode_byte (buf, &buf, limit); //ignore is boxed
klass = decode_typeid (buf, &buf, limit, &d, &err);
if (err != ERR_NONE)
Expand Down Expand Up @@ -8927,7 +8916,7 @@ thread_commands (int command, guint8 *p, guint8 *end, Buffer *buf)

for (int i = 0; i < tls->frame_count; i++)
{
PRINT_DEBUG_MSG(1, "[dbg] Searching Context [%d] - [%lld] - [%lld]\n", i, (uint64_t) MONO_CONTEXT_GET_SP (&tls->frames [i]->ctx), sp_received);
PRINT_DEBUG_MSG(1, "[dbg] Searching Context [%d] - [%" PRIu64 "] - [%" PRId64 "]\n", i, (uint64_t) MONO_CONTEXT_GET_SP (&tls->frames [i]->ctx), sp_received);
if (sp_received == (uint64_t)MONO_CONTEXT_GET_SP (&tls->frames [i]->ctx)) {
buffer_add_int(buf, i);
break;
Expand Down Expand Up @@ -9625,8 +9614,6 @@ object_commands (int command, guint8 *p, guint8 *end, Buffer *buf)
buffer_add_typeid (buf, obj->vtable->domain, mono_class_from_mono_type_internal (((MonoReflectionType*)obj->vtable->type)->type));
break;
case CMD_OBJECT_REF_GET_VALUES_ICORDBG: {
gpointer iter;
iter = NULL;
len = 1;
MonoClass *dummy_class;
int field_token = decode_int (p, &p, end);
Expand Down
6 changes: 3 additions & 3 deletions src/mono/mono/component/debugger-engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -715,16 +715,16 @@ ss_req_acquire (MonoInternalThread *thread)
for (i = 0; i < the_ss_reqs->len; ++i) {
SingleStepReq *current_req = (SingleStepReq *)g_ptr_array_index (the_ss_reqs, i);
if (current_req->thread == thread) {
current_req->refcount ++;
current_req->refcount ++;
req = current_req;
}
}
dbg_unlock ();
return req;
}

static int
ss_req_count ()
static int
ss_req_count (void)
{
return the_ss_reqs->len;
}
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/component/event_pipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <eventpipe/ep-event-instance.h>
#include <eventpipe/ep-session.h>

extern void ep_rt_mono_component_init (void);
static bool _event_pipe_component_inited = false;

struct _EventPipeProviderConfigurationNative {
Expand Down Expand Up @@ -287,7 +288,6 @@ MonoComponentEventPipe *
mono_component_event_pipe_init (void)
{
if (!_event_pipe_component_inited) {
extern void ep_rt_mono_component_init (void);
ep_rt_mono_component_init ();
_event_pipe_component_inited = true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/component/hot_reload.c
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ hot_reload_effective_table_slow (const MonoTableInfo **t, int *idx)
return;

GList *list = info->delta_image;
MonoImage *dmeta;
MonoImage *dmeta = NULL;
int ridx;
MonoTableInfo *table;
int g = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/eglib/gmarkup.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ parse_name (const char *p, const char *end, char **value)

l = (int)(p - start);
*value = g_malloc (l + 1);
if (*value == NULL)
if (*value == NULL || l <= 0)
return end;
strncpy (*value, start, l);
(*value) [l] = 0;
Expand Down
14 changes: 7 additions & 7 deletions src/mono/mono/eglib/gstr.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,11 @@ g_strerror (gint errnum)
size_t buff_len = sizeof (tmp_buff);
buff [0] = 0;

#ifndef STRERROR_R_CHAR_P
#if HAVE_GNU_STRERROR_R
buff = strerror_r (errnum, buff, buff_len);
if (!error_messages [errnum])
error_messages [errnum] = g_strdup (buff);
#else /* HAVE_GNU_STRERROR_R */
int r;
while ((r = strerror_r (errnum, buff, buff_len - 1))) {
if (r != ERANGE) {
Expand All @@ -261,17 +265,13 @@ g_strerror (gint errnum)
else
buff = g_realloc (buff, buff_len * 2);
buff_len *= 2;
//Spec is not clean on whether size argument includes space for null terminator or not
//Spec is not clean on whether size argument includes space for null terminator or not
}
if (!error_messages [errnum])
error_messages [errnum] = g_strdup (buff);
if (buff != tmp_buff)
g_free (buff);
#else /* STRERROR_R_CHAR_P */
buff = strerror_r (errnum, buff, buff_len);
if (!error_messages [errnum])
error_messages [errnum] = g_strdup (buff);
#endif /* STRERROR_R_CHAR_P */
#endif /* HAVE_GNU_STRERROR_R */

#else /* HAVE_STRERROR_R */
if (!error_messages [errnum])
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/eventpipe/ds-rt-mono.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ ipc_get_process_id_disambiguation_key (

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

if (result_sscanf != 1) {
Expand Down
4 changes: 2 additions & 2 deletions src/mono/mono/eventpipe/ep-rt-mono.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#include <runtime_version.h>
#include <clretwallmain.h>

extern void InitProvidersAndEvents (void);

// EventPipe rt init state.
gboolean _ep_rt_mono_initialized;

Expand Down Expand Up @@ -1826,7 +1828,6 @@ profiler_eventpipe_thread_exited (
MonoProfiler *prof,
uintptr_t tid)
{
void ep_rt_mono_thread_exited (void);
ep_rt_mono_thread_exited ();
}

Expand Down Expand Up @@ -2414,7 +2415,6 @@ ep_rt_mono_os_environment_get_utf16 (ep_rt_env_array_utf16_t *env_array)
void
ep_rt_mono_init_providers_and_events (void)
{
extern void InitProvidersAndEvents (void);
InitProvidersAndEvents ();
}

Expand Down
Loading

0 comments on commit 577a70a

Please sign in to comment.