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

Fix strict aliasing violation from conditional typedef of wchar_t by building entire project as C++ for Unix #6801

Merged
merged 14 commits into from
Sep 7, 2016
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
11 changes: 5 additions & 6 deletions src/ilasm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,23 @@ set(ILASM_SOURCES
asmman.cpp
main.cpp
assembler.cpp
prebuilt/asmparse.c
prebuilt/asmparse.cpp
)
if(WIN32)
set(ILASM_RESOURCES Native.rc)
add_definitions(-DFX_VER_INTERNALNAME_STR=ilasm.exe)
endif(WIN32)

set_source_files_properties( prebuilt/asmparse.c PROPERTIES LANGUAGE CXX )

if(CLR_CMAKE_PLATFORM_UNIX)
add_compile_options(-x c++)
# Need generate a right form of asmparse.c to avoid the following options.
# Need generate a right form of asmparse.cpp to avoid the following options.
# Clang also produces a bad-codegen on this prebuilt file with optimization.
# https://github.com/dotnet/coreclr/issues/2305
add_compile_options(-Wno-delete-non-virtual-dtor)
add_compile_options(-Wno-deprecated-register)
add_compile_options(-Wno-array-bounds)
add_compile_options(-Wno-unused-label)
set_source_files_properties( prebuilt/asmparse.c PROPERTIES COMPILE_FLAGS -O0 )
set_source_files_properties( prebuilt/asmparse.cpp PROPERTIES COMPILE_FLAGS "-O0" )
endif(CLR_CMAKE_PLATFORM_UNIX)

_add_executable(ilasm
Expand Down Expand Up @@ -82,4 +80,5 @@ else()
)
endif(CLR_CMAKE_PLATFORM_UNIX)

install_clr(ilasm)
install_clr(ilasm)

9 changes: 4 additions & 5 deletions src/inc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,22 @@ add_compile_options(/TC)

else()

#The MIDL tool exists for Windows only, so for other systems, we have the prebuilt xxx_i.c files checked in
#The MIDL tool exists for Windows only, so for other systems, we have the prebuilt xxx_i.cpp files checked in

# The prebuilt files contain extra '!_MIDL_USE_GUIDDEF_' after the #endif, but not in the comment.
# In order to not to have to modify these prebuilt files, we disable the extra tokens warning.
add_compile_options(-Wno-extra-tokens)

add_compile_options(-D_MIDL_USE_GUIDDEF_)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this define needed?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was undefind reference error when linking executable crossgen:

Linking CXX executable crossgen
/home/kchoi/coreclr/src/pal/inc/rt/palrt.h:326: error: undefined reference to 'IID_ICorSvcLogger'
/home/kchoi/coreclr/src/vm/ceeload.cpp:4636: error: undefined reference to 'IID_ISymUnmanagedWriter3'

        // manipulate the writer.
        SafeComHolderPreemp<ISymUnmanagedWriter3> pWriter3;
      > HRESULT thr = pWriter->QueryInterface(IID_ISymUnmanagedWriter3, (void**)&pWriter3);
        CONSISTENCY_CHECK(SUCCEEDED(thr));
        if (SUCCEEDED(thr))

foreach(IDL_SOURCE IN LISTS CORGUIDS_IDL_SOURCES)
get_filename_component(IDLNAME ${IDL_SOURCE} NAME_WE)
set(C_SOURCE ../pal/prebuilt/idl/${IDLNAME}_i.c)
set(C_SOURCE ../pal/prebuilt/idl/${IDLNAME}_i.cpp)
list(APPEND CORGUIDS_SOURCES ${C_SOURCE})
endforeach(IDL_SOURCE)

add_compile_options(-fPIC)

endif(WIN32)

# Compile *_i.c to lib
# Compile *_i.cpp to lib
_add_library(corguids ${CORGUIDS_SOURCES})

