Skip to content

Instantly share code, notes, and snippets.

@degski
Last active September 29, 2020 09:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save degski/389cfe5669b858d2ffa3e6f114762c0e to your computer and use it in GitHub Desktop.
Save degski/389cfe5669b858d2ffa3e6f114762c0e to your computer and use it in GitHub Desktop.
Compile mimalloc with clang/llvm, both with and without thin-lto, both standard and secure.
:: MIT License
::
:: Copyright (c) 2019, 2020 degski
::
:: Permission is hereby granted, free of charge, to any person obtaining a copy
:: of this software and associated documentation files (the "Software"), to deal
:: in the Software without restriction, including without limitation the rights
:: to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
:: copies of the Software, and to permit persons to whom the Software is
:: furnished to do so, subject to the following conditions:
::
:: The above copyright notice and this permission notice shall be included in all
:: copies or substantial portions of the Software.
::
:: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
:: IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
:: FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
:: AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
:: LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
:: OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
:: SOFTWARE.
:: Fiddle with a bug in clang.
rename "c:\Program Files\LLVM\lib\clang\10.0.0\include\prfchwintrin.h" "prfchwintrin.h.tmp"
copy /Y "prfchwintrin.h" "c:\Program Files\LLVM\lib\clang\10.0.0\include\"
:: Copy header.
copy /Y "..\include\mimalloc.h" "c:\vcpkg\installed\x64-windows-static\include\mimalloc\"
cd src
:: Compile.
clang-cl /c /w -m64 -fmsc-version=1927 -flto=thin /D "NDEBUG" /D "_CONSOLE" /D "NOMINMAX" /D "_UNICODE" /D "UNICODE" -Xclang -std=c11 -fno-delayed-template-parsing -march=native -mmmx -msse -msse2 -msse3 -msse4.1 -msse4.2 -maes -mavx -mavx2 -mbmi -mbmi2 -mpopcnt -mf16c -mxsaveopt -mlzcnt -mfma -mpclmul -mxsave -mrdrnd -mfxsr -madx -Xclang -fforce-enable-int128 -Xclang -faligned-allocation -Xclang -pedantic -Xclang -ffast-math -Xclang -fcolor-diagnostics -Xclang -ffine-grained-bitfield-accesses -Xclang -ffixed-point -Xclang -fsized-deallocation -I"..\include" /O2 /Qvec /TC /MT /GS- /Gy /Gd /Zc:wchar_t alloc-aligned.c alloc.c heap.c init.c options.c page.c segment.c os.c stats.c
llvm-lib /OUT:"c:\vcpkg\installed\x64-windows-static\lib\mimalloc-clang10-thin-lto-s.lib" /MACHINE:X64 alloc-aligned.obj alloc.obj heap.obj init.obj options.obj page.obj segment.obj os.obj stats.obj
del /Q *.obj
clang-cl /Z7 /c /w -m64 -fmsc-version=1927 -flto=thin /D "_DEBUG" /D "MI_DEBUG=3" /D "_CONSOLE" /D "NOMINMAX" /D "_UNICODE" /D "UNICODE" -Xclang -std=c11 -fno-delayed-template-parsing -march=native -mmmx -msse -msse2 -msse3 -msse4.1 -msse4.2 -maes -mavx -mavx2 -mbmi -mbmi2 -mpopcnt -mf16c -mxsaveopt -mlzcnt -mfma -mpclmul -mxsave -mrdrnd -mfxsr -madx -Xclang -fforce-enable-int128 -Xclang -faligned-allocation -Xclang -pedantic -Xclang -ffast-math -Xclang -fcolor-diagnostics -Xclang -ffine-grained-bitfield-accesses -Xclang -ffixed-point -Xclang -fsized-deallocation -I"..\include" /Od /TC /MTd /sdl /GS /Gd /Zc:wchar_t alloc-aligned.c alloc.c heap.c init.c options.c page.c segment.c os.c stats.c
llvm-lib /OUT:"c:\vcpkg\installed\x64-windows-static\debug\lib\mimalloc-clang10-thin-lto-s-d.lib" /MACHINE:X64 alloc-aligned.obj alloc.obj heap.obj init.obj options.obj page.obj segment.obj os.obj stats.obj
del /Q *.obj
clang-cl /c /w -m64 -fmsc-version=1927 /D "NDEBUG" /D "_CONSOLE" /D "NOMINMAX" /D "_UNICODE" /D "UNICODE" -Xclang -std=c11 -fno-delayed-template-parsing -march=native -mmmx -msse -msse2 -msse3 -msse4.1 -msse4.2 -maes -mavx -mavx2 -mbmi -mbmi2 -mpopcnt -mf16c -mxsaveopt -mlzcnt -mfma -mpclmul -mxsave -mrdrnd -mfxsr -madx -Xclang -fforce-enable-int128 -Xclang -faligned-allocation -Xclang -pedantic -Xclang -ffast-math -Xclang -fcolor-diagnostics -Xclang -ffine-grained-bitfield-accesses -Xclang -ffixed-point -Xclang -fsized-deallocation -I"..\include" /O2 /Qvec /TC /MT /GS- /Gy /Gd /Zc:wchar_t alloc-aligned.c alloc.c heap.c init.c options.c page.c segment.c os.c stats.c
llvm-lib /OUT:"c:\vcpkg\installed\x64-windows-static\lib\mimalloc-clang10-s.lib" /MACHINE:X64 alloc-aligned.obj alloc.obj heap.obj init.obj options.obj page.obj segment.obj os.obj stats.obj
del /Q *.obj
clang-cl /Z7 /c /w -m64 -fmsc-version=1927 /D "_DEBUG" /D "MI_DEBUG=3" /D "_CONSOLE" /D "NOMINMAX" /D "_UNICODE" /D "UNICODE" -Xclang -std=c11 -fno-delayed-template-parsing -march=native -mmmx -msse -msse2 -msse3 -msse4.1 -msse4.2 -maes -mavx -mavx2 -mbmi -mbmi2 -mpopcnt -mf16c -mxsaveopt -mlzcnt -mfma -mpclmul -mxsave -mrdrnd -mfxsr -madx -Xclang -fforce-enable-int128 -Xclang -faligned-allocation -Xclang -pedantic -Xclang -ffast-math -Xclang -fcolor-diagnostics -Xclang -ffine-grained-bitfield-accesses -Xclang -ffixed-point -Xclang -fsized-deallocation -I"..\include" /Od /TC /MTd /sdl /GS /Gd /Zc:wchar_t alloc-aligned.c alloc.c heap.c init.c options.c page.c segment.c os.c stats.c
llvm-lib /OUT:"c:\vcpkg\installed\x64-windows-static\debug\lib\mimalloc-clang10-s-d.lib" /MACHINE:X64 alloc-aligned.obj alloc.obj heap.obj init.obj options.obj page.obj segment.obj os.obj stats.obj
del /Q *.obj
:: Secure.
clang-cl /c /w -m64 -fmsc-version=1927 -flto=thin /D "NDEBUG" /D "MI_SECURE=true" /D "_CONSOLE" /D "NOMINMAX" /D "_UNICODE" /D "UNICODE" -Xclang -std=c11 -fno-delayed-template-parsing -march=native -mmmx -msse -msse2 -msse3 -msse4.1 -msse4.2 -maes -mavx -mavx2 -mbmi -mbmi2 -mpopcnt -mf16c -mxsaveopt -mlzcnt -mfma -mpclmul -mxsave -mrdrnd -mfxsr -madx -Xclang -fforce-enable-int128 -Xclang -faligned-allocation -Xclang -pedantic -Xclang -ffast-math -Xclang -fcolor-diagnostics -Xclang -ffine-grained-bitfield-accesses -Xclang -ffixed-point -Xclang -fsized-deallocation -I"..\include" /O2 /Qvec /TC /MT /GS- /Gy /Gd /Zc:wchar_t alloc-aligned.c alloc.c heap.c init.c options.c page.c segment.c os.c stats.c
llvm-lib /OUT:"c:\vcpkg\installed\x64-windows-static\lib\mimalloc-secure-clang10-thin-lto-s.lib" /MACHINE:X64 alloc-aligned.obj alloc.obj heap.obj init.obj options.obj page.obj segment.obj os.obj stats.obj
del /Q *.obj
clang-cl /Z7 /c /w -m64 -fmsc-version=1927 -flto=thin /D "_DEBUG" /D "MI_DEBUG=3" /D "MI_SECURE=true" /D "_CONSOLE" /D "NOMINMAX" /D "_UNICODE" /D "UNICODE" -Xclang -std=c11 -fno-delayed-template-parsing -march=native -mmmx -msse -msse2 -msse3 -msse4.1 -msse4.2 -maes -mavx -mavx2 -mbmi -mbmi2 -mpopcnt -mf16c -mxsaveopt -mlzcnt -mfma -mpclmul -mxsave -mrdrnd -mfxsr -madx -Xclang -fforce-enable-int128 -Xclang -faligned-allocation -Xclang -pedantic -Xclang -ffast-math -Xclang -fcolor-diagnostics -Xclang -ffine-grained-bitfield-accesses -Xclang -ffixed-point -Xclang -fsized-deallocation -I"..\include" /Od /TC /MTd /sdl /GS /Gd /Zc:wchar_t alloc-aligned.c alloc.c heap.c init.c options.c page.c segment.c os.c stats.c
llvm-lib /OUT:"c:\vcpkg\installed\x64-windows-static\debug\lib\mimalloc-secure-clang10-thin-lto-s-d.lib" /MACHINE:X64 alloc-aligned.obj alloc.obj heap.obj init.obj options.obj page.obj segment.obj os.obj stats.obj
del /Q *.obj
clang-cl /c /w -m64 -fmsc-version=1927 /D "NDEBUG" /D "MI_SECURE=true" /D "_CONSOLE" /D "NOMINMAX" /D "_UNICODE" /D "UNICODE" -Xclang -std=c11 -fno-delayed-template-parsing -march=native -mmmx -msse -msse2 -msse3 -msse4.1 -msse4.2 -maes -mavx -mavx2 -mbmi -mbmi2 -mpopcnt -mf16c -mxsaveopt -mlzcnt -mfma -mpclmul -mxsave -mrdrnd -mfxsr -madx -Xclang -fforce-enable-int128 -Xclang -faligned-allocation -Xclang -pedantic -Xclang -ffast-math -Xclang -fcolor-diagnostics -Xclang -ffine-grained-bitfield-accesses -Xclang -ffixed-point -Xclang -fsized-deallocation -I"..\include" /O2 /Qvec /TC /MT /GS- /Gy /Gd /Zc:wchar_t alloc-aligned.c alloc.c heap.c init.c options.c page.c segment.c os.c stats.c
llvm-lib /OUT:"c:\vcpkg\installed\x64-windows-static\lib\mimalloc-secure-clang10-s.lib" /MACHINE:X64 alloc-aligned.obj alloc.obj heap.obj init.obj options.obj page.obj segment.obj os.obj stats.obj
del /Q *.obj
clang-cl /Z7 /c /w -m64 -fmsc-version=1927 /D "_DEBUG" /D "MI_DEBUG=3" /D "MI_SECURE=true" /D "_CONSOLE" /D "NOMINMAX" /D "_UNICODE" /D "UNICODE" -Xclang -std=c11 -fno-delayed-template-parsing -march=native -mmmx -msse -msse2 -msse3 -msse4.1 -msse4.2 -maes -mavx -mavx2 -mbmi -mbmi2 -mpopcnt -mf16c -mxsaveopt -mlzcnt -mfma -mpclmul -mxsave -mrdrnd -mfxsr -madx -Xclang -fforce-enable-int128 -Xclang -faligned-allocation -Xclang -pedantic -Xclang -ffast-math -Xclang -fcolor-diagnostics -Xclang -ffine-grained-bitfield-accesses -Xclang -ffixed-point -Xclang -fsized-deallocation -I"..\include" /Od /TC /MTd /sdl /GS /Gd /Zc:wchar_t alloc-aligned.c alloc.c heap.c init.c options.c page.c segment.c os.c stats.c
llvm-lib /OUT:"c:\vcpkg\installed\x64-windows-static\debug\lib\mimalloc-secure-clang10-s-d.lib" /MACHINE:X64 alloc-aligned.obj alloc.obj heap.obj init.obj options.obj page.obj segment.obj os.obj stats.obj
del /Q *.obj
:: Reverse fiddle with a bug in clang.
del /Q "c:\Program Files\LLVM\lib\clang\10.0.0\include\prfchwintrin.h"
rename "c:\Program Files\LLVM\lib\clang\10.0.0\include\prfchwintrin.h.tmp" "prfchwintrin.h"
cl /c /D "NDEBUG" /D "_CONSOLE" /D "NOMINMAX" /D "_UNICODE" /D "UNICODE" -I"..\include" /O2 /TC /MT /GS- /Gy /Gd /GL /Zc:wchar_t /arch:AVX2 /Zc:inline /fp:precise /Zc:forScope /nologo alloc-aligned.c alloc.c heap.c init.c options.c page.c segment.c os.c stats.c
lib /OUT:"c:\vcpkg\installed\x64-windows-static\lib\mimalloc-msvc142-ltcg-s.lib" /LTCG /MACHINE:X64 /SUBSYSTEM:CONSOLE /NOLOGO alloc-aligned.obj alloc.obj heap.obj init.obj options.obj page.obj segment.obj os.obj stats.obj
del /Q *.obj
cl /Z7 /c /D "_DEBUG" /D "MI_DEBUG=3" /D "_CONSOLE" /D "NOMINMAX" /D "_UNICODE" /D "UNICODE" -I"..\include" /Od /TC /MTd /sdl /GS /Gd /GL /Zc:wchar_t /arch:AVX2 /Zc:inline /fp:precise /Zc:forScope /nologo alloc-aligned.c alloc.c heap.c init.c options.c page.c segment.c os.c stats.c
lib /OUT:"c:\vcpkg\installed\x64-windows-static\debug\lib\mimalloc-msvc142-ltcg-s-d.lib" /LTCG /MACHINE:X64 /SUBSYSTEM:CONSOLE /NOLOGO alloc-aligned.obj alloc.obj heap.obj init.obj options.obj page.obj segment.obj os.obj stats.obj
del /Q *.obj
cl /c /D "NDEBUG" /D "_CONSOLE" /D "NOMINMAX" /D "_UNICODE" /D "UNICODE" -I"..\include" /O2 /TC /MT /GS- /Gy /Gd /Zc:wchar_t /arch:AVX2 /Zc:inline /fp:precise /Zc:forScope /nologo alloc-aligned.c alloc.c heap.c init.c options.c page.c segment.c os.c stats.c
lib /OUT:"c:\vcpkg\installed\x64-windows-static\lib\mimalloc-msvc142-s.lib" /MACHINE:X64 /SUBSYSTEM:CONSOLE /NOLOGO alloc-aligned.obj alloc.obj heap.obj init.obj options.obj page.obj segment.obj os.obj stats.obj
del /Q *.obj
cl /Z7 /c /D "_DEBUG" /D "MI_DEBUG=3" /D "_CONSOLE" /D "NOMINMAX" /D "_UNICODE" /D "UNICODE" -I"..\include" /Od /TC /MTd /sdl /GS /Gd /Zc:wchar_t /arch:AVX2 /Zc:inline /fp:precise /Zc:forScope /nologo alloc-aligned.c alloc.c heap.c init.c options.c page.c segment.c os.c stats.c
lib /OUT:"c:\vcpkg\installed\x64-windows-static\debug\lib\mimalloc-msvc142-s-d.lib" /MACHINE:X64 /SUBSYSTEM:CONSOLE /NOLOGO alloc-aligned.obj alloc.obj heap.obj init.obj options.obj page.obj segment.obj os.obj stats.obj
del /Q *.obj
:: Secure.
cl /c /D "NDEBUG" /D "MI_SECURE=true" /D "_CONSOLE" /D "NOMINMAX" /D "_UNICODE" /D "UNICODE" -I"..\include" /O2 /TC /MT /GS- /Gy /Gd /GL /Zc:wchar_t /arch:AVX2 /Zc:inline /fp:precise /Zc:forScope /nologo alloc-aligned.c alloc.c heap.c init.c options.c page.c segment.c os.c stats.c
lib /OUT:"c:\vcpkg\installed\x64-windows-static\lib\mimalloc-secure-msvc142-ltcg-s.lib" /LTCG /MACHINE:X64 /SUBSYSTEM:CONSOLE /NOLOGO alloc-aligned.obj alloc.obj heap.obj init.obj options.obj page.obj segment.obj os.obj stats.obj
del /Q *.obj
cl /Z7 /c /D "_DEBUG" /D "MI_DEBUG=3" /D "MI_SECURE=true" /D "_CONSOLE" /D "NOMINMAX" /D "_UNICODE" /D "UNICODE" -I"..\include" /Od /TC /MTd /sdl /GS /Gd /GL /Zc:wchar_t /arch:AVX2 /Zc:inline /fp:precise /Zc:forScope /nologo alloc-aligned.c alloc.c heap.c init.c options.c page.c segment.c os.c stats.c
lib /OUT:"c:\vcpkg\installed\x64-windows-static\debug\lib\mimalloc-secure-msvc142-ltcg-s-d.lib" /LTCG /MACHINE:X64 /SUBSYSTEM:CONSOLE /NOLOGO alloc-aligned.obj alloc.obj heap.obj init.obj options.obj page.obj segment.obj os.obj stats.obj
del /Q *.obj
cl /c /D "NDEBUG" /D "MI_SECURE=true" /D "_CONSOLE" /D "NOMINMAX" /D "_UNICODE" /D "UNICODE" -I"..\include" /O2 /TC /MT /GS- /Gy /Gd /Zc:wchar_t /arch:AVX2 /Zc:inline /fp:precise /Zc:forScope /nologo alloc-aligned.c alloc.c heap.c init.c options.c page.c segment.c os.c stats.c
lib /OUT:"c:\vcpkg\installed\x64-windows-static\lib\mimalloc-secure-msvc142-s.lib" /MACHINE:X64 /SUBSYSTEM:CONSOLE /NOLOGO alloc-aligned.obj alloc.obj heap.obj init.obj options.obj page.obj segment.obj os.obj stats.obj
del /Q *.obj
cl /Z7 /c /D "_DEBUG" /D "MI_DEBUG=3" /D "MI_SECURE=true" /D "_CONSOLE" /D "NOMINMAX" /D "_UNICODE" /D "UNICODE" -I"..\include" /Od /TC /MTd /sdl /GS /Gd /Zc:wchar_t /arch:AVX2 /Zc:inline /fp:precise /Zc:forScope /nologo alloc-aligned.c alloc.c heap.c init.c options.c page.c segment.c os.c stats.c
lib /OUT:"c:\vcpkg\installed\x64-windows-static\debug\lib\mimalloc-secure-msvc142-s-d.lib" /MACHINE:X64 /SUBSYSTEM:CONSOLE /NOLOGO alloc-aligned.obj alloc.obj heap.obj init.obj options.obj page.obj segment.obj os.obj stats.obj
del /Q *.obj
cd ..
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment