Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 34d50b0

Browse files
franksinankayajanvorli
authored andcommitted
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.
1 parent 46cbd93 commit 34d50b0

File tree

33 files changed

+394
-85
lines changed

33 files changed

+394
-85
lines changed

build.sh

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ export PYTHON
2525

2626
usage()
2727
{
28-
echo "Usage: $0 [BuildArch] [BuildType] [-verbose] [-coverage] [-cross] [-clangx.y] [-ninja] [-configureonly] [-skipconfigure] [-skipnative] [-skipcrossarchnative] [-skipmanaged] [-skipmscorlib] [-skiptests] [-stripsymbols] [-ignorewarnings] [-cmakeargs] [-bindir]"
28+
echo "Usage: $0 [BuildArch] [BuildType] [-verbose] [-coverage] [-cross] [-gccx.y] [-clangx.y] [-ninja] [-configureonly] [-skipconfigure] [-skipnative] [-skipcrossarchnative] [-skipmanaged] [-skipmscorlib] [-skiptests] [-stripsymbols] [-ignorewarnings] [-cmakeargs] [-bindir]"
2929
echo "BuildArch can be: -x64, -x86, -arm, -armel, -arm64"
3030
echo "BuildType can be: -debug, -checked, -release"
3131
echo "-coverage - optional argument to enable code coverage build (currently supported only for Linux and OSX)."
3232
echo "-ninja - target ninja instead of GNU make"
33+
echo "-gccx.y - optional argument to build using gcc version x.y."
3334
echo "-clangx.y - optional argument to build using clang version x.y."
3435
echo "-cross - optional argument to signify cross compilation,"
3536
echo " - will use ROOTFS_DIR environment variable if set."
@@ -159,18 +160,26 @@ check_prereqs()
159160

160161

161162
# Minimum required version of clang is version 4.0 for arm/armel cross build
162-
if [[ $__CrossBuild == 1 && ("$__BuildArch" == "arm" || "$__BuildArch" == "armel") ]]; then
163+
if [[ $__CrossBuild == 1 && $__GccBuild == 0 && ("$__BuildArch" == "arm" || "$__BuildArch" == "armel") ]]; then
163164
if ! [[ "$__ClangMajorVersion" -ge "4" ]]; then
164165
echo "Please install clang4.0 or latest for arm/armel cross build"; exit 1;
165166
fi
166167
fi
167168

168169
# Check for clang
169-
__ClangCombinedDottedVersion=$__ClangMajorVersion;
170-
if [[ "$__ClangMinorVersion" != "" ]]; then
171-
__ClangCombinedDottedVersion=$__ClangCombinedDottedVersion.$__ClangMinorVersion
170+
if [[ $__GccBuild == 0 ]]; then
171+
__ClangCombinedDottedVersion=$__ClangMajorVersion;
172+
if [[ "$__ClangMinorVersion" != "" ]]; then
173+
__ClangCombinedDottedVersion=$__ClangCombinedDottedVersion.$__ClangMinorVersion
174+
fi
175+
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; }
176+
else
177+
__GccCombinedDottedVersion=$__GccMajorVersion;
178+
if [[ "$__GccMinorVersion" != "" ]]; then
179+
__GccCombinedDottedVersion=$__GccCombinedDottedVersion.$__GccMinorVersion
180+
fi
181+
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; }
172182
fi
173-
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; }
174183

175184
}
176185

@@ -318,8 +327,14 @@ build_native()
318327

