[Bug target/100706] New: Invalid instructions in plt calls on PPC
alexander.grund@tu-dresden.de
gcc-bugzilla@gcc.gnu.org
Thu May 20 15:36:02 GMT 2021
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100706
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<nsync::nsync_mu *>(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=1' -DNDEBUG -ffunction-sections -fdata-sections -O3
'-mcpu=native' -fno-math-errno -fPIC '-std=c++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 linked
against this shared library during init (i.e. in a static global context) and
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
=> 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 offset is
the same.
I hope that is enough to find the problem. I'm happy to provide more insight 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.
More information about the Gcc-bugs
mailing list