From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 00019385E007; Thu, 20 May 2021 15:36:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 00019385E007 From: "alexander.grund@tu-dresden.de" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/100706] New: Invalid instructions in plt calls on PPC Date: Thu, 20 May 2021 15:36:02 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Version: 10.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: alexander.grund@tu-dresden.de X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 20 May 2021 15:36:03 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D100706 Bug ID: 100706 Summary: Invalid instructions in plt calls on PPC Product: gcc Version: 10.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: alexander.grund@tu-dresden.de Target Milestone: --- This turns up when compiling TensorFlow 2.5.0 on ppc9le. I wasn't yet able = to reduce the code to reproduce it with a small example, so only got the following: The relevant code is this: mutex.h: struct MuData { void* space[2]; }; struct mutex{ mutex(); MuData m_; }; -- mutex.cc: #include "mutex.h" #include "nsync_mu.h" static inline nsync::nsync_mu *mu_cast(MuData *mu) { return reinterpret_cast(mu); } mutex::mutex() { nsync::nsync_mu_init(mu_cast(&mu_)); } -- This is compiled into a shared library with the following compile command: = `gcc -U_FORTIFY_SOURCE -fstack-protector -fno-omit-frame-pointer -g0 '-D_FORTIFY_SOURCE=3D1' -DNDEBUG -ffunction-sections -fdata-sections -O3 '-mcpu=3Dnative' -fno-math-errno -fPIC '-std=3Dc++14' -fno-canonical-system-headers` Linker flags used later are `-Wl,-no-as-needed -Wl,-z,relro,-z,now -Wl,--gc-sections` The nsync library is from https://github.com/google/nsync (version 1.24) An instance of the mutex class is than later created by an application link= ed against this shared library during init (i.e. in a static global context) a= nd that raises an SIGILL. Doing that manually I see a plt_call being made which looks like this: Dump of assembler code for function 00000000.plt_call._ZN5nsync13nsync_mu_initEPNS_11nsync_mu_s_E: 0x0000200000074900 <+0>: std r2,24(r1) 0x0000200000074904 <+4>: ld r12,-32584(r2) 0x0000200000074908 <+8>: mtctr r12 0x000020000007490c <+12>: bctr 0x0000200000074910 <+16>: .long 0x0 0x0000200000074914 <+20>: .long 0x0 0x0000200000074918 <+24>: .long 0x0 0x000020000007491c <+28>: .long 0x0 This looks good and works (as mentioned my reduced example didn't run into = the problem) The TF compiled version of this plt call looks like this: Dump of assembler code for function 00000003.plt_call._ZN5nsync13nsync_mu_initEPNS_11nsync_mu_s_E: 0x0000200b19851660 <+0>: std r2,24(r1) 0x0000200b19851664 <+4>: nop =3D> 0x0000200b19851668 <+8>: .long 0x41004ce 0x0000200b1985166c <+12>: lfdp f12,264(0) 0x0000200b19851670 <+16>: mtctr r12 0x0000200b19851674 <+20>: bctr 0x0000200b19851678 <+24>: .long 0x0 0x0000200b1985167c <+28>: .long 0x0 As you can see something inserted a strange value into the asm code. I'm not sure if gcc or the linker (gold linker used here) creates those plt calls, = but something is obviously wrong here. I also checked another call into the nsync library: nsync::nsync_mu_lock The plt call looks very similar: Dump of assembler code for function 00000003.plt_call._ZN5nsync13nsync_mu_lockEPNS_11nsync_mu_s_E: 0x0000200b19851680 <+0>: std r2,24(r1) 0x0000200b19851684 <+4>: nop 0x0000200b19851688 <+8>: .long 0x41004ce 0x0000200b1985168c <+12>: lfdp f12,240(0) 0x0000200b19851690 <+16>: mtctr r12 0x0000200b19851694 <+20>: bctr 0x0000200b19851698 <+24>: .long 0x0 0x0000200b1985169c <+28>: .long 0x0 As you can see the constant inserted and everything else but the lfdp offse= t is the same. I hope that is enough to find the problem. I'm happy to provide more insigh= t or do some further tests if required. However I'm not a PPC expert so I have no idea where to go further with that.=