Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release/6.0] Fix gcc warnings during mono linux-x64 build (backport of #60675) #77505

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/mono/cmake/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -501,14 +501,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 @@ -695,6 +692,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
39 changes: 31 additions & 8 deletions src/mono/cmake/configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -139,21 +139,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
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/utils/mono-proclib.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
#endif

#ifdef HAVE_SCHED_GETAFFINITY
# ifndef GLIBC_HAS_CPU_COUNT
# ifndef HAVE_GNU_CPU_COUNT
static int
CPU_COUNT(cpu_set_t *set)
{
Expand Down