From 24ea140d5faf56a845e01a686a0c687713bfdd6b Mon Sep 17 00:00:00 2001 From: Artur Sinila Date: Tue, 29 Jun 2021 03:30:50 +0300 Subject: [PATCH 1/2] New package: mimalloc-1.7.2 --- common/shlibs | 1 + srcpkgs/mimalloc-devel | 1 + .../mimalloc/patches/00-fix-cmakelists.patch | 20 ++++ srcpkgs/mimalloc/patches/01-fix-test.patch | 11 ++ srcpkgs/mimalloc/patches/03-libatomic.patch | 112 ++++++++++++++++++ ...4-remove-secure-suffix-from-basename.patch | 15 +++ srcpkgs/mimalloc/template | 32 +++++ 7 files changed, 192 insertions(+) create mode 120000 srcpkgs/mimalloc-devel create mode 100644 srcpkgs/mimalloc/patches/00-fix-cmakelists.patch create mode 100644 srcpkgs/mimalloc/patches/01-fix-test.patch create mode 100644 srcpkgs/mimalloc/patches/03-libatomic.patch create mode 100644 srcpkgs/mimalloc/patches/04-remove-secure-suffix-from-basename.patch create mode 100644 srcpkgs/mimalloc/template diff --git a/common/shlibs b/common/shlibs index 8a7eef8df8c3..79fd2f5c3de0 100644 --- a/common/shlibs +++ b/common/shlibs @@ -417,6 +417,7 @@ libMAC.so.6 libMAC-5.28_1 libmad.so.0 libmad-0.15.1b_1 libmatroska.so.7 libmatroska-1.6.0_1 libmatrix_client.so.0.5.1 mtxclient-0.5.1_1 +libmimalloc.so.1.7 mimalloc-1.7.2_1 libebml.so.5 libebml-1.4.0_1 libdvdread.so.8 libdvdread-6.1.1_1 libdvdnav.so.4 libdvdnav-4.1.3_1 diff --git a/srcpkgs/mimalloc-devel b/srcpkgs/mimalloc-devel new file mode 120000 index 000000000000..9af584a917a5 --- /dev/null +++ b/srcpkgs/mimalloc-devel @@ -0,0 +1 @@ +mimalloc \ No newline at end of file diff --git a/srcpkgs/mimalloc/patches/00-fix-cmakelists.patch b/srcpkgs/mimalloc/patches/00-fix-cmakelists.patch new file mode 100644 index 000000000000..1d18ccd7d859 --- /dev/null +++ b/srcpkgs/mimalloc/patches/00-fix-cmakelists.patch @@ -0,0 +1,20 @@ +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -210,7 +210,7 @@ endif() + if (MI_INSTALL_TOPLEVEL) + set(mi_install_libdir "lib") + set(mi_install_incdir "include") +- set(mi_install_cmakedir "cmake") ++ set(mi_install_cmakedir "share/cmake") + else() + set(mi_install_libdir "lib/mimalloc-${mi_version}") + set(mi_install_incdir "include/mimalloc-${mi_version}") +@@ -224,7 +224,7 @@ else() + endif() + + string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LC) +-if(NOT(CMAKE_BUILD_TYPE_LC MATCHES "^(release|relwithdebinfo|minsizerel)$")) ++if(NOT(CMAKE_BUILD_TYPE_LC MATCHES "^(release|relwithdebinfo|minsizerel|none)$")) + set(mi_basename "${mi_basename}-${CMAKE_BUILD_TYPE_LC}") #append build type (e.g. -debug) if not a release version + endif() + if(MI_BUILD_SHARED) diff --git a/srcpkgs/mimalloc/patches/01-fix-test.patch b/srcpkgs/mimalloc/patches/01-fix-test.patch new file mode 100644 index 000000000000..f1c35c37ea28 --- /dev/null +++ b/srcpkgs/mimalloc/patches/01-fix-test.patch @@ -0,0 +1,11 @@ +--- a/test/test-api.c ++++ b/test/test-api.c +@@ -83,7 +83,7 @@ int main() { + void* p = mi_malloc(0); mi_free(p); + }); + CHECK_BODY("malloc-nomem1",{ +- result = (mi_malloc(SIZE_MAX/2) == NULL); ++ result = (mi_malloc((size_t)PTRDIFF_MAX + (size_t)1) == NULL); + }); + CHECK_BODY("malloc-null",{ + mi_free(NULL); diff --git a/srcpkgs/mimalloc/patches/03-libatomic.patch b/srcpkgs/mimalloc/patches/03-libatomic.patch new file mode 100644 index 000000000000..ca9af8ddfb1a --- /dev/null +++ b/srcpkgs/mimalloc/patches/03-libatomic.patch @@ -0,0 +1,112 @@ +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -203,6 +203,9 @@ else() + endif() + endif() + ++include("cmake/atomic.cmake") ++list(APPEND mi_libraries ${CMAKE_REQUIRED_LIBRARIES}) ++ + # ----------------------------------------------------------------------------- + # Install and output names + # ----------------------------------------------------------------------------- +--- /dev/null ++++ b/cmake/atomic.cmake +@@ -0,0 +1,97 @@ ++# Based on: ++# https://github.com/llvm/llvm-project/blob/d4dcb55c7050fd908af2378fa551078d859d994f/llvm/cmake/modules/DetermineGCCCompatible.cmake ++# https://github.com/llvm/llvm-project/blob/d4dcb55c7050fd908af2378fa551078d859d994f/llvm/cmake/modules/CheckAtomic.cmake ++ ++INCLUDE(CheckCXXSourceCompiles) ++INCLUDE(CheckLibraryExists) ++ ++# Determine if the compiler has GCC-compatible command-line syntax. ++ ++if(CMAKE_COMPILER_IS_GNUCXX) ++ set(COMPILER_IS_GCC_COMPATIBLE ON) ++elseif( MSVC ) ++ set(COMPILER_IS_GCC_COMPATIBLE OFF) ++elseif( "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" ) ++ set(COMPILER_IS_GCC_COMPATIBLE ON) ++elseif( "${CMAKE_CXX_COMPILER_ID}" MATCHES "Intel" ) ++ set(COMPILER_IS_GCC_COMPATIBLE ON) ++endif() ++ ++# Sometimes linking against libatomic is required for atomic ops, if ++# the platform doesn't support lock-free atomics. ++ ++function(check_working_cxx_atomics varname) ++ set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) ++ set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -std=c++11") ++ CHECK_CXX_SOURCE_COMPILES(" ++#include ++std::atomic x; ++std::atomic y; ++std::atomic z; ++int main() { ++ ++z; ++ ++y; ++ return ++x; ++} ++" ${varname}) ++ set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS}) ++endfunction(check_working_cxx_atomics) ++ ++function(check_working_cxx_atomics64 varname) ++ set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) ++ set(CMAKE_REQUIRED_FLAGS "-std=c++11 ${CMAKE_REQUIRED_FLAGS}") ++ CHECK_CXX_SOURCE_COMPILES(" ++#include ++#include ++std::atomic x (0); ++int main() { ++ uint64_t i = x.load(std::memory_order_relaxed); ++ (void)i; ++ return 0; ++} ++" ${varname}) ++ set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS}) ++endfunction(check_working_cxx_atomics64) ++ ++ ++# Check for (non-64-bit) atomic operations. ++if(MSVC) ++ set(HAVE_CXX_ATOMICS_WITHOUT_LIB True) ++elseif(COMPILER_IS_GCC_COMPATIBLE) ++ # First check if atomics work without the library. ++ check_working_cxx_atomics(HAVE_CXX_ATOMICS_WITHOUT_LIB) ++ # If not, check if the library exists, and atomics work with it. ++ if(NOT HAVE_CXX_ATOMICS_WITHOUT_LIB) ++ check_library_exists(atomic __atomic_fetch_add_4 "" HAVE_LIBATOMIC) ++ if(HAVE_LIBATOMIC) ++ list(APPEND CMAKE_REQUIRED_LIBRARIES "atomic") ++ check_working_cxx_atomics(HAVE_CXX_ATOMICS_WITH_LIB) ++ if (NOT HAVE_CXX_ATOMICS_WITH_LIB) ++ message(FATAL_ERROR "Host compiler must support std::atomic!") ++ endif() ++ else() ++ message(FATAL_ERROR "Host compiler appears to require libatomic, but cannot find it.") ++ endif() ++ endif() ++endif() ++ ++# Check for 64 bit atomic operations. ++if(MSVC) ++ set(HAVE_CXX_ATOMICS64_WITHOUT_LIB True) ++elseif(COMPILER_IS_GCC_COMPATIBLE) ++ # First check if atomics work without the library. ++ check_working_cxx_atomics64(HAVE_CXX_ATOMICS64_WITHOUT_LIB) ++ # If not, check if the library exists, and atomics work with it. ++ if(NOT HAVE_CXX_ATOMICS64_WITHOUT_LIB) ++ check_library_exists(atomic __atomic_load_8 "" HAVE_CXX_LIBATOMICS64) ++ if(HAVE_CXX_LIBATOMICS64) ++ list(APPEND CMAKE_REQUIRED_LIBRARIES "atomic") ++ check_working_cxx_atomics64(HAVE_CXX_ATOMICS64_WITH_LIB) ++ if (NOT HAVE_CXX_ATOMICS64_WITH_LIB) ++ message(FATAL_ERROR "Host compiler must support 64-bit std::atomic!") ++ endif() ++ else() ++ message(FATAL_ERROR "Host compiler appears to require libatomic for 64-bit operations, but cannot find it.") ++ endif() ++ endif() ++endif() diff --git a/srcpkgs/mimalloc/patches/04-remove-secure-suffix-from-basename.patch b/srcpkgs/mimalloc/patches/04-remove-secure-suffix-from-basename.patch new file mode 100644 index 000000000000..604df22d38ce --- /dev/null +++ b/srcpkgs/mimalloc/patches/04-remove-secure-suffix-from-basename.patch @@ -0,0 +1,15 @@ +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -220,11 +220,7 @@ else() + set(mi_install_cmakedir "share/mimalloc-${mi_version}/cmake") + endif() + +-if(MI_SECURE) +- set(mi_basename "mimalloc-secure") +-else() +- set(mi_basename "mimalloc") +-endif() ++set(mi_basename "mimalloc") + + string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LC) + if(NOT(CMAKE_BUILD_TYPE_LC MATCHES "^(release|relwithdebinfo|minsizerel|none)$")) diff --git a/srcpkgs/mimalloc/template b/srcpkgs/mimalloc/template new file mode 100644 index 000000000000..fa14ba485b6c --- /dev/null +++ b/srcpkgs/mimalloc/template @@ -0,0 +1,32 @@ +# Template file for 'mimalloc' +pkgname=mimalloc +version=1.7.2 +revision=1 +build_style=cmake +configure_args="-DMI_INSTALL_TOPLEVEL=ON -DMI_SECURE=ON" +short_desc="MIcrosoft's malloc" +maintainer="Artur Sinila " +license="MIT" +homepage="https://github.com/microsoft/mimalloc" +distfiles="https://github.com/microsoft/mimalloc/archive/refs/tags/v${version}.tar.gz" +checksum=b1912e354565a4b698410f7583c0f83934a6dbb3ade54ab7ddcb1569320936bd + +if [ "$XBPS_TARGET_NO_ATOMIC8" ]; then + makedepends+=" libatomic-devel" +fi + +post_install() { + vlicense LICENSE +} + +mimalloc-devel_package() { + depends="${pkgname}>=${version}_${revision}" + short_desc+=" - development files" + pkg_install() { + vmove usr/include + vmove usr/share/cmake + vmove usr/lib/*.a + vmove usr/lib/*.o + vmove usr/lib/*.so + } +} From 4a8ae0bbfaf8b18f23d5cf796640d1d39da39371 Mon Sep 17 00:00:00 2001 From: Artur Sinila Date: Tue, 29 Jun 2021 03:31:54 +0300 Subject: [PATCH 2/2] New package: mold-0.9.1 --- srcpkgs/mold/patches/00-makefile.patch | 84 ++++++++++++++++++++ srcpkgs/mold/patches/01-grep-pcre-test.patch | 14 ++++ srcpkgs/mold/template | 46 +++++++++++ 3 files changed, 144 insertions(+) create mode 100644 srcpkgs/mold/patches/00-makefile.patch create mode 100644 srcpkgs/mold/patches/01-grep-pcre-test.patch create mode 100644 srcpkgs/mold/template diff --git a/srcpkgs/mold/patches/00-makefile.patch b/srcpkgs/mold/patches/00-makefile.patch new file mode 100644 index 000000000000..9bb0594b6141 --- /dev/null +++ b/srcpkgs/mold/patches/00-makefile.patch @@ -0,0 +1,84 @@ +diff --git a/Makefile b/Makefile +index 207f54c..e20a55d 100644 +--- a/Makefile ++++ b/Makefile +@@ -1,15 +1,14 @@ + CC = clang + CXX = clang++ + +-MIMALLOC_LIB = mimalloc/out/release/libmimalloc.a +-GIT_HASH = $(shell [ -d .git ] && git rev-parse HEAD) ++GIT_HASH ?= $(shell [ -d .git ] && git rev-parse HEAD) + + CPPFLAGS = -g -Imimalloc/include -pthread -std=c++20 \ + -Wno-deprecated-volatile \ + -DMOLD_VERSION=\"0.9.1\" \ + -DGIT_HASH=\"$(GIT_HASH)\" \ + $(EXTRA_CPPFLAGS) +-LDFLAGS = $(EXTRA_LDFLAGS) ++LDFLAGS += $(EXTRA_LDFLAGS) + LIBS = -Wl,-as-needed -lcrypto -pthread -ltbb -lz -lxxhash -ldl + OBJS = main.o object_file.o input_sections.o output_chunks.o \ + mapfile.o perf.o linker_script.o archive_file.o output_file.o \ +@@ -41,7 +40,12 @@ else + # By default, we want to use mimalloc as a memory allocator. + # Since replacing the standard malloc is not compatible with ASAN, + # we do that only when ASAN is not enabled. +- LDFLAGS += -Wl,-whole-archive $(MIMALLOC_LIB) -Wl,-no-whole-archive ++ ifdef SYSTEM_MIMALLOC ++ LIBS += -lmimalloc ++ else ++ MIMALLOC_LIB = mimalloc/out/release/libmimalloc.a ++ LIBS += -Wl,-whole-archive $(MIMALLOC_LIB) -Wl,-no-whole-archive ++ endif + endif + + ifeq ($(TSAN), 1) +@@ -52,7 +56,7 @@ endif + all: mold mold-wrapper.so + + mold: $(OBJS) $(MIMALLOC_LIB) +- $(CXX) $(CFLAGS) $(OBJS) -o $@ $(LDFLAGS) $(LIBS) ++ $(CXX) $(CXXFLAGS) $(OBJS) -o $@ $(LDFLAGS) $(LIBS) + + mold-wrapper.so: mold-wrapper.c Makefile + $(CC) -fPIC -shared -o $@ $< -ldl +@@ -62,26 +66,27 @@ $(OBJS): mold.h elf.h Makefile + $(MIMALLOC_LIB): + mkdir -p mimalloc/out/release + (cd mimalloc/out/release; CFLAGS=-DMI_USE_ENVIRON=0 cmake ../..) +- $(MAKE) -C mimalloc/out/release ++ $(MAKE) -C mimalloc/out/release mimalloc-static + + test tests check: all + $(MAKE) -C test --output-sync --no-print-directory + + install: all +- install -m 755 mold $(PREFIX)/bin +- strip $(PREFIX)/bin/mold ++ install -m 755 mold $(DESTDIR)$(PREFIX)/bin ++ strip $(DESTDIR)$(PREFIX)/bin/mold + +- install -m 755 -d $(PREFIX)/lib/mold +- install -m 644 mold-wrapper.so $(PREFIX)/lib/mold +- strip $(PREFIX)/lib/mold/mold-wrapper.so ++ install -m 755 -d $(DESTDIR)$(PREFIX)/lib/mold ++ install -m 644 mold-wrapper.so $(DESTDIR)$(PREFIX)/lib/mold ++ strip $(DESTDIR)$(PREFIX)/lib/mold/mold-wrapper.so + +- install -m 644 docs/mold.1 $(PREFIX)/share/man/man1 +- rm -f $(PREFIX)/share/man/man1/mold.1.gz +- gzip -9 $(PREFIX)/share/man/man1/mold.1 ++ install -m 755 -d $(DESTDIR)$(PREFIX)/share/man/man1 ++ install -m 644 docs/mold.1 $(DESTDIR)$(PREFIX)/share/man/man1 ++ rm -f $(DESTDIR)$(PREFIX)/share/man/man1/mold.1.gz ++ gzip -9 $(DESTDIR)$(PREFIX)/share/man/man1/mold.1 + + uninstall: +- rm -rf $(PREFIX)/bin/mold $(PREFIX)/share/man/man1/mold.1.gz \ +- $(PREFIX)/lib/mold ++ rm -rf $(DESTDIR)$(PREFIX)/bin/mold $(DESTDIR)$(PREFIX)/share/man/man1/mold.1.gz \ ++ $(DESTDIR)$(PREFIX)/lib/mold + + clean: + rm -rf *.o *~ mold mold-wrapper.so test/tmp diff --git a/srcpkgs/mold/patches/01-grep-pcre-test.patch b/srcpkgs/mold/patches/01-grep-pcre-test.patch new file mode 100644 index 000000000000..34eb0222bc66 --- /dev/null +++ b/srcpkgs/mold/patches/01-grep-pcre-test.patch @@ -0,0 +1,14 @@ +# This patch is required because `chroot-grep` doesn't support PCRE. +# Adding ordinary `grep` to `checkdepends` won't work because `grep` conflicts with `chroot-grep`. +# So instead we use `ripgrep`, which is a tool similar to `grep`. +--- a/test/build-id.sh ++++ b/test/build-id.sh +@@ -12,7 +12,7 @@ readelf -n $t/exe | grep -qv 'GNU.*0x00000010.*NT_GNU_BUILD_ID' + + clang -o $t/exe $t/a.c -fuse-ld=`pwd`/../mold -Wl,-build-id=uuid + readelf -nW $t/exe | +- grep -Pq 'GNU.*0x00000010.*NT_GNU_BUILD_ID.*Build ID: ............4...[89abcdef]' ++ rg -Pq 'GNU.*0x00000010.*NT_GNU_BUILD_ID.*Build ID: ............4...[89abcdef]' + + clang -o $t/exe $t/a.c -fuse-ld=`pwd`/../mold -Wl,-build-id=md5 + readelf -n $t/exe | grep -q 'GNU.*0x00000010.*NT_GNU_BUILD_ID' diff --git a/srcpkgs/mold/template b/srcpkgs/mold/template new file mode 100644 index 000000000000..1c2f7f8bf0a3 --- /dev/null +++ b/srcpkgs/mold/template @@ -0,0 +1,46 @@ +# Template file for 'mold' +pkgname=mold +_commit_hash=9a09c777d9460ebe7eb498d1cc0327915f8bbcdc +version=0.9.1 +revision=1 +build_style=gnu-makefile +hostmakedepends="clang" +makedepends="mimalloc-devel openssl-devel xxHash-devel tbb-devel zlib-devel" +checkdepends="ripgrep libdwarf" +short_desc="High performance drop-in replacement for existing Unix linkers" +maintainer="Artur Sinila " +license="AGPL-3.0-or-later" +homepage="https://github.com/rui314/mold" +changelog="https://github.com/rui314/mold/releases" +distfiles="https://github.com/rui314/mold/archive/refs/tags/v${version}.tar.gz" +checksum=02b156de6cd2d94fea4eed9748a7c96955673d810ec672359f603f2f90e2990d + +# use system-wide installed mimalloc instead of the vendored one +export SYSTEM_MIMALLOC=1 + +pre_build() { + # gcc 10.2 doesn't fully support C++20 + # export CXX=clang++ + + # # fix cross + # if [ "$CROSS_BUILD" ]; then + # CXXFLAGS+=" -target ${XBPS_CROSS_TRIPLET}" + # CXXFLAGS+=" -I/usr/${XBPS_CROSS_TRIPLET}/usr/include/c++/10.2/${XBPS_CROSS_TRIPLET}" + # LDFLAGS+=" -L/usr/${XBPS_CROSS_TRIPLET}/lib" + # fi + + # "non-PIE executable found in PIE build" without these lines + # CXXFLAGS+=" -fPIC" + # LDFLAGS+=" -pie" + + # commit hash for --version + export GIT_HASH=$_commit_hash +} + +pre_install() { + vmkdir usr/bin +} + +post_install() { + vlicense LICENSE +}