summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSinan Kaya <41809318+franksinankaya@users.noreply.github.com>2019-02-07 16:39:13 -0500
committerJan Vorlicek <janvorli@microsoft.com>2019-02-07 22:39:13 +0100
commit34d50b056150ba9101ee977dded9cee3c663fab6 (patch)
tree87c392937ae80e2dabf379b3c1a58b229daacf00
parent46cbd93c20780bcacd9f39fe18079acf2a9f4178 (diff)
downloadcoreclr-34d50b056150ba9101ee977dded9cee3c663fab6.tar.gz
coreclr-34d50b056150ba9101ee977dded9cee3c663fab6.tar.bz2
coreclr-34d50b056150ba9101ee977dded9cee3c663fab6.zip
More PAL layer cleanup for GNU and add build script support for GCC (#22369)
* Declare throw only when compiling for c++ Prevent the definition from getting defined multiple times and map it to throw() only when compiling c++ code. * Suppress warnings for tests Suppress: -Wno-write-strings -Wno-sign-compare -Wno-narrowing -fpermissive -Wno-int-to-pointer-cast to allow tests to compile * Add gcc option to build.sh script Following clangx.y model add -gccx.y command line arguments with gcc5 and gcc7 being the currnetly supported options. * Allow environment variable to be used for TOOLCHAIN Remove CLANG specific compiler options as well. * Hide non-GNU compiler options * Do not include local directory if cross compiling [ 0%] Building CXX object src/pal/src/eventprovider/tracepointprovider/CMakeFiles/coreclrtraceptprovider.dir/__/lttng/traceptprovdotnetruntime.cpp.o cc1plus: error: include location "/usr/local/include" is unsafe for cross-compilation [-Werror=poison-system-directories] * Suppress unknown pragma warnings src/pal/src/exception/seh-unwind.cpp:37:0: warning: ignoring #pragma clang diagnostic [-Wunknown-pragmas] #pragma clang diagnostic pop Removing these cause compilation error on clang7 and arm as follows: In file included from /bin/obj/Linux.arm.Debug/src/pal/src/libunwind/include/libunwind.h:9: /src/pal/src/libunwind/include/libunwind-arm.h:247:9: error: empty struct has size 0 in C, size 1 in C++ [-Werror,-Wextern-c-compat] typedef struct unw_tdep_save_loc ^ /src/pal/src/libunwind/include/libunwind-arm.h:288:9: error: empty struct has size 0 in C, size 1 in C++ [-Werror,-Wextern-c-compat] typedef struct * plt not useful for GNU and ARM64/ARM src/pal/src/arch/arm64/callsignalhandlerwrapper.S: Assembler messages: src/pal/src/arch/arm64/callsignalhandlerwrapper.S:31: Error: unexpected characters following instruction at operand 1 -- `bl signal_handler_worker@plt' src/pal/src/arch/arm64/callsignalhandlerwrapper.S:32: Error: unexpected characters following instruction at operand 1 -- `bl signal_handler_worker@plt' * Remove double const from argv in PAL_Initialize Seeing compilation error with GNU for C source files as follows: if (PAL_Initialize(argc, argv) != 0) ^ src/pal/tests/palsuite/common/palsuite.h:21:0, from src/pal/tests/palsuite/c_runtime/asinhf/test1/test1.c:18: src/pal/inc/pal.h:374:1: note: expected ‘const char * const*’ but argument is of type ‘char **’ * Suppress format warnings using GNU for libunwind warning: format ‘%li’ expects argument of type ‘long int’, but argument 3 has type ‘int’ [-Wformat=] Debug (4, " aligned frame, offset %li\n", f->cfa_reg_offset); * Fix -fpermissive warnings for GNU * Suppress unused variable warning in libunwind src/pal/src/libunwind/include/libunwind-aarch64.h:201:5: warning: right-hand operand of comma expression has no effect [-Wunused-value] #define unw_tdep_getcontext(uc) (({ \ ~~~~~~~~~ unw_tdep_context_t *unw_ctx = (uc); \ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ register uint64_t *unw_base asm ("x0") = (uint64_t*) unw_ctx->uc_mcontext.regs; \ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ __asm__ __volatile__ ( \ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "stp x0, x1, [%[base], #0]\n" \ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "stp x2, x3, [%[base], #16]\n" \ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "stp x4, x5, [%[base], #32]\n" \ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "stp x6, x7, [%[base], #48]\n" \ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "stp x8, x9, [%[base], #64]\n" \ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "stp x10, x11, [%[base], #80]\n" \ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "stp x12, x13, [%[base], #96]\n" \ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "stp x14, x13, [%[base], #112]\n" \ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "stp x16, x17, [%[base], #128]\n" \ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "stp x18, x19, [%[base], #144]\n" \ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "stp x20, x21, [%[base], #160]\n" \ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "stp x22, x23, [%[base], #176]\n" \ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "stp x24, x25, [%[base], #192]\n" \ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "stp x26, x27, [%[base], #208]\n" \ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "stp x28, x29, [%[base], #224]\n" \ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "str x30, [%[base], #240]\n" \ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "mov x1, sp\n" \ ~~~~~~~~~~~~~~~~ "stp x1, x30, [%[base], #248]\n" \ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ : [base] "+r" (unw_base) : : "x1", "memory"); \ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ }), 0) * Fix warning: ‘memset’ used with length equal to number of elements warning Fix similar warnings to these by including the element size into total size calculation. src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableW/test1/test.cpp: In function ‘int main(int, char**)’: src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableW/test1/test.cpp:89:31: warning: ‘memset’ used with length equal to number of elements without multiplication by element size [-Wmemset-elt-size] memset(NewValue,0,BUF_SIZE); * Define CLR specific compiler option CLR_CMAKE_COMPILER By the time toolchain.cmake is called, the compiler detection from cmake is not active. We need an intermediate definition to pass to compiler detection.
-rwxr-xr-xbuild.sh52
-rw-r--r--configurecompiler.cmake54
-rw-r--r--cross/toolchain.cmake26
-rw-r--r--src/pal/inc/mbusafecrt.h6
-rw-r--r--src/pal/inc/pal.h10
-rw-r--r--src/pal/inc/unixasmmacros.inc4
-rw-r--r--src/pal/src/CMakeLists.txt4
-rw-r--r--src/pal/src/examples/example1.cpp2
-rw-r--r--src/pal/src/exception/remote-unwind.cpp4
-rw-r--r--src/pal/src/exception/seh-unwind.cpp4
-rw-r--r--src/pal/src/init/pal.cpp2
-rw-r--r--src/pal/src/libunwind/src/CMakeLists.txt21
-rw-r--r--src/pal/tests/CMakeLists.txt6
-rw-r--r--src/pal/tests/palsuite/CMakeLists.txt11
-rw-r--r--src/pal/tests/palsuite/c_runtime/_wfopen/test1/test1.cpp2
-rw-r--r--src/pal/tests/palsuite/file_io/GetFullPathNameW/test3/test3.cpp2
-rw-r--r--src/pal/tests/palsuite/file_io/GetFullPathNameW/test4/test4.cpp2
-rw-r--r--src/pal/tests/palsuite/miscellaneous/FormatMessageW/test2/test.cpp24
-rw-r--r--src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableW/test1/test.cpp4
-rw-r--r--src/pal/tests/palsuite/threading/CreateThread/test2/test2.cpp6
-rw-r--r--src/pal/tests/palsuite/threading/ExitThread/test1/test1.cpp4
-rw-r--r--src/pal/tests/palsuite/threading/ResumeThread/test1/test1.cpp4
-rw-r--r--src/pal/tests/palsuite/threading/SleepEx/test2/test2.cpp2
-rw-r--r--src/pal/tests/palsuite/threading/SwitchToThread/test1/test1.cpp2
-rw-r--r--src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test2/test2.cpp2
-rw-r--r--src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test5/test5.cpp2
-rw-r--r--src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test6/test6.cpp2
-rw-r--r--src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOExMutexTest/WFSOExMutexTest.cpp2
-rw-r--r--src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOExSemaphoreTest/WFSOExSemaphoreTest.cpp2
-rw-r--r--src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOExThreadTest/WFSOExThreadTest.cpp2
-rw-r--r--src/pal/tools/gcc-compiler-override.txt20
-rwxr-xr-xsrc/pal/tools/gen-buildsys-clang.sh1
-rwxr-xr-xsrc/pal/tools/gen-buildsys-gcc.sh188
33 files changed, 394 insertions, 85 deletions
diff --git a/build.sh b/build.sh
index ef50b3e8af..45ac18a70e 100755
--- a/build.sh
+++ b/build.sh
@@ -25,11 +25,12 @@ export PYTHON
usage()
{
- echo "Usage: $0 [BuildArch] [BuildType] [-verbose] [-coverage] [-cross] [-clangx.y] [-ninja] [-configureonly] [-skipconfigure] [-skipnative] [-skipcrossarchnative] [-skipmanaged] [-skipmscorlib] [-skiptests] [-stripsymbols] [-ignorewarnings] [-cmakeargs] [-bindir]"
+ echo "Usage: $0 [BuildArch] [BuildType] [-verbose] [-coverage] [-cross] [-gccx.y] [-clangx.y] [-ninja] [-configureonly] [-skipconfigure] [-skipnative] [-skipcrossarchnative] [-skipmanaged] [-skipmscorlib] [-skiptests] [-stripsymbols] [-ignorewarnings] [-cmakeargs] [-bindir]"
echo "BuildArch can be: -x64, -x86, -arm, -armel, -arm64"
echo "BuildType can be: -debug, -checked, -release"
echo "-coverage - optional argument to enable code coverage build (currently supported only for Linux and OSX)."
echo "-ninja - target ninja instead of GNU make"
+ echo "-gccx.y - optional argument to build using gcc version x.y."
echo "-clangx.y - optional argument to build using clang version x.y."
echo "-cross - optional argument to signify cross compilation,"
echo " - will use ROOTFS_DIR environment variable if set."
@@ -159,18 +160,26 @@ check_prereqs()
# Minimum required version of clang is version 4.0 for arm/armel cross build
- if [[ $__CrossBuild == 1 && ("$__BuildArch" == "arm" || "$__BuildArch" == "armel") ]]; then
+ if [[ $__CrossBuild == 1 && $__GccBuild == 0 && ("$__BuildArch" == "arm" || "$__BuildArch" == "armel") ]]; then
if ! [[ "$__ClangMajorVersion" -ge "4" ]]; then
echo "Please install clang4.0 or latest for arm/armel cross build"; exit 1;
fi
fi
# Check for clang
- __ClangCombinedDottedVersion=$__ClangMajorVersion;
- if [[ "$__ClangMinorVersion" != "" ]]; then
- __ClangCombinedDottedVersion=$__ClangCombinedDottedVersion.$__ClangMinorVersion
+ if [[ $__GccBuild == 0 ]]; then
+ __ClangCombinedDottedVersion=$__ClangMajorVersion;
+ if [[ "$__ClangMinorVersion" != "" ]]; then
+ __ClangCombinedDottedVersion=$__ClangCombinedDottedVersion.$__ClangMinorVersion
+ fi
+ hash clang-$__ClangCombinedDottedVersion 2>/dev/null || hash clang$__ClangMajorVersion$__ClangMinorVersion 2>/dev/null || hash clang 2>/dev/null || { echo >&2 "Please install clang-$__ClangMajorVersion.$__ClangMinorVersion before running this script"; exit 1; }
+ else
+ __GccCombinedDottedVersion=$__GccMajorVersion;
+ if [[ "$__GccMinorVersion" != "" ]]; then
+ __GccCombinedDottedVersion=$__GccCombinedDottedVersion.$__GccMinorVersion
+ fi
+ hash gcc-$__GccCombinedDottedVersion 2>/dev/null || hash gcc$__GccMajorVersion$__GccMinorVersion 2>/dev/null || hash gcc 2>/dev/null || { echo >&2 "Please install gcc-$__GccMajorVersion.$__GccMinorVersion before running this script"; exit 1; }
fi
- hash clang-$__ClangCombinedDottedVersion 2>/dev/null || hash clang$__ClangMajorVersion$__ClangMinorVersion 2>/dev/null || hash clang 2>/dev/null || { echo >&2 "Please install clang-$__ClangMajorVersion.$__ClangMinorVersion before running this script"; exit 1; }
}
@@ -318,8 +327,14 @@ build_native()
pushd "$intermediatesForBuild"
# Regenerate the CMake solution
- echo "Invoking \"$__ProjectRoot/src/pal/tools/gen-buildsys-clang.sh\" \"$__ProjectRoot\" $__ClangMajorVersion \"$__ClangMinorVersion\" $platformArch $__BuildType $__CodeCoverage $generator $extraCmakeArguments $__cmakeargs"
- "$__ProjectRoot/src/pal/tools/gen-buildsys-clang.sh" "$__ProjectRoot" $__ClangMajorVersion "$__ClangMinorVersion" $platformArch $__BuildType $__CodeCoverage $generator "$extraCmakeArguments" "$__cmakeargs"
+
+ if [[ $__GccBuild == 0 ]]; then
+ echo "Invoking \"$__ProjectRoot/src/pal/tools/gen-buildsys-clang.sh\" \"$__ProjectRoot\" $__ClangMajorVersion \"$__ClangMinorVersion\" $platformArch $__BuildType $__CodeCoverage $generator $extraCmakeArguments $__cmakeargs"
+ "$__ProjectRoot/src/pal/tools/gen-buildsys-clang.sh" "$__ProjectRoot" $__ClangMajorVersion "$__ClangMinorVersion" $platformArch $__BuildType $__CodeCoverage $generator "$extraCmakeArguments" "$__cmakeargs"
+ else
+ echo "Invoking \"$__ProjectRoot/src/pal/tools/gen-buildsys-gcc.sh\" \"$__ProjectRoot\" $__GccMajorVersion \"$__GccMinorVersion\" $platformArch $__BuildType $__CodeCoverage $generator $extraCmakeArguments $__cmakeargs"
+ "$__ProjectRoot/src/pal/tools/gen-buildsys-gcc.sh" "$__ProjectRoot" "$__GccMajorVersion" "$__CGccMinorVersion" $platformArch $__BuildType $__CodeCoverage $generator "$extraCmakeArguments" "$__cmakeargs"
+ fi
popd
fi
@@ -672,6 +687,9 @@ __SkipTests=0
__CrossBuild=0
__ClangMajorVersion=0
__ClangMinorVersion=0
+__GccBuild=0
+__GccMajorVersion=0
+__GccMinorVersion=0
__NuGetPath="$__PackagesDir/NuGet.exe"
__HostDistroRid=""
__DistroRid=""
@@ -808,6 +826,24 @@ while :; do
__ClangMinorVersion=
;;
+ gcc5|-gcc5)
+ __GccMajorVersion=5
+ __GccMinorVersion=
+ __GccBuild=1
+ ;;
+
+ gcc7|-gcc7)
+ __GccMajorVersion=7
+ __GccMinorVersion=
+ __GccBuild=1
+ ;;
+
+ gcc|-gcc)
+ __GccMajorVersion=
+ __GccMinorVersion=
+ __GccBuild=1
+ ;;
+
ninja|-ninja)
__UseNinja=1
;;
diff --git a/configurecompiler.cmake b/configurecompiler.cmake
index 371e6e0a7c..5afca2da71 100644
--- a/configurecompiler.cmake
+++ b/configurecompiler.cmake
@@ -441,36 +441,42 @@ if (CLR_CMAKE_PLATFORM_UNIX)
add_definitions(-DDISABLE_CONTRACTS)
# The -ferror-limit is helpful during the porting, it makes sure the compiler doesn't stop
# after hitting just about 20 errors.
- add_compile_options(-ferror-limit=4096)
if (CLR_CMAKE_WARNINGS_ARE_ERRORS)
# All warnings that are not explicitly disabled are reported as errors
add_compile_options(-Werror)
endif(CLR_CMAKE_WARNINGS_ARE_ERRORS)
- # Disabled warnings
- add_compile_options(-Wno-unused-private-field)
- add_compile_options(-Wno-unused-variable)
- # Explicit constructor calls are not supported by clang (this->ClassName::ClassName())
- add_compile_options(-Wno-microsoft)
- # This warning is caused by comparing 'this' to NULL
- add_compile_options(-Wno-tautological-compare)
- # There are constants of type BOOL used in a condition. But BOOL is defined as int
- # and so the compiler thinks that there is a mistake.
- add_compile_options(-Wno-constant-logical-operand)
- # We use pshpack1/2/4/8.h and poppack.h headers to set and restore packing. However
- # clang 6.0 complains when the packing change lifetime is not contained within
- # a header file.
- add_compile_options(-Wno-pragma-pack)
-
- add_compile_options(-Wno-unknown-warning-option)
-
- #These seem to indicate real issues
- add_compile_options(-Wno-invalid-offsetof)
- # The following warning indicates that an attribute __attribute__((__ms_struct__)) was applied
- # to a struct or a class that has virtual members or a base class. In that case, clang
- # may not generate the same object layout as MSVC.
- add_compile_options(-Wno-incompatible-ms-struct)
+ if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
+ add_compile_options(-ferror-limit=4096)
+
+ # Disabled warnings
+ add_compile_options(-Wno-unused-private-field)
+ add_compile_options(-Wno-unused-variable)
+ # Explicit constructor calls are not supported by clang (this->ClassName::ClassName())
+ add_compile_options(-Wno-microsoft)
+ # This warning is caused by comparing 'this' to NULL
+ add_compile_options(-Wno-tautological-compare)
+ # There are constants of type BOOL used in a condition. But BOOL is defined as int
+ # and so the compiler thinks that there is a mistake.
+ add_compile_options(-Wno-constant-logical-operand)
+ # We use pshpack1/2/4/8.h and poppack.h headers to set and restore packing. However
+ # clang 6.0 complains when the packing change lifetime is not contained within
+ # a header file.
+ add_compile_options(-Wno-pragma-pack)
+
+ add_compile_options(-Wno-unknown-warning-option)
+
+ #These seem to indicate real issues
+ add_compile_options(-Wno-invalid-offsetof)
+ # The following warning indicates that an attribute __attribute__((__ms_struct__)) was applied
+ # to a struct or a class that has virtual members or a base class. In that case, clang
+ # may not generate the same object layout as MSVC.
+ add_compile_options(-Wno-incompatible-ms-struct)
+ else()
+ add_compile_options(-Wno-unused-variable)
+ add_compile_options(-Wno-unused-but-set-variable)
+ endif()
# Some architectures (e.g., ARM) assume char type is unsigned while CoreCLR assumes char is signed
# as x64 does. It has been causing issues in ARM (https://github.com/dotnet/coreclr/issues/4746)
diff --git a/cross/toolchain.cmake b/cross/toolchain.cmake
index 071d411241..07d3a41160 100644
--- a/cross/toolchain.cmake
+++ b/cross/toolchain.cmake
@@ -31,6 +31,19 @@ else()
message(FATAL_ERROR "Arch is ${TARGET_ARCH_NAME}. Only armel, arm, arm64 and x86 are supported!")
endif()
+if(DEFINED ENV{TOOLCHAIN})
+ set(TOOLCHAIN $ENV{TOOLCHAIN})
+endif()
+
+# This gets called with CLR_CMAKE_COMPILER set on the first invocation
+# but the cmake variable is not getting populated into other calls.
+# Use environment variable to keep CLR_CMAKE_COMPILER around.
+if (NOT DEFINED CLR_CMAKE_COMPILER)
+ set(CLR_CMAKE_COMPILER $ENV{CLR_CMAKE_COMPILER})
+else()
+ set(ENV{CLR_CMAKE_COMPILER} ${CLR_CMAKE_COMPILER})
+endif()
+
# Specify include paths
if(TARGET_ARCH_NAME STREQUAL "armel")
if(DEFINED TIZEN_TOOLCHAIN)
@@ -58,8 +71,11 @@ endmacro()
# Specify link flags
add_compile_param(CROSS_LINK_FLAGS "--sysroot=${CROSS_ROOTFS}")
-add_compile_param(CROSS_LINK_FLAGS "--gcc-toolchain=${CROSS_ROOTFS}/usr")
-add_compile_param(CROSS_LINK_FLAGS "--target=${TOOLCHAIN}")
+if (CLR_CMAKE_COMPILER STREQUAL "Clang")
+ add_compile_param(CROSS_LINK_FLAGS "--gcc-toolchain=${CROSS_ROOTFS}/usr")
+ add_compile_param(CROSS_LINK_FLAGS "--target=${TOOLCHAIN}")
+endif()
+
add_compile_param(CROSS_LINK_FLAGS "-fuse-ld=gold")
if(TARGET_ARCH_NAME STREQUAL "armel")
@@ -79,8 +95,10 @@ add_compile_param(CMAKE_MODULE_LINKER_FLAGS "${CROSS_LINK_FLAGS}" "TOOLCHAIN_EXE
# Specify compile options
add_compile_options("--sysroot=${CROSS_ROOTFS}")
-add_compile_options("--target=${TOOLCHAIN}")
-add_compile_options("--gcc-toolchain=${CROSS_ROOTFS}/usr")
+if (CLR_CMAKE_COMPILER STREQUAL "Clang")
+ add_compile_options("--target=${TOOLCHAIN}")
+ add_compile_options("--gcc-toolchain=${CROSS_ROOTFS}/usr")
+endif()
if(TARGET_ARCH_NAME MATCHES "^(arm|armel|arm64)$")
set(CMAKE_C_COMPILER_TARGET ${TOOLCHAIN})
diff --git a/src/pal/inc/mbusafecrt.h b/src/pal/inc/mbusafecrt.h
index 9c516e032b..abc2dca406 100644
--- a/src/pal/inc/mbusafecrt.h
+++ b/src/pal/inc/mbusafecrt.h
@@ -31,11 +31,13 @@ typedef int errno_t;
// define the return value for success
#define SAFECRT_SUCCESS 0
-#if defined(_MSC_VER) || defined(__llvm__)
+#ifndef THROW_DECL
+#if defined(_MSC_VER) || defined(__llvm__) || !defined(__cplusplus)
#define THROW_DECL
#else
#define THROW_DECL throw()
-#endif
+#endif // !_MSC_VER
+#endif // !THROW_DECL
#ifdef __cplusplus
extern "C" {
diff --git a/src/pal/inc/pal.h b/src/pal/inc/pal.h
index 7bf34963fc..67e39ae44f 100644
--- a/src/pal/inc/pal.h
+++ b/src/pal/inc/pal.h
@@ -143,11 +143,13 @@ typedef void * NATIVE_LIBRARY_HANDLE;
#define LANG_THAI 0x1e
/******************* Compiler-specific glue *******************************/
-#if defined(_MSC_VER) || defined(__llvm__)
+#ifndef THROW_DECL
+#if defined(_MSC_VER) || defined(__llvm__) || !defined(__cplusplus)
#define THROW_DECL
#else
#define THROW_DECL throw()
-#endif
+#endif // !_MSC_VER
+#endif // !THROW_DECL
#ifndef _MSC_VER
#if defined(CORECLR)
@@ -367,7 +369,7 @@ int
PALAPI
PAL_Initialize(
int argc,
- const char * const argv[]);
+ char * const argv[]);
PALIMPORT
void
@@ -4316,7 +4318,7 @@ EXTERN_C
PALIMPORT
void *PAL_memcpy (void *dest, const void *src, size_t count);
-PALIMPORT void * __cdecl memcpy(void *, const void *, size_t);
+PALIMPORT void * __cdecl memcpy(void *, const void *, size_t) THROW_DECL;
#define memcpy PAL_memcpy
#define IS_PAL_memcpy 1
diff --git a/src/pal/inc/unixasmmacros.inc b/src/pal/inc/unixasmmacros.inc
index e7a5eba898..a1f1a694ee 100644
--- a/src/pal/inc/unixasmmacros.inc
+++ b/src/pal/inc/unixasmmacros.inc
@@ -10,7 +10,11 @@
#define LOCAL_LABEL(name) L##name
#else
#define C_FUNC(name) name
+#if defined(_AMD64_) || defined(_X86_)
#define EXTERNAL_C_FUNC(name) C_FUNC(name)@plt
+#else
+#define EXTERNAL_C_FUNC(name) C_FUNC(name)
+#endif
#define LOCAL_LABEL(name) .L##name
#endif
diff --git a/src/pal/src/CMakeLists.txt b/src/pal/src/CMakeLists.txt
index 8e69ee9ee9..be5b5bd872 100644
--- a/src/pal/src/CMakeLists.txt
+++ b/src/pal/src/CMakeLists.txt
@@ -5,7 +5,9 @@ if(CMAKE_SYSTEM_NAME STREQUAL Darwin OR CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
set(CLR_CMAKE_USE_SYSTEM_LIBUNWIND 1)
endif(CMAKE_SYSTEM_NAME STREQUAL Darwin OR CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
-include_directories(SYSTEM /usr/local/include)
+if(NOT DEFINED ENV{ROOTFS_DIR})
+ include_directories(SYSTEM /usr/local/include)
+endif()
add_compile_options(-fPIC)
diff --git a/src/pal/src/examples/example1.cpp b/src/pal/src/examples/example1.cpp
index 576e76632e..fce8c367b5 100644
--- a/src/pal/src/examples/example1.cpp
+++ b/src/pal/src/examples/example1.cpp
@@ -32,7 +32,7 @@ int main(int argc, char *argv[])
HANDLE h;
unsigned int b;
- PAL_Initialize(argc, (const char**)argv);
+ PAL_Initialize(argc, argv);
SetCurrentDirectoryW(dir);
SetCurrentDirectoryW(dir);
h = CreateFileW(src, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_NEW, 0, NULL);
diff --git a/src/pal/src/exception/remote-unwind.cpp b/src/pal/src/exception/remote-unwind.cpp
index 4934e77115..fe7a4c814f 100644
--- a/src/pal/src/exception/remote-unwind.cpp
+++ b/src/pal/src/exception/remote-unwind.cpp
@@ -51,10 +51,14 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// Sub-headers included from the libunwind.h contain an empty struct
// and clang issues a warning. Until the libunwind is fixed, disable
// the warning.
+#ifdef __llvm__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wextern-c-compat"
+#endif
#include <libunwind.h>
+#ifdef __llvm__
#pragma clang diagnostic pop
+#endif
SET_DEFAULT_DEBUG_CHANNEL(EXCEPT);
diff --git a/src/pal/src/exception/seh-unwind.cpp b/src/pal/src/exception/seh-unwind.cpp
index 094036189c..3f40057d88 100644
--- a/src/pal/src/exception/seh-unwind.cpp
+++ b/src/pal/src/exception/seh-unwind.cpp
@@ -31,10 +31,14 @@ Abstract:
// Sub-headers included from the libunwind.h contain an empty struct
// and clang issues a warning. Until the libunwind is fixed, disable
// the warning.
+#ifdef __llvm__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wextern-c-compat"
+#endif
#include <libunwind.h>
+#ifdef __llvm__
#pragma clang diagnostic pop
+#endif
//----------------------------------------------------------------------
// Virtual Unwinding
diff --git a/src/pal/src/init/pal.cpp b/src/pal/src/init/pal.cpp
index d683ca7345..f6bbd6a82c 100644
--- a/src/pal/src/init/pal.cpp
+++ b/src/pal/src/init/pal.cpp
@@ -153,7 +153,7 @@ int
PALAPI
PAL_Initialize(
int argc,
- const char *const argv[])
+ char *const argv[])
{
return Initialize(argc, argv, PAL_INITIALIZE);
}
diff --git a/src/pal/src/libunwind/src/CMakeLists.txt b/src/pal/src/libunwind/src/CMakeLists.txt
index c035f64c11..98d3d3e7a9 100644
--- a/src/pal/src/libunwind/src/CMakeLists.txt
+++ b/src/pal/src/libunwind/src/CMakeLists.txt
@@ -7,6 +7,11 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)
include(configure.cmake)
+if (NOT CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
+ add_compile_options(-Wformat=0)
+ add_compile_options(-Wno-unused-value)
+endif()
+
# The HAVE___THREAD set to 1 causes creation of thread local variable with tls_model("initial-exec")
# which is incompatible with usage of the unwind code in a shared library.
add_definitions(-DHAVE___THREAD=0)
@@ -19,15 +24,19 @@ add_definitions(-D_GNU_SOURCE)
# Ensure that the remote and local unwind code can reside in the same binary without name clashing
add_definitions("-Ddwarf_search_unwind_table_int=UNW_OBJ(dwarf_search_unwind_table_int)")
-add_compile_options(-Wno-header-guard)
+if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
+ add_compile_options(-Wno-header-guard)
+endif()
if(CLR_CMAKE_PLATFORM_ARCH_ARM)
# Ensure that the remote and local unwind code can reside in the same binary without name clashing
add_definitions("-Darm_search_unwind_table=UNW_OBJ(arm_search_unwind_table)")
# Disable warning in asm: use of SP or PC in the list is deprecated
add_compile_options(-Wno-inline-asm)
- # Disable warning due to labs function called on unsigned argument
- add_compile_options(-Wno-absolute-value)
+ if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
+ # Disable warning due to labs function called on unsigned argument
+ add_compile_options(-Wno-absolute-value)
+ endif()
# Disable warning due to incorrect format specifier in debugging printf via the Debug macro
add_compile_options(-Wno-format)
# Disable warning for a bug in the libunwind source src/arm/Gtrace.c:529, but not in code that we exercise
@@ -41,8 +50,10 @@ if(CLR_CMAKE_PLATFORM_ARCH_ARM)
# the include/tdep-arm to include directories
include_directories(../include/tdep-arm)
elseif(CLR_CMAKE_PLATFORM_ARCH_ARM64)
- # Disable warning due to labs function called on unsigned argument
- add_compile_options(-Wno-absolute-value)
+ if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
+ # Disable warning due to labs function called on unsigned argument
+ add_compile_options(-Wno-absolute-value)
+ endif()
# We compile code with -std=c99 and the asm keyword is not recognized as it is a gnu extension
add_definitions(-Dasm=__asm__)
elseif(CLR_CMAKE_PLATFORM_ARCH_I386)
diff --git a/src/pal/tests/CMakeLists.txt b/src/pal/tests/CMakeLists.txt
index 39d5852889..5597922f72 100644
--- a/src/pal/tests/CMakeLists.txt
+++ b/src/pal/tests/CMakeLists.txt
@@ -32,7 +32,11 @@ endif()
# C++ emits errors and warnings for c-string literal fed into char* parameter
# this is just to take care of the warnings
-add_compile_options(-Wno-writable-strings)
+if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
+ add_compile_options(-Wno-writable-strings)
+elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
+ add_compile_options(-Wno-write-strings)
+endif()
add_compile_options(-Wno-empty-body)
diff --git a/src/pal/tests/palsuite/CMakeLists.txt b/src/pal/tests/palsuite/CMakeLists.txt
index 6f36025d1a..38b8ed0459 100644
--- a/src/pal/tests/palsuite/CMakeLists.txt
+++ b/src/pal/tests/palsuite/CMakeLists.txt
@@ -14,8 +14,15 @@ endif()
list(APPEND COMMON_TEST_LIBRARIES coreclrpal)
-add_compile_options(-Wno-incompatible-pointer-types-discards-qualifiers)
-add_compile_options(-Wno-int-to-void-pointer-cast)
+if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
+ add_compile_options(-Wno-incompatible-pointer-types-discards-qualifiers)
+ add_compile_options(-Wno-int-to-void-pointer-cast)
+elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
+ add_compile_options(-Wno-sign-compare)
+ add_compile_options(-Wno-narrowing)
+ SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive" )
+ add_compile_options(-Wno-int-to-pointer-cast)
+endif()
# TODO: make these tests compile
# add_subdirectory(composite)
diff --git a/src/pal/tests/palsuite/c_runtime/_wfopen/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/_wfopen/test1/test1.cpp
index 81d2502cd5..93fdb012d2 100644
--- a/src/pal/tests/palsuite/c_runtime/_wfopen/test1/test1.cpp
+++ b/src/pal/tests/palsuite/c_runtime/_wfopen/test1/test1.cpp
@@ -69,7 +69,7 @@ int __cdecl main(int argc, char **argv)
free(PrintResult);
}
- memset(name, '\0', 128);
+ memset(name, '\0', 128 * sizeof(name[0]));
}
PAL_Terminate();
diff --git a/src/pal/tests/palsuite/file_io/GetFullPathNameW/test3/test3.cpp b/src/pal/tests/palsuite/file_io/GetFullPathNameW/test3/test3.cpp
index ba80cf222d..45c0c98505 100644
--- a/src/pal/tests/palsuite/file_io/GetFullPathNameW/test3/test3.cpp
+++ b/src/pal/tests/palsuite/file_io/GetFullPathNameW/test3/test3.cpp
@@ -62,7 +62,7 @@ int __cdecl main(int argc, char *argv[])
/* Initialize the buffer.
*/
- memset( szDirectory, '\0', 256 );
+ memset( szDirectory, '\0', 256 * sizeof(szDirectory[0]) );
/* Change the current working directory.
*/
diff --git a/src/pal/tests/palsuite/file_io/GetFullPathNameW/test4/test4.cpp b/src/pal/tests/palsuite/file_io/GetFullPathNameW/test4/test4.cpp
index 25eb10d654..baf4b344f0 100644
--- a/src/pal/tests/palsuite/file_io/GetFullPathNameW/test4/test4.cpp
+++ b/src/pal/tests/palsuite/file_io/GetFullPathNameW/test4/test4.cpp
@@ -61,7 +61,7 @@ int __cdecl main(int argc, char *argv[])
/* Initialize the buffer.
*/
- memset(szDirectory, '\0', 256);
+ memset(szDirectory, '\0', 256 * sizeof(szDirectory[0]));
/* Create the path to the next level of directory to create.
*/
diff --git a/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test2/test.cpp b/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test2/test.cpp
index d45dc92f04..3895b71af9 100644
--- a/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test2/test.cpp
+++ b/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test2/test.cpp
@@ -25,7 +25,7 @@ int test1(int num, ...)
int ReturnResult;
va_list TheList;
va_start(TheList,num);
- memset( OutBuffer, 0, 1024 );
+ memset( OutBuffer, 0, 1024 * sizeof(OutBuffer[0]) );
ReturnResult = FormatMessage(
FORMAT_MESSAGE_FROM_STRING, /* source and processing options */
@@ -69,7 +69,7 @@ int test2(int num, ...)
va_list TheList;
va_start(TheList,num);
- memset( OutBuffer, 0, 1024 );
+ memset( OutBuffer, 0, 1024 * sizeof(OutBuffer[0]) );
ReturnResult = FormatMessage(
FORMAT_MESSAGE_FROM_STRING, /* source and processing options */
@@ -106,7 +106,7 @@ int test3(int num, ...) {
int ReturnResult;
va_list TheList;
va_start(TheList,num);
- memset( OutBuffer, 0, 1024 );
+ memset( OutBuffer, 0, 1024 * sizeof(OutBuffer[0]) );
ReturnResult = FormatMessage(
FORMAT_MESSAGE_FROM_STRING, /* source and processing options */
TheString, /* message source */
@@ -144,7 +144,7 @@ int test4(int num, ...) {
int ReturnResult;
va_list TheList;
va_start(TheList,num);
- memset( OutBuffer, 0, 1024 );
+ memset( OutBuffer, 0, 1024 * sizeof(OutBuffer[0]) );
ReturnResult = FormatMessage(
FORMAT_MESSAGE_FROM_STRING, /* source and processing options */
TheString, /* message source */
@@ -182,7 +182,7 @@ int test5(int num, ...)
int ReturnResult;
va_list TheList;
va_start(TheList,num);
- memset( OutBuffer, 0, 1024 );
+ memset( OutBuffer, 0, 1024 * sizeof(OutBuffer[0]) );
ReturnResult = FormatMessage(
FORMAT_MESSAGE_FROM_STRING, /* source and processing options */
@@ -222,7 +222,7 @@ int test6(int num, ...) {
int ReturnResult;
va_list TheList;
va_start(TheList,num);
- memset( OutBuffer, 0, 1024 );
+ memset( OutBuffer, 0, 1024 * sizeof(OutBuffer[0]) );
ReturnResult = FormatMessage(
FORMAT_MESSAGE_FROM_STRING, /* source and processing options */
@@ -264,7 +264,7 @@ int test7(int num, ...)
int ReturnResult;
va_list TheList;
va_start(TheList,num);
- memset( OutBuffer, 0, 1024 );
+ memset( OutBuffer, 0, 1024 * sizeof(OutBuffer[0]) );
ReturnResult = FormatMessage(
FORMAT_MESSAGE_FROM_STRING, /* source and processing options */
@@ -307,7 +307,7 @@ int test8(int num, ...)
int ReturnResult;
va_list TheList;
va_start(TheList,num);
- memset( OutBuffer, 0, 1024 );
+ memset( OutBuffer, 0, 1024 * sizeof(OutBuffer[0]) );
ReturnResult = FormatMessage(
FORMAT_MESSAGE_FROM_STRING, /* source and processing options */
@@ -351,7 +351,7 @@ int test9(int num, ...) {
int ReturnResult;
va_list TheList;
va_start(TheList,num);
- memset( OutBuffer, 0, 1024 );
+ memset( OutBuffer, 0, 1024 * sizeof(OutBuffer[0]) );
ReturnResult = FormatMessage(
FORMAT_MESSAGE_FROM_STRING, /* source and processing options */
TheString, /* message source */
@@ -393,7 +393,7 @@ int test10(int num, ...)
int ReturnResult;
va_list TheList;
va_start(TheList,num);
- memset( OutBuffer, 0, 1024 );
+ memset( OutBuffer, 0, 1024 * sizeof(OutBuffer[0]) );
ReturnResult = FormatMessage(
FORMAT_MESSAGE_FROM_STRING, /* source and processing options */
TheString, /* message source */
@@ -435,7 +435,7 @@ int test11(int num, ...)
int ReturnResult;
va_list TheList;
va_start(TheList,num);
- memset( OutBuffer, 0, 1024 );
+ memset( OutBuffer, 0, 1024 * sizeof(OutBuffer[0]) );
ReturnResult = FormatMessage(
FORMAT_MESSAGE_FROM_STRING, /* source and processing options */
@@ -505,7 +505,7 @@ int test12(int num, ...)
int ReturnResult;
va_list TheList;
va_start(TheList,num);
- memset( OutBuffer, 0, 1024 );
+ memset( OutBuffer, 0, 1024 * sizeof(OutBuffer[0]) );
ReturnResult = FormatMessage(
FORMAT_MESSAGE_FROM_STRING, /* source and processing options */
diff --git a/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableW/test1/test.cpp b/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableW/test1/test.cpp
index bddbba7940..0c753be781 100644
--- a/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableW/test1/test.cpp
+++ b/src/pal/tests/palsuite/miscellaneous/SetEnvironmentVariableW/test1/test.cpp
@@ -86,7 +86,7 @@ int __cdecl main(int argc, char *argv[])
"the variable PALTEST.\n");
}
- memset(NewValue,0,BUF_SIZE);
+ memset(NewValue,0,BUF_SIZE * sizeof(NewValue[0]));
/* Grab the Environment variable we just set */
if(GetEnvironmentVariable(VariableBuffer,NewValue,BUF_SIZE) <= 0)
@@ -122,7 +122,7 @@ int __cdecl main(int argc, char *argv[])
"the variable PALTEST.\n");
}
- memset(NewValue,0,BUF_SIZE);
+ memset(NewValue,0,BUF_SIZE*sizeof(NewValue[0]));
/* Grab the Environment variable we just set, ensure that it's
empty now.
diff --git a/src/pal/tests/palsuite/threading/CreateThread/test2/test2.cpp b/src/pal/tests/palsuite/threading/CreateThread/test2/test2.cpp
index 1ee410a6c5..34d3afbfb6 100644
--- a/src/pal/tests/palsuite/threading/CreateThread/test2/test2.cpp
+++ b/src/pal/tests/palsuite/threading/CreateThread/test2/test2.cpp
@@ -23,9 +23,9 @@ volatile DWORD dwThreadId1[NUM_TESTS];
DWORD PALAPI Thread( LPVOID lpParameter)
{
- dwThreadId1[(DWORD) lpParameter] = GetCurrentThreadId();
- bResult[(DWORD) lpParameter] = TRUE;
- return (DWORD) lpParameter;
+ dwThreadId1[(DWORD)(SIZE_T)lpParameter] = GetCurrentThreadId();
+ bResult[(DWORD)(SIZE_T) lpParameter] = TRUE;
+ return (DWORD)(SIZE_T) lpParameter;
}
struct testCase
diff --git a/src/pal/tests/palsuite/threading/ExitThread/test1/test1.cpp b/src/pal/tests/palsuite/threading/ExitThread/test1/test1.cpp
index caf1409406..9477633126 100644
--- a/src/pal/tests/palsuite/threading/ExitThread/test1/test1.cpp
+++ b/src/pal/tests/palsuite/threading/ExitThread/test1/test1.cpp
@@ -22,7 +22,7 @@ DWORD PALAPI ExitThreadTestThread( LPVOID lpParameter)
DWORD dwRet = 0;
/* Save parameter for test */
- dwExitThreadTestParameter = (DWORD)lpParameter;
+ dwExitThreadTestParameter = (DWORD)(SIZE_T)lpParameter;
/* Call the ExitThread function */
ExitThread(dwRet);
@@ -77,7 +77,7 @@ BOOL ExitThreadTest()
/* Check to ensure that the parameter set in the Thread
function is correct.
*/
- if (dwExitThreadTestParameter != (DWORD)lpParameter)
+ if (dwExitThreadTestParameter != (DWORD)(SIZE_T)lpParameter)
{
Trace("ERROR: The paramater passed should have been "
"%d but turned up as %d.",
diff --git a/src/pal/tests/palsuite/threading/ResumeThread/test1/test1.cpp b/src/pal/tests/palsuite/threading/ResumeThread/test1/test1.cpp
index d2be262e4d..825064e23b 100644
--- a/src/pal/tests/palsuite/threading/ResumeThread/test1/test1.cpp
+++ b/src/pal/tests/palsuite/threading/ResumeThread/test1/test1.cpp
@@ -25,7 +25,7 @@ DWORD PALAPI ResumeThreadTestThread( LPVOID lpParameter)
properly.
*/
- dwResumeThreadTestParameter = (DWORD)lpParameter;
+ dwResumeThreadTestParameter = (DWORD)(SIZE_T)lpParameter;
return dwRet;
}
@@ -101,7 +101,7 @@ BOOL ResumeThreadTest()
/* Check the param now and it should have been
set.
*/
- if (dwResumeThreadTestParameter != (DWORD)lpParameter)
+ if (dwResumeThreadTestParameter != (DWORD)(SIZE_T)lpParameter)
{
Trace("ResumeThreadTest:parameter error\n");
}
diff --git a/src/pal/tests/palsuite/threading/SleepEx/test2/test2.cpp b/src/pal/tests/palsuite/threading/SleepEx/test2/test2.cpp
index c2ba4e704d..690acf5ce7 100644
--- a/src/pal/tests/palsuite/threading/SleepEx/test2/test2.cpp
+++ b/src/pal/tests/palsuite/threading/SleepEx/test2/test2.cpp
@@ -152,7 +152,7 @@ DWORD PALAPI SleeperProc(LPVOID lpParameter)
BOOL Alertable;
DWORD ret;
- Alertable = (BOOL) lpParameter;
+ Alertable = (BOOL)(SIZE_T) lpParameter;
LARGE_INTEGER performanceFrequency;
if (!QueryPerformanceFrequency(&performanceFrequency))
diff --git a/src/pal/tests/palsuite/threading/SwitchToThread/test1/test1.cpp b/src/pal/tests/palsuite/threading/SwitchToThread/test1/test1.cpp
index 76ecdd3572..ce03021b9e 100644
--- a/src/pal/tests/palsuite/threading/SwitchToThread/test1/test1.cpp
+++ b/src/pal/tests/palsuite/threading/SwitchToThread/test1/test1.cpp
@@ -83,7 +83,7 @@ INT __cdecl main( INT argc, CHAR **argv )
void PALAPI Run_Thread (LPVOID lpParam)
{
int i = 0;
- int Id=(int)lpParam;
+ int Id=(int)(SIZE_T)lpParam;
for(i=0; i < REPEAT_COUNT; i++ )
{
diff --git a/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test2/test2.cpp b/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test2/test2.cpp
index b2bc301128..ffa496dd82 100644
--- a/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test2/test2.cpp
+++ b/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test2/test2.cpp
@@ -146,7 +146,7 @@ DWORD PALAPI WaiterProc(LPVOID lpParameter)
GetLastError());
}
- Alertable = (BOOL) lpParameter;
+ Alertable = (BOOL)(SIZE_T) lpParameter;
LARGE_INTEGER performanceFrequency;
if (!QueryPerformanceFrequency(&performanceFrequency))
diff --git a/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test5/test5.cpp b/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test5/test5.cpp
index a0216494ba..9d9e75b522 100644
--- a/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test5/test5.cpp
+++ b/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test5/test5.cpp
@@ -74,7 +74,7 @@ DWORD PALAPI WaitForProcess(LPVOID lpParameter)
DWORD dwRet;
HANDLE handles[MAX_HELPER_PROCESS+1];
- index = (DWORD) lpParameter;
+ index = (DWORD)(SIZE_T) lpParameter;
/* The helper thread 0 will wait for helper process 0, helper thread 1 will
wait for helper process 0 and 1, helper thread 2 will wait for helper
diff --git a/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test6/test6.cpp b/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test6/test6.cpp
index d5e3137899..1cec3492db 100644
--- a/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test6/test6.cpp
+++ b/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test6/test6.cpp
@@ -154,7 +154,7 @@ DWORD PALAPI TestThread(PVOID pArg)
BOOL bRemoteWaitAll = g_bRemoteWaitAll;
int iDesiredExitCode;
- dwThreadNum = (DWORD)pArg;
+ dwThreadNum = (DWORD)(SIZE_T)pArg;
sprintf_s (szTestName, 128, "Test6_%u", dwThreadNum);
szTestName[127] = 0;
diff --git a/src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOExMutexTest/WFSOExMutexTest.cpp b/src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOExMutexTest/WFSOExMutexTest.cpp
index 3737f9cc10..f8fd7cbccc 100644
--- a/src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOExMutexTest/WFSOExMutexTest.cpp
+++ b/src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOExMutexTest/WFSOExMutexTest.cpp
@@ -178,7 +178,7 @@ DWORD PALAPI WaiterProc(LPVOID lpParameter)
BOOL Alertable;
DWORD ret;
- Alertable = (BOOL) lpParameter;
+ Alertable = (BOOL)(SIZE_T) lpParameter;
LARGE_INTEGER performanceFrequency;
if (!QueryPerformanceFrequency(&performanceFrequency))
diff --git a/src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOExSemaphoreTest/WFSOExSemaphoreTest.cpp b/src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOExSemaphoreTest/WFSOExSemaphoreTest.cpp
index 793c50995c..d8816a7b98 100644
--- a/src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOExSemaphoreTest/WFSOExSemaphoreTest.cpp
+++ b/src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOExSemaphoreTest/WFSOExSemaphoreTest.cpp
@@ -145,7 +145,7 @@ DWORD PALAPI WaiterProc(LPVOID lpParameter)
GetLastError());
}
- Alertable = (BOOL) lpParameter;
+ Alertable = (BOOL)(SIZE_T) lpParameter;
OldTimeStamp = GetHighPrecisionTimeStamp(performanceFrequency);
diff --git a/src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOExThreadTest/WFSOExThreadTest.cpp b/src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOExThreadTest/WFSOExThreadTest.cpp
index 894d2804aa..a2c8850f79 100644
--- a/src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOExThreadTest/WFSOExThreadTest.cpp
+++ b/src/pal/tests/palsuite/threading/WaitForSingleObject/WFSOExThreadTest/WFSOExThreadTest.cpp
@@ -153,7 +153,7 @@ satisfying any threads that were waiting on the object.
"GetLastError returned %d\n", GetLastError());
}
- Alertable = (BOOL) lpParameter;
+ Alertable = (BOOL)(SIZE_T) lpParameter;
LARGE_INTEGER performanceFrequency;
if (!QueryPerformanceFrequency(&performanceFrequency))
diff --git a/src/pal/tools/gcc-compiler-override.txt b/src/pal/tools/gcc-compiler-override.txt
new file mode 100644
index 0000000000..337d41af16
--- /dev/null
+++ b/src/pal/tools/gcc-compiler-override.txt
@@ -0,0 +1,20 @@
+SET (CMAKE_C_FLAGS_INIT "-Wall -std=c11")
+SET (CMAKE_C_FLAGS_DEBUG_INIT "-g -O0")
+SET (CLR_C_FLAGS_CHECKED_INIT "-g -O2")
+# Refer to the below instruction to support __thread with -O2/-O3 on Linux/ARM
+# https://github.com/dotnet/coreclr/blob/master/Documentation/building/linux-instructions.md
+SET (CMAKE_C_FLAGS_RELEASE_INIT "-g -O3")
+SET (CMAKE_C_FLAGS_RELWITHDEBINFO_INIT "-g -O2")
+
+SET (CMAKE_CXX_FLAGS_INIT "-Wall -Werror=conversion-null -std=c++11")
+SET (CMAKE_CXX_FLAGS_DEBUG_INIT "-g -O0")
+SET (CLR_CXX_FLAGS_CHECKED_INIT "-g -O2")
+SET (CMAKE_CXX_FLAGS_RELEASE_INIT "-g -O3")
+SET (CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT "-g -O2")
+
+SET (CLR_DEFINES_DEBUG_INIT DEBUG _DEBUG _DBG URTBLDENV_FRIENDLY=Checked BUILDENV_CHECKED=1)
+SET (CLR_DEFINES_CHECKED_INIT DEBUG _DEBUG _DBG URTBLDENV_FRIENDLY=Checked BUILDENV_CHECKED=1)
+SET (CLR_DEFINES_RELEASE_INIT NDEBUG URTBLDENV_FRIENDLY=Retail)
+SET (CLR_DEFINES_RELWITHDEBINFO_INIT NDEBUG URTBLDENV_FRIENDLY=Retail)
+
+SET (CMAKE_INSTALL_PREFIX $ENV{__CMakeBinDir})
diff --git a/src/pal/tools/gen-buildsys-clang.sh b/src/pal/tools/gen-buildsys-clang.sh
index 597ae5d76d..2047b1eccf 100755
--- a/src/pal/tools/gen-buildsys-clang.sh
+++ b/src/pal/tools/gen-buildsys-clang.sh
@@ -162,6 +162,7 @@ cmake \
"-DCMAKE_BUILD_TYPE=$buildtype" \
"-DCMAKE_EXPORT_COMPILE_COMMANDS=1 " \
"-DCLR_CMAKE_ENABLE_CODE_COVERAGE=$code_coverage" \
+ "-DCLR_CMAKE_COMPILER=Clang" \
$cmake_extra_defines \
$__UnprocessedCMakeArgs \
"$1"
diff --git a/src/pal/tools/gen-buildsys-gcc.sh b/src/pal/tools/gen-buildsys-gcc.sh
new file mode 100755
index 0000000000..cc141baae9
--- /dev/null
+++ b/src/pal/tools/gen-buildsys-gcc.sh
@@ -0,0 +1,188 @@
+#!/usr/bin/env sh
+#
+# This file invokes cmake and generates the build system for Gcc.
+#
+
+if [ $# -lt 4 ]
+then
+ echo "Usage..."
+ echo "gen-buildsys-gcc.sh <path to top level CMakeLists.txt> <GccMajorVersion> <GccMinorVersion> <Architecture> [build flavor] [coverage] [ninja] [cmakeargs]"
+ echo "Specify the path to the top level CMake file - <ProjectK>/src/NDP"
+ echo "Specify the Gcc version to use, split into major and minor version"
+ echo "Specify the target architecture."
+ echo "Optionally specify the build configuration (flavor.) Defaults to DEBUG."
+ echo "Optionally specify 'coverage' to enable code coverage build."
+ echo "Target ninja instead of make. ninja must be on the PATH."
+ echo "Pass additional arguments to CMake call."
+ exit 1
+fi
+
+# Locate gcc
+gcc_prefix=""
+
+if [ "$CROSSCOMPILE" = "1" ]; then
+ # Locate gcc
+ if [ ! -z "$TOOLCHAIN" ]; then
+ gcc_prefix="$TOOLCHAIN-"
+ fi
+fi
+
+# Set up the environment to be used for building with gcc.
+if command -v "${gcc_prefix}gcc-$2.$3" > /dev/null
+ then
+ desired_gcc_version="-$2.$3"
+elif command -v "${gcc_prefix}gcc$2$3" > /dev/null
+ then
+ desired_gcc_version="$2$3"
+elif command -v "${gcc_prefix}gcc-$2$3" > /dev/null
+ then
+ desired_gcc_version="-$2$3"
+elif command -v ${gcc_prefix}gcc > /dev/null
+ then
+ desired_gcc_version=
+else
+ echo "Unable to find $gcc_prefixgcc Compiler"
+ exit 1
+fi
+
+if [ -z "$CC" ]; then
+ export CC="$(command -v ${gcc_prefix}gcc$desired_gcc_version)"
+fi
+if [ -z "$CXX" ]; then
+ export CXX="$(command -v ${gcc_prefix}g++$desired_gcc_version)"
+fi
+
+build_arch="$4"
+buildtype=DEBUG
+code_coverage=OFF
+generator="Unix Makefiles"
+__UnprocessedCMakeArgs=""
+
+ITER=-1
+for i in "$@"; do
+ ITER=$(($ITER + 1))
+ if [ $ITER -lt 5 ]; then continue; fi
+ upperI="$(echo $i | awk '{print toupper($0)}')"
+ case $upperI in
+ # Possible build types are DEBUG, CHECKED, RELEASE, RELWITHDEBINFO, MINSIZEREL.
+ DEBUG | CHECKED | RELEASE | RELWITHDEBINFO | MINSIZEREL)
+ buildtype=$upperI
+ ;;
+ COVERAGE)
+ echo "Code coverage is turned on for this build."
+ code_coverage=ON
+ ;;
+ NINJA)
+ generator=Ninja
+ ;;
+ *)
+ __UnprocessedCMakeArgs="${__UnprocessedCMakeArgs}${__UnprocessedCMakeArgs:+ }$i"
+ esac
+done
+
+OS=`uname`
+
+locate_gcc_exec() {
+ if command -v "$gcc_prefix$1$desired_gcc_version" > /dev/null 2>&1
+ then
+ echo "$(command -v $gcc_prefix$1$desired_gcc_version)"
+ elif command -v "$gcc_prefix$1" > /dev/null 2>&1
+ then
+ echo "$(command -v $gcc_prefix$1)"
+ else
+ exit 1
+ fi
+}
+
+gcc_ar="$(locate_gcc_exec ar)"
+[ $? -eq 0 ] || { echo "Unable to locate gcc-ar"; exit 1; }
+
+if [ -z "$CC" ]; then
+ gcc_link="$(locate_gcc_exec gcc)"
+ [ $? -eq 0 ] || { echo "Unable to locate gcc-link"; exit 1; }
+else
+ gcc_link="$CC"
+fi
+
+if [ -z "$NM" ]; then
+ gcc_nm="$(locate_gcc_exec nm)"
+ [ $? -eq 0 ] || { echo "Unable to locate gcc-nm"; exit 1; }
+else
+ gcc_nm="$NM"
+fi
+
+if [ "$OS" = "Linux" ] || [ "$OS" = "FreeBSD" ] || [ "$OS" = "OpenBSD" ] || [ "$OS" = "NetBSD" ] || [ "$OS" = "SunOS" ]; then
+ if [ -z "$OBJDUMP" ]; then
+ gcc_objdump="$(locate_gcc_exec objdump)"
+ [ $? -eq 0 ] || { echo "Unable to locate gcc-objdump"; exit 1; }
+ else
+ gcc_objdump="$OBJDUMP"
+ fi
+fi
+
+if [ -z "$OBJCOPY" ]; then
+ gcc_objcopy="$(locate_gcc_exec objcopy)"
+ [ $? -eq 0 ] || { echo "Unable to locate gcc-objcopy"; exit 1; }
+else
+ gcc_objcopy="$OBJCOPY"
+fi
+
+gcc_ranlib="$(locate_gcc_exec ranlib)"
+[ $? -eq 0 ] || { echo "Unable to locate gcc-ranlib"; exit 1; }
+
+cmake_extra_defines=
+if [ -n "$LLDB_LIB_DIR" ]; then
+ cmake_extra_defines="$cmake_extra_defines -DWITH_LLDB_LIBS=$LLDB_LIB_DIR"
+fi
+if [ -n "$LLDB_INCLUDE_DIR" ]; then
+ cmake_extra_defines="$cmake_extra_defines -DWITH_LLDB_INCLUDES=$LLDB_INCLUDE_DIR"
+fi
+if [ "$CROSSCOMPILE" = "1" ]; then
+ if [ -z "$ROOTFS_DIR" ]; then
+ echo "ROOTFS_DIR not set for crosscompile"
+ exit 1
+ fi
+ if [ -z "$CONFIG_DIR" ]; then
+ CONFIG_DIR="$1/cross"
+ fi
+ export TARGET_BUILD_ARCH=$build_arch
+ cmake_extra_defines="$cmake_extra_defines -C $CONFIG_DIR/tryrun.cmake"
+ cmake_extra_defines="$cmake_extra_defines -DCMAKE_TOOLCHAIN_FILE=$CONFIG_DIR/toolchain.cmake"
+ cmake_extra_defines="$cmake_extra_defines --sysroot=$ROOTFS_DIR"
+ cmake_extra_defines="$cmake_extra_defines -DCLR_UNIX_CROSS_BUILD=1"
+fi
+if [ "$OS" = "Linux" ]; then
+ linux_id_file="/etc/os-release"
+ if [ -n "$CROSSCOMPILE" ]; then
+ linux_id_file="$ROOTFS_DIR/$linux_id_file"
+ fi
+ if [ -e "$linux_id_file" ]; then
+ . "$linux_id_file"
+ cmake_extra_defines="$cmake_extra_defines -DCLR_CMAKE_LINUX_ID=$ID"
+ fi
+fi
+if [ "$build_arch" = "armel" ]; then
+ cmake_extra_defines="$cmake_extra_defines -DARM_SOFTFP=1"
+fi
+
+overridefile=gcc-compiler-override.txt
+
+# Determine the current script directory
+__currentScriptDir="$(cd -- "$(dirname -- "$0")" && pwd -P)"
+
+cmake \
+ -G "$generator" \
+ "-DCMAKE_USER_MAKE_RULES_OVERRIDE=${__currentScriptDir}/$overridefile" \
+ "-DCMAKE_AR=$gcc_ar" \
+ "-DCMAKE_LINKER=$gcc_link" \
+ "-DCMAKE_NM=$gcc_nm" \
+ "-DCMAKE_RANLIB=$gcc_ranlib" \
+ "-DCMAKE_OBJCOPY=$gcc_objcopy" \
+ "-DCMAKE_OBJDUMP=$gcc_objdump" \
+ "-DCMAKE_BUILD_TYPE=$buildtype" \
+ "-DCMAKE_EXPORT_COMPILE_COMMANDS=1 " \
+ "-DCLR_CMAKE_ENABLE_CODE_COVERAGE=$code_coverage" \
+ "-DCLR_CMAKE_COMPILER=GNU" \
+ $cmake_extra_defines \
+ $__UnprocessedCMakeArgs \
+ "$1"