319328
pushd "$intermediatesForBuild"
320329
# Regenerate the CMake solution
321-
echo "Invoking \"$__ProjectRoot/src/pal/tools/gen-buildsys-clang.sh\" \"$__ProjectRoot\" $__ClangMajorVersion \"$__ClangMinorVersion\" $platformArch $__BuildType $__CodeCoverage $generator $extraCmakeArguments $__cmakeargs"
322-
"$__ProjectRoot/src/pal/tools/gen-buildsys-clang.sh" "$__ProjectRoot" $__ClangMajorVersion "$__ClangMinorVersion" $platformArch $__BuildType $__CodeCoverage $generator "$extraCmakeArguments" "$__cmakeargs"
330+
331+
if [[ $__GccBuild == 0 ]]; then
332+
echo "Invoking \"$__ProjectRoot/src/pal/tools/gen-buildsys-clang.sh\" \"$__ProjectRoot\" $__ClangMajorVersion \"$__ClangMinorVersion\" $platformArch $__BuildType $__CodeCoverage $generator $extraCmakeArguments $__cmakeargs"
333+
"$__ProjectRoot/src/pal/tools/gen-buildsys-clang.sh" "$__ProjectRoot" $__ClangMajorVersion "$__ClangMinorVersion" $platformArch $__BuildType $__CodeCoverage $generator "$extraCmakeArguments" "$__cmakeargs"
334+
else
335+
echo "Invoking \"$__ProjectRoot/src/pal/tools/gen-buildsys-gcc.sh\" \"$__ProjectRoot\" $__GccMajorVersion \"$__GccMinorVersion\" $platformArch $__BuildType $__CodeCoverage $generator $extraCmakeArguments $__cmakeargs"
336+
"$__ProjectRoot/src/pal/tools/gen-buildsys-gcc.sh" "$__ProjectRoot" "$__GccMajorVersion" "$__CGccMinorVersion" $platformArch $__BuildType $__CodeCoverage $generator "$extraCmakeArguments" "$__cmakeargs"
337+
fi
323338
popd
324339
fi
325340

@@ -672,6 +687,9 @@ __SkipTests=0
672687
__CrossBuild=0
673688
__ClangMajorVersion=0
674689
__ClangMinorVersion=0
690+
__GccBuild=0
691+
__GccMajorVersion=0
692+
__GccMinorVersion=0
675693
__NuGetPath="$__PackagesDir/NuGet.exe"
676694
__HostDistroRid=""
677695
__DistroRid=""
@@ -808,6 +826,24 @@ while :; do
808826
__ClangMinorVersion=
809827
;;
810828

829+
gcc5|-gcc5)
830+
__GccMajorVersion=5
831+
__GccMinorVersion=
832+
__GccBuild=1
833+
;;
834+
835+
gcc7|-gcc7)
836+
__GccMajorVersion=7
837+
__GccMinorVersion=
838+
__GccBuild=1
839+
;;
840+
841+
gcc|-gcc)
842+
__GccMajorVersion=
843+
__GccMinorVersion=
844+
__GccBuild=1
845+
;;
846+
811847
ninja|-ninja)
812848
__UseNinja=1
813849
;;

configurecompiler.cmake

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -441,36 +441,42 @@ if (CLR_CMAKE_PLATFORM_UNIX)
441441
add_definitions(-DDISABLE_CONTRACTS)
442442
# The -ferror-limit is helpful during the porting, it makes sure the compiler doesn't stop
443443
# after hitting just about 20 errors.
444-
add_compile_options(-ferror-limit=4096)
445444

446445
if (CLR_CMAKE_WARNINGS_ARE_ERRORS)
447446
# All warnings that are not explicitly disabled are reported as errors
448447
add_compile_options(-Werror)
449448
endif(CLR_CMAKE_WARNINGS_ARE_ERRORS)
450449

