mirror of
https://github.com/git-for-windows/git.git
synced 2026-02-04 03:33:01 -06:00
mimalloc: offer a build-time option to enable it
By defining `USE_MIMALLOC`, Git can now be compiled with that nicely-fast and small allocator. Note that we have to disable a couple `DEVELOPER` options to build mimalloc's source code, as it makes heavy use of declarations after statements, among other things that disagree with Git's conventions. We even have to silence some GCC warnings in non-DEVELOPER mode. For example, the `-Wno-array-bounds` flag is needed because in `-O2` builds, trying to call `NtCurrentTeb()` (which `_mi_thread_id()` does on Windows) causes the bogus warning about a system header, likely related to https://sourceforge.net/p/mingw-w64/mailman/message/37674519/ and to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99578: C:/git-sdk-64-minimal/mingw64/include/psdk_inc/intrin-impl.h:838:1: error: array subscript 0 is outside array bounds of 'long long unsigned int[0]' [-Werror=array-bounds] 838 | __buildreadseg(__readgsqword, unsigned __int64, "gs", "q") | ^~~~~~~~~~~~~~ Also: The `mimalloc` library uses C11-style atomics, therefore we must require that standard when compiling with GCC if we want to use `mimalloc` (instead of requiring "only" C99). This is what we do in the CMake definition already, therefore this commit does not need to touch `contrib/buildsystems/`. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
This commit is contained in:
parent
b25103beab
commit
bb72a9963d
41
Makefile
41
Makefile
@ -1344,6 +1344,7 @@ BUILTIN_OBJS += builtin/write-tree.o
|
||||
# upstream unnecessarily (making merging in future changes easier).
|
||||
THIRD_PARTY_SOURCES += compat/inet_ntop.c
|
||||
THIRD_PARTY_SOURCES += compat/inet_pton.c
|
||||
THIRD_PARTY_SOURCES += compat/mimalloc/%
|
||||
THIRD_PARTY_SOURCES += compat/nedmalloc/%
|
||||
THIRD_PARTY_SOURCES += compat/obstack.%
|
||||
THIRD_PARTY_SOURCES += compat/poll/%
|
||||
@ -2143,6 +2144,46 @@ ifdef USE_NED_ALLOCATOR
|
||||
OVERRIDE_STRDUP = YesPlease
|
||||
endif
|
||||
|
||||
ifdef USE_MIMALLOC
|
||||
MIMALLOC_OBJS = \
|
||||
compat/mimalloc/alloc-aligned.o \
|
||||
compat/mimalloc/alloc.o \
|
||||
compat/mimalloc/arena.o \
|
||||
compat/mimalloc/bitmap.o \
|
||||
compat/mimalloc/heap.o \
|
||||
compat/mimalloc/init.o \
|
||||
compat/mimalloc/libc.o \
|
||||
compat/mimalloc/options.o \
|
||||
compat/mimalloc/os.o \
|
||||
compat/mimalloc/page.o \
|
||||
compat/mimalloc/random.o \
|
||||
compat/mimalloc/prim/prim.o \
|
||||
compat/mimalloc/segment.o \
|
||||
compat/mimalloc/segment-map.o \
|
||||
compat/mimalloc/stats.o
|
||||
|
||||
COMPAT_CFLAGS += -Icompat/mimalloc -DMI_DEBUG=0 -DUSE_MIMALLOC --std=gnu11
|
||||
COMPAT_OBJS += $(MIMALLOC_OBJS)
|
||||
|
||||
$(MIMALLOC_OBJS): COMPAT_CFLAGS += -DBANNED_H
|
||||
|
||||
$(MIMALLOC_OBJS): COMPAT_CFLAGS += \
|
||||
-DMI_WIN_USE_FLS \
|
||||
-Wno-attributes \
|
||||
-Wno-unknown-pragmas \
|
||||
-Wno-unused-function \
|
||||
-Wno-array-bounds
|
||||
|
||||
ifdef DEVELOPER
|
||||
$(MIMALLOC_OBJS): COMPAT_CFLAGS += \
|
||||
-Wno-pedantic \
|
||||
-Wno-declaration-after-statement \
|
||||
-Wno-old-style-definition \
|
||||
-Wno-missing-prototypes \
|
||||
-Wno-implicit-function-declaration
|
||||
endif
|
||||
endif
|
||||
|
||||
ifdef OVERRIDE_STRDUP
|
||||
COMPAT_CFLAGS += -DOVERRIDE_STRDUP
|
||||
COMPAT_OBJS += compat/strdup.o
|
||||
|
||||
1
compat/.gitattributes
vendored
1
compat/.gitattributes
vendored
@ -1 +1,2 @@
|
||||
/zlib-uncompress2.c whitespace=-indent-with-non-tab,-trailing-space
|
||||
/mimalloc/**/* whitespace=-trailing-space
|
||||
|
||||
@ -176,6 +176,16 @@ typedef unsigned long uintptr_t;
|
||||
#define _ALL_SOURCE 1
|
||||
#endif
|
||||
|
||||
#ifdef USE_MIMALLOC
|
||||
#include "mimalloc.h"
|
||||
#define malloc mi_malloc
|
||||
#define calloc mi_calloc
|
||||
#define realloc mi_realloc
|
||||
#define free mi_free
|
||||
#define strdup mi_strdup
|
||||
#define strndup mi_strndup
|
||||
#endif
|
||||
|
||||
#ifdef MKDIR_WO_TRAILING_SLASH
|
||||
#define mkdir(a,b) compat_mkdir_wo_trailing_slash((a),(b))
|
||||
int compat_mkdir_wo_trailing_slash(const char*, mode_t);
|
||||
|
||||
@ -22,8 +22,10 @@ endif
|
||||
|
||||
ifneq ($(uname_S),FreeBSD)
|
||||
ifneq ($(or $(filter gcc6,$(COMPILER_FEATURES)),$(filter clang7,$(COMPILER_FEATURES))),)
|
||||
ifndef USE_MIMALLOC
|
||||
DEVELOPER_CFLAGS += -std=gnu99
|
||||
endif
|
||||
endif
|
||||
else
|
||||
# FreeBSD cannot limit to C99 because its system headers unconditionally
|
||||
# rely on C11 features.
|
||||
|
||||
@ -521,7 +521,7 @@ endif
|
||||
CC = compat/vcbuild/scripts/clink.pl
|
||||
AR = compat/vcbuild/scripts/lib.pl
|
||||
CFLAGS =
|
||||
BASIC_CFLAGS = -nologo -I. -Icompat/vcbuild/include -DWIN32 -D_CONSOLE -DHAVE_STRING_H -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE
|
||||
BASIC_CFLAGS = -nologo -I. -Icompat/vcbuild/include -DWIN32 -D_CONSOLE -DHAVE_STRING_H -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE -MP -std:c11
|
||||
COMPAT_OBJS = compat/msvc.o compat/winansi.o \
|
||||
compat/win32/flush.o \
|
||||
compat/win32/path-utils.o \
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user