This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/66666] New: ARM compiled code segmentation fault on multiple inheritance
- From: "antonio.poggiali at datalogic dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 25 Jun 2015 13:10:01 +0000
- Subject: [Bug c++/66666] New: ARM compiled code segmentation fault on multiple inheritance
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66666
Bug ID: 66666
Summary: ARM compiled code segmentation fault on multiple
inheritance
Product: gcc
Version: 4.9.1
Status: UNCONFIRMED
Severity: major
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: antonio.poggiali at datalogic dot com
Target Milestone: ---
Created attachment 35854
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=35854&action=edit
Source files, compiled file, gcc output, etc.
Host system:
Linux MatrixPlatVb-lx-apoggiali 3.13.0-44-generic #73~precise1-Ubuntu SMP Wed
Dec 17 00:39:15 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
Target system:
ARM cortex A5 (but same behavior on A9).
Linux sama5d4ek 3.18.0-linux4sam_5.0-alpha1 #1 Wed Jun 24 09:45:58 CEST 2015
armv7l GNU/Linux
Cross-compiler invocation and output:
Invoking: GCC C++ Compiler
arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-g++ -O0 -g3 -Wall -Wextra -c
-fmessage-length=0 --sysroot=<...> -march=armv7-a -mfloat-abi=hard
-fno-strict-aliasing -fwrapv -fno-aggressive-loop-optimizations -MMD -MP
-MF"liste.d" -MT"liste.d" -o "liste.o" "liste.cpp"
Finished building:
liste.cpp
Invoking: GCC C++ Linker
arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-g++ --sysroot=<...>
-march=armv7-a -mfloat-abi=hard -o "liste" liste.o
Finished building target: liste
Input file (liste.cpp):
#include <list>
#include <iostream>
class SmartObject
{
public:
virtual ~SmartObject(){
}
void method(void) {}
};
class IMyInterface
{
public:
virtual ~IMyInterface(){
}
virtual std::list<int> getList() = 0;
};
class MyObject : public virtual IMyInterface, public SmartObject
{
public:
MyObject()
{
list.push_back(4);
list.push_back(5);
}
virtual std::list<int> getList() {
return list;
}
virtual ~MyObject(){
}
std::list<int> list;
};
int main()
{
IMyInterface * ip = new MyObject();
std::list<int> list_clone = ip->getList();
// On size() I get a segmentation fault
std::cout << list_clone.size() << std::endl;
delete ip;
return 0;
}
Stack at fault:
liste [C/C++ Remote Application]
list [1573] [cores: 0]
Thread [1] 1573 [core: 0] (Suspended : Signal :
SIGSEGV:Segmentation fault)
std::_List_const_iterator<int>::operator++() at
stl_list.h:244 0x9738
std::__distance<std::_List_const_iterator<int> >() at
stl_iterator_base_funcs.h:82 0x97d4
std::distance<std::_List_const_iterator<int> >() at
stl_iterator_base_funcs.h:118 0x9430
std::list<int, std::allocator<int> >::size() at
stl_list.h:887 0x9144
main() at liste.cpp:50 0x8a14
Comment:
The list obtained through ip->getList(); is incorrect: the tail pointer is
malformed. When size() is called the list is scanned to count the number of
elements. As the tail pointer is malformed the scan end condition is not met
and i get a segmentation fault (or an endless loop when optimization in on).
The same code works correctly on host system (x86_64-linux).
Notes:
Declaring "class MyObject : public virtual IMyInterface, public virtual
SmartObject" makes it work.
Also removing ~SmartObject() destructor makes it work.
In attachment source code and compiler outputs.