# Binplace the inc files for packaging later.
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/pal/inc/mbusafecrt.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ extern WCHAR* wcstok_s( WCHAR* inString, const WCHAR* inControl, WCHAR** ioConte

// strnlen is not required unless the source string is completely untrusted (e.g. anonymous input on a website)
#ifndef SUPPRESS_STRNLEN
extern size_t strnlen( const char* inString, size_t inMaxSize );
extern size_t PAL_strnlen( const char* inString, size_t inMaxSize );
extern size_t wcsnlen( const WCHAR* inString, size_t inMaxSize );
#endif

Expand Down
1 change: 1 addition & 0 deletions src/pal/inc/pal.h
Original file line number Diff line number Diff line change
Expand Up @@ -5802,6 +5802,7 @@ CoCreateGuid(OUT GUID * pguid);
#define _wcstoui64 PAL__wcstoui64
#define _flushall PAL__flushall
#define _vsnprintf PAL__vsnprintf
#define strnlen PAL_strnlen

#ifdef _AMD64_
#define _mm_getcsr PAL__mm_getcsr
Expand Down
3 changes: 2 additions & 1 deletion src/pal/inc/pal_char16.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ This file is used to define the wchar_t type as a 16-bit type on Unix.
// Set up the wchar_t type (which got preprocessed to __wchar_16_cpp__).
// In C++11, the standard gives us char16_t, which is what we want (and matches types with u"")
// In C, this doesn't exist, so use unsigned short.

// **** WARNING: Linking C and C++ objects will break with -fstrict-aliasing with GCC/Clang
// due to conditional typedef
#if !defined(_WCHAR_T_DEFINED) || !defined(_MSC_VER)
#if defined (PLATFORM_UNIX)
#if defined(__cplusplus)
Expand Down
5 changes: 5 additions & 0 deletions src/pal/inc/pal_mstypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,9 @@ extern "C" {
// Defined in gnu's types.h. For non PAL_IMPLEMENTATION system
// includes are not included, so we need to define them.
#ifndef PAL_IMPLEMENTATION

// OS X already defines these types in 64 bit
#if !defined(_TARGET_MAC64)
typedef __int64 int64_t;
typedef unsigned __int64 uint64_t;
typedef __int32 int32_t;
Expand All @@ -223,6 +226,8 @@ typedef __int16 int16_t;
typedef unsigned __int16 uint16_t;
typedef __int8 int8_t;
typedef unsigned __int8 uint8_t;
#endif

#endif // PAL_IMPLEMENTATION

#ifndef _MSC_VER
Expand Down
4 changes: 4 additions & 0 deletions src/pal/inc/rt/palrt.h
Original file line number Diff line number Diff line change
Expand Up @@ -1076,6 +1076,7 @@ _SAFECRT__EXTERN_C
errno_t __cdecl _itow_s(int _Value, WCHAR *_Dst, size_t _SizeInWords, int _Radix);

#if defined(__cplusplus) && _SAFECRT_USE_CPP_OVERLOADS
extern "C++"
template <size_t _SizeInWords>
inline
errno_t __cdecl _itow_s(int _Value, WCHAR (&_Dst)[_SizeInWords], int _Radix)
Expand Down Expand Up @@ -1104,6 +1105,7 @@ _SAFECRT__EXTERN_C
errno_t __cdecl _i64tow_s(__int64 _Value, WCHAR *_Dst, size_t _SizeInWords, int _Radix);

#if defined(__cplusplus) && _SAFECRT_USE_CPP_OVERLOADS
extern "C++"
template <size_t _SizeInWords>
inline
errno_t __cdecl _i64tow_s(__int64 _Value, WCHAR (&_Dst)[_SizeInWords], int _Radix)
Expand Down Expand Up @@ -1135,6 +1137,7 @@ _SAFECRT__EXTERN_C
errno_t __cdecl getenv_s(size_t *_ReturnValue, char *_Dst, size_t _SizeInWords, const char *_Name);

#if defined(__cplusplus) && _SAFECRT_USE_CPP_OVERLOADS
extern "C++"
template <size_t _SizeInWords>
inline
errno_t __cdecl getenv_s(size_t *_ReturnValue, char *_Dst, size_t _SizeInWords, const char *_Name)
Expand Down Expand Up @@ -1247,6 +1250,7 @@ namespace std
typedef decltype(nullptr) nullptr_t;
}

extern "C++"
template< class T >
typename std::remove_reference<T>::type&& move( T&& t );
#endif // __cplusplus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@

#pragma warning( disable: 4049 ) /* more than 64k source lines */

#include <rpc.h>
#include <rpcndr.h>

#ifdef __cplusplus
extern "C"{
#endif


#include <rpc.h>
#include <rpcndr.h>

#ifdef _MIDL_USE_GUIDDEF_

#ifndef INITGUID
Expand Down
62 changes: 31 additions & 31 deletions src/pal/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -160,37 +160,37 @@ set(SOURCES
objmgr/palobjbase.cpp
objmgr/shmobject.cpp
objmgr/shmobjectmanager.cpp
safecrt/makepath_s.c
safecrt/memcpy_s.c
safecrt/memmove_s.c
safecrt/mbusafecrt.c
safecrt/safecrt_input_s.c
safecrt/safecrt_output_l.c
safecrt/safecrt_output_s.c
safecrt/safecrt_winput_s.c
safecrt/safecrt_woutput_s.c
safecrt/splitpath_s.c
safecrt/sprintf.c
safecrt/sscanf.c
safecrt/strcat_s.c
safecrt/strcpy_s.c
safecrt/strlen_s.c
safecrt/strncat_s.c
safecrt/strncpy_s.c
safecrt/strtok_s.c
safecrt/swprintf.c
safecrt/vsprintf.c
safecrt/vswprint.c
safecrt/wcscat_s.c
safecrt/wcscpy_s.c
safecrt/wcslen_s.c
safecrt/wcsncat_s.c
safecrt/wcsncpy_s.c
safecrt/wcstok_s.c
safecrt/wmakepath_s.c
safecrt/wsplitpath_s.c
safecrt/xtoa_s.c
safecrt/xtow_s.c
safecrt/makepath_s.cpp
safecrt/memcpy_s.cpp
safecrt/memmove_s.cpp
safecrt/mbusafecrt.cpp
safecrt/safecrt_input_s.cpp
safecrt/safecrt_output_l.cpp
safecrt/safecrt_output_s.cpp
safecrt/safecrt_winput_s.cpp
safecrt/safecrt_woutput_s.cpp
safecrt/splitpath_s.cpp
safecrt/sprintf.cpp
safecrt/sscanf.cpp
safecrt/strcat_s.cpp
safecrt/strcpy_s.cpp
safecrt/strlen_s.cpp
safecrt/strncat_s.cpp
safecrt/strncpy_s.cpp
safecrt/strtok_s.cpp
safecrt/swprintf.cpp
safecrt/vsprintf.cpp
safecrt/vswprint.cpp
safecrt/wcscat_s.cpp
safecrt/wcscpy_s.cpp
safecrt/wcslen_s.cpp
safecrt/wcsncat_s.cpp
safecrt/wcsncpy_s.cpp
safecrt/wcstok_s.cpp
safecrt/wmakepath_s.cpp
safecrt/wsplitpath_s.cpp
safecrt/xtoa_s.cpp
safecrt/xtow_s.cpp
sharedmemory/sharedmemory.cpp
shmemory/shmemory.cpp
sync/cs.cpp
Expand Down
2 changes: 1 addition & 1 deletion src/pal/src/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ project(palexmpl)
set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(SOURCES
example1.c
example1.cpp
)

add_executable(palexmpl
Expand Down
1 change: 0 additions & 1 deletion src/pal/src/include/pal/palinternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ function_name() to call the system's implementation
#define memmove DUMMY_memmove
#define memchr DUMMY_memchr
#define strlen DUMMY_strlen
#define strnlen DUMMY_strnlen
#define stricmp DUMMY_stricmp
#define strstr DUMMY_strstr
#define strcmp DUMMY_strcmp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include "mbusafecrt_internal.h"

typedef int (*INPUTFN)(miniFILE *, const unsigned char*, va_list);
typedef int (*WINPUTFN)(miniFILE *, const unsigned short*, va_list);
typedef int (*WINPUTFN)(miniFILE *, const wchar_t*, va_list);


/***
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
*
*******************************************************************************/

size_t __cdecl strnlen(const char *str, size_t maxsize)
size_t __cdecl PAL_strnlen(const char *str, size_t maxsize)
{
size_t n;

Expand Down
5 changes: 5 additions & 0 deletions src/pal/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ else()
message(FATAL_ERROR "Only ARM, ARM64 and AMD64 is supported")
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have this issue at many places? I would prefer fixing the code if it happens at only a few spots.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There were too many testcases that feed char literal to char* parameter.


add_compile_options(-Wno-empty-body)

add_subdirectory(palsuite)


Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2)
set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(SOURCES
__iscsym.c
__iscsym.cpp
)

add_executable(paltest_iscsym_test1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2)
set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(SOURCES
test1.c
test1.cpp
)

add_executable(paltest_alloca_test1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2)
set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(SOURCES
test1.c
test1.cpp
)

add_executable(paltest_ecvt_test1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2)
set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(SOURCES
test1.c
test1.cpp
)

add_executable(paltest_fdopen_test1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2)
set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(SOURCES
test1.c
test1.cpp
)

add_executable(paltest_finite_test1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2)
set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(SOURCES
test1.c
test1.cpp
)

add_executable(paltest_fullpath_test1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2)
set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(SOURCES
_gcvt.c
_gcvt.cpp
)

add_executable(paltest_gcvt_test1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2)
set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(SOURCES
test2.c
test2.cpp
)

add_executable(paltest_gcvt_test2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2)
set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(SOURCES
test1.c
test1.cpp
)

add_executable(paltest_getw_test1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2)
set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(SOURCES
test1.c
test1.cpp
)

add_executable(paltest_isnan_test1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2)
set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(SOURCES
test1.c
test1.cpp
)

add_executable(paltest_itow_test1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2)
set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(SOURCES
test1.c
test1.cpp
)

add_executable(paltest_makepath_test1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2)
set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(SOURCES
test1.c
test1.cpp
)

add_executable(paltest_mbsdec_test1
Expand Down
Loading