Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.

corrupted vptr with icc 16.0

Mancusi__Davide
Beginner
582 Views

Hello,

I am using icpc/icc/ifort 16.0 to compile a C++/C/Fortran application (about 500 kSLOC) on a Linux machine, with the default optimization level (-O2). I am running into a crash that I have trouble explaining.

I have a class C that is part of an inheritance chain (say C -> B -> A); the base classes have some virtual methods and a virtual destructor. At some point during the execution of the code, an object of class C is instantiated for the first time:

C *c = new C(/*some parameters*/);

The constructor invokes some virtual methods of C and the code segfaults. The reason seems to be that the vtables are full of garbage, as shown by the following excerpt from my gdb session:

Program received signal SIGSEGV, Segmentation fault.
0x0000000000000000 in ?? ()
(gdb) up
#1  0x00000000006c49b0 in C::method (this=0x21ccde0, foo=42)
(gdb) info vtbl this
warning: can't find linker symbol for virtual table for `C' value
warning:   found `C::_ZTV1C(void)' instead
vtable for 'C' @ 0x12efa38 (subobject @ 0x21ccde0):
[0]: 0x6c0c68 <C::method2()>
[1]: 0x6c0cf8 <C::method3()>
[2]: 0x0
[3]: 0x0
[4]: 0x0
[5]: 0x0
[6]: 0x0
[7]: 0x0
[8]: 0x0
[9]: 0x0
[10]: 0x0
[11]: 0x0
[12]: 0x0
[13]: 0x0
[14]: 0x0
[15]: 0x0
[16]: 0x0
[17]: 0x0
[18]: 0x0
[19]: 0x0
[20]: 0x0
[21]: 0x0
[22]: 0x0
[23]: 0x0
[24]: 0x0
[25]: 0x0
[26]: 0x0
[27]: 0x0
[28]: 0x0
[29]: 0x0
[30]: 0x0
[31]: 0x0
[32]: 0x0
[33]: 0x0
[34]: 0x0
[35]: 0x0
[36]: 0x0
[37]: 0x0
[38]: 0x0
[39]: 0x0
[40]: 0x0
[41]: 0x0
[42]: 0x0
[43]: 0x0
[44]: 0x0
[45]: 0x0
[46]: 0x0
[47]: 0x0
[48]: 0x0
[49]: 0x0
[50]: 0x0
[51]: 0x6c36fa <C::method4()>
[52]: 0x6c3a26 <C::method5()>
[53]: 0x6c41d6 <C::method5()>

vtable for 'A' @ 0x12efe78 (subobject @ 0x21ccfd8):
[0]: 0x0
[1]: 0x0
[2]: 0x0
[3]: 0x0
[4]: 0x0
[5]: 0x0

I can confirm that the vptr values are wrong by inspecting the output of `nm -C`. For what it's worth, the vptr for C is off by only 136 bytes (should be 0x12eff00); the vptr for A is way off.

The same source code runs without a hitch when compiled with icpc/icc/ifort v15.1, icpc/icc/ifort v16.4 and several versions of the GNU suite.

Does this ring a bell for anyone? Perhaps it is a known bug of Intel compilers around v16.0? (Yes, I am aware of the First Rule of Programming). Otherwise, I am at a loss about how I should debug this. I cannot exclude that some of my application code is somehow corrupting the memory, although I ran it under valgrind and no invalid memory access were detected.

I am painfully trying to disassemble the code between the call to operator new() and the call to the constructor, hoping to spot the place where the vptr is incorrectly initialized. Do you have any simpler suggestions for debugging this?

Thank you for reading!

Davide

0 Kudos
2 Replies
Mancusi__Davide
Beginner
582 Views

I could narrow it down further to the following icc versions:

  • Crashes: 15.6, 16.0, 16.2
  • No crash: 15.1, 16.3, 16.4

So, if it is a bug, it should have appeared sometime between 15.1 and 15.6 and disappeared in 16.3.

0 Kudos
Mancusi__Davide
Beginner
582 Views

A further detail: I have tested several compiler versions and I found the following:

  • Versions that produce a working executable: 15.1, 16.3, 16.4.
  • Versions that do not produce a working executable (crash): 15.6, 16.0, 16.2

If this was a compiler bug, it would seem it was fixed in v16.3.

Davide

0 Kudos
Reply