public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/66666] New: ARM compiled code segmentation fault on multiple inheritance
@ 2015-06-25 13:10 antonio.poggiali at datalogic dot com
  2015-06-25 17:49 ` [Bug c++/66666] " ramana at gcc dot gnu.org
                   ` (13 more replies)
  0 siblings, 14 replies; 15+ messages in thread
From: antonio.poggiali at datalogic dot com @ 2015-06-25 13:10 UTC (permalink / raw)
  To: gcc-bugs

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.


^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2015-07-03 15:57 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-25 13:10 [Bug c++/66666] New: ARM compiled code segmentation fault on multiple inheritance antonio.poggiali at datalogic dot com
2015-06-25 17:49 ` [Bug c++/66666] " ramana at gcc dot gnu.org
2015-06-26  7:04 ` antonio.poggiali at datalogic dot com
2015-06-26 11:23 ` antonio.poggiali at datalogic dot com
2015-06-26 11:24 ` antonio.poggiali at datalogic dot com
2015-06-27 12:42 ` [Bug c++/66666] ARM wrong copy constructor address " mikpelinux at gmail dot com
2015-06-28 12:40 ` mikpelinux at gmail dot com
2015-06-29 15:56 ` antonio.poggiali at datalogic dot com
2015-06-29 15:59 ` antonio.poggiali at datalogic dot com
2015-06-30  7:01 ` antonio.poggiali at datalogic dot com
2015-06-30 13:24 ` antonio.poggiali at datalogic dot com
2015-06-30 17:09 ` jgreenhalgh at gcc dot gnu.org
2015-07-01 10:18 ` jgreenhalgh at gcc dot gnu.org
2015-07-01 10:26 ` antonio.poggiali at datalogic dot com
2015-07-03 15:57 ` jgreenhalgh at gcc dot gnu.org

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).