Skip to content

Commit 5c4e2a3

Browse files
authored
Remove remaining CRT PAL wrappers and enable including standard headers in the CoreCLR build (#98336)
- Remove malloc-family PAL and update callsites that might get passed 0 to bump up to 1. - Move `getenv` usage to use the `PAL` function directly when on non-Windows (to preserve the existing behavior). - Remove other remaining CRT PAL shims - Remove header shims and enable building with the CRT and STL headers across the product, with various build fixes required (mostly around using the standard min/max definitions)
1 parent 01f039c commit 5c4e2a3

File tree

240 files changed

+559
-5127
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

240 files changed

+559
-5127
lines changed

eng/native/configurecompiler.cmake

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ if (CLR_CMAKE_HOST_UNIX)
2828
add_compile_options(-Wno-null-conversion)
2929
add_compile_options(-glldb)
3030
else()
31-
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-Werror=conversion-null>)
3231
add_compile_options(-g)
3332
endif()
3433
endif()

eng/native/functions.cmake

+6
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,12 @@ endfunction(convert_to_absolute_path)
220220
function(preprocess_file inputFilename outputFilename)
221221
get_compile_definitions(PREPROCESS_DEFINITIONS)
222222
get_include_directories(PREPROCESS_INCLUDE_DIRECTORIES)
223+
get_source_file_property(SOURCE_FILE_DEFINITIONS ${inputFilename} COMPILE_DEFINITIONS)
224+
225+
foreach(DEFINITION IN LISTS SOURCE_FILE_DEFINITIONS)
226+
list(APPEND PREPROCESS_DEFINITIONS -D${DEFINITION})
227+
endforeach()
228+
223229
if (MSVC)
224230
add_custom_command(
225231
OUTPUT ${outputFilename}

src/coreclr/CMakeLists.txt

+7-6
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,12 @@ if(CLR_CMAKE_HOST_UNIX)
202202
add_subdirectory(debug/createdump)
203203
endif(CLR_CMAKE_HOST_OSX OR (CLR_CMAKE_HOST_LINUX AND NOT CLR_CMAKE_HOST_UNIX_X86 AND NOT CLR_CMAKE_HOST_ANDROID))
204204

205-
# Include the dummy c++ include files
206-
include_directories("pal/inc/rt/cpp")
207-
208-
# This prevents inclusion of standard C compiler headers
209-
add_compile_options(-nostdinc)
205+
# The CoreCLR PAL used to redefine NULL, which caused a number of null conversion and arithmetic
206+
# warnings and errors to be suppressed.
207+
# Suppress these warnings here to avoid breaking the build.
208+
add_compile_options($<$<COMPILE_LANG_AND_ID:CXX,Clang,AppleClang>:-Wno-null-arithmetic>)
209+
add_compile_options($<$<COMPILE_LANG_AND_ID:CXX,GNU>:-Wno-conversion-null>)
210+
add_compile_options($<$<COMPILE_LANG_AND_ID:CXX,GNU>:-Wno-pointer-arith>)
210211

211212
set (NATIVE_RESOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/nativeresources)
212213
include_directories(${NATIVE_RESOURCE_DIR})
@@ -218,7 +219,7 @@ if(CLR_CMAKE_HOST_UNIX)
218219
# given Windows .rc file. The target C++ file path is returned in the
219220
# variable specified by the TARGET_FILE parameter.
220221
function(build_resources SOURCE TARGET_NAME TARGET_FILE)
221-
222+
set_property(SOURCE ${SOURCE} APPEND PROPERTY COMPILE_DEFINITIONS "RC_INVOKED")
222223
set(PREPROCESSED_SOURCE ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_NAME}.rc.i)
223224

224225
preprocess_file(${SOURCE} ${PREPROCESSED_SOURCE})

src/coreclr/binder/assemblyname.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
//
1212
// ============================================================
1313

14+
#include "common.h"
1415
#include "assemblyname.hpp"
1516
#include "assemblybindercommon.hpp"
1617

17-
#include "common.h"
1818
#include "utils.hpp"
1919

2020
#include "textualidentityparser.hpp"

src/coreclr/clrdefinitions.cmake

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ if(CLR_CMAKE_HOST_WIN32)
5353
add_definitions(-D_WIN32_WINNT=0x0602)
5454
add_definitions(-DWIN32_LEAN_AND_MEAN)
5555
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
56+
add_compile_definitions(NOMINMAX)
5657
endif(CLR_CMAKE_HOST_WIN32)
5758

