MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / libmimalloc

Class libmimalloc

tools/system_libs.py:1860–1917  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1858
1859
1860class libmimalloc(MTLibrary):
1861 name = 'libmimalloc'
1862
1863 cflags = [
1864 '-fno-builtin',
1865 '-Wno-unused-function',
1866 '-Wno-unused-but-set-variable',
1867 '-Wno-unused-variable',
1868 '-Wno-deprecated-pragma',
1869 # build emmalloc as only a system allocator, without exporting itself onto
1870 # malloc/free in the global scope
1871 '-DEMMALLOC_NO_STD_EXPORTS',
1872 # disable large pages by default, see:
1873 # https://github.com/microsoft/mimalloc/commit/9199d54bcf1e6dea0deb61a3a8a4b3ea4b45a341
1874 '-DMI_ENABLE_LARGE_PAGES=0',
1875 # halve the page size to 32KiB on wasm64 and to 16KiB on wasm32
1876 # https://github.com/microsoft/mimalloc/issues/647#issuecomment-1324109021
1877 # https://github.com/emscripten-core/emscripten/issues/20645#issuecomment-1962964755
1878 '-DMI_ARENA_SLICE_SHIFT=(12+MI_SIZE_SHIFT)',
1879 # `malloc`ed pointers must be aligned at least as strictly as max_align_t
1880 '-DMI_MAX_ALIGN_SIZE=8',
1881 # reserve memory in 64 MiB chunks (internally divided by 4)
1882 # Note: keep in sync with the -sINITIAL_HEAP default
1883 '-DMI_DEFAULT_ARENA_RESERVE=65536',
1884 # build mimalloc with an override of malloc/free
1885 '-DMI_MALLOC_OVERRIDE',
1886 # TODO: add build modes that include debug checks 1,2,3
1887 '-DMI_DEBUG=0',
1888 # disable `assert()` in the underlying emmalloc allocator
1889 '-DNDEBUG',
1890 # Emscripten uses musl libc internally
1891 '-DMI_LIBC_MUSL',
1892 # enable use of `__builtin_thread_pointer()`
1893 '-DMI_USE_BUILTIN_THREAD_POINTER',
1894 ]
1895
1896 # malloc/free/calloc are runtime functions and can be generated during LTO
1897 # Therefore they cannot themselves be part of LTO.
1898 force_object_files = True
1899
1900 includes = ['system/lib/mimalloc/include']
1901
1902 # Build all of mimalloc, and also emmalloc which is used as the system
1903 # allocator underneath it.
1904 src_dir = 'system/lib/'
1905 src_files = glob_in_path(
1906 path='system/lib/mimalloc/src',
1907 glob_pattern='*.c',
1908 # mimalloc includes some files at the source level, so exclude them here.
1909 excludes={'alloc-override.c', 'free.c', 'page-queue.c', 'static.c'},
1910 )
1911 src_files += [utils.path_from_root('system/lib/mimalloc/src/prim/prim.c')]
1912 src_files += [utils.path_from_root('system/lib/emmalloc.c')]
1913 # Include sbrk.c in libc, it uses tracing and libc itself doesn't have a tracing variant.
1914 src_files += [utils.path_from_root('system/lib/libc/sbrk.c')]
1915
1916 def can_use(self):
1917 return super().can_use() and settings.MALLOC == 'mimalloc'

Callers

nothing calls this directly

Calls 1

glob_in_pathFunction · 0.85

Tested by

no test coverage detected