public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/100706] New: Invalid instructions in plt calls on PPC
@ 2021-05-20 15:36 alexander.grund@tu-dresden.de
  2021-05-20 18:07 ` [Bug target/100706] " pinskia at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: alexander.grund@tu-dresden.de @ 2021-05-20 15:36 UTC (permalink / raw)
  To: gcc-bugs

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.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug target/100706] Invalid instructions in plt calls on PPC
  2021-05-20 15:36 [Bug target/100706] New: Invalid instructions in plt calls on PPC alexander.grund@tu-dresden.de
@ 2021-05-20 18:07 ` pinskia at gcc dot gnu.org
  2021-05-21  7:19 ` alexander.grund@tu-dresden.de
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-05-20 18:07 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100706

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
GCC does not generate the PLTs directly normally.  It is the linker.
Does using BFD ld instead of gold fix the issue?

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug target/100706] Invalid instructions in plt calls on PPC
  2021-05-20 15:36 [Bug target/100706] New: Invalid instructions in plt calls on PPC alexander.grund@tu-dresden.de
  2021-05-20 18:07 ` [Bug target/100706] " pinskia at gcc dot gnu.org
@ 2021-05-21  7:19 ` alexander.grund@tu-dresden.de
  2021-05-21  7:55 ` alexander.grund@tu-dresden.de
  2021-06-02 21:09 ` wschmidt at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: alexander.grund@tu-dresden.de @ 2021-05-21  7:19 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100706

--- Comment #2 from Alexander Grund <alexander.grund@tu-dresden.de> ---
Thanks for the reply. Although this was hard to test (need to interfere with
TFs build process which must use the gold linker) I managed to link that one
library manually with bfd and it did work. Hence yes, that is a gold linker
issue.

Any suggestions on how to proceed?

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug target/100706] Invalid instructions in plt calls on PPC
  2021-05-20 15:36 [Bug target/100706] New: Invalid instructions in plt calls on PPC alexander.grund@tu-dresden.de
  2021-05-20 18:07 ` [Bug target/100706] " pinskia at gcc dot gnu.org
  2021-05-21  7:19 ` alexander.grund@tu-dresden.de
@ 2021-05-21  7:55 ` alexander.grund@tu-dresden.de
  2021-06-02 21:09 ` wschmidt at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: alexander.grund@tu-dresden.de @ 2021-05-21  7:55 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100706

--- Comment #3 from Alexander Grund <alexander.grund@tu-dresden.de> ---
Ok, tested a few different bintuils versions. Bug occurs with 2.35 and 2.35.1
and seems to be fixed in 2.35.2

So I guess this can be closed

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug target/100706] Invalid instructions in plt calls on PPC
  2021-05-20 15:36 [Bug target/100706] New: Invalid instructions in plt calls on PPC alexander.grund@tu-dresden.de
                   ` (2 preceding siblings ...)
  2021-05-21  7:55 ` alexander.grund@tu-dresden.de
@ 2021-06-02 21:09 ` wschmidt at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: wschmidt at gcc dot gnu.org @ 2021-06-02 21:09 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100706

Bill Schmidt <wschmidt at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |wschmidt at gcc dot gnu.org
         Resolution|---                         |INVALID
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #4 from Bill Schmidt <wschmidt at gcc dot gnu.org> ---
Sorry, just now saw this...closing.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-06-02 21:09 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-20 15:36 [Bug target/100706] New: Invalid instructions in plt calls on PPC alexander.grund@tu-dresden.de
2021-05-20 18:07 ` [Bug target/100706] " pinskia at gcc dot gnu.org
2021-05-21  7:19 ` alexander.grund@tu-dresden.de
2021-05-21  7:55 ` alexander.grund@tu-dresden.de
2021-06-02 21:09 ` wschmidt at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).