gcc 9.0.1 segfault while compiling GSdx
PCSX2 version: git checkout: 56a976e277a4a05622bd6396d8ee9049b62049cd
- Notes:
- It's preferred to only report bugs which are present on the latest development builds.
- The PSX backward compatibility mode is still in its early stage of development. Issue reports are too early at this point.
gcc version 9.0.1 20190312 (Red Hat 9.0.1-0.10) (GCC) [fedora 30] fails to compile the GSdx plugin with a segmentation fault.
Description of the issue:
(What's the problem? - Screenshots showing the issue if applicable)
gcc 9.0.1 segfaults while compiling GSdx
With the following patch, the compilation ends and the hw rasterizer works; however the software rasterizer does not work (as it should have been expected).
--- a/plugins/GSdx/Renderers/SW/GSRasterizer.h
+++ b/plugins/GSdx/Renderers/SW/GSRasterizer.h
@@ -72,7 +72,7 @@ class IDrawScanline : public GSAlignedClass<32>
{
public:
typedef void (*SetupPrimPtr)(const GSVertexSW* vertex, const uint32* index, const GSVertexSW& dscan);
- typedef void (__fastcall *DrawScanlinePtr)(int pixels, int left, int top, const GSVertexSW& scan);
+ typedef void (*DrawScanlinePtr)(int pixels, int left, int top, const GSVertexSW& scan);
typedef void (IDrawScanline::*DrawRectPtr)(const GSVector4i& r, const GSVertexSW& v); // TODO: jit
If gcc segfault. It is a gcc bug. Even with invalid code, compiler shouldn't crash.
Indeed; actually it appears that pcsx2 would be a good test for the functionality of gcc (every time I upgrade gcc, I find some issue with the compiler). In any case gcc-9.1.1 (currently in fedora-updates-testing) seems to have fixed the problem (at least the compilation does not break).
Indeed, PCSX2 hit too much gcc bug. I already opened 2 or 3 gcc bugs... And we even have some cmake code to blacklist some gcc version
@gregory38 Can you please share the links for these gcc bug reports?
Edit: Also I can confirm 9.1.0 is still affected.
I can confirm this gcc patch from fedora allows pcsx2 to compile (With many new warnings).
2019-05-03 Jakub Jelinek <[email protected]>
PR tree-optimization/90303
* ipa-devirt.c (obj_type_ref_class, get_odr_type): Don't use
TYPE_CANONICAL for TYPE_STRUCTURAL_EQUALITY_P types in !in_lto_p mode.
* g++.target/i386/pr90303.C: New test.
--- gcc/ipa-devirt.c (revision 270834)
+++ gcc/ipa-devirt.c (revision 270835)
@@ -2020,7 +2020,7 @@ obj_type_ref_class (const_tree ref)
ref = TREE_VALUE (TYPE_ARG_TYPES (ref));
gcc_checking_assert (TREE_CODE (ref) == POINTER_TYPE);
tree ret = TREE_TYPE (ref);
- if (!in_lto_p)
+ if (!in_lto_p && !TYPE_STRUCTURAL_EQUALITY_P (ret))
ret = TYPE_CANONICAL (ret);
else
ret = get_odr_type (ret)->type;
@@ -2042,7 +2042,7 @@ get_odr_type (tree type, bool insert)
int base_id = -1;
type = TYPE_MAIN_VARIANT (type);
- if (!in_lto_p)
+ if (!in_lto_p && !TYPE_STRUCTURAL_EQUALITY_P (type))
type = TYPE_CANONICAL (type);
gcc_checking_assert (can_be_name_hashed_p (type)
--- gcc/testsuite/g++.target/i386/pr90303.C (nonexistent)
+++ gcc/testsuite/g++.target/i386/pr90303.C (revision 270835)
@@ -0,0 +1,8 @@
+// PR tree-optimization/90303
+// { dg-do compile { target ia32 } }
+// { dg-additional-options "-O2" }
+
+struct A { virtual void foo (); };
+template <class> class B : A {};
+typedef void (__attribute__((fastcall)) F) ();
+B<F> e;
https://src.fedoraproject.org/rpms/gcc/blob/master/f/gcc9-pr90303.patch
Maybe @arcum42 can lend a hand here too. Cleanup the patch, maybe silence the warnings ..etc.
That's a gcc patch, not a pcsx2 patch. I'm not familiar with gcc's code, nor do I have commit rights there. ^_^
If I knew what the warnings were, I could look at those, though.
@arcum42 Here is a complete build log with warnings.
LOG: pcsx2.log
I am seeing many warnings like this.
/tmp/SBo/pcsx2/common/src/x86emitter/x86emitter.cpp:726:20: warning: implicitly-declared ‘x86Emitter::xAddressReg& x86Emitter::xAddressReg::operator=(const x86Emitter::xAddressReg&)’ is deprecated [-Wdeprecated-copy]
726 | Base = Index;
| ^~~~~
In file included from /tmp/SBo/pcsx2/common/include/x86emitter/internal.h:18,
from /tmp/SBo/pcsx2/common/src/x86emitter/x86emitter.cpp:32:
/tmp/SBo/pcsx2/common/include/x86emitter/x86types.h:480:5: note: because ‘x86Emitter::xAddressReg’ has user-provided ‘x86Emitter::xAddressReg::xAddressReg(const x86Emitter::xAddressReg&)’
480 | xAddressReg(const xAddressReg &src)
| ^~~~~~~~~~~
Relevant upstream gcc documentation.
-Wdeprecated-copy (C++ and Objective-C++ only)
Warn that the implicit declaration of a copy constructor or copy assignment operator is deprecated if the class has a user-provided copy constructor or copy assignment operator, in C++11 and up. This warning is enabled by -Wextra. With -Wdeprecated-copy-dtor, also deprecate if the class has a user-provided destructor.
https://gcc.gnu.org/onlinedocs/gcc-9.1.0/gcc/C_002b_002b-Dialect-Options.html#index-Wdeprecated-copy
And their changelog.
-Wdeprecated-copy, implied by -Wextra, warns about the C++11 deprecation of implicitly declared copy constructor and assignment operator if one of them is user-provided. -Wdeprecated-copy-dtor also warns if the destructor is user-provided, as specified in C++11.
https://gcc.gnu.org/gcc-9/changes.html
@orbea Thanks. Sounds like a bunch of explicitly telling it to use the default on constructors and destructors in places. I wish they had an option to automatically generate patches to fix warnings like this...
There is a clang-based tool.that can improve code. Maybe they add this case. Otherwise you can silence the warning and we will fix it later
Unless I'm mistaken, a lot of it will be taking a warning like this: /tmp/SBo/pcsx2/common/include/Utilities/pxEvents.h: In member function ‘virtual wxEvent* pxSimpleEvent::Clone() const’: /tmp/SBo/pcsx2/common/include/Utilities/pxEvents.h:84:68: warning: implicitly-declared ‘pxSimpleEvent::pxSimpleEvent(const pxSimpleEvent&)’ is deprecated [-Wdeprecated-copy] 84 | virtual wxEvent *Clone() const { return new pxSimpleEvent(*this); }
And taking the bit in quotes and adding something like: pxSimpleEvent::pxSimpleEvent(const pxSimpleEvent&) = default;
Haven't tested that yet, though...
Orbea search my name/email (note I mean in older gcc version).
Arcum. Yes. My understanding is that either all constructors are user defined or all are default. So we need to add declaration of implicit constructor with = default.
Orbea search my name/email (note I mean in older gcc version).
Oh I thought you meant you made a new issue, my mistake.
Btw does it fully work (no crash?)
I have tested it only briefly, but I have experienced no crashes and it seems to work the same as before.
I went and installed gcc 9 in my 32-bit chroot. I had to do it from a ppm because apparently the chroot can't be upgraded because Ubuntu is thinking of getting rid of 32-bit builds, which is worrisome.
I was able to replicate the segfault. Got rid of it, but commenting out compiling GSdx isn't exactly a solution we can use, though it's nice to know gcc 9 specifically doesn't like that plugin.
I believe I've taken care of most or all of the new depreciated warnings, but unfortunately, the segfault doesn't appear related. Wish I knew specifically what that patch fixed so I could see if I could find a workaround. I'll have to look around.
Here's some currently untested (but compiled) code that gets rid of the warnings: `diff --git a/common/include/Utilities/pxEvents.h b/common/include/Utilities/pxEvents.h index 409b72dbd..cd5e2679f 100644 --- a/common/include/Utilities/pxEvents.h +++ b/common/include/Utilities/pxEvents.h @@ -81,6 +81,8 @@ public: { }
- pxSimpleEvent(const pxSimpleEvent&) = default;
- virtual wxEvent *Clone() const { return new pxSimpleEvent(*this); } };
diff --git a/common/include/x86emitter/x86types.h b/common/include/x86emitter/x86types.h index 9b2d1f426..71f9f9d02 100644 --- a/common/include/x86emitter/x86types.h +++ b/common/include/x86emitter/x86types.h @@ -504,6 +504,9 @@ public: xAddressVoid operator-(const void right) const; xAddressVoid operator(int factor) const; xAddressVoid operator<<(u32 shift) const; +
- xAddressReg& operator=(const xAddressReg&) = default; + };
// -------------------------------------------------------------------------------------- diff --git a/common/src/x86emitter/x86emitter.cpp b/common/src/x86emitter/x86emitter.cpp index 078cdda27..2c2b109b2 100644 --- a/common/src/x86emitter/x86emitter.cpp +++ b/common/src/x86emitter/x86emitter.cpp @@ -542,7 +542,6 @@ xAddressVoid xAddressReg::operator<<(u32 shift) const return xAddressVoid(xEmptyReg, *this, 1 << shift); }
- // -------------------------------------------------------------------------------------- // xAddressVoid (method implementations) // -------------------------------------------------------------------------------------- diff --git a/pcsx2/gui/AppCorePlugins.cpp b/pcsx2/gui/AppCorePlugins.cpp index 5a74bb696..51907c66c 100644 --- a/pcsx2/gui/AppCorePlugins.cpp +++ b/pcsx2/gui/AppCorePlugins.cpp @@ -138,6 +138,7 @@ protected: PluginsEnum_t m_pid;
public:
- LoadSinglePluginEvent(const LoadSinglePluginEvent&) = default; virtual ~LoadSinglePluginEvent() = default; virtual LoadSinglePluginEvent *Clone() const { return new LoadSinglePluginEvent(*this); }
@@ -167,6 +168,7 @@ protected: FnPtr_AppPluginPid m_method;
public:
- SinglePluginMethodEvent(const SinglePluginMethodEvent&) = default; virtual ~SinglePluginMethodEvent() = default; virtual SinglePluginMethodEvent *Clone() const { return new SinglePluginMethodEvent(*this); }
diff --git a/plugins/GSdx/GSVector4.h b/plugins/GSdx/GSVector4.h index 955fbf935..06be7cb73 100644 --- a/plugins/GSdx/GSVector4.h +++ b/plugins/GSdx/GSVector4.h @@ -57,6 +57,8 @@ public: { }
- constexpr GSVector4(const GSVector4&) = default; + __forceinline GSVector4(float x, float y, float z, float w) { m = _mm_set_ps(w, z, y, x); `
I don't think the segfault needs to be fixed in pcsx2, gcc itself is segfaulting and this should be fixed in gcc. Given the fedora patch I wonder if it was already done?
Yeah, I'm just mostly seeing if there's any sort of workaround I can put in place. I doubt this is the last time we'll have people compiling on gcc 9.x. Though it may end up just being a matter of blocking gcc 9.0.1-9.10.
Though I should've read the thread a little more carefully, as it specifies that it is the fastcall attribute on DrawScanlinePtr that's crashing the compile, and that removing it causes the software renderer to stop working.
Fwiw the fedora patch has been applied to gcc9 in Slackware current and this is effectively worked around here.