Skip to content

Commit 16495db

Browse files
committed
statically linking GC PAL on linux (dotnet#76985)
* statically linking GC PAL The GC PAL will be used for both coreclr and standalone GC on linux * fixing arm64 and nativeaot build breaks * macos build break and reducing renaming. * trying to remove numa support from PAL * one more rename to resolve MacOS break * delete pal numa code. * Adding missing madvise in GC PAL * added missing MADV_DONTDUMP calls. * CR feedback * undo (long long) cast in GetMemoryStatus * only invoke madvise on success.
1 parent 8183541 commit 16495db

15 files changed

Lines changed: 56 additions & 354 deletions

File tree

src/coreclr/dlls/mscordac/mscordac_unixexports.src

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ nativeStringResourceTable_mscorrc
3131
#PAL_fwprintf
3232
#PAL_GetLogicalCpuCountFromOS
3333
#PAL_GetTotalCpuCount
34-
#PAL_GetNumaProcessorNode
3534
#PAL_GetUnwindInfoSize
3635
#PAL_get_stdout
3736
#PAL_get_stderr
@@ -126,7 +125,6 @@ nativeStringResourceTable_mscorrc
126125
#GetFullPathNameW
127126
#GetLastError
128127
#GetModuleFileNameW
129-
#GetNumaHighestNodeNumber
130128
#GetProcAddress
131129
#GetStdHandle
132130
#GetSystemInfo
@@ -168,7 +166,6 @@ nativeStringResourceTable_mscorrc
168166
#SwitchToThread
169167
#TerminateProcess
170168
#VirtualAlloc
171-
#VirtualAllocExNuma
172169
#VirtualFree
173170
#VirtualProtect
174171
#VirtualQuery

src/coreclr/dlls/mscoree/coreclr/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ set_property(TARGET coreclr APPEND_STRING PROPERTY LINK_DEPENDS ${EXPORTS_FILE})
8282

8383
if (CLR_CMAKE_HOST_UNIX)
8484
set(LIB_UNWINDER unwinder_wks)
85+
set(GC_PAL gc_unix)
8586
endif (CLR_CMAKE_HOST_UNIX)
8687

8788
# IMPORTANT! Please do not rearrange the order of the libraries. The linker on Linux is
@@ -108,6 +109,7 @@ set(CORECLR_LIBRARIES
108109
System.Globalization.Native-Static
109110
interop
110111
coreclrminipal
112+
${GC_PAL}
111113
)
112114

113115
if(CLR_CMAKE_TARGET_WIN32)

src/coreclr/gc/CMakeLists.txt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,10 @@ set(GC_SOURCES
2727
handletablecache.cpp)
2828

2929
if(CLR_CMAKE_HOST_UNIX)
30+
add_subdirectory(unix)
3031
include(unix/configure.cmake)
3132
set (GC_SOURCES
32-
${GC_SOURCES}
33-
unix/gcenv.unix.cpp
34-
unix/events.cpp
35-
unix/cgroup.cpp)
33+
${GC_SOURCES})
3634
else()
3735
set (GC_SOURCES
3836
${GC_SOURCES}
@@ -101,7 +99,7 @@ if(CLR_CMAKE_HOST_WIN32)
10199
kernel32.lib
102100
advapi32.lib)
103101
else()
104-
set (GC_LINK_LIBRARIES)
102+
set (GC_LINK_LIBRARIES gc_unix)
105103
endif(CLR_CMAKE_HOST_WIN32)
106104

107105
list(APPEND GC_SOURCES ${GC_HEADERS})

src/coreclr/gc/unix/cgroup.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ Module Name:
5454

5555
extern bool ReadMemoryValueFromFile(const char* filename, uint64_t* val);
5656

57+
namespace
58+
{
5759
class CGroup
5860
{
5961
// the cgroup version number or 0 to indicate cgroups are not found or not enabled
@@ -453,6 +455,7 @@ class CGroup
453455
return foundInactiveFileValue;
454456
}
455457
};
458+
}
456459

457460
int CGroup::s_cgroup_version = 0;
458461
char *CGroup::s_memory_cgroup_path = nullptr;

src/coreclr/gc/unix/gcenv.unix.cpp

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,10 @@ static void* VirtualReserveInner(size_t size, size_t alignment, uint32_t flags,
659659
}
660660

661661
pRetVal = pAlignedRetVal;
662+
#ifdef MADV_DONTDUMP
663+
// Do not include reserved memory in coredump.
664+
madvise(pRetVal, size, MADV_DONTDUMP);
665+
#endif
662666
}
663667

