From 599a7f11c19b52eca82745b93c8b800dd375249a Mon Sep 17 00:00:00 2001 From: laokz Date: Mon, 27 Mar 2023 17:44:36 +0800 Subject: [PATCH] riscv64: Modify gcc specs to unconditional 'as-needed -latomic' RISC-V has no 1, 2 byte atomic instructions and gcc has no inlined subword atomic functions for RISC-V yet. Applications with these operations need to explicitly link against libatomic.so/.a. Gcc has inlined '%{pthread:... as-needed -latomic ...}' specs which works under '-pthread' prerequisite, but not work for many other scenarios. Modify all these applications build receipts would be mostly error- prone and easily lead to inconsistency. The patch modify gcc specs instead. But due to complex 2 stage buildings, we hack the static string enbedded in gcc binaries directly. With the patch, gcc will depend on atomic library, so add 'Requires'. The idea comes from ArchLinux, specially thanks to r-value@github, XieJiSS@github: https://github.com/felixonmars/archriscv-packages/pull/1096/files --- gcc.spec | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/gcc.spec b/gcc.spec index 0da483c..0697bf5 100644 --- a/gcc.spec +++ b/gcc.spec @@ -61,7 +61,7 @@ Summary: Various compilers (C, C++, Objective-C, ...) Name: gcc Version: %{gcc_version} -Release: 27 +Release: 28 License: GPLv3+ and GPLv3+ with exceptions and GPLv2+ with exceptions and LGPLv2+ and BSD URL: https://gcc.gnu.org @@ -102,6 +102,10 @@ Conflicts: gdb < 5.1-2 Requires: glibc-devel >= 2.17 Requires: libgcc >= %{version}-%{release} Requires: libgomp = %{version}-%{release} +%if %{build_libatomic} && "%{_arch}" == "riscv64" +Requires: libatomic = %{version}-%{release} +Requires: libatomic-static = %{version}-%{release} +%endif %if !%{build_ada} Obsoletes: gcc-gnat < %{version}-%{release} %endif @@ -832,6 +836,11 @@ make %{?_smp_mflags} BOOT_CFLAGS="$OPT_FLAGS" bootstrap make %{?_smp_mflags} BOOT_CFLAGS="$OPT_FLAGS" BOOT_LDFLAGS="-pie -Wl,-z,relro,-z,now" %endif +%ifarch riscv64 +# work around -latomic problem: https://github.com/riscv-collab/riscv-gcc/issues/12 +sed -i 's/%{pthread:--push-state --as-needed -latomic --pop-state}/ --push-state --as-needed -latomic --pop-state /' gcc/{xgcc,xg++} +%endif + # Build libgccjit separately, so that normal compiler binaries aren't -fpic # unnecessarily. mkdir objlibgccjit @@ -2767,6 +2776,13 @@ end %doc rpm.doc/changelogs/libcc1/ChangeLog* %changelog +* Tue Apr 18 2023 laokz - 10.3.1-28 +- Type:Fix RISC-V +- ID:NA +- SUG:NA +- DESC:Enforce unconditional 'as-needed -latomic' of gcc specs. + Gcc main package dependency add atomic libraries. + * Wed Apr 12 2023 huangxiaoquan - 10.3.1-27 - Type:enhancement - ID:NA -- Gitee