From de823d904563649c87cff119af21bfeb8730ec44 Mon Sep 17 00:00:00 2001 From: Eric Long Date: Mon, 26 Jun 2023 21:59:07 +0800 Subject: [PATCH] addpatch: gcc12 Reused previous gcc patch with modifications. --- gcc12/libitm-riscv64.patch | 205 ++++++++++++++++++++++ gcc12/riscv64.patch | 120 +++++++++++++ gcc12/unfilter-default-library-path.patch | 22 +++ 3 files changed, 347 insertions(+) create mode 100644 gcc12/libitm-riscv64.patch create mode 100644 gcc12/riscv64.patch create mode 100644 gcc12/unfilter-default-library-path.patch diff --git a/gcc12/libitm-riscv64.patch b/gcc12/libitm-riscv64.patch new file mode 100644 index 000000000..2eca5855d --- /dev/null +++ b/gcc12/libitm-riscv64.patch @@ -0,0 +1,205 @@ +diff --git a/libitm/config/riscv/asm.h b/libitm/config/riscv/asm.h +new file mode 100644 +index 0000000..0f58bc1 +--- /dev/null ++++ b/libitm/config/riscv/asm.h +@@ -0,0 +1,28 @@ ++#ifndef _RV_ASM_H ++#define _RV_ASM_H ++ ++#if __riscv_xlen == 64 ++# define GPR_L ld ++# define GPR_S sd ++# define SZ_GPR 8 ++#elif __riscv_xlen == 32 ++# define GPR_L lw ++# define GPR_S sw ++# define SZ_GPR 4 ++#else ++# error Unsupported XLEN (must be 64-bit or 32-bit). ++#endif ++ ++#if defined(__riscv_flen) && __riscv_flen == 64 ++# define FPR_L fld ++# define FPR_S fsd ++# define SZ_FPR 8 ++#elif defined(__riscv_flen) && __riscv_flen == 32 ++# define FPR_L flw ++# define FPR_S fsw ++# define SZ_FPR 4 ++#else ++# define SZ_FPR 0 ++#endif ++ ++#endif /* _RV_ASM_H */ +diff --git a/libitm/config/riscv/sjlj.S b/libitm/config/riscv/sjlj.S +new file mode 100644 +index 0000000..b4e15fc +--- /dev/null ++++ b/libitm/config/riscv/sjlj.S +@@ -0,0 +1,120 @@ ++#include "asmcfi.h" ++#include "asm.h" ++ ++ .text ++ .align 2 ++ .global _ITM_beginTransaction ++ .type _ITM_beginTransaction, @function ++ ++_ITM_beginTransaction: ++ cfi_startproc ++ mv a1, sp ++ addi sp, sp, -(14*SZ_GPR+12*SZ_FPR) ++ cfi_adjust_cfa_offset(14*SZ_GPR+12*SZ_FPR) ++ ++ /* Return Address */ ++ GPR_S ra, 0*SZ_GPR(sp) ++ cfi_rel_offset(ra, 0*SZ_GPR) ++ ++ /* Caller's sp */ ++ GPR_S a1, 1*SZ_GPR(sp) ++ ++ /* Caller's s0/fp */ ++ GPR_S fp, 2*SZ_GPR(sp) ++ cfi_rel_offset(fp, 2*SZ_GPR) ++ ++ /* Callee-saved registers */ ++ GPR_S s1, 3*SZ_GPR(sp) ++ GPR_S s2, 4*SZ_GPR(sp) ++ GPR_S s3, 5*SZ_GPR(sp) ++ GPR_S s4, 6*SZ_GPR(sp) ++ GPR_S s5, 7*SZ_GPR(sp) ++ GPR_S s6, 8*SZ_GPR(sp) ++ GPR_S s7, 9*SZ_GPR(sp) ++ GPR_S s8, 10*SZ_GPR(sp) ++ GPR_S s9, 11*SZ_GPR(sp) ++ GPR_S s10, 12*SZ_GPR(sp) ++ GPR_S s11, 13*SZ_GPR(sp) ++ ++#if defined(__riscv_flen) ++ /* Callee-saved floating-point registers */ ++ FPR_S fs0, 0*SZ_FPR+14*SZ_GPR(sp) ++ FPR_S fs1, 1*SZ_FPR+14*SZ_GPR(sp) ++ FPR_S fs2, 2*SZ_FPR+14*SZ_GPR(sp) ++ FPR_S fs3, 3*SZ_FPR+14*SZ_GPR(sp) ++ FPR_S fs4, 4*SZ_FPR+14*SZ_GPR(sp) ++ FPR_S fs5, 5*SZ_FPR+14*SZ_GPR(sp) ++ FPR_S fs6, 6*SZ_FPR+14*SZ_GPR(sp) ++ FPR_S fs7, 7*SZ_FPR+14*SZ_GPR(sp) ++ FPR_S fs8, 8*SZ_FPR+14*SZ_GPR(sp) ++ FPR_S fs9, 9*SZ_FPR+14*SZ_GPR(sp) ++ FPR_S fs10, 10*SZ_FPR+14*SZ_GPR(sp) ++ FPR_S fs11, 11*SZ_FPR+14*SZ_GPR(sp) ++#endif ++ mv fp, sp ++ ++ /* Invoke GTM_begin_transaction with the struct we've just built. */ ++ mv a1, sp ++ jal ra, GTM_begin_transaction ++ ++ /* Return; we don't need to restore any of the call-saved regs. */ ++ GPR_L ra, 0*SZ_GPR(sp) ++ cfi_restore(ra) ++ GPR_L fp, 2*SZ_GPR(sp) ++ cfi_restore(fp) ++ ++ addi sp, sp, 14*SZ_GPR+12*SZ_FPR ++ cfi_adjust_cfa_offset(-(14*SZ_GPR+12*SZ_FPR)) ++ ++ ret ++ cfi_endproc ++ .size _ITM_beginTransaction, . - _ITM_beginTransaction ++ ++ .align 2 ++ .global GTM_longjmp ++ .hidden GTM_longjmp ++ .type GTM_longjmp, @function ++ ++GTM_longjmp: ++ /* The first parameter becomes the return value (x0). ++ The third parameter is ignored for now. */ ++ cfi_startproc ++ GPR_L s1, 3*SZ_GPR(a1) ++ GPR_L s2, 4*SZ_GPR(a1) ++ GPR_L s3, 5*SZ_GPR(a1) ++ GPR_L s4, 6*SZ_GPR(a1) ++ GPR_L s5, 7*SZ_GPR(a1) ++ GPR_L s6, 8*SZ_GPR(a1) ++ GPR_L s7, 9*SZ_GPR(a1) ++ GPR_L s8, 10*SZ_GPR(a1) ++ GPR_L s9, 11*SZ_GPR(a1) ++ GPR_L s10, 12*SZ_GPR(a1) ++ GPR_L s11, 13*SZ_GPR(a1) ++ ++#if defined(__riscv_flen) ++ FPR_L fs0, 0*SZ_FPR+14*SZ_GPR(a1) ++ FPR_L fs1, 1*SZ_FPR+14*SZ_GPR(a1) ++ FPR_L fs2, 2*SZ_FPR+14*SZ_GPR(a1) ++ FPR_L fs3, 3*SZ_FPR+14*SZ_GPR(a1) ++ FPR_L fs4, 4*SZ_FPR+14*SZ_GPR(a1) ++ FPR_L fs5, 5*SZ_FPR+14*SZ_GPR(a1) ++ FPR_L fs6, 6*SZ_FPR+14*SZ_GPR(a1) ++ FPR_L fs7, 7*SZ_FPR+14*SZ_GPR(a1) ++ FPR_L fs8, 8*SZ_FPR+14*SZ_GPR(a1) ++ FPR_L fs9, 9*SZ_FPR+14*SZ_GPR(a1) ++ FPR_L fs10, 10*SZ_FPR+14*SZ_GPR(a1) ++ FPR_L fs11, 11*SZ_FPR+14*SZ_GPR(a1) ++#endif ++ ++ GPR_L ra, 0*SZ_GPR(a1) ++ GPR_L fp, 2*SZ_GPR(a1) ++ GPR_L a3, 1*SZ_GPR(a1) ++ cfi_def_cfa(a1, 0) ++ mv sp, a3 ++ jr ra ++ cfi_endproc ++ .size GTM_longjmp, . - GTM_longjmp ++ ++#ifdef __linux__ ++.section .note.GNU-stack, "", @progbits ++#endif +diff --git a/libitm/config/riscv/target.h b/libitm/config/riscv/target.h +new file mode 100644 +index 0000000..b20de73 +--- /dev/null ++++ b/libitm/config/riscv/target.h +@@ -0,0 +1,26 @@ ++namespace GTM HIDDEN { ++ ++typedef struct gtm_jmpbuf ++ { ++ long int pc; ++ void *cfa; ++ long int s[12]; /* Saved registers, s0 is fp */ ++ ++ /* FP saved registers */ ++#if defined(__riscv_flen) && __riscv_flen == 64 ++ double fs[12]; ++#elif defined(__riscv_flen) && __riscv_flen == 32 ++ float fs[12]; ++#endif ++ } gtm_jmpbuf; ++ ++/* ??? The size of one line in hardware caches (in bytes). */ ++#define HW_CACHELINE_SIZE 64 ++ ++static inline void ++cpu_relax (void) ++{ ++ __asm__ volatile ("" : : : "memory"); ++} ++ ++} // namespace GTM +diff --git a/libitm/configure.tgt b/libitm/configure.tgt +index 4c0e78c..635c1d4 100644 +--- a/libitm/configure.tgt ++++ b/libitm/configure.tgt +@@ -82,6 +82,8 @@ EOF + + loongarch*) ARCH=loongarch ;; + ++ riscv*) ARCH=riscv ;; ++ + sh*) ARCH=sh ;; + + sparc) diff --git a/gcc12/riscv64.patch b/gcc12/riscv64.patch new file mode 100644 index 000000000..19fe0f3f0 --- /dev/null +++ b/gcc12/riscv64.patch @@ -0,0 +1,120 @@ +--- PKGBUILD ++++ PKGBUILD +@@ -20,7 +20,6 @@ url='https://gcc.gnu.org' + makedepends=( + binutils + doxygen +- gcc-ada + gcc-d + git + libisl +@@ -39,6 +38,8 @@ options=(!emptydirs !lto) + _libdir=usr/lib/gcc/$CHOST/${pkgver%%+*} + source=(git+https://sourceware.org/git/gcc.git#commit=${_commit} + c89 c99 ++ libitm-riscv64.patch ++ unfilter-default-library-path.patch + ) + validpgpkeys=(F3691687D867B81B51CE07D9BBE43771487328A9 # bpiotrowski@archlinux.org + 86CFFCA918CF3AF47147588051E8B148A9999C34 # evangelos@foutrelis.com +@@ -46,7 +47,9 @@ validpgpkeys=(F3691687D867B81B51CE07D9BBE43771487328A9 # bpiotrowski@archlinux. + D3A93CAD751C2AF4F8C7AD516C35B99309B5FA62) # Jakub Jelinek + sha256sums=('SKIP' + 'de48736f6e4153f03d0a5d38ceb6c6fdb7f054e8f47ddd6af0a3dbf14f27b931' +- '2513c6d9984dd0a2058557bf00f06d8d5181734e41dcfe07be7ed86f2959622a') ++ '2513c6d9984dd0a2058557bf00f06d8d5181734e41dcfe07be7ed86f2959622a' ++ '8a71bbb41463fb0e8518d5cff671097704fb8b01867ea224b8ebfe6ba3e4f6d6' ++ '7183fdeea8fd148cf9dd03b0932f9d439b818a5ab3bc9a5e20d8e0b41c9e0efd') + + prepare() { + [[ ! -d gcc ]] && ln -s gcc-${pkgver/+/-} gcc +@@ -58,6 +61,12 @@ prepare() { + # Arch Linux installs x86_64 libraries /lib + sed -i '/m64=/s/lib64/lib/' gcc/config/i386/t-linux64 + ++ # libitm riscv ++ patch -Np1 < ../libitm-riscv64.patch ++ ++ # Remove codes filtering default library paths to make mold work correctly ++ patch -Np1 < ../unfilter-default-library-path.patch ++ + mkdir -p "$srcdir/gcc-build" + } + +@@ -117,6 +126,10 @@ build() { + + # make documentation + make -O -C $CHOST/libstdc++-v3/doc doc-man-doxygen ++ ++ # Patch spec strings embedded in binaries ++ sed -i 's/%{pthread:--push-state --as-needed -latomic --pop-state}/ --push-state --as-needed -latomic --pop-state /' gcc/xgcc ++ sed -i 's/%{pthread:--push-state --as-needed -latomic --pop-state}/ --push-state --as-needed -latomic --pop-state /' gcc/xg++ + } + + check() { +@@ -130,12 +143,10 @@ check() { + package_gcc12-libs() { + pkgdesc='Runtime libraries shipped by GCC (12.x.x)' + depends=('glibc>=2.27') +- options=(!emptydirs !strip) ++ options=(!emptydirs !strip staticlibs) + + cd gcc-build + make -C $CHOST/libgcc DESTDIR="$pkgdir" install-shared +- mv "${pkgdir}/${_libdir}"/../lib/* "${pkgdir}/${_libdir}" +- rmdir "${pkgdir}/${_libdir}"/../lib + rm -f "$pkgdir/$_libdir/libgcc_eh.a" + + for lib in libatomic \ +@@ -143,9 +154,8 @@ package_gcc12-libs() { + libgomp \ + libitm \ + libquadmath \ +- libsanitizer/{a,l,ub,t}san \ +- libstdc++-v3/src \ +- libvtv; do ++ libsanitizer/{a,l,ub}san \ ++ libstdc++-v3/src; do + make -C $CHOST/$lib DESTDIR="$pkgdir" install-toolexeclibLTLIBRARIES + done + +@@ -158,6 +168,9 @@ package_gcc12-libs() { + install -Dm644 "$srcdir/gcc/COPYING.RUNTIME" \ + "$pkgdir/usr/share/licenses/gcc12-libs/RUNTIME.LIBRARY.EXCEPTION" + ++ # Remove static library (.a) files except libatomic.a ++ find "$pkgdir" -name '*.a' ! -name libatomic.a -delete ++ + # remove conflicting files + rm -rf "${pkgdir}"/usr/share/locale + } +@@ -175,7 +188,8 @@ package_gcc12() { + install -m755 -t "$pkgdir/${_libdir}/" gcc/{cc1,cc1plus,collect2,lto1,gcov{,-tool}} + + make -C $CHOST/libgcc DESTDIR="$pkgdir" install +- rm -f "$pkgdir"/usr/lib/libgcc_s.so* ++ rm -rf "$pkgdir/${_libdir}"/../lib ++ rm -f "$pkgdir/${_libdir}"/libgcc_s.so* + + make -C $CHOST/libstdc++-v3/src DESTDIR="$pkgdir" install + make -C $CHOST/libstdc++-v3/include DESTDIR="$pkgdir" install +@@ -196,7 +210,6 @@ package_gcc12() { + make -C $CHOST/libquadmath DESTDIR="$pkgdir" install-nodist_libsubincludeHEADERS + make -C $CHOST/libsanitizer DESTDIR="$pkgdir" install-nodist_{saninclude,toolexeclib}HEADERS + make -C $CHOST/libsanitizer/asan DESTDIR="$pkgdir" install-nodist_toolexeclibHEADERS +- make -C $CHOST/libsanitizer/tsan DESTDIR="$pkgdir" install-nodist_toolexeclibHEADERS + make -C $CHOST/libsanitizer/lsan DESTDIR="$pkgdir" install-nodist_toolexeclibHEADERS + + make -C libcpp DESTDIR="$pkgdir" install +@@ -206,9 +219,9 @@ package_gcc12() { + ln -s gcc "$pkgdir"/usr/bin/cc-12 + + # create cc-rs compatible symlinks +- # https://github.com/rust-lang/cc-rs/blob/1.0.73/src/lib.rs#L2578-L2581 ++ # https://github.com/rust-lang/cc-rs/blob/1.0.73/src/lib.rs#L2624 + for binary in {c++,g++,gcc,gcc-ar,gcc-nm,gcc-ranlib}; do +- ln -s /usr/bin/${binary} "${pkgdir}"/usr/bin/x86_64-linux-gnu-${binary}-12 ++ ln -s /usr/bin/${binary} "${pkgdir}"/usr/bin/riscv64-linux-gnu-${binary}-12 + done + + # POSIX conformance launcher scripts for c89 and c99 diff --git a/gcc12/unfilter-default-library-path.patch b/gcc12/unfilter-default-library-path.patch new file mode 100644 index 000000000..6a944dfcb --- /dev/null +++ b/gcc12/unfilter-default-library-path.patch @@ -0,0 +1,22 @@ +diff --git a/gcc/gcc.cc b/gcc/gcc.cc +index 16bb07f2cdc..1beb23ba279 100644 +--- a/gcc/gcc.cc ++++ b/gcc/gcc.cc +@@ -7904,17 +7904,6 @@ is_directory (const char *path1, bool linker) + *cp++ = '.'; + *cp = '\0'; + +- /* Exclude directories that the linker is known to search. */ +- if (linker +- && IS_DIR_SEPARATOR (path[0]) +- && ((cp - path == 6 +- && filename_ncmp (path + 1, "lib", 3) == 0) +- || (cp - path == 10 +- && filename_ncmp (path + 1, "usr", 3) == 0 +- && IS_DIR_SEPARATOR (path[4]) +- && filename_ncmp (path + 5, "lib", 3) == 0))) +- return 0; +- + return (stat (path, &st) >= 0 && S_ISDIR (st.st_mode)); + } +