664668
return pRetVal;
@@ -724,6 +728,14 @@ bool GCToOSInterface::VirtualCommit(void* address, size_t size, uint16_t node)
724728
{
725729
bool success = mprotect(address, size, PROT_WRITE | PROT_READ) == 0;
726730

731+
#ifdef MADV_DODUMP
732+
if (success)
733+
{
734+
// Include committed memory in coredump.
735+
madvise(address, size, MADV_DODUMP);
736+
}
737+
#endif
738+
727739
#if HAVE_NUMA_H
728740
if (success && g_numaAvailable && (node != NUMA_NODE_UNDEFINED))
729741
{
@@ -760,7 +772,17 @@ bool GCToOSInterface::VirtualDecommit(void* address, size_t size)
760772
// that much more clear to the operating system that we no
761773
// longer need these pages. Also, GC depends on re-committed pages to
762774
// be zeroed-out.
763-
return mmap(address, size, PROT_NONE, MAP_FIXED | MAP_ANON | MAP_PRIVATE, -1, 0) != NULL;
775+
bool bRetVal = mmap(address, size, PROT_NONE, MAP_FIXED | MAP_ANON | MAP_PRIVATE, -1, 0) != MAP_FAILED;
776+
777+
#ifdef MADV_DONTDUMP
778+
if (bRetVal)
779+
{
780+
// Do not include freed memory in coredump.
781+
madvise(address, size, MADV_DONTDUMP);
782+
}
783+
#endif
784+
785+
return bRetVal;
764786
}
765787

766788
// Reset virtual memory range. Indicates that data in the memory range specified by address and size is no
@@ -791,6 +813,14 @@ bool GCToOSInterface::VirtualReset(void * address, size_t size, bool unlock)
791813
#endif
792814
}
793815

816+
#ifdef MADV_DONTDUMP
817+
if (st == 0)
818+
{
819+
// Do not include reset memory in coredump.
820+
madvise(address, size, MADV_DONTDUMP);
821+
}
822+
#endif
823+
794824
return (st == 0);
795825
}
796826

src/coreclr/pal/src/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ set(SOURCES
171171
misc/sysinfo.cpp
172172
misc/time.cpp
173173
misc/utils.cpp
174-
numa/numa.cpp
175174
objmgr/palobjbase.cpp
176175
objmgr/shmobject.cpp
177176
objmgr/shmobjectmanager.cpp

src/coreclr/pal/src/include/pal/palinternal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ typedef enum _TimeConversionConstants
652652
}
653653

654654
bool
655-
ReadMemoryValueFromFile(const char* filename, uint64_t* val);
655+
PAL_ReadMemoryValueFromFile(const char* filename, uint64_t* val);
656656

657657
#ifdef __APPLE__
658658
bool

src/coreclr/pal/src/init/pal.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -673,13 +673,6 @@ Initialize(
673673
goto CLEANUP15;
674674
}
675675

676-
if (FALSE == NUMASupportInitialize())
677-
{
678-
ERROR("Unable to initialize NUMA support\n");
679-
palError = ERROR_PALINIT_NUMA;
680-
goto CLEANUP15;
681-
}
682-
683676
TRACE("First-time PAL initialization complete.\n");
684677
init_count++;
685678

src/coreclr/pal/src/misc/cgroup.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ class CGroup
470470

471471
static bool ReadMemoryValueFromFile(const char* filename, uint64_t* val)
472472
{
473-
return ::ReadMemoryValueFromFile(filename, val);
473+
return ::PAL_ReadMemoryValueFromFile(filename, val);
474474
}
475475

476476
static bool GetCGroup1CpuLimit(UINT *val)

src/coreclr/pal/src/misc/sysinfo.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ PAL_HasGetCurrentProcessorNumber()
504504
}
505505

506506
bool
507-
ReadMemoryValueFromFile(const char* filename, uint64_t* val)
507+
PAL_ReadMemoryValueFromFile(const char* filename, uint64_t* val)
508508
{
509509
bool result = false;
510510
char *line = nullptr;
@@ -585,11 +585,11 @@ PAL_GetLogicalProcessorCacheSizeFromOS()
585585
{
586586
path_to_size_file[index] = (char)(48 + i);
587587

588-
if (ReadMemoryValueFromFile(path_to_size_file, &size))
588+
if (PAL_ReadMemoryValueFromFile(path_to_size_file, &size))
589589
{
590590
path_to_level_file[index] = (char)(48 + i);
591591

592-
if (ReadMemoryValueFromFile(path_to_level_file, &level))
592+
if (PAL_ReadMemoryValueFromFile(path_to_level_file, &level))
593593
{
594594
UPDATE_CACHE_SIZE_AND_LEVEL(size, level)
595595
}

0 commit comments

Comments
 (0)