5859
if (NOT (CLR_CMAKE_TARGET_ARCH_I386 AND CLR_CMAKE_TARGET_UNIX))

src/coreclr/debug/createdump/CMakeLists.txt

-2
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ else(CLR_CMAKE_HOST_WIN32)
5656
endif(CLR_CMAKE_HOST_OSX)
5757
endif (CORECLR_SET_RPATH)
5858

59-
add_definitions(-DPAL_STDCPP_COMPAT)
60-
6159
# This is so we can include "version.c"
6260
include_directories(${CMAKE_BINARY_DIR})
6361

src/coreclr/debug/daccess/daccess.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -5793,7 +5793,7 @@ ClrDataAccess::RawGetMethodName(
57935793
SIZE_T maxPrecodeSize = sizeof(StubPrecode);
57945794

57955795
#ifdef HAS_THISPTR_RETBUF_PRECODE
5796-
maxPrecodeSize = max(maxPrecodeSize, sizeof(ThisPtrRetBufPrecode));
5796+
maxPrecodeSize = max((size_t)maxPrecodeSize, sizeof(ThisPtrRetBufPrecode));
57975797
#endif
57985798

57995799
for (SIZE_T i = 0; i < maxPrecodeSize / PRECODE_ALIGNMENT; i++)

src/coreclr/debug/dbgutil/CMakeLists.txt

-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ if(CLR_CMAKE_HOST_WIN32 OR CLR_CMAKE_HOST_OSX)
99
include_directories(${CLR_DIR}/inc/llvm)
1010
endif(CLR_CMAKE_HOST_WIN32 OR CLR_CMAKE_HOST_OSX)
1111

12-
add_definitions(-DPAL_STDCPP_COMPAT)
13-
1412
if(CLR_CMAKE_TARGET_LINUX_MUSL)
1513
add_definitions(-DTARGET_LINUX_MUSL)
1614
endif(CLR_CMAKE_TARGET_LINUX_MUSL)

src/coreclr/debug/debug-pal/CMakeLists.txt

-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ include_directories(../inc)
22
include_directories(../../pal/inc)
33
include_directories(${EP_GENERATED_HEADER_PATH})
44

5-
add_definitions(-DPAL_STDCPP_COMPAT)
6-
75
set(SHARED_EVENTPIPE_SOURCE_PATH ${CLR_SRC_NATIVE_DIR}/eventpipe)
86
add_definitions(-DFEATURE_CORECLR)
97
add_definitions(-DFEATURE_PERFTRACING)

src/coreclr/debug/di/rspriv.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -3975,9 +3975,9 @@ class CordbProcess :
39753975

39763976
// CORDB_ADDRESS's are UINT_PTR's (64 bit under HOST_64BIT, 32 bit otherwise)
39773977
#if defined(TARGET_64BIT)
3978-
#define MAX_ADDRESS (_UI64_MAX)
3978+
#define MAX_ADDRESS (UINT64_MAX)
39793979
#else
3980-
#define MAX_ADDRESS (_UI32_MAX)
3980+
#define MAX_ADDRESS (UINT32_MAX)
39813981
#endif
39823982
#define MIN_ADDRESS (0x0)
39833983
CORDB_ADDRESS m_minPatchAddr; //smallest patch in table

src/coreclr/debug/di/rsthread.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -5122,7 +5122,7 @@ HRESULT CordbValueEnum::Next(ULONG celt, ICorDebugValue *values[], ULONG *pceltF
51225122

51235123
HRESULT hr = S_OK;
51245124

5125-
int iMax = min( m_iMax, m_iCurrent+celt);
5125+
int iMax = (int)min( (ULONG)m_iMax, m_iCurrent+celt);
51265126
int i;
51275127
for (i = m_iCurrent; i< iMax;i++)
51285128
{
@@ -8186,7 +8186,7 @@ HRESULT CordbJITILFrame::FabricateNativeInfo(DWORD dwIndex,
81868186
// first argument, but thereafter we have to decrement it
81878187
// before getting the variable's location from it. So increment
81888188
// it here to be consistent later.
8189-
rpCur += max(cbType, cbArchitectureMin);
8189+
rpCur += max((ULONG)cbType, cbArchitectureMin);
81908190
#endif
81918191

81928192
// Grab the IL code's function's method signature so we can see if it's static.
@@ -8219,7 +8219,7 @@ HRESULT CordbJITILFrame::FabricateNativeInfo(DWORD dwIndex,
82198219
IfFailThrow(pArgType->GetUnboxedObjectSize(&cbType));
82208220

82218221
#if defined(TARGET_X86) // STACK_GROWS_DOWN_ON_ARGS_WALK
8222-
rpCur -= max(cbType, cbArchitectureMin);
8222+
rpCur -= max((ULONG)cbType, cbArchitectureMin);
82238223
m_rgNVI[i].loc.vlFixedVarArg.vlfvOffset =
82248224
(unsigned)(m_FirstArgAddr - rpCur);
82258225

@@ -8229,7 +8229,7 @@ HRESULT CordbJITILFrame::FabricateNativeInfo(DWORD dwIndex,
82298229
#else // STACK_GROWS_UP_ON_ARGS_WALK
82308230
m_rgNVI[i].loc.vlFixedVarArg.vlfvOffset =
82318231
(unsigned)(rpCur - m_FirstArgAddr);
8232-
rpCur += max(cbType, cbArchitectureMin);
8232+
rpCur += max((ULONG)cbType, cbArchitectureMin);
82338233
AlignAddressForType(pArgType, rpCur);
82348234
#endif
82358235

@@ -10877,7 +10877,7 @@ HRESULT CordbCodeEnum::Next(ULONG celt, ICorDebugCode *values[], ULONG *pceltFet
1087710877

1087810878
HRESULT hr = S_OK;
1087910879

10880-
int iMax = min( m_iMax, m_iCurrent+celt);
10880+
int iMax = (int)min( (ULONG)m_iMax, m_iCurrent+celt);
1088110881
int i;
1088210882

1088310883
for (i = m_iCurrent; i < iMax; i++)

src/coreclr/debug/di/rstype.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2898,7 +2898,7 @@ HRESULT CordbTypeEnum::Next(ULONG celt, ICorDebugType *values[], ULONG *pceltFet
28982898

28992899
HRESULT hr = S_OK;
29002900

2901-
int iMax = min( m_iMax, m_iCurrent+celt);
2901+
int iMax = (int)min( (ULONG)m_iMax, m_iCurrent+celt);
29022902
int i;
29032903

29042904
for (i = m_iCurrent; i < iMax; i++)

src/coreclr/debug/di/shimcallback.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1408,7 +1408,7 @@ HRESULT ShimProxyCallback::DataBreakpoint(ICorDebugProcess* pProcess, ICorDebugT
14081408
this->m_pThread.Assign(pThread);
14091409

14101410
_ASSERTE(contextSize == sizeof(CONTEXT));
1411-
this->m_contextSize = min(contextSize, sizeof(CONTEXT));
1411+
this->m_contextSize = min(contextSize, (ULONG32)sizeof(CONTEXT));
14121412
memcpy(&(this->m_context), pContext, this->m_contextSize);
14131413
}
14141414

src/coreclr/debug/di/stdafx.h

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
#include <stdio.h>
1111
#include <windows.h>
1212
#include <winnt.h>
13+
#include <algorithm>
14+
using std::min;
15+
using std::max;
1316

1417
#include <dbgtargetcontext.h>
1518

src/coreclr/debug/ee/debugger.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -3029,7 +3029,7 @@ HRESULT Debugger::GetILToNativeMappingIntoArrays(
30293029
if (pDJI == NULL)
30303030
return E_FAIL;
30313031

3032-
ULONG32 cMap = min(cMapMax, pDJI->GetSequenceMapCount());
3032+
ULONG32 cMap = min((ULONG32)cMapMax, pDJI->GetSequenceMapCount());
30333033
DebuggerILToNativeMap * rgMapInt = pDJI->GetSequenceMap();
30343034

30353035
NewArrayHolder<UINT> rguiILOffsetTemp = new (nothrow) UINT[cMap];

src/coreclr/debug/ee/funceval.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2806,7 +2806,7 @@ void PackArgumentArray(DebuggerEval *pDE,
28062806

28072807
#ifdef FEATURE_HFA
28082808
// The buffer for HFAs has to be always ENREGISTERED_RETURNTYPE_MAXSIZE
2809-
size = max(size, ENREGISTERED_RETURNTYPE_MAXSIZE);
2809+
size = max(size, (unsigned)ENREGISTERED_RETURNTYPE_MAXSIZE);
28102810
#endif
28112811

28122812
BYTE * pTemp = new (interopsafe) BYTE[ALIGN_UP(sizeof(ValueClassInfo), 8) + size];

src/coreclr/debug/ee/stdafx.h

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#include <stdint.h>
1313
#include <wchar.h>
1414
#include <stdio.h>
15+
#include <algorithm>
16+
#include <cmath>
1517

1618
#include <windows.h>
1719

src/coreclr/debug/inc/dbgipcevents.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@ class MSLAYOUT VMPTR_Base
768768
//
769769
// Operators to emulate Pointer semantics.
770770
//
771-
bool IsNull() { SUPPORTS_DAC; return m_addr == NULL; }
771+
bool IsNull() { SUPPORTS_DAC; return m_addr == (TADDR)0; }
772772

773773
static VMPTR_This NullPtr()
774774
{

src/coreclr/debug/shared/dbgtransportsession.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1949,7 +1949,7 @@ void DbgTransportSession::TransportWorker()
19491949
DWORD cbBytesToRead = sReceiveHeader.TypeSpecificData.MemoryAccess.m_cbLeftSideBuffer;
19501950
while (cbBytesToRead)
19511951
{
1952-
DWORD cbTransfer = min(cbBytesToRead, sizeof(rgDummy));
1952+
DWORD cbTransfer = min(cbBytesToRead, (DWORD)sizeof(rgDummy));
19531953
if (!ReceiveBlock(rgDummy, cbTransfer))
19541954
HANDLE_TRANSIENT_ERROR();
19551955
cbBytesToRead -= cbTransfer;

src/coreclr/dlls/mscordac/mscordac_unixexports.src

-8
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,10 @@ nativeStringResourceTable_mscorrc
2222
; All the # exports are prefixed with DAC_
2323
#PAL_CatchHardwareExceptionHolderEnter
2424
#PAL_CatchHardwareExceptionHolderExit
25-
#PAL_bsearch
2625
#PAL_CopyModuleData
27-
#PAL_errno
28-
#PAL_free
2926
#PAL_GetLogicalCpuCountFromOS
3027
#PAL_GetTotalCpuCount
3128
#PAL_GetUnwindInfoSize
32-
#PAL_stdout
33-
#PAL_stderr
3429
#PAL_GetApplicationGroupId
3530
#PAL_GetTransportName
3631
#PAL_GetCurrentThread
@@ -47,9 +42,6 @@ nativeStringResourceTable_mscorrc
4742
#PAL_ReadProcessMemory
4843
#PAL_ProbeMemory
4944
#PAL_Random
50-
#PAL_malloc
51-
#PAL_realloc
52-
#PAL_qsort
5345
#PAL__wcstoui64
5446
#PAL_wcstoul
5547
#PAL_wcstod

src/coreclr/dlls/mscorpe/stdafx.h

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <assert.h>
1212
#include <stdio.h>
1313
#include <stddef.h>
14+
#include <algorithm>
1415

1516
#define FEATURE_NO_HOST // Do not use host interface
1617
#include <utilcode.h>
@@ -21,3 +22,6 @@
2122
#include "ceegen.h"
2223
#include "ceefilegenwriter.h"
2324
#include "ceesectionstring.h"
25+
26+
using std::min;
27+
using std::max;

src/coreclr/gc/env/common.h

+3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
#include <math.h>
2626

2727
#include <new>
28+
#include <type_traits>
29+
#include <limits>
30+
#include <algorithm>
2831

2932
#ifdef TARGET_UNIX
3033
#include <pthread.h>

src/coreclr/gc/env/gcenv.base.h

-9
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,6 @@ inline HRESULT HRESULT_FROM_WIN32(unsigned long x)
100100

101101
#define ZeroMemory(Destination,Length) memset((Destination),0,(Length))
102102

103-
#ifndef min
104-
#define min(a,b) (((a) < (b)) ? (a) : (b))
105-
#endif
106-
107-
#ifndef max
108-
#define max(a,b) (((a) > (b)) ? (a) : (b))
109-
#endif
110-
111103
#define C_ASSERT(cond) static_assert( cond, #cond )
112104

113105
#define UNREFERENCED_PARAMETER(P) (void)(P)
@@ -393,7 +385,6 @@ typedef struct _PROCESSOR_NUMBER {
393385
uint8_t Number;
394386
uint8_t Reserved;
395387
} PROCESSOR_NUMBER, *PPROCESSOR_NUMBER;
396-
397388
#endif // _INC_WINDOWS
398389

399390
// -----------------------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)