This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/68738] call to overridden function segfaults


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

--- Comment #3 from Rian Quinn <rianquinn at gmail dot com> ---
Just for completeness, here is the exact code out objdump output:

class Blah1
{
public:
    Blah1() {}
    virtual ~Blah1() {}

    virtual int foo() { return 0; }
};

class Blah2 : public Blah1
{
public:
    Blah2() {}
    ~Blah2() {}

    int foo() override { return 1; }
};

Blah2 g_blah2;

void
do_something()
{
    Blah2 *bp1 = &g_blah2;
    Blah2 &bp2 = g_blah2;
    bp1->foo();               // Crashes
    bp2.foo();                // Does not crash
}

Using the cross-compiler (TARGET=x86_64-elf) you get the following:

0000000000000cd5 <_Z12do_somethingv>:
 cd5:   55                      push   %rbp
 cd6:   48 89 e5                mov    %rsp,%rbp
 cd9:   48 83 ec 10             sub    $0x10,%rsp
 cdd:   48 8b 05 3c 07 20 00    mov    0x20073c(%rip),%rax        # 201420
<_DYNAMIC+0x150>
 ce4:   48 89 45 f8             mov    %rax,-0x8(%rbp)
 ce8:   48 8b 05 31 07 20 00    mov    0x200731(%rip),%rax        # 201420
<_DYNAMIC+0x150>
 cef:   48 89 45 f0             mov    %rax,-0x10(%rbp)
 cf3:   48 8b 45 f8             mov    -0x8(%rbp),%rax
 cf7:   48 8b 00                mov    (%rax),%rax
 cfa:   48 83 c0 10             add    $0x10,%rax
 cfe:   48 8b 00                mov    (%rax),%rax
 d01:   48 8b 55 f8             mov    -0x8(%rbp),%rdx
 d05:   48 89 d7                mov    %rdx,%rdi
 d08:   ff d0                   callq  *%rax
 d0a:   48 8b 45 f0             mov    -0x10(%rbp),%rax
 d0e:   48 89 c7                mov    %rax,%rdi
 d11:   e8 5a fe ff ff          callq  b70 <_ZN5Blah23fooEv@plt>
 d16:   90                      nop
 d17:   c9                      leaveq
 d18:   c3                      retq

For the Native Ubuntu compiler I get:

0000000000400b58 <_Z12do_somethingv>:
  400b58:       55                      push   %rbp
  400b59:       48 89 e5                mov    %rsp,%rbp
  400b5c:       48 83 ec 10             sub    $0x10,%rsp
  400b60:       48 c7 45 f0 50 22 60    movq   $0x602250,-0x10(%rbp)
  400b67:       00
  400b68:       48 c7 45 f8 50 22 60    movq   $0x602250,-0x8(%rbp)
  400b6f:       00
  400b70:       48 8b 45 f0             mov    -0x10(%rbp),%rax
  400b74:       48 8b 00                mov    (%rax),%rax
  400b77:       48 83 c0 10             add    $0x10,%rax
  400b7b:       48 8b 00                mov    (%rax),%rax
  400b7e:       48 8b 55 f0             mov    -0x10(%rbp),%rdx
  400b82:       48 89 d7                mov    %rdx,%rdi
  400b85:       ff d0                   callq  *%rax
  400b87:       48 8b 45 f8             mov    -0x8(%rbp),%rax
  400b8b:       48 89 c7                mov    %rax,%rdi
  400b8e:       e8 9f 06 00 00          callq  401232 <_ZN5Blah23fooEv>
  400b93:       90                      nop
  400b94:       c9                      leaveq
  400b95:       c3                      retq


The flags I am passing to the cross-compiler are:

-fpic -fno-rtti -fno-sized-deallocation -fno-exceptions -fno-use-cxa-atexit
-fno-threadsafe-statics

- Rian

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]