Skip to content

Commit 4e688d2

Browse files
committed
Merge branch 'dev' of https://github.com/microsoft/mimalloc into dev
2 parents 9a351c9 + 289b689 commit 4e688d2

53 files changed

Lines changed: 1402 additions & 925 deletions

Some content is hidden

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

CMakeLists.txt

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ option(MI_PADDING "Enable padding to detect heap block overflow (alway
99
option(MI_OVERRIDE "Override the standard malloc interface (i.e. define entry points for 'malloc', 'free', etc)" ON)
1010
option(MI_XMALLOC "Enable abort() call on memory allocation failure by default" OFF)
1111
option(MI_SHOW_ERRORS "Show error and warning messages by default (only enabled by default in DEBUG mode)" OFF)
12-
option(MI_GUARDED "Build with guard pages behind certain object allocations (implies MI_NO_PADDING=ON)" OFF)
12+
option(MI_GUARDED "Build with guard pages behind certain object allocations (enabled by default in a debug build)" OFF)
1313
option(MI_USE_CXX "Use the C++ compiler to compile the library (instead of the C compiler)" OFF)
1414
option(MI_OPT_ARCH "Only for optimized builds: turn on architecture specific optimizations (for arm64: '-march=armv8.1-a' (2016))" OFF)
1515
option(MI_SEE_ASM "Generate assembly files" OFF)
@@ -273,15 +273,6 @@ if(MI_TRACK_ETW)
273273
endif()
274274
endif()
275275

276-
if(MI_GUARDED)
277-
message(STATUS "Compile guard pages behind certain object allocations (MI_GUARDED=ON)")
278-
list(APPEND mi_defines MI_GUARDED=1)
279-
if(NOT MI_NO_PADDING)
280-
message(STATUS " Disabling padding due to guard pages (MI_NO_PADDING=ON)")
281-
set(MI_NO_PADDING ON)
282-
endif()
283-
endif()
284-
285276
if(MI_SEE_ASM)
286277
message(STATUS "Generate assembly listings (MI_SEE_ASM=ON)")
287278
list(APPEND mi_cflags -save-temps)
@@ -303,19 +294,31 @@ endif()
303294

304295
if(MI_DEBUG_FULL)
305296
message(STATUS "Set debug level to full assertion and internal invariant checking (MI_DEBUG_FULL=ON, expensive)")
297+
set(MI_DEBUG ON)
306298
list(APPEND mi_defines MI_DEBUG=3) # full invariant checking (mi_assert, mi_assert_internal, and mi_assert_expensive)
307299
elseif(MI_DEBUG_INTERNAL)
308300
message(STATUS "Set debug level to internal assertion and invariant checking (MI_DEBUG_INTERNAL=ON)")
301+
set(MI_DEBUG ON)
309302
list(APPEND mi_defines MI_DEBUG=2) # invariant checking (mi_assert and mi_assert_internal)
310303
elseif(MI_DEBUG)
311304
message(STATUS "Set debug level to assertion checking (MI_DEBUG=ON)")
312305
list(APPEND mi_defines MI_DEBUG=1) # assertion checking (mi_assert)
313306
elseif(CMAKE_BUILD_TYPE MATCHES "Debug")
314307
message(STATUS "Set debug level to internal assertion and invariant checking (CMAKE_BUILD_TYPE=Debug)")
315308
set(MI_DEBUG_INTERNAL ON)
309+
set(MI_DEBUG ON)
316310
list(APPEND mi_defines MI_DEBUG=2) # invariant checking (mi_assert and mi_assert_internal)
317311
endif()
318312

313+
if(MI_DEBUG AND !MI_GUARDED)
314+
message(STATUS "Enable MI_GUARDED (since MI_DEBUG=ON)")
315+
set(MI_GUARDED=ON)
316+
endif()
317+
if(MI_GUARDED)
318+
message(STATUS "Compile guard pages behind certain object allocations (MI_GUARDED=ON)")
319+
list(APPEND mi_defines MI_GUARDED=1)
320+
endif()
321+
319322
if(MI_NO_PADDING)
320323
message(STATUS "Suppress any padding of heap blocks (MI_NO_PADDING=ON)")
321324
list(APPEND mi_defines MI_PADDING=0)
@@ -381,7 +384,7 @@ endif()
381384
if(CMAKE_SYSTEM_NAME MATCHES "Linux|Android")
382385
if(MI_NO_THP)
383386
message(STATUS "Disable transparent huge pages support (MI_NO_THP=ON)")
384-
list(APPEND mi_defines MI_NO_THP=1)
387+
list(APPEND mi_defines MI_DEFAULT_ALLOW_THP=0)
385388
endif()
386389
endif()
387390

bin/bundle.sh

Lines changed: 277 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,277 @@
1+
#!/bin/sh -e
2+
3+
#-----------------------------------------------------------------------------
4+
# Bundle release
5+
#-----------------------------------------------------------------------------
6+
7+
QUIET=""
8+
FORCE=""
9+
OSARCH=""
10+
OSNAME=""
11+
MI_TAG=""
12+
MI_COMMIT=""
13+
14+
#---------------------------------------------------------
15+
# Helper functions
16+
#---------------------------------------------------------
17+
18+
info() {
19+
if [ -z "$QUIET" ] ; then
20+
echo "$@"
21+
fi
22+
}
23+
24+
warn() {
25+
echo "$@" >&2
26+
}
27+
28+
stop() {
29+
warn $@
30+
exit 1
31+
}
32+
33+
has_cmd() {
34+
command -v "$1" > /dev/null 2>&1
35+
}
36+
37+
on_path() {
38+
echo ":$PATH:" | grep -q :"$1":
39+
}
40+
41+
42+
#---------------------------------------------------------
43+
# Detect OS and cpu architecture
44+
#---------------------------------------------------------
45+
46+
contains() {
47+
if echo "$1" | grep -i -E "$2" > /dev/null; then
48+
return 0
49+
else
50+
return 1
51+
fi
52+
}
53+
54+
detect_osarch() {
55+
arch="$(uname -m)"
56+
case "$arch" in
57+
x86_64*|amd64*)
58+
arch="x64";;
59+
x86*|i[35678]86*)
60+
arch="x86";;
61+
arm64*|aarch64*|armv8*)
62+
arch="arm64";;
63+
arm*)
64+
arch="arm";;
65+
parisc*)
66+
arch="hppa";;
67+
esac
68+
69+
OSNAME="linux"
70+
case "$(uname)" in
71+
[Ll]inux)
72+
OSNAME="linux";;
73+
[Dd]arwin)
74+
OSNAME="macos";;
75+
[Ff]ree[Bb][Ss][Dd])
76+
OSNAME="unix-freebsd";;
77+
[Oo]pen[Bb][Ss][Dd])
78+
OSNAME="unix-openbsd";;
79+
*)
80+
info "Warning: assuming generic Linux"
81+
esac
82+
OSARCH="$OSNAME-$arch"
83+
84+
if [ "$OSNAME" = "linux" ]; then
85+
distrocfg=`cat $(find /etc/*-release -type f)`
86+
if contains "$distrocfg" "rhel"; then
87+
OSDISTRO="rhel"
88+
elif contains "$distrocfg" "opensuse"; then
89+
OSDISTRO="opensuse"
90+
elif contains "$distrocfg" "alpine"; then
91+
OSDISTRO="alpine"
92+
elif contains "$distrocfg" "arch"; then
93+
OSDISTRO="arch"
94+
elif contains "$distrocfg" "ubuntu|debian"; then
95+
OSDISTRO="ubuntu"
96+
else
97+
OSDISTRO="ubuntu" # default
98+
fi
99+
fi
100+
}
101+
102+
103+
104+
#---------------------------------------------------------
105+
# Command line options
106+
#---------------------------------------------------------
107+
108+
process_options() {
109+
while : ; do
110+
flag="$1"
111+
case "$flag" in
112+
*=*) flag_arg="${flag#*=}";;
113+
*) flag_arg="yes" ;;
114+
esac
115+
# echo "option: $flag, arg: $flag_arg"
116+
case "$flag" in
117+
"") break;;
118+
-q|--quiet)
119+
QUIET="yes";;
120+
-p) shift
121+
PREFIX="$1";;
122+
-p=*|--prefix=*)
123+
PREFIX=`eval echo $flag_arg`;; # no quotes so ~ gets expanded (issue #412)
124+
-t) shift
125+
MI_TAG="$1";;
126+
-t=*|--tag=*)
127+
MI_TAG="$flag_arg";;
128+
-h|--help|-\?|help|\?)
129+
MODE="help";;
130+
*) case "$flag" in
131+
*) warn "warning: unknown option \"$1\".";;
132+
esac;;
133+
esac
134+
shift
135+
done
136+
137+
if [ -z "$MI_COMMIT" ] ; then
138+
MI_COMMIT=`git log -n 1 --pretty=format:"%H"`
139+
fi
140+
if [ -z "$MI_TAG" ] ; then
141+
MI_TAG=`git describe --tag`
142+
fi
143+
info "Tag : $MI_TAG"
144+
info "Commit : $MI_COMMIT"
145+
}
146+
147+
148+
149+
#---------------------------------------------------------
150+
# Download
151+
#---------------------------------------------------------
152+
153+
download_failed() { # <program> <url>
154+
warn ""
155+
warn "unable to download: $2"
156+
stop ""
157+
}
158+
159+
download_file() { # <url|file> <destination file>
160+
case "$1" in
161+
ftp://*|http://*|https://*)
162+
info "Downloading: $1"
163+
if has_cmd curl ; then
164+
if ! curl ${QUIET:+-sS} --proto =https --tlsv1.2 -f -L -o "$2" "$1"; then
165+
download_failed "curl" $1
166+
fi
167+
elif has_cmd wget ; then
168+
if ! wget ${QUIET:+-q} --https-only "-O$2" "$1"; then
169+
download_failed "wget" $1
170+
fi
171+
else
172+
stop "Neither 'curl' nor 'wget' is available; install one to continue."
173+
fi;;
174+
*)
175+
# echo "cp $1 to $2"
176+
info "Copying: $1"
177+
if ! cp $1 $2 ; then
178+
stop "Unable to copy from $1"
179+
fi;;
180+
esac
181+
}
182+
183+
download_available() { # <url|file>
184+
case "$1" in
185+
ftp://*|http://*|https://*)
186+
if has_cmd curl ; then
187+
if ! curl -sS --proto =https --tlsv1.2 -L -I "$1" | grep -E "^HTTP/2 200" ; then # -I is headers only
188+
return 1
189+
fi
190+
fi;;
191+
*)
192+
if ! [ -f "$1" ] ; then
193+
return 1
194+
fi;;
195+
esac
196+
return 0
197+
}
198+
199+
download_source_at_tag() { # <tag> <output file>
200+
download_file "https://github.com/microsoft/mimalloc/archive/refs/tags/$1.tar.gz" "$2"
201+
}
202+
203+
download_source_at_commit() { # <commit> <output file>
204+
download_file "https://github.com/microsoft/mimalloc/archive/$1.tar.gz" "$2"
205+
}
206+
207+
build_test_install() { # <type> <bundledir> <prefix> <cmake args>
208+
info "Build, test, install: $1 to $3"
209+
build_dir="$2/$1"
210+
mkdir -p "$build_dir"
211+
cmake . -B "$build_dir" $4
212+
cmake --build "$build_dir"
213+
ctest --test-dir "$build_dir"
214+
cmake --install "$build_dir" --prefix "$3"
215+
}
216+
217+
#---------------------------------------------------------
218+
# Main
219+
#---------------------------------------------------------
220+
221+
main_bundle() {
222+
# config
223+
bundle_dir="out/bundle"
224+
mkdir -p "$bundle_dir"
225+
226+
# source archive
227+
info "Download source archive for $MI_TAG"
228+
source_archive="$bundle_dir/mimalloc-$MI_TAG-source.tar.gz"
229+
download_source_at_commit "$MI_COMMIT" "$source_archive"
230+
231+
# build
232+
prefix_dir="$bundle_dir/prefix"
233+
build_test_install "debug" "$bundle_dir" "$prefix_dir" "-DCMAKE_BUILD_TYPE=Debug"
234+
build_test_install "release" "$bundle_dir" "$prefix_dir" "-DCMAKE_BUILD_TYPE=Release -DMI_OPT_ARCH=ON"
235+
build_test_install "secure" "$bundle_dir" "$prefix_dir" "-DCMAKE_BUILD_TYPE=Release -DMI_OPT_ARCH=ON -DMI_SECURE=ON"
236+
237+
# archive binaries
238+
binary_archive_name="mimalloc-$MI_TAG-$OSARCH.tar.gz"
239+
binary_archive="$bundle_dir/$binary_archive_name"
240+
info "Create binary archive: $binary_archive_name"
241+
pushd $bundle_dir
242+
tar -czvf "$binary_archive_name" prefix
243+
popd
244+
245+
# done
246+
info ""
247+
info "Created:"
248+
info " - $binary_archive"
249+
info " - $source_archive"
250+
info ""
251+
info "Done."
252+
}
253+
254+
255+
main_help() {
256+
info "command:"
257+
info " ./bin/bundle.sh [options]"
258+
info ""
259+
info "options:"
260+
info " -q, --quiet suppress output"
261+
info " -f, --force continue without prompting"
262+
info " -p, --prefix=<dir> prefix directory ($PREFIX)"
263+
info ""
264+
}
265+
266+
main_start() {
267+
detect_osarch
268+
process_options $@
269+
if [ "$MODE" = "help" ] ; then
270+
main_help
271+
else
272+
main_bundle
273+
fi
274+
}
275+
276+
# note: only start executing commands now to guard against partial downloads
277+
main_start $@

0 commit comments

Comments
 (0)