Merge branch 'dev' into dev-exp

This commit is contained in:
daan 2019-09-02 10:10:08 -07:00
commit d6e35ffd83
4 changed files with 40 additions and 33 deletions

View file

@ -10,6 +10,7 @@ option(MI_SEE_ASM "Generate assembly files" OFF)
option(MI_CHECK_FULL "Use full internal invariant checking in DEBUG mode" OFF) option(MI_CHECK_FULL "Use full internal invariant checking in DEBUG mode" OFF)
option(MI_USE_CXX "Use the C++ compiler to compile the library" OFF) option(MI_USE_CXX "Use the C++ compiler to compile the library" OFF)
option(MI_SECURE "Use security mitigations (like guard pages and randomization)" OFF) option(MI_SECURE "Use security mitigations (like guard pages and randomization)" OFF)
option(MI_BUILD_TESTS "Build test executables" ON)
set(mi_install_dir "lib/mimalloc-${mi_version}") set(mi_install_dir "lib/mimalloc-${mi_version}")
@ -95,7 +96,7 @@ if(CMAKE_C_COMPILER_ID MATCHES "AppleClang|Clang|GNU")
endif() endif()
endif() endif()
if(NOT(CMAKE_BUILD_TYPE MATCHES "Release|RelWithDebInfo")) if(NOT(CMAKE_BUILD_TYPE MATCHES "Release|release|RelWithDebInfo|relwithdebinfo"))
string(TOLOWER "${CMAKE_BUILD_TYPE}" build_type) string(TOLOWER "${CMAKE_BUILD_TYPE}" build_type)
set(mi_basename "mimalloc-${build_type}") set(mi_basename "mimalloc-${build_type}")
else() else()
@ -191,21 +192,24 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/mimalloc-obj.dir/src/static
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
# API surface testing # API surface testing
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
if (MI_BUILD_TESTS MATCHES "ON")
add_executable(mimalloc-test-api test/test-api.c) add_executable(mimalloc-test-api test/test-api.c)
target_compile_definitions(mimalloc-test-api PRIVATE ${mi_defines}) target_compile_definitions(mimalloc-test-api PRIVATE ${mi_defines})
target_compile_options(mimalloc-test-api PRIVATE ${mi_cflags}) target_compile_options(mimalloc-test-api PRIVATE ${mi_cflags})
target_include_directories(mimalloc-test-api PRIVATE include) target_include_directories(mimalloc-test-api PRIVATE include)
target_link_libraries(mimalloc-test-api PRIVATE mimalloc-static) target_link_libraries(mimalloc-test-api PRIVATE mimalloc-static ${mi_libraries})
add_executable(mimalloc-test-stress test/test-stress.c) add_executable(mimalloc-test-stress test/test-stress.c)
target_compile_definitions(mimalloc-test-stress PRIVATE ${mi_defines}) target_compile_definitions(mimalloc-test-stress PRIVATE ${mi_defines})
target_compile_options(mimalloc-test-stress PRIVATE ${mi_cflags}) target_compile_options(mimalloc-test-stress PRIVATE ${mi_cflags})
target_include_directories(mimalloc-test-stress PRIVATE include) target_include_directories(mimalloc-test-stress PRIVATE include)
target_link_libraries(mimalloc-test-stress PRIVATE mimalloc-static) target_link_libraries(mimalloc-test-stress PRIVATE mimalloc-static ${mi_libraries})
enable_testing() enable_testing()
add_test(test_api, mimalloc-test-api) add_test(test_api, mimalloc-test-api)
add_test(test_stress, mimalloc-test-stress) add_test(test_stress, mimalloc-test-stress)
endif()
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
# Set override properties # Set override properties

View file

@ -10,7 +10,7 @@ terms of the MIT license. A copy of the license can be found in the file
#include "mimalloc-types.h" #include "mimalloc-types.h"
#if defined(MI_MALLOC_OVERRIDE) && defined(__APPLE__) #if defined(MI_MALLOC_OVERRIDE) && (defined(__APPLE__) || defined(__OpenBSD__))
#define MI_TLS_RECURSE_GUARD #define MI_TLS_RECURSE_GUARD
#endif #endif

View file