451-
# Disabled warnings
452-
add_compile_options(-Wno-unused-private-field)
453-
add_compile_options(-Wno-unused-variable)
454-
# Explicit constructor calls are not supported by clang (this->ClassName::ClassName())
455-
add_compile_options(-Wno-microsoft)
456-
# This warning is caused by comparing 'this' to NULL
457-
add_compile_options(-Wno-tautological-compare)
458-
# There are constants of type BOOL used in a condition. But BOOL is defined as int
459-
# and so the compiler thinks that there is a mistake.
460-
add_compile_options(-Wno-constant-logical-operand)
461-
# We use pshpack1/2/4/8.h and poppack.h headers to set and restore packing. However
462-
# clang 6.0 complains when the packing change lifetime is not contained within
463-
# a header file.
464-
add_compile_options(-Wno-pragma-pack)
465-
466-
add_compile_options(-Wno-unknown-warning-option)
467-
468-
#These seem to indicate real issues
469-
add_compile_options(-Wno-invalid-offsetof)
470-
# The following warning indicates that an attribute __attribute__((__ms_struct__)) was applied
471-
# to a struct or a class that has virtual members or a base class. In that case, clang
472-
# may not generate the same object layout as MSVC.
473-
add_compile_options(-Wno-incompatible-ms-struct)
450+
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
451+
add_compile_options(-ferror-limit=4096)
452+
453+
# Disabled warnings
454+
add_compile_options(-Wno-unused-private-field)
455+
add_compile_options(-Wno-unused-variable)
456+
# Explicit constructor calls are not supported by clang (this->ClassName::ClassName())
457+
add_compile_options(-Wno-microsoft)
458+
# This warning is caused by comparing 'this' to NULL
459+
add_compile_options(-Wno-tautological-compare)
460+
# There are constants of type BOOL used in a condition. But BOOL is defined as int
461+
# and so the compiler thinks that there is a mistake.
462+
add_compile_options(-Wno-constant-logical-operand)
463+
# We use pshpack1/2/4/8.h and poppack.h headers to set and restore packing. However
464+
# clang 6.0 complains when the packing change lifetime is not contained within
465+
# a header file.
466+
add_compile_options(-Wno-pragma-pack)
467+
468+
add_compile_options(-Wno-unknown-warning-option)
469+
470+
#These seem to indicate real issues
471+
add_compile_options(-Wno-invalid-offsetof)
472+
# The following warning indicates that an attribute __attribute__((__ms_struct__)) was applied
473+
# to a struct or a class that has virtual members or a base class. In that case, clang
474+
# may not generate the same object layout as MSVC.
475+
add_compile_options(-Wno-incompatible-ms-struct)
476+
else()
477+
add_compile_options(-Wno-unused-variable)
478+
add_compile_options(-Wno-unused-but-set-variable)
479+
endif()
474480

475481
# Some architectures (e.g., ARM) assume char type is unsigned while CoreCLR assumes char is signed
476482
# as x64 does. It has been causing issues in ARM (https://github.com/dotnet/coreclr/issues/4746)

cross/toolchain.cmake

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,19 @@ else()
3131
message(FATAL_ERROR "Arch is ${TARGET_ARCH_NAME}. Only armel, arm, arm64 and x86 are supported!")
3232
endif()
3333

34+
if(DEFINED ENV{TOOLCHAIN})
35+
set(TOOLCHAIN $ENV{TOOLCHAIN})
36+
endif()
37+
38+
# This gets called with CLR_CMAKE_COMPILER set on the first invocation
39+
# but the cmake variable is not getting populated into other calls.
40+
# Use environment variable to keep CLR_CMAKE_COMPILER around.
41+
if (NOT DEFINED CLR_CMAKE_COMPILER)
42+
set(CLR_CMAKE_COMPILER $ENV{CLR_CMAKE_COMPILER})
43+
else()
44+
set(ENV{CLR_CMAKE_COMPILER} ${CLR_CMAKE_COMPILER})
45+
endif()
46+
3447
# Specify include paths
3548
if(TARGET_ARCH_NAME STREQUAL "armel")
3649
if(DEFINED TIZEN_TOOLCHAIN)
@@ -58,8 +71,11 @@ endmacro()
5871

5972
# Specify link flags
6073
add_compile_param(CROSS_LINK_FLAGS "--sysroot=${CROSS_ROOTFS}")
61-
add_compile_param(CROSS_LINK_FLAGS "--gcc-toolchain=${CROSS_ROOTFS}/usr")
62-
add_compile_param(CROSS_LINK_FLAGS "--target=${TOOLCHAIN}")
74+
if (CLR_CMAKE_COMPILER STREQUAL "Clang")
75+
add_compile_param(CROSS_LINK_FLAGS "--gcc-toolchain=${CROSS_ROOTFS}/usr")
76+
add_compile_param(CROSS_LINK_FLAGS "--target=${TOOLCHAIN}")
77+
endif()
78+
6379
add_compile_param(CROSS_LINK_FLAGS "-fuse-ld=gold")
6480

