Skip to content

Commit

Permalink
[mono] Pass -Wc++-compat on all platforms, -Werror on OSX, fix errors (
Browse files Browse the repository at this point in the history
…dotnet#41233)

This PR:
* Enables `-Wc++-compat` on all platforms: we support building the runtime as C++, so this helps catch errors before they're found in CI and will help keep the netcore build C++-compatible
* Sets `-Werror` on netcore CI for OSX

It also fixes various warnings currently present in the build.

`-Werror` should probably be extended to cover all CI platforms eventually. Adding a new platform is as simple as adding to the line in mono.proj whitelisting platforms and fixing the warnings.

Not sure if there's a better way to handle the cpuidex function, but if we're using that from mini it should definitely be in a header somewhere.
  • Loading branch information
CoffeeFlux authored Aug 25, 2020
1 parent 7cd7783 commit 4e6abac
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/mono/configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,7 @@ AC_ARG_ENABLE(visibility-hidden,
WARN=''
if test x"$GCC" = xyes; then
WARN='-Wall -Wunused -Wmissing-declarations -Wpointer-arith -Wno-cast-qual -Wwrite-strings -Wno-switch -Wno-switch-enum -Wno-unused-value -Wno-attributes'
CFLAGS="$CFLAGS -Wmissing-prototypes -Wstrict-prototypes -Wnested-externs -Wno-format-zero-length"
CFLAGS="$CFLAGS -Wmissing-prototypes -Wstrict-prototypes -Wnested-externs -Wno-format-zero-length -Wc++-compat"

# We require C99 with some GNU extensions, e.g. `linux` macro
CFLAGS="$CFLAGS -std=gnu99"
Expand Down
5 changes: 5 additions & 0 deletions src/mono/mono.proj
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,11 @@
<_MonoCXXFLAGS Include="-Wl,--build-id=sha1" />
</ItemGroup>

<!-- CI-specific build options -->
<ItemGroup Condition="'$(ContinuousIntegrationBuild)' == 'true' and '$(TargetsOSX)' == 'true'">
<_MonoConfigureParams Include="--enable-werror" />
</ItemGroup>

<ItemGroup Condition="'$(MonoCrossDir)' != '' and ('$(TargetArchitecture)' == 'arm' Or '$(TargetArchitecture)' == 'arm64')">
<_MonoConfigureParams Include="--host=$(_MonoTuple)" />
<_MonoConfigureParams Include="--target=$(_MonoTuple)" />
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/metadata/w32socket-internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ SOCKET
mono_w32socket_accept (SOCKET s, struct sockaddr *addr, socklen_t *addrlen, gboolean blocking);

int
mono_w32socket_connect (SOCKET s, const struct sockaddr *name, int namelen, gboolean blocking);
mono_w32socket_connect (SOCKET s, const struct sockaddr *name, socklen_t namelen, gboolean blocking);

int
mono_w32socket_recv (SOCKET s, char *buf, int len, int flags, gboolean blocking);
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/metadata/w32socket-unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ mono_w32socket_accept (SOCKET sock, struct sockaddr *addr, socklen_t *addrlen, g
}

int
mono_w32socket_connect (SOCKET sock, const struct sockaddr *addr, int addrlen, gboolean blocking)
mono_w32socket_connect (SOCKET sock, const struct sockaddr *addr, socklen_t addrlen, gboolean blocking)
{
SocketHandle *sockethandle;
gint ret;
Expand Down
5 changes: 2 additions & 3 deletions src/mono/mono/mini/helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,8 @@ mono_disassemble_code (MonoCompile *cfg, guint8 *code, int size, char *id)
#ifdef HOST_WIN32
const char *tmp = g_get_tmp_dir ();
#endif
char *objdump_args = g_getenv ("MONO_OBJDUMP_ARGS");
char *as_file;
char *o_file;
char *cmd;
int unused G_GNUC_UNUSED;

#ifdef HOST_WIN32
Expand Down Expand Up @@ -255,9 +253,10 @@ mono_disassemble_code (MonoCompile *cfg, guint8 *code, int size, char *id)
#endif

#ifdef HAVE_SYSTEM
cmd = g_strdup_printf (ARCH_PREFIX AS_CMD " %s -o %s", as_file, o_file);
char *cmd = g_strdup_printf (ARCH_PREFIX AS_CMD " %s -o %s", as_file, o_file);
unused = system (cmd);
g_free (cmd);
char *objdump_args = g_getenv ("MONO_OBJDUMP_ARGS");
if (!objdump_args)
objdump_args = g_strdup ("");

Expand Down
6 changes: 2 additions & 4 deletions src/mono/mono/mini/simd-intrinsics-netcore.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ mono_simd_intrinsics_init (void)
#include "mono/utils/bsearch.h"
#include <mono/metadata/abi-details.h>
#include <mono/metadata/reflection-internals.h>
#include <mono/utils/mono-hwcap.h>

#if defined (MONO_ARCH_SIMD_INTRINSICS) && defined(ENABLE_NETCORE)

Expand Down Expand Up @@ -2177,13 +2178,10 @@ MONO_EMPTY_SOURCE_FILE (simd_intrinsics_netcore);


#if defined(ENABLE_NETCORE) && defined(TARGET_AMD64)
gboolean
mono_cpuidex (int id, int sub_id, int *p_eax, int *p_ebx, int *p_ecx, int *p_edx);

void
ves_icall_System_Runtime_Intrinsics_X86_X86Base___cpuidex (int abcd[4], int function_id, int subfunction_id)
{
mono_cpuidex (function_id, subfunction_id,
mono_hwcap_x86_call_cpuidex (function_id, subfunction_id,
&abcd [0], &abcd [1], &abcd [2], &abcd [3]);
}
#endif
3 changes: 3 additions & 0 deletions src/mono/mono/utils/mono-hwcap-vars.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,7 @@ MONO_HWCAP_VAR(x86_has_lzcnt)
MONO_HWCAP_VAR(x86_has_popcnt)
MONO_HWCAP_VAR(x86_has_avx)

gboolean
mono_hwcap_x86_call_cpuidex (int id, int sub_id, int *p_eax, int *p_ebx, int *p_ecx, int *p_edx);

#endif
10 changes: 5 additions & 5 deletions src/mono/mono/utils/mono-hwcap-x86.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#endif

gboolean
mono_cpuidex (int id, int sub_id, int *p_eax, int *p_ebx, int *p_ecx, int *p_edx)
mono_hwcap_x86_call_cpuidex (int id, int sub_id, int *p_eax, int *p_ebx, int *p_ecx, int *p_edx)
{
#if defined(_MSC_VER)
int info [4];
Expand Down Expand Up @@ -111,7 +111,7 @@ mono_hwcap_arch_init (void)
{
int eax, ebx, ecx, edx;

if (mono_cpuidex (1, 0, &eax, &ebx, &ecx, &edx)) {
if (mono_hwcap_x86_call_cpuidex (1, 0, &eax, &ebx, &ecx, &edx)) {
if (edx & (1 << 15)) {
mono_hwcap_x86_has_cmov = TRUE;

Expand Down Expand Up @@ -144,16 +144,16 @@ mono_hwcap_arch_init (void)
mono_hwcap_x86_has_avx = TRUE;
}

if (mono_cpuidex (0x80000000, 0, &eax, &ebx, &ecx, &edx)) {
if (mono_hwcap_x86_call_cpuidex (0x80000000, 0, &eax, &ebx, &ecx, &edx)) {
if ((unsigned int) eax >= 0x80000001 && ebx == 0x68747541 && ecx == 0x444D4163 && edx == 0x69746E65) {
if (mono_cpuidex (0x80000001, 0, &eax, &ebx, &ecx, &edx)) {
if (mono_hwcap_x86_call_cpuidex (0x80000001, 0, &eax, &ebx, &ecx, &edx)) {
if (ecx & (1 << 6))
mono_hwcap_x86_has_sse4a = TRUE;
}
}
}

if (mono_cpuidex (0x80000001, 0, &eax, &ebx, &ecx, &edx)) {
if (mono_hwcap_x86_call_cpuidex (0x80000001, 0, &eax, &ebx, &ecx, &edx)) {
if (ecx & (1 << 5))
mono_hwcap_x86_has_lzcnt = TRUE;
}
Expand Down

0 comments on commit 4e6abac

Please sign in to comment.