From 3b84ae50486c528d83218c861d2311fe116e3d61 Mon Sep 17 00:00:00 2001 From: falkTX Date: Wed, 25 Oct 2023 23:29:00 +0200 Subject: [PATCH] Add patch to skip optimizations on glibc memset for dwarf Signed-off-by: falkTX --- bootstrap.sh | 4 + .../0004-non-optimized-memset.patch | 437 ++++++++++++++++++ 2 files changed, 441 insertions(+) create mode 100644 patches/crosstool-ng-1.25.0/glibc-2.27-dwarf/0004-non-optimized-memset.patch diff --git a/bootstrap.sh b/bootstrap.sh index e5db6202..545476b7 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -52,6 +52,10 @@ if [ ! -f ${TOOLCHAIN_BUILD_DIR}/${CT_NG_VERSION}/configure ]; then elif [ "${CT_NG_VERSION}" = "crosstool-ng-1.25.0" ]; then cp ${SOURCE_DIR}/patches/${CT_NG_VERSION}/glibc-2.27/*.patch ${TOOLCHAIN_BUILD_DIR}/${CT_NG_VERSION}/packages/glibc/2.27/ cp ${SOURCE_DIR}/patches/${CT_NG_VERSION}/glibc-2.35/*.patch ${TOOLCHAIN_BUILD_DIR}/${CT_NG_VERSION}/packages/glibc/2.35/ + + if [ "${TOOLCHAIN_PLATFORM}" == "moddwarf-new" ]; then + cp ${SOURCE_DIR}/patches/${CT_NG_VERSION}/glibc-2.27-dwarf/*.patch ${TOOLCHAIN_BUILD_DIR}/${CT_NG_VERSION}/packages/glibc/2.27/ + fi fi fi diff --git a/patches/crosstool-ng-1.25.0/glibc-2.27-dwarf/0004-non-optimized-memset.patch b/patches/crosstool-ng-1.25.0/glibc-2.27-dwarf/0004-non-optimized-memset.patch new file mode 100644 index 00000000..daf8c68f --- /dev/null +++ b/patches/crosstool-ng-1.25.0/glibc-2.27-dwarf/0004-non-optimized-memset.patch @@ -0,0 +1,437 @@ +diff --git a/sysdeps/aarch64/multiarch/ifunc-impl-list.c b/sysdeps/aarch64/multiarch/ifunc-impl-list.c +index f84956c..987d7a1 100644 +--- a/sysdeps/aarch64/multiarch/ifunc-impl-list.c ++++ b/sysdeps/aarch64/multiarch/ifunc-impl-list.c +@@ -46,11 +46,6 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array, + IFUNC_IMPL_ADD (array, i, memmove, 1, __memmove_thunderx) + IFUNC_IMPL_ADD (array, i, memmove, 1, __memmove_falkor) + IFUNC_IMPL_ADD (array, i, memmove, 1, __memmove_generic)) +- IFUNC_IMPL (i, name, memset, +- /* Enable this on non-falkor processors too so that other cores +- can do a comparative analysis with __memset_generic. */ +- IFUNC_IMPL_ADD (array, i, memset, (zva_size == 64), __memset_falkor) +- IFUNC_IMPL_ADD (array, i, memset, 1, __memset_generic)) + + return i; + } +diff --git a/string/memset.c b/string/memset.c +index 9e56bb6..9a82280 100644 +--- a/string/memset.c ++++ b/string/memset.c +@@ -20,6 +20,7 @@ + + #undef memset + ++__attribute__((optimize(0))) + void * + inhibit_loop_to_libcall + memset (void *dstpp, int c, size_t len) +diff --git a/sysdeps/aarch64/multiarch/Makefile b/sysdeps/aarch64/multiarch/Makefile +index aa179c4..9aa1e79 100644 +--- a/sysdeps/aarch64/multiarch/Makefile ++++ b/sysdeps/aarch64/multiarch/Makefile +@@ -1,4 +1,4 @@ + ifeq ($(subdir),string) + sysdep_routines += memcpy_generic memcpy_thunderx memcpy_falkor \ +- memmove_falkor memset_generic memset_falkor ++ memmove_falkor + endif +diff --git a/sysdeps/aarch64/multiarch/memset.c b/sysdeps/aarch64/multiarch/memset.c +deleted file mode 100644 +index 6df93d5..0000000 +--- a/sysdeps/aarch64/multiarch/memset.c ++++ /dev/null +@@ -1,40 +0,0 @@ +-/* Multiple versions of memset. AARCH64 version. +- Copyright (C) 2017-2018 Free Software Foundation, Inc. +- This file is part of the GNU C Library. +- +- The GNU C Library is free software; you can redistribute it and/or +- modify it under the terms of the GNU Lesser General Public +- License as published by the Free Software Foundation; either +- version 2.1 of the License, or (at your option) any later version. +- +- The GNU C Library is distributed in the hope that it will be useful, +- but WITHOUT ANY WARRANTY; without even the implied warranty of +- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +- Lesser General Public License for more details. +- +- You should have received a copy of the GNU Lesser General Public +- License along with the GNU C Library; if not, see +- . */ +- +-/* Define multiple versions only for the definition in libc. */ +- +-#if IS_IN (libc) +-/* Redefine memset so that the compiler won't complain about the type +- mismatch with the IFUNC selector in strong_alias, below. */ +-# undef memset +-# define memset __redirect_memset +-# include +-# include +- +-extern __typeof (__redirect_memset) __libc_memset; +- +-extern __typeof (__redirect_memset) __memset_falkor attribute_hidden; +-extern __typeof (__redirect_memset) __memset_generic attribute_hidden; +- +-libc_ifunc (__libc_memset, (IS_FALKOR (midr) && zva_size == 64 +- ? __memset_falkor +- : __memset_generic)); +- +-# undef memset +-strong_alias (__libc_memset, memset); +-#endif +diff --git a/sysdeps/aarch64/multiarch/memset_falkor.S b/sysdeps/aarch64/multiarch/memset_falkor.S +deleted file mode 100644 +index 16849a5..0000000 +--- a/sysdeps/aarch64/multiarch/memset_falkor.S ++++ /dev/null +@@ -1,53 +0,0 @@ +-/* Memset for falkor. +- Copyright (C) 2017-2018 Free Software Foundation, Inc. +- +- This file is part of the GNU C Library. +- +- The GNU C Library is free software; you can redistribute it and/or +- modify it under the terms of the GNU Lesser General Public +- License as published by the Free Software Foundation; either +- version 2.1 of the License, or (at your option) any later version. +- +- The GNU C Library is distributed in the hope that it will be useful, +- but WITHOUT ANY WARRANTY; without even the implied warranty of +- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +- Lesser General Public License for more details. +- +- You should have received a copy of the GNU Lesser General Public +- License along with the GNU C Library. If not, see +- . */ +- +-#include +- +-/* Reading dczid_el0 is expensive on falkor so move it into the ifunc +- resolver and assume ZVA size of 64 bytes. The IFUNC resolver takes care to +- use this function only when ZVA is enabled. */ +- +-#if IS_IN (libc) +-.macro zva_macro +- .p2align 4 +- /* Write the first and last 64 byte aligned block using stp rather +- than using DC ZVA. This is faster on some cores. */ +- str q0, [dst, 16] +- stp q0, q0, [dst, 32] +- bic dst, dst, 63 +- stp q0, q0, [dst, 64] +- stp q0, q0, [dst, 96] +- sub count, dstend, dst /* Count is now 128 too large. */ +- sub count, count, 128+64+64 /* Adjust count and bias for loop. */ +- add dst, dst, 128 +-1: dc zva, dst +- add dst, dst, 64 +- subs count, count, 64 +- b.hi 1b +- stp q0, q0, [dst, 0] +- stp q0, q0, [dst, 32] +- stp q0, q0, [dstend, -64] +- stp q0, q0, [dstend, -32] +- ret +-.endm +- +-# define ZVA_MACRO zva_macro +-# define MEMSET __memset_falkor +-# include +-#endif +diff --git a/sysdeps/aarch64/multiarch/memset_generic.S b/sysdeps/aarch64/multiarch/memset_generic.S +deleted file mode 100644 +index 345a88b..0000000 +--- a/sysdeps/aarch64/multiarch/memset_generic.S ++++ /dev/null +@@ -1,27 +0,0 @@ +-/* Memset for aarch64, default version for internal use. +- Copyright (C) 2017-2018 Free Software Foundation, Inc. +- +- This file is part of the GNU C Library. +- +- The GNU C Library is free software; you can redistribute it and/or +- modify it under the terms of the GNU Lesser General Public +- License as published by the Free Software Foundation; either +- version 2.1 of the License, or (at your option) any later version. +- +- The GNU C Library is distributed in the hope that it will be useful, +- but WITHOUT ANY WARRANTY; without even the implied warranty of +- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +- Lesser General Public License for more details. +- +- You should have received a copy of the GNU Lesser General Public +- License along with the GNU C Library. If not, see +- . */ +- +-#if IS_IN (libc) +-# define MEMSET __memset_generic +-/* Add a hidden definition for use within libc.so. */ +-# ifdef SHARED +- .globl __GI_memset; __GI_memset = __memset_generic +-# endif +-# include +-#endif +diff --git a/sysdeps/aarch64/multiarch/rtld-memset.S b/sysdeps/aarch64/multiarch/rtld-memset.S +deleted file mode 100644 +index 8cdc6e1..0000000 +--- a/sysdeps/aarch64/multiarch/rtld-memset.S ++++ /dev/null +@@ -1,23 +0,0 @@ +-/* Memset for aarch64, for the dynamic linker. +- Copyright (C) 2017-2018 Free Software Foundation, Inc. +- +- This file is part of the GNU C Library. +- +- The GNU C Library is free software; you can redistribute it and/or +- modify it under the terms of the GNU Lesser General Public +- License as published by the Free Software Foundation; either +- version 2.1 of the License, or (at your option) any later version. +- +- The GNU C Library is distributed in the hope that it will be useful, +- but WITHOUT ANY WARRANTY; without even the implied warranty of +- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +- Lesser General Public License for more details. +- +- You should have received a copy of the GNU Lesser General Public +- License along with the GNU C Library. If not, see +- . */ +- +-#if IS_IN (rtld) +-# define MEMSET memset +-# include +-#endif +diff --git a/sysdeps/aarch64/memset-reg.h b/sysdeps/aarch64/memset-reg.h +deleted file mode 100644 +index ac7c083..0000000 +--- a/sysdeps/aarch64/memset-reg.h ++++ /dev/null +@@ -1,30 +0,0 @@ +-/* Register aliases for memset to be used across implementations. +- Copyright (C) 2017-2018 Free Software Foundation, Inc. +- This file is part of the GNU C Library. +- +- The GNU C Library is free software; you can redistribute it and/or +- modify it under the terms of the GNU Lesser General Public +- License as published by the Free Software Foundation; either +- version 2.1 of the License, or (at your option) any later version. +- +- The GNU C Library is distributed in the hope that it will be useful, +- but WITHOUT ANY WARRANTY; without even the implied warranty of +- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +- Lesser General Public License for more details. +- +- You should have received a copy of the GNU Lesser General Public +- License along with the GNU C Library; if not, see +- . */ +- +-#define dstin x0 +-#define val x1 +-#define valw w1 +-#define count x2 +-#define dst x3 +-#define dstend x4 +-#define tmp1 x5 +-#define tmp1w w5 +-#define tmp2 x6 +-#define tmp2w w6 +-#define zva_len x7 +-#define zva_lenw w7 +diff --git a/sysdeps/aarch64/memset.S b/sysdeps/aarch64/memset.S +deleted file mode 100644 +index 4a45459..0000000 +--- a/sysdeps/aarch64/memset.S ++++ /dev/null +@@ -1,190 +0,0 @@ +-/* Copyright (C) 2012-2018 Free Software Foundation, Inc. +- +- This file is part of the GNU C Library. +- +- The GNU C Library is free software; you can redistribute it and/or +- modify it under the terms of the GNU Lesser General Public +- License as published by the Free Software Foundation; either +- version 2.1 of the License, or (at your option) any later version. +- +- The GNU C Library is distributed in the hope that it will be useful, +- but WITHOUT ANY WARRANTY; without even the implied warranty of +- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +- Lesser General Public License for more details. +- +- You should have received a copy of the GNU Lesser General Public +- License along with the GNU C Library. If not, see +- . */ +- +-#include +-#include "memset-reg.h" +- +-#ifndef MEMSET +-# define MEMSET memset +-#endif +- +-/* Assumptions: +- * +- * ARMv8-a, AArch64, unaligned accesses +- * +- */ +- +-ENTRY_ALIGN (MEMSET, 6) +- +- DELOUSE (0) +- DELOUSE (2) +- +- dup v0.16B, valw +- add dstend, dstin, count +- +- cmp count, 96 +- b.hi L(set_long) +- cmp count, 16 +- b.hs L(set_medium) +- mov val, v0.D[0] +- +- /* Set 0..15 bytes. */ +- tbz count, 3, 1f +- str val, [dstin] +- str val, [dstend, -8] +- ret +- nop +-1: tbz count, 2, 2f +- str valw, [dstin] +- str valw, [dstend, -4] +- ret +-2: cbz count, 3f +- strb valw, [dstin] +- tbz count, 1, 3f +- strh valw, [dstend, -2] +-3: ret +- +- /* Set 17..96 bytes. */ +-L(set_medium): +- str q0, [dstin] +- tbnz count, 6, L(set96) +- str q0, [dstend, -16] +- tbz count, 5, 1f +- str q0, [dstin, 16] +- str q0, [dstend, -32] +-1: ret +- +- .p2align 4 +- /* Set 64..96 bytes. Write 64 bytes from the start and +- 32 bytes from the end. */ +-L(set96): +- str q0, [dstin, 16] +- stp q0, q0, [dstin, 32] +- stp q0, q0, [dstend, -32] +- ret +- +- .p2align 3 +- nop +-L(set_long): +- and valw, valw, 255 +- bic dst, dstin, 15 +- str q0, [dstin] +- cmp count, 256 +- ccmp valw, 0, 0, cs +- b.eq L(try_zva) +-L(no_zva): +- sub count, dstend, dst /* Count is 16 too large. */ +- add dst, dst, 16 +- sub count, count, 64 + 16 /* Adjust count and bias for loop. */ +-1: stp q0, q0, [dst], 64 +- stp q0, q0, [dst, -32] +-L(tail64): +- subs count, count, 64 +- b.hi 1b +-2: stp q0, q0, [dstend, -64] +- stp q0, q0, [dstend, -32] +- ret +- +-L(try_zva): +-#ifdef ZVA_MACRO +- zva_macro +-#else +- .p2align 3 +- mrs tmp1, dczid_el0 +- tbnz tmp1w, 4, L(no_zva) +- and tmp1w, tmp1w, 15 +- cmp tmp1w, 4 /* ZVA size is 64 bytes. */ +- b.ne L(zva_128) +- +- /* Write the first and last 64 byte aligned block using stp rather +- than using DC ZVA. This is faster on some cores. +- */ +-L(zva_64): +- str q0, [dst, 16] +- stp q0, q0, [dst, 32] +- bic dst, dst, 63 +- stp q0, q0, [dst, 64] +- stp q0, q0, [dst, 96] +- sub count, dstend, dst /* Count is now 128 too large. */ +- sub count, count, 128+64+64 /* Adjust count and bias for loop. */ +- add dst, dst, 128 +- nop +-1: dc zva, dst +- add dst, dst, 64 +- subs count, count, 64 +- b.hi 1b +- stp q0, q0, [dst, 0] +- stp q0, q0, [dst, 32] +- stp q0, q0, [dstend, -64] +- stp q0, q0, [dstend, -32] +- ret +- +- .p2align 3 +-L(zva_128): +- cmp tmp1w, 5 /* ZVA size is 128 bytes. */ +- b.ne L(zva_other) +- +- str q0, [dst, 16] +- stp q0, q0, [dst, 32] +- stp q0, q0, [dst, 64] +- stp q0, q0, [dst, 96] +- bic dst, dst, 127 +- sub count, dstend, dst /* Count is now 128 too large. */ +- sub count, count, 128+128 /* Adjust count and bias for loop. */ +- add dst, dst, 128 +-1: dc zva, dst +- add dst, dst, 128 +- subs count, count, 128 +- b.hi 1b +- stp q0, q0, [dstend, -128] +- stp q0, q0, [dstend, -96] +- stp q0, q0, [dstend, -64] +- stp q0, q0, [dstend, -32] +- ret +- +-L(zva_other): +- mov tmp2w, 4 +- lsl zva_lenw, tmp2w, tmp1w +- add tmp1, zva_len, 64 /* Max alignment bytes written. */ +- cmp count, tmp1 +- blo L(no_zva) +- +- sub tmp2, zva_len, 1 +- add tmp1, dst, zva_len +- add dst, dst, 16 +- subs count, tmp1, dst /* Actual alignment bytes to write. */ +- bic tmp1, tmp1, tmp2 /* Aligned dc zva start address. */ +- beq 2f +-1: stp q0, q0, [dst], 64 +- stp q0, q0, [dst, -32] +- subs count, count, 64 +- b.hi 1b +-2: mov dst, tmp1 +- sub count, dstend, tmp1 /* Remaining bytes to write. */ +- subs count, count, zva_len +- b.lo 4f +-3: dc zva, dst +- add dst, dst, zva_len +- subs count, count, zva_len +- b.hs 3b +-4: add count, count, zva_len +- b L(tail64) +-#endif +- +-END (MEMSET) +-libc_hidden_builtin_def (MEMSET)