https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68738
Bug ID: 68738 Summary: call to overridden function segfaults Product: gcc Version: 5.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: rianquinn at gmail dot com Target Milestone: --- Using the TARGET=elf-x86_64 compiler (OS development), I get a strange crash with C++. The class definition is as follows: class Blah1 { public: Blah1() {} virtual ~Blah1() {} virtual int foo() { return 0; } }; class Blah2 : public Blah1 { public: Blah2() {} ~Blah2() {} int boo() { return 1; } int foo() override { return 1; } }; Blah2 g_blah2; int do_something() { Blah2 *p_blah2 = &g_blah2; int i = p_blah2->foo(); // <----- crash here } The compiled assembly for this looks something like: c68: 48 89 45 e8 mov %rax,-0x18(%rbp) c6c: 48 8b 45 e8 mov -0x18(%rbp),%rax c70: 48 8b 00 mov (%rax),%rax c73: 48 83 c0 10 add $0x10,%rax c77: 48 8b 00 mov (%rax),%rax c7a: 48 8b 55 e8 mov -0x18(%rbp),%rdx c7e: 48 89 d7 mov %rdx,%rdi c81: ff d0 callq *%rax What's strange to me is it's not attempting to lookup the global symbol from the GOT. If I change the code to: int do_something() { Blah2 &p_blah2 = g_blah2; int i = p_blah2.foo(); // <----- works fine } And the compiled assembly looks like: ca3: e8 88 fe ff ff callq b30 <_ZN5Blah23fooEv@plt> Which has the GOT lookup like you would expect. Not sure what's going on here, but it seems like a bug with G++. Thanks, - Rian