@ -13,7 +13,7 @@ Initially developed by Daan Leijen for the run-time systems of the
[Koka](https://github.com/koka-lang/koka) and [Lean](https://github.com/leanprover/lean) languages. [Koka](https://github.com/koka-lang/koka) and [Lean](https://github.com/leanprover/lean) languages.
It is a drop-in replacement for `malloc` and can be used in other programs It is a drop-in replacement for `malloc` and can be used in other programs
without code changes, for example, on Unix you can use it as: without code changes, for example, on dynamically linked ELF-based systems (Linux, BSD, etc.) you can use it as:
``` ```
> LD_PRELOAD=/usr/bin/libmimalloc.so myprogram > LD_PRELOAD=/usr/bin/libmimalloc.so myprogram
``` ```
@ -117,7 +117,7 @@ Notes:
The preferred usage is including `<mimalloc.h>`, linking with The preferred usage is including `<mimalloc.h>`, linking with
the shared- or static library, and using the `mi_malloc` API exclusively for allocation. For example, the shared- or static library, and using the `mi_malloc` API exclusively for allocation. For example,
``` ```
gcc -o myprogram -lmimalloc myfile.c > gcc -o myprogram -lmimalloc myfile.c
``` ```
mimalloc uses only safe OS calls (`mmap` and `VirtualAlloc`) and can co-exist mimalloc uses only safe OS calls (`mmap` and `VirtualAlloc`) and can co-exist
@ -207,20 +207,21 @@ This is the recommended way to override the standard malloc interface.
### Linux, BSD ### Linux, BSD
On these systems we preload the mimalloc shared On these ELF-based systems we preload the mimalloc shared
library so all calls to the standard `malloc` interface are library so all calls to the standard `malloc` interface are
resolved to the _mimalloc_ library. resolved to the _mimalloc_ library.
```
- `env LD_PRELOAD=/usr/lib/libmimalloc.so myprogram` > env LD_PRELOAD=/usr/lib/libmimalloc.so myprogram
```
You can set extra environment variables to check that mimalloc is running, You can set extra environment variables to check that mimalloc is running,
like: like:
``` ```
env MIMALLOC_VERBOSE=1 LD_PRELOAD=/usr/lib/libmimalloc.so myprogram > env MIMALLOC_VERBOSE=1 LD_PRELOAD=/usr/lib/libmimalloc.so myprogram
``` ```
or run with the debug version to get detailed statistics: or run with the debug version to get detailed statistics:
``` ```
env MIMALLOC_SHOW_STATS=1 LD_PRELOAD=/usr/lib/libmimalloc-debug.so myprogram > env MIMALLOC_SHOW_STATS=1 LD_PRELOAD=/usr/lib/libmimalloc-debug.so myprogram
``` ```
### MacOS ### MacOS
@ -228,8 +229,9 @@ env MIMALLOC_SHOW_STATS=1 LD_PRELOAD=/usr/lib/libmimalloc-debug.so myprogram
On macOS we can also preload the mimalloc shared On macOS we can also preload the mimalloc shared
library so all calls to the standard `malloc` interface are library so all calls to the standard `malloc` interface are
resolved to the _mimalloc_ library. resolved to the _mimalloc_ library.
```
- `env DYLD_FORCE_FLAT_NAMESPACE=1 DYLD_INSERT_LIBRARIES=/usr/lib/libmimalloc.dylib myprogram` > env DYLD_FORCE_FLAT_NAMESPACE=1 DYLD_INSERT_LIBRARIES=/usr/lib/libmimalloc.dylib myprogram
```
Note that certain security restrictions may apply when doing this from Note that certain security restrictions may apply when doing this from
the [shell](https://stackoverflow.com/questions/43941322/dyld-insert-libraries-ignored-when-calling-application-through-bash). the [shell](https://stackoverflow.com/questions/43941322/dyld-insert-libraries-ignored-when-calling-application-through-bash).
@ -257,16 +259,15 @@ robust; try this out if you experience troubles.
## Static override ## Static override
On Unix systems, you can also statically link with _mimalloc_ to override the standard On Unix-like systems, you can also statically link with _mimalloc_ to override the standard
malloc interface. The recommended way is to link the final program with the malloc interface. The recommended way is to link the final program with the
_mimalloc_ single object file (`mimalloc-override.o`). We use _mimalloc_ single object file (`mimalloc-override.o`). We use
an object file instead of a library file as linkers give preference to an object file instead of a library file as linkers give preference to
that over archives to resolve symbols. To ensure that the standard that over archives to resolve symbols. To ensure that the standard
malloc interface resolves to the _mimalloc_ library, link it as the first malloc interface resolves to the _mimalloc_ library, link it as the first
object file. For example: object file. For example:
``` ```
gcc -o myprogram mimalloc-override.o myfile1.c ... > gcc -o myprogram mimalloc-override.o myfile1.c ...
``` ```

View file

@ -306,6 +306,8 @@ static void* mi_unix_mmapx(void* addr, size_t size, size_t try_alignment, int pr
if (p==MAP_FAILED) p = NULL; // fall back to regular mmap if (p==MAP_FAILED) p = NULL; // fall back to regular mmap
} }
} }
#else
UNUSED(try_alignment);
#endif #endif
if (p==NULL) { if (p==NULL) {
p = mmap(addr,size,protect_flags,flags,fd,0); p = mmap(addr,size,protect_flags,flags,fd,0);