From 76391c452693f12dc833516647f21a6f9cd4f9d7 Mon Sep 17 00:00:00 2001 From: Christoph Erhardt Date: Tue, 25 Jan 2022 19:46:31 +0100 Subject: [PATCH] Initial import (fedora#2036468). --- .gitignore | 1 + ...s-error-on-aarch64-with-_GLIBCXX_ASS.patch | 42 ++++++ bundled_lib_system_flags.patch | 30 +++++ mold.spec | 125 ++++++++++++++++++ sources | 1 + tbb-strip-werror.patch | 16 +++ 6 files changed, 215 insertions(+) create mode 100644 .gitignore create mode 100644 0001-Fix-out-of-bounds-error-on-aarch64-with-_GLIBCXX_ASS.patch create mode 100644 bundled_lib_system_flags.patch create mode 100644 mold.spec create mode 100644 sources create mode 100644 tbb-strip-werror.patch diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..306fe31 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/mold-1.0.2.tar.gz diff --git a/0001-Fix-out-of-bounds-error-on-aarch64-with-_GLIBCXX_ASS.patch b/0001-Fix-out-of-bounds-error-on-aarch64-with-_GLIBCXX_ASS.patch new file mode 100644 index 0000000..be1412e --- /dev/null +++ b/0001-Fix-out-of-bounds-error-on-aarch64-with-_GLIBCXX_ASS.patch @@ -0,0 +1,42 @@ +From 03ba8f93255055adaf69984c17bcfea3b22340db Mon Sep 17 00:00:00 2001 +Message-Id: <03ba8f93255055adaf69984c17bcfea3b22340db.1642970958.git.github@sicherha.de> +From: Christoph Erhardt +Date: Sun, 23 Jan 2022 21:42:21 +0100 +Subject: [PATCH] Fix out-of-bounds error on aarch64 with `_GLIBCXX_ASSERTIONS` + enabled + +While an iterator may point beyond the last element of a `std::span`, a +pointer may not. + +Fixes #298. + +Signed-off-by: Christoph Erhardt +--- + elf/arch-arm64.cc | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/elf/arch-arm64.cc b/elf/arch-arm64.cc +index aba86330..c608ae49 100644 +--- a/elf/arch-arm64.cc ++++ b/elf/arch-arm64.cc +@@ -574,7 +574,7 @@ static void create_thunks(Context &ctx, OutputSection &osec) { + thunk.offset = offset; + + // Scan relocations between B and C to collect symbols that need thunks. +- tbb::parallel_for_each(&members[b], &members[c], [&](InputSection *isec) { ++ tbb::parallel_for_each(members.begin() + b, members.begin() + c, [&](InputSection *isec) { + std::span> rels = isec->get_rels(ctx); + isec->range_extn.resize(rels.size()); + +@@ -619,7 +619,7 @@ static void create_thunks(Context &ctx, OutputSection &osec) { + } + + // Scan relocations again to fix symbol offsets in the last thunk. +- tbb::parallel_for_each(&members[b], &members[c], [&](InputSection *isec) { ++ tbb::parallel_for_each(members.begin() + b, members.begin() + c, [&](InputSection *isec) { + std::span> rels = isec->get_rels(ctx); + + for (i64 i = 0; i < rels.size(); i++) { +-- +2.34.1 + diff --git a/bundled_lib_system_flags.patch b/bundled_lib_system_flags.patch new file mode 100644 index 0000000..e5704e0 --- /dev/null +++ b/bundled_lib_system_flags.patch @@ -0,0 +1,30 @@ +From 06537164083e0af844224651bf7e7c7340a47675 Mon Sep 17 00:00:00 2001 +Message-Id: <06537164083e0af844224651bf7e7c7340a47675.1642950243.git.github@sicherha.de> +From: Christoph Erhardt +Date: Sun, 23 Jan 2022 14:28:45 +0100 +Subject: [PATCH] Pass `CXXFLAGS` to bundled tbb + +This makes work easier for distributions that specify custom hardened +compiler flags. + +Signed-off-by: Christoph Erhardt +--- + Makefile | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/Makefile b/Makefile +index e2d7cd97..913ac97a 100644 +--- a/Makefile ++++ b/Makefile +@@ -147,7 +147,7 @@ $(MIMALLOC_LIB): + + $(TBB_LIB): + mkdir -p out/tbb +- (cd out/tbb; cmake -G'Unix Makefiles' -DBUILD_SHARED_LIBS=OFF -DTBB_TEST=OFF -DCMAKE_CXX_FLAGS=-D__TBB_DYNAMIC_LOAD_ENABLED=0 -DTBB_STRICT=OFF ../../third-party/tbb) ++ (cd out/tbb; cmake -G'Unix Makefiles' -DBUILD_SHARED_LIBS=OFF -DTBB_TEST=OFF -DCMAKE_CXX_FLAGS="$(CXXFLAGS) -D__TBB_DYNAMIC_LOAD_ENABLED=0" -DTBB_STRICT=OFF ../../third-party/tbb) + $(MAKE) -C out/tbb tbb + (cd out/tbb; ln -sf *_relwithdebinfo libs) + +-- +2.34.1 + diff --git a/mold.spec b/mold.spec new file mode 100644 index 0000000..8f77e35 --- /dev/null +++ b/mold.spec @@ -0,0 +1,125 @@ +Name: mold +Version: 1.0.2 +Release: 1%{?dist} +Summary: A Modern Linker + +License: AGPLv3+ +URL: https://github.com/rui314/mold +Source0: %{url}/archive/v%{version}/%{name}-%{version}.tar.gz + +# The bundled build system for tbb tries to strip all Werror from the +# CFLAGS/CXXFLAGS when not building in strict mode (mold doesn't use strict +# mode). We don't want that because it causes the "Werror=format-security" +# option to become "=format-security" and break the build. (similar to a patch +# in the Fedora tbb package) +Patch0: tbb-strip-werror.patch + +# Pass the system's CXXFLAGS and CFLAGS to the bundled libraries to ensure they +# are built with all the Fedora hardening flags and with PIE (otherwise the +# linker errors linking non-PIE code with PIE code). +Patch1: bundled_lib_system_flags.patch + +# Fix for failed assertion on aarch64 +Patch2: 0001-Fix-out-of-bounds-error-on-aarch64-with-_GLIBCXX_ASS.patch + +# mold can currently produce native binaries for these architectures only +ExclusiveArch: x86_64 %{ix86} aarch64 + +BuildRequires: cmake +BuildRequires: gcc +%if 0%{?el7} +BuildRequires: devtoolset-10-toolchain +%endif +%if 0%{?el8} +BuildRequires: gcc-toolset-10-toolchain +%endif +%if 0%{!?el7} && 0%{!?el8} +BuildRequires: gcc-c++ >= 10 +%endif +%if 0%{?fedora} +BuildRequires: libdwarf-tools +%endif +BuildRequires: mimalloc-devel +BuildRequires: openssl-devel +BuildRequires: xxhash-devel +BuildRequires: zlib-devel + +# The following packages are only required for executing the tests +BuildRequires: clang +BuildRequires: glibc-static +%ifarch x86_64 +BuildRequires: glibc-static(x86-32) +%endif +BuildRequires: libstdc++-static + +Requires(post): %{_sbindir}/alternatives +Requires(preun): %{_sbindir}/alternatives + +# API-incompatible with older tbb 2020.3 currently shipped by Fedora: +# https://bugzilla.redhat.com/show_bug.cgi?id=2036372 +Provides: bundled(tbb) = 2021.3 + +%define build_args PREFIX=%{_prefix} LIBDIR=%{_libdir} CC=gcc CXX=g++ CFLAGS="%{build_cflags}" CXXFLAGS="%{build_cxxflags}" LDFLAGS="%{build_ldflags}" STRIP=echo SYSTEM_MIMALLOC=1 SYSTEM_XXHASH=1 + +%description +mold is a multi-threaded, high-performance linker that is several times faster +than the industry-standard ones, namely, GNU ld, GNU gold or LLVM lld. It is +developed as a drop-in replacement for these linkers and command-line compatible +with them with a few exceptions. + +%prep +%autosetup -p1 +rm -r third-party/{mimalloc,xxhash} + +%build +%if 0%{?el7} +. /opt/rh/devtoolset-10/enable +%endif +%if 0%{?el8} +. /opt/rh/gcc-toolset-10/enable +%endif +%make_build %{build_args} + +%install +%make_install %{build_args} +# Overwrite absolute symlink with relative symlink +ln -srf %{buildroot}%{_bindir}/mold %{buildroot}%{_libexecdir}/mold/ld +chmod +x %{buildroot}%{_libdir}/mold/mold-wrapper.so + +%post +if [ "$1" = 1 ]; then + %{_sbindir}/alternatives --install %{_bindir}/ld ld %{_bindir}/ld.mold 1 +fi + +%postun +if [ "$1" = 0 ]; then + %{_sbindir}/alternatives --remove ld %{_bindir}/ld.mold +fi + +%check +%if 0%{?el7} +. /opt/rh/devtoolset-10/enable +%endif +%if 0%{?el8} +. /opt/rh/gcc-toolset-10/enable +%endif +%make_build %{build_args} test + +%files +%license LICENSE +%ghost %{_bindir}/ld +%{_bindir}/mold +%{_bindir}/ld.mold +%{_bindir}/ld64.mold +%{_libdir}/mold +%{_libdir}/mold/mold-wrapper.so +%{_libexecdir}/mold +%{_libexecdir}/mold/ld +%{_mandir}/man1/mold.1* + +%changelog +* Sun Jan 23 2022 Christoph Erhardt - 1.0.2-1 +- Bump version to 1.0.2. + +* Sat Jan 01 2022 Christoph Erhardt - 1.0.1-1 +- Initial package for version 1.0.1. diff --git a/sources b/sources new file mode 100644 index 0000000..59c74a6 --- /dev/null +++ b/sources @@ -0,0 +1 @@ +SHA512 (mold-1.0.2.tar.gz) = 27f6664e63c76c32a6e3ec8bfc4b204138926001f5431be94da9ce47a5d9d3b51aa634c5cd6df45be660d52ac0507f7b7eec17134e35db402db5747d2ecc3715 diff --git a/tbb-strip-werror.patch b/tbb-strip-werror.patch new file mode 100644 index 0000000..fe489ea --- /dev/null +++ b/tbb-strip-werror.patch @@ -0,0 +1,16 @@ +diff --git a/third-party/tbb/cmake/compilers/GNU.cmake b/third-party/tbb/cmake/compilers/GNU.cmake +index 902fa786..9c364803 100644 +--- a/third-party/tbb/cmake/compilers/GNU.cmake ++++ b/third-party/tbb/cmake/compilers/GNU.cmake +@@ -44,11 +44,6 @@ endif() + set(TBB_COMMON_LINK_LIBS dl) + endif() + +-# Ignore -Werror set through add_compile_options() or added to CMAKE_CXX_FLAGS if TBB_STRICT is disabled. +-if (NOT TBB_STRICT AND COMMAND tbb_remove_compile_flag) +- tbb_remove_compile_flag(-Werror) +-endif() +- + if (NOT ${CMAKE_CXX_COMPILER_ID} STREQUAL Intel) + # gcc 6.0 and later have -flifetime-dse option that controls elimination of stores done outside the object lifetime + set(TBB_DSE_FLAG $<$>:-flifetime-dse=1>)