From 73656b01cb4a22ab03894e6007d645ddaf727aa6 Mon Sep 17 00:00:00 2001 From: Xing Li Date: Fri, 28 Jul 2023 17:45:46 +0800 Subject: [PATCH] Add static PIE support for LoongArch --- ...LoongArch-Prepare-static-PIE-support.patch | 41 +++++++++++++++++++ ...gned-overflow-in-loongarch_emit_int_.patch | 41 +++++++++++++++++++ ...e-simplify-limitation-when-in-struct.patch | 0 ...x-speccpu2006-462-double-free-I60YUV.patch | 0 ...overflow-with-VLA-of-elements-larger.patch | 0 ...o-masking-for-vcvtps2ph-when-dest-op.patch | 0 ...Revert-Enable-libquadmath-on-kunpeng.patch | 0 ...factor-Enable-libquadmath-on-kunpeng.patch | 0 gcc.spec | 29 +++++++++---- 9 files changed, 102 insertions(+), 9 deletions(-) create mode 100644 0042-LoongArch-Prepare-static-PIE-support.patch create mode 100644 0043-LoongArch-fix-signed-overflow-in-loongarch_emit_int_.patch rename 0042-Struct-Reorg-Type-simplify-limitation-when-in-struct.patch => 0044-Struct-Reorg-Type-simplify-limitation-when-in-struct.patch (100%) rename 0043-Struct-Reorg-Fix-speccpu2006-462-double-free-I60YUV.patch => 0045-Struct-Reorg-Fix-speccpu2006-462-double-free-I60YUV.patch (100%) rename 0044-bogus-Wstringop-overflow-with-VLA-of-elements-larger.patch => 0046-bogus-Wstringop-overflow-with-VLA-of-elements-larger.patch (100%) rename 0045-Backport-Fix-zero-masking-for-vcvtps2ph-when-dest-op.patch => 0047-Backport-Fix-zero-masking-for-vcvtps2ph-when-dest-op.patch (100%) rename 0046-libquadmath-Revert-Enable-libquadmath-on-kunpeng.patch => 0048-libquadmath-Revert-Enable-libquadmath-on-kunpeng.patch (100%) rename 0047-libquadmath-refactor-Enable-libquadmath-on-kunpeng.patch => 0049-libquadmath-refactor-Enable-libquadmath-on-kunpeng.patch (100%) diff --git a/0042-LoongArch-Prepare-static-PIE-support.patch b/0042-LoongArch-Prepare-static-PIE-support.patch new file mode 100644 index 0000000..4e91cb4 --- /dev/null +++ b/0042-LoongArch-Prepare-static-PIE-support.patch @@ -0,0 +1,41 @@ +From e6b68277694b2d95dfb60b4c306188ca5b75d6e7 Mon Sep 17 00:00:00 2001 +From: Xi Ruoyao +Date: Tue, 13 Sep 2022 23:21:39 +0800 +Subject: [PATCH 1/2] LoongArch: Prepare static PIE support + +Static PIE allows us to extend the ASLR to cover static executables and +it's not too difficult to support it. On GCC side, we just pass a group +of options to the linker, like other ports with static PIE support. + +The real implementation of static PIE (rcrt1.o) will be added into Glibc +later. + +gcc/ChangeLog: + + * config/loongarch/gnu-user.h (GNU_USER_TARGET_LINK_SPEC): For + -static-pie, pass -static -pie --no-dynamic-linker -z text to + the linker, and do not pass --dynamic-linker. +--- + gcc/config/loongarch/gnu-user.h | 6 ++++-- + 1 file changed, 4 insertions(+), 2 deletions(-) + +diff --git a/gcc/config/loongarch/gnu-user.h b/gcc/config/loongarch/gnu-user.h +index 664dc9206..c5b1afe53 100644 +--- a/gcc/config/loongarch/gnu-user.h ++++ b/gcc/config/loongarch/gnu-user.h +@@ -40,8 +40,10 @@ along with GCC; see the file COPYING3. If not see + #undef GNU_USER_TARGET_LINK_SPEC + #define GNU_USER_TARGET_LINK_SPEC \ + "%{G*} %{shared} -m " GNU_USER_LINK_EMULATION \ +- "%{!shared: %{static} %{!static: %{rdynamic:-export-dynamic} " \ +- "-dynamic-linker " GNU_USER_DYNAMIC_LINKER "}}" ++ "%{!shared: %{static} " \ ++ "%{!static: %{!static-pie: %{rdynamic:-export-dynamic} " \ ++ "-dynamic-linker " GNU_USER_DYNAMIC_LINKER "}} " \ ++ "%{static-pie: -static -pie --no-dynamic-linker -z text}}" + + + /* Similar to standard Linux, but adding -ffast-math support. */ +-- +2.27.0 + diff --git a/0043-LoongArch-fix-signed-overflow-in-loongarch_emit_int_.patch b/0043-LoongArch-fix-signed-overflow-in-loongarch_emit_int_.patch new file mode 100644 index 0000000..e430df3 --- /dev/null +++ b/0043-LoongArch-fix-signed-overflow-in-loongarch_emit_int_.patch @@ -0,0 +1,41 @@ +From cbebeb6af741b628e9714240fdcebca58c61e56e Mon Sep 17 00:00:00 2001 +From: XingLi +Date: Thu, 27 Jul 2023 09:16:55 +0800 +Subject: [PATCH 2/2] LoongArch: fix signed overflow in + loongarch_emit_int_compare + +Signed overflow is an undefined behavior, so we need to prevent it from +happening, instead of "checking" the result. + +gcc/ChangeLog: + + * config/loongarch/loongarch.cc (loongarch_emit_int_compare): + Avoid signed overflow. +From: Xi Ruoyao +--- + gcc/config/loongarch/loongarch.c | 7 +++++-- + 1 file changed, 5 insertions(+), 2 deletions(-) + +diff --git a/gcc/config/loongarch/loongarch.c b/gcc/config/loongarch/loongarch.c +index 4ddcaa446..95b4ed5d9 100644 +--- a/gcc/config/loongarch/loongarch.c ++++ b/gcc/config/loongarch/loongarch.c +@@ -4174,10 +4174,13 @@ loongarch_emit_int_compare (enum rtx_code *code, rtx *op0, rtx *op1) + if (!increment && !decrement) + continue; + ++ if ((increment && rhs == HOST_WIDE_INT_MAX) ++ || (decrement && rhs == HOST_WIDE_INT_MIN)) ++ break; ++ + new_rhs = rhs + (increment ? 1 : -1); + if (loongarch_integer_cost (new_rhs) +- < loongarch_integer_cost (rhs) +- && (rhs < 0) == (new_rhs < 0)) ++ < loongarch_integer_cost (rhs)) + { + *op1 = GEN_INT (new_rhs); + *code = mag_comparisons[i][increment]; +-- +2.27.0 + diff --git a/0042-Struct-Reorg-Type-simplify-limitation-when-in-struct.patch b/0044-Struct-Reorg-Type-simplify-limitation-when-in-struct.patch similarity index 100% rename from 0042-Struct-Reorg-Type-simplify-limitation-when-in-struct.patch rename to 0044-Struct-Reorg-Type-simplify-limitation-when-in-struct.patch diff --git a/0043-Struct-Reorg-Fix-speccpu2006-462-double-free-I60YUV.patch b/0045-Struct-Reorg-Fix-speccpu2006-462-double-free-I60YUV.patch similarity index 100% rename from 0043-Struct-Reorg-Fix-speccpu2006-462-double-free-I60YUV.patch rename to 0045-Struct-Reorg-Fix-speccpu2006-462-double-free-I60YUV.patch diff --git a/0044-bogus-Wstringop-overflow-with-VLA-of-elements-larger.patch b/0046-bogus-Wstringop-overflow-with-VLA-of-elements-larger.patch similarity index 100% rename from 0044-bogus-Wstringop-overflow-with-VLA-of-elements-larger.patch rename to 0046-bogus-Wstringop-overflow-with-VLA-of-elements-larger.patch diff --git a/0045-Backport-Fix-zero-masking-for-vcvtps2ph-when-dest-op.patch b/0047-Backport-Fix-zero-masking-for-vcvtps2ph-when-dest-op.patch similarity index 100% rename from 0045-Backport-Fix-zero-masking-for-vcvtps2ph-when-dest-op.patch rename to 0047-Backport-Fix-zero-masking-for-vcvtps2ph-when-dest-op.patch diff --git a/0046-libquadmath-Revert-Enable-libquadmath-on-kunpeng.patch b/0048-libquadmath-Revert-Enable-libquadmath-on-kunpeng.patch similarity index 100% rename from 0046-libquadmath-Revert-Enable-libquadmath-on-kunpeng.patch rename to 0048-libquadmath-Revert-Enable-libquadmath-on-kunpeng.patch diff --git a/0047-libquadmath-refactor-Enable-libquadmath-on-kunpeng.patch b/0049-libquadmath-refactor-Enable-libquadmath-on-kunpeng.patch similarity index 100% rename from 0047-libquadmath-refactor-Enable-libquadmath-on-kunpeng.patch rename to 0049-libquadmath-refactor-Enable-libquadmath-on-kunpeng.patch diff --git a/gcc.spec b/gcc.spec index abca608..ee89546 100644 --- a/gcc.spec +++ b/gcc.spec @@ -61,7 +61,7 @@ Summary: Various compilers (C, C++, Objective-C, ...) Name: gcc Version: %{gcc_version} -Release: 17 +Release: 18 License: GPLv3+ and GPLv3+ with exceptions and GPLv2+ with exceptions and LGPLv2+ and BSD URL: https://gcc.gnu.org @@ -153,13 +153,15 @@ Patch38: 0038-libsanitizer-Add-LoongArch-support.patch Patch39: 0039-libsanitizer-Fixup-pr59063-2-link-error.patch Patch40: 0040-libstdc-Fixup-pthread_join-weak-define-after-glibc-2.patch Patch41: 0041-add-missed-headers.patch +Patch42: 0042-LoongArch-Prepare-static-PIE-support.patch +Patch43: 0043-LoongArch-fix-signed-overflow-in-loongarch_emit_int_.patch %endif -Patch42: 0042-Struct-Reorg-Type-simplify-limitation-when-in-struct.patch -Patch43: 0043-Struct-Reorg-Fix-speccpu2006-462-double-free-I60YUV.patch -Patch44: 0044-bogus-Wstringop-overflow-with-VLA-of-elements-larger.patch -Patch45: 0045-Backport-Fix-zero-masking-for-vcvtps2ph-when-dest-op.patch -Patch46: 0046-libquadmath-Revert-Enable-libquadmath-on-kunpeng.patch -Patch47: 0047-libquadmath-refactor-Enable-libquadmath-on-kunpeng.patch +Patch44: 0044-Struct-Reorg-Type-simplify-limitation-when-in-struct.patch +Patch45: 0045-Struct-Reorg-Fix-speccpu2006-462-double-free-I60YUV.patch +Patch46: 0046-bogus-Wstringop-overflow-with-VLA-of-elements-larger.patch +Patch47: 0047-Backport-Fix-zero-masking-for-vcvtps2ph-when-dest-op.patch +Patch48: 0048-libquadmath-Revert-Enable-libquadmath-on-kunpeng.patch +Patch49: 0049-libquadmath-refactor-Enable-libquadmath-on-kunpeng.patch %global gcc_target_platform %{_arch}-linux-gnu @@ -643,13 +645,15 @@ not stable, so plugins must be rebuilt any time GCC is updated. %patch39 -p1 %patch40 -p1 %patch41 -p1 -%endif %patch42 -p1 %patch43 -p1 +%endif %patch44 -p1 %patch45 -p1 %patch46 -p1 %patch47 -p1 +%patch48 -p1 +%patch49 -p1 %build @@ -734,7 +738,8 @@ CC="$CC" CFLAGS="$OPT_FLAGS" \ %endif %ifarch loongarch64 --with-arch=loongarch64 --with-abi=lp64d \ - --disable-libquadmath --disable-multilib --enable-tls + --disable-libquadmath --disable-multilib --enable-tls \ + --enable-default-pie %endif %ifarch sparc sparcv9 sparc64 @@ -2628,6 +2633,12 @@ end %doc rpm.doc/changelogs/libcc1/ChangeLog* %changelog +* Fri Jul 28 2023 lixing - 10.3.1-18 +- Type:Sync bugfix +- ID:NA +- SUG:NA +- DESC: Add static PIE support for LoongArch + * Mon Jun 26 2023 liyancheng <412998149@qq.com> - 10.3.1-17 - Type:Sync bugfix - ID:NA -- Gitee