public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "hp at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/14346] New: With -fpic/-fPIC, thunks jump through PLT, not directly to thunked function
Date: Sun, 29 Feb 2004 16:12:00 -0000	[thread overview]
Message-ID: <20040229161232.14346.hp@gcc.gnu.org> (raw)

As in summary.  Because thunks do not set up the PIC register, going through the
PLT causes a SEGV in best case.  Another PIC construct than for normal calls
must be used, but unfortunately the only (currently) available PC-relative PIC
reloc for cris-axis-linux-gnu requests a PLT.  The thunked function is global. 
Using a local symbol makes the linker omit the redirection through the PLT and
the jump goes directly to the right place.

On trunk and 3.4 branch, the thunk uses a local symbol (equated to the thunked
function, generated by generic code), so TRT happens.
See <URL:http://gcc.gnu.org/ml/gcc-patches/2003-06/msg02603.html> for
the first of the patch where the generic local-thunk was implemented (needed
follow-up patches for correctness).  I'll go with a target-local patch.

Testcase:
-------------- th1.h
class B
{
  int bb1;
  int bb2;
 public:
  virtual void b();
};
extern class B* mka();
-------------- th1.cc (compile and link with -fpic -shared -o libth1.so)
#include "th1.h"
class A
{
  int aa;
public:
  virtual void a() = 0;
};

class C : public A, public B
{
  int cc;
public:
  virtual void b();
  virtual void a();
};

extern "C" void abort (void);
extern "C" void exit (int);

class B* mka (void)
{
  return new C;
}

void C::b(void)
{
  exit (0);
}

void B::b(void)
{
  abort ();
}

void C::a(void)
{
  abort ();
}
-------------- m.cc (compile and link with -L. -lth1, expect normal exit)

#include "th1.h"
extern "C" void abort (void);
int ii[10];
int main(void)
{
  register int picreg
#if defined (__CRIS__) && !defined (__PIC__) && !defined (__pic__)
    __asm__ ("r0")
#endif
    = -1;
  class B *bb = mka();
  bb->b();
  // Make sure picreg is alive and used after bb->b() above.
  asm ("" : : "r" (picreg));
  abort ();
}

-- 
           Summary: With -fpic/-fPIC, thunks jump through PLT, not directly
                    to thunked function
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P1
         Component: target
        AssignedTo: hp at gcc dot gnu dot org
        ReportedBy: hp at gcc dot gnu dot org
                CC: gcc-bugs at gcc dot gnu dot org
GCC target triplet: cris-axis-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14346


             reply	other threads:[~2004-02-29 16:12 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-02-29 16:12 hp at gcc dot gnu dot org [this message]
2004-02-29 16:14 ` [Bug target/14346] " hp at gcc dot gnu dot org
2004-02-29 16:31 ` [Bug target/14346] [3.3 only] " hp at gcc dot gnu dot org
2004-02-29 21:46 ` cvs-commit at gcc dot gnu dot org
2004-02-29 21:52 ` hp at gcc dot gnu dot org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20040229161232.14346.hp@gcc.gnu.org \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).