6581
if(TARGET_ARCH_NAME STREQUAL "armel")
@@ -79,8 +95,10 @@ add_compile_param(CMAKE_MODULE_LINKER_FLAGS "${CROSS_LINK_FLAGS}" "TOOLCHAIN_EXE
7995

8096
# Specify compile options
8197
add_compile_options("--sysroot=${CROSS_ROOTFS}")
82-
add_compile_options("--target=${TOOLCHAIN}")
83-
add_compile_options("--gcc-toolchain=${CROSS_ROOTFS}/usr")
98+
if (CLR_CMAKE_COMPILER STREQUAL "Clang")
99+
add_compile_options("--target=${TOOLCHAIN}")
100+
add_compile_options("--gcc-toolchain=${CROSS_ROOTFS}/usr")
101+
endif()
84102

85103
if(TARGET_ARCH_NAME MATCHES "^(arm|armel|arm64)$")
86104
set(CMAKE_C_COMPILER_TARGET ${TOOLCHAIN})

src/pal/inc/mbusafecrt.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@ typedef int errno_t;
3131
// define the return value for success
3232
#define SAFECRT_SUCCESS 0
3333

34-
#if defined(_MSC_VER) || defined(__llvm__)
34+
#ifndef THROW_DECL
35+
#if defined(_MSC_VER) || defined(__llvm__) || !defined(__cplusplus)
3536
#define THROW_DECL
3637
#else
3738
#define THROW_DECL throw()
38-
#endif
39+
#endif // !_MSC_VER
40+
#endif // !THROW_DECL
3941

4042
#ifdef __cplusplus
4143
extern "C" {

src/pal/inc/pal.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,13 @@ typedef void * NATIVE_LIBRARY_HANDLE;
143143
#define LANG_THAI 0x1e
144144

145145
/******************* Compiler-specific glue *******************************/
146-
#if defined(_MSC_VER) || defined(__llvm__)
146+
#ifndef THROW_DECL
147+
#if defined(_MSC_VER) || defined(__llvm__) || !defined(__cplusplus)
147148
#define THROW_DECL
148149
#else
149150
#define THROW_DECL throw()
150-
#endif
151+
#endif // !_MSC_VER
152+
#endif // !THROW_DECL
151153

152154
#ifndef _MSC_VER
153155
#if defined(CORECLR)
@@ -367,7 +369,7 @@ int
367369
PALAPI
368370
PAL_Initialize(
369371
int argc,
370-
const char * const argv[]);
372+
char * const argv[]);
371373

372374
PALIMPORT
373375
void
@@ -4316,7 +4318,7 @@ EXTERN_C
43164318
PALIMPORT
43174319
void *PAL_memcpy (void *dest, const void *src, size_t count);
43184320

4319-
PALIMPORT void * __cdecl memcpy(void *, const void *, size_t);
4321+
PALIMPORT void * __cdecl memcpy(void *, const void *, size_t) THROW_DECL;
43204322

43214323
#define memcpy PAL_memcpy
43224324
#define IS_PAL_memcpy 1

src/pal/inc/unixasmmacros.inc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010
#define LOCAL_LABEL(name) L##name
1111
#else
1212
#define C_FUNC(name) name
13+
#if defined(_AMD64_) || defined(_X86_)
1314
#define EXTERNAL_C_FUNC(name) C_FUNC(name)@plt
15+
#else
16+
#define EXTERNAL_C_FUNC(name) C_FUNC(name)
17+
#endif
1418
#define LOCAL_LABEL(name) .L##name
1519
#endif
1620

src/pal/src/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ if(CMAKE_SYSTEM_NAME STREQUAL Darwin OR CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
55
set(CLR_CMAKE_USE_SYSTEM_LIBUNWIND 1)
66
endif(CMAKE_SYSTEM_NAME STREQUAL Darwin OR CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
77

8-
include_directories(SYSTEM /usr/local/include)
8+
if(NOT DEFINED ENV{ROOTFS_DIR})
9+
include_directories(SYSTEM /usr/local/include)
10+
endif()
911

1012
add_compile_options(-fPIC)
1113

src/pal/src/examples/example1.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ int main(int argc, char *argv[])
3232
HANDLE h;
3333
unsigned int b;
3434

35-
PAL_Initialize(argc, (const char**)argv);
35+
PAL_Initialize(argc, argv);
3636
SetCurrentDirectoryW(dir);
3737
SetCurrentDirectoryW(dir);
3838
h = CreateFileW(src, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_NEW, 0, NULL);

src/pal/src/exception/remote-unwind.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,14 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
5151
// Sub-headers included from the libunwind.h contain an empty struct
5252
// and clang issues a warning. Until the libunwind is fixed, disable
5353
// the warning.
54+
#ifdef __llvm__
5455
#pragma clang diagnostic push
5556
#pragma clang diagnostic ignored "-Wextern-c-compat"
57+
#endif
5658
#include <libunwind.h>
59+
#ifdef __llvm__
5760
#pragma clang diagnostic pop
61+
#endif
5862

5963
SET_DEFAULT_DEBUG_CHANNEL(EXCEPT);
6064

src/pal/src/exception/seh-unwind.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,14 @@ Module Name:
3131
// Sub-headers included from the libunwind.h contain an empty struct
3232
// and clang issues a warning. Until the libunwind is fixed, disable
3333
// the warning.
34+
#ifdef __llvm__
3435
#pragma clang diagnostic push
3536
#pragma clang diagnostic ignored "-Wextern-c-compat"
37+
#endif
3638
#include <libunwind.h>
39+
#ifdef __llvm__
3740
#pragma clang diagnostic pop
41+
#endif
3842

3943
//----------------------------------------------------------------------
4044
// Virtual Unwinding

src/pal/src/init/pal.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ int
153153
PALAPI
154154
PAL_Initialize(
155155
int argc,
156-
const char *const argv[])
156+
char *const argv[])
157157
{
158158
return Initialize(argc, argv, PAL_INITIALIZE);
159159
}

src/pal/src/libunwind/src/CMakeLists.txt

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)
77

88
include(configure.cmake)
99

10+
if (NOT CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
11+
add_compile_options(-Wformat=0)
12+
add_compile_options(-Wno-unused-value)
13+
endif()
14+
1015
# The HAVE___THREAD set to 1 causes creation of thread local variable with tls_model("initial-exec")
1116
# which is incompatible with usage of the unwind code in a shared library.
1217
add_definitions(-DHAVE___THREAD=0)
@@ -19,15 +24,19 @@ add_definitions(-D_GNU_SOURCE)
1924
# Ensure that the remote and local unwind code can reside in the same binary without name clashing
2025
add_definitions("-Ddwarf_search_unwind_table_int=UNW_OBJ(dwarf_search_unwind_table_int)")
2126

22-
add_compile_options(-Wno-header-guard)
27+
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
28+
add_compile_options(-Wno-header-guard)
29+
endif()
2330

2431
if(CLR_CMAKE_PLATFORM_ARCH_ARM)
2532
# Ensure that the remote and local unwind code can reside in the same binary without name clashing
2633
add_definitions("-Darm_search_unwind_table=UNW_OBJ(arm_search_unwind_table)")
2734
# Disable warning in asm: use of SP or PC in the list is deprecated
2835
add_compile_options(-Wno-inline-asm)
29-
# Disable warning due to labs function called on unsigned argument
30-
add_compile_options(-Wno-absolute-value)
36+
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
37+
# Disable warning due to labs function called on unsigned argument
38+
add_compile_options(-Wno-absolute-value)
39+
endif()
3140
# Disable warning due to incorrect format specifier in debugging printf via the Debug macro
3241
add_compile_options(-Wno-format)
3342
# 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)
4150
# the include/tdep-arm to include directories
4251
include_directories(../include/tdep-arm)
4352
elseif(CLR_CMAKE_PLATFORM_ARCH_ARM64)
44-
# Disable warning due to labs function called on unsigned argument
45-
add_compile_options(-Wno-absolute-value)
53+
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
54+
# Disable warning due to labs function called on unsigned argument
55+
add_compile_options(-Wno-absolute-value)
56+
endif()
4657
# We compile code with -std=c99 and the asm keyword is not recognized as it is a gnu extension
4758
add_definitions(-Dasm=__asm__)
4859
elseif(CLR_CMAKE_PLATFORM_ARCH_I386)

src/pal/tests/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ endif()
3232

3333
# C++ emits errors and warnings for c-string literal fed into char* parameter
3434
# this is just to take care of the warnings
35-
add_compile_options(-Wno-writable-strings)
35+
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
36+
add_compile_options(-Wno-writable-strings)
37+
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
38+
add_compile_options(-Wno-write-strings)
39+
endif()
3640

3741
add_compile_options(-Wno-empty-body)
3842

0 commit comments

Comments
 (0)