From c7cd511b411c9b2895b26869180f735f2fe62293 Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Thu, 15 Jun 2023 08:03:24 -0400 Subject: [PATCH] 8.5.0-20 - fix for TLSLD references (#2213753) - fix crash in dynamic_cast<>() on null pointer (PR c++/99074, #2211506) - adjust a pattern in s390.md (PR target/87723, #2214847) Resolves: #2213753, #2211506, #2214847 --- gcc.spec | 13 +++++++- gcc8-pr87723.patch | 71 ++++++++++++++++++++++++++++++++++++++++ gcc8-pr99074.patch | 77 ++++++++++++++++++++++++++++++++++++++++++++ gcc8-rh2213753.patch | 75 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 235 insertions(+), 1 deletion(-) create mode 100644 gcc8-pr87723.patch create mode 100644 gcc8-pr99074.patch create mode 100644 gcc8-rh2213753.patch diff --git a/gcc.spec b/gcc.spec index 2d3d051..5e7a29e 100644 --- a/gcc.spec +++ b/gcc.spec @@ -4,7 +4,7 @@ %global gcc_major 8 # Note, gcc_release must be integer, if you want to add suffixes to # %%{release}, append them after %%{gcc_release} on Release: line. -%global gcc_release 19 +%global gcc_release 20 %global nvptx_tools_gitrev c28050f60193b3b95a18866a96f03334e874e78f %global nvptx_newlib_gitrev aadc8eb0ec43b7cd0dd2dfb484bae63c8b05ef24 %global _unpackaged_files_terminate_build 0 @@ -301,6 +301,9 @@ Patch40: gcc8-rh2137448.patch Patch41: gcc8-s390x-regarg-1.patch Patch42: gcc8-s390x-regarg-2.patch Patch43: gcc8-s390x-regarg-3.patch +Patch44: gcc8-rh2213753.patch +Patch45: gcc8-pr99074.patch +Patch46: gcc8-pr87723.patch Patch1000: nvptx-tools-no-ptxas.patch Patch1001: nvptx-tools-build.patch @@ -919,6 +922,9 @@ so that there cannot be any synchronization problems. %patch41 -p1 -b .s390x-regarg-1~ %patch42 -p1 -b .s390x-regarg-2~ %patch43 -p1 -b .s390x-regarg-3~ +%patch44 -p1 -b .rh2213753~ +%patch45 -p1 -b .pr99074~ +%patch46 -p1 -b .pr87723~ cd nvptx-tools-%{nvptx_tools_gitrev} %patch1000 -p1 -b .nvptx-tools-no-ptxas~ @@ -3326,6 +3332,11 @@ fi %{ANNOBIN_GCC_PLUGIN_DIR}/gcc-annobin.so.0.0.0 %changelog +* Wed Jun 14 2023 Marek Polacek 8.5.0-20 +- fix for TLSLD references (#2213753) +- fix crash in dynamic_cast<>() on null pointer (PR c++/99074, #2211506) +- adjust a pattern in s390.md (PR target/87723, #2214847) + * Tue Apr 4 2023 Marek Polacek 8.5.0-19 - s390x: add support for register arguments preserving (#2168205) diff --git a/gcc8-pr87723.patch b/gcc8-pr87723.patch new file mode 100644 index 0000000..d0aafcf --- /dev/null +++ b/gcc8-pr87723.patch @@ -0,0 +1,71 @@ +commit 8c21b0d164f33d9d47acc26f4f9b99b53e3b1945 +Author: Andreas Krebbel +Date: Tue Nov 6 10:22:05 2018 +0000 + + S/390: Fix PR87723 + + gcc/ChangeLog: + + 2018-11-06 Andreas Krebbel + + PR target/87723 + * config/s390/s390.md ("*rsbg_di_rotl"): Remove mode + attributes for operands 3 and 4. + + gcc/testsuite/ChangeLog: + + 2018-11-06 Andreas Krebbel + + PR target/87723 + * gcc.target/s390/pr87723.c: New test. + + From-SVN: r265832 + +diff --git a/gcc/config/s390/s390.md b/gcc/config/s390/s390.md +index 8e7b285e1c3..4ffd438c07c 100644 +--- a/gcc/config/s390/s390.md ++++ b/gcc/config/s390/s390.md +@@ -4230,7 +4230,7 @@ (define_insn "*rsbg_di_rotl" + (match_operand:DI 4 "nonimmediate_operand" "0"))) + (clobber (reg:CC CC_REGNUM))] + "TARGET_Z10" +- "rsbg\t%0,%1,%2,%2,%b3" ++ "rsbg\t%0,%1,%s2,%e2,%b3" + [(set_attr "op_type" "RIE")]) + + ; rosbg, rxsbg +diff --git a/gcc/testsuite/gcc.target/s390/pr87723.c b/gcc/testsuite/gcc.target/s390/pr87723.c +new file mode 100644 +index 00000000000..b0e8a5a3118 +--- /dev/null ++++ b/gcc/testsuite/gcc.target/s390/pr87723.c +@@ -0,0 +1,29 @@ ++/* { dg-do compile } */ ++/* { dg-options "-O3 -march=z196 -m64 -mzarch" } */ ++ ++unsigned long a; ++int b; ++void c(char* i) { ++ for (;;) { ++ char g = 0; ++ for (; g < 24; ++g) ++ b = a << g | a >> 64 - g; ++ { ++ char *d = i; ++ long h = b; ++ char e = 0; ++ for (; e < 8; ++e) ++ d[e] = h; ++ } ++ char *d = i; ++ signed e; ++ unsigned long f = 0; ++ e = 7; ++ for (; e; --e) { ++ f <<= 8; ++ f |= d[e]; ++ } ++ for (; e < 8; ++e) ++ d[e] = f; ++ } ++} diff --git a/gcc8-pr99074.patch b/gcc8-pr99074.patch new file mode 100644 index 0000000..83e9285 --- /dev/null +++ b/gcc8-pr99074.patch @@ -0,0 +1,77 @@ +commit 6d134ca4b963706f31251f061fc180e517b32546 +Author: Martin Sebor +Date: Tue Feb 23 14:09:00 2021 -0700 + + PR c++/99074 - crash in dynamic_cast<>() on null pointer + + libstdc++-v3/ChangeLog: + + PR c++/99074 + * libsupc++/dyncast.cc (__dynamic_cast): Return null when + first argument is null. + + gcc/testsuite/ChangeLog: + + PR c++/99074 + * g++.dg/warn/Wnonnull11.C: New test. + +diff --git a/gcc/testsuite/g++.dg/warn/Wnonnull11.C b/gcc/testsuite/g++.dg/warn/Wnonnull11.C +new file mode 100644 +index 00000000000..5f1b69d9a41 +--- /dev/null ++++ b/gcc/testsuite/g++.dg/warn/Wnonnull11.C +@@ -0,0 +1,40 @@ ++/* PR c++/99074 - gcc 8 and above is crashing with dynamic_cast<>() on null ++ pointer with optimization level -O1 and above ++ { dg-do run } ++ { dg-options "-O1 -Wall" } */ ++ ++class Base ++{ ++public: ++ virtual ~Base() {} ++ virtual void op() = 0; ++}; ++ ++class Object: public virtual Base { }; ++ ++class AbstractBase: public virtual Base ++{ ++public: ++ Object* _to_object () ++ { ++ return dynamic_cast(this); // { dg-warning "\\\[-Wnonnull" "" { xfail *-*-* } } ++ } ++}; ++ ++class MyAbstractClass: public virtual AbstractBase ++{ ++public: ++ static MyAbstractClass* _nil () { return 0; } ++}; ++ ++ ++int main () ++{ ++ MyAbstractClass *my_abs_type = MyAbstractClass::_nil (); ++ AbstractBase *abs_base = my_abs_type; ++ Object *obj = abs_base->_to_object (); ++ ++ __builtin_printf ("object is: %p\n", obj); ++ ++ return 0; ++} +diff --git a/libstdc++-v3/libsupc++/dyncast.cc b/libstdc++-v3/libsupc++/dyncast.cc +index b7d98495ad3..f8f707ee4d4 100644 +--- a/libstdc++-v3/libsupc++/dyncast.cc ++++ b/libstdc++-v3/libsupc++/dyncast.cc +@@ -47,6 +47,9 @@ __dynamic_cast (const void *src_ptr, // object started from + const __class_type_info *dst_type, // desired target type + ptrdiff_t src2dst) // how src and dst are related + { ++ if (!src_ptr) ++ /* Handle precondition violations gracefully. */ ++ return NULL; + const void *vtable = *static_cast (src_ptr); + const vtable_prefix *prefix = + adjust_pointer (vtable, diff --git a/gcc8-rh2213753.patch b/gcc8-rh2213753.patch new file mode 100644 index 0000000..f20c70b --- /dev/null +++ b/gcc8-rh2213753.patch @@ -0,0 +1,75 @@ +From 6f989c5c6e5f909996a117bb24ecac936e7526c1 Mon Sep 17 00:00:00 2001 +From: Marek Polacek +Date: Wed, 14 Jun 2023 17:09:15 -0400 +Subject: [PATCH] final: fix for TLSLD references [BZ#2213753] + +Patch by Jakub Jelinek. +--- + gcc/final.c | 17 +++++++++++++++++ + gcc/testsuite/g++.dg/tls/bz2213753.C | 26 ++++++++++++++++++++++++++ + 2 files changed, 43 insertions(+) + create mode 100644 gcc/testsuite/g++.dg/tls/bz2213753.C + +diff --git a/gcc/final.c b/gcc/final.c +index 5a65a8ce07c..c783fbb83d7 100644 +--- a/gcc/final.c ++++ b/gcc/final.c +@@ -1691,6 +1691,23 @@ get_some_local_dynamic_name () + } + } + ++ /* If all the TLSLD references from current function were DCEd, try harder and pick ++ name of any TLSLD symbol in current TU. */ ++ varpool_node *node; ++ if (!this_is_asm_operands) ++ FOR_EACH_VARIABLE (node) ++ if (DECL_THREAD_LOCAL_P (node->decl) ++ && TREE_STATIC (node->decl) ++ && decl_tls_model (node->decl) == TLS_MODEL_LOCAL_DYNAMIC ++ && DECL_RTL_SET_P (node->decl)) ++ { ++ rtx rtl = DECL_RTL (node->decl); ++ if (MEM_P (rtl) ++ && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF ++ && SYMBOL_REF_TLS_MODEL (XEXP (rtl, 0)) == TLS_MODEL_LOCAL_DYNAMIC) ++ return XSTR (XEXP (rtl, 0), 0); ++ } ++ + return 0; + } + +diff --git a/gcc/testsuite/g++.dg/tls/bz2213753.C b/gcc/testsuite/g++.dg/tls/bz2213753.C +new file mode 100644 +index 00000000000..0c4742d8058 +--- /dev/null ++++ b/gcc/testsuite/g++.dg/tls/bz2213753.C +@@ -0,0 +1,26 @@ ++// RHBZ #2213753 ++// { dg-do compile { target c++11 } } ++// { dg-require-effective-target fpic } ++// { dg-require-effective-target shared } ++// { dg-require-effective-target tls } ++// { dg-options "-fPIC -O2" } ++// { dg-add-options tls } ++ ++struct A { ~A (); }; ++static thread_local int *t; ++int a; ++A::~A () { t = &a; } ++long b; ++ ++void * ++foo () ++{ ++ void *c; ++ if (t) ++ { ++ c = operator new (b); ++ return c; ++ } ++ void *d = operator new (b); ++ return d; ++} +-- +2.40.1 +