SIGILL on std::ios_base::Init::Init() 和 std::string::assign(std::string const&)

SIGILL on std::ios_base::Init::Init() and std::string::assign(std::string const&)

本文关键字:std string Init assign const on SIGILL ios base      更新时间:2023-10-16

使用嵌入式linux在Ubuntu上交叉编译代码以在COMX-p2020模块上运行。我假设我要么缺失或有一些编译器设置不正确,这是导致非法指令。这是我的编译器标志。

CPPFLAGS = -MD -MP -w -g $(DEFINES) $(INCLUDES) -pthread -mcpu=powerpc

下面是gdb的输出。

Program received signal SIGILL, Illegal instruction.
0x0ff1d3f4 in std::ios_base::Init::Init() () from /usr/lib/libstdc++.so.6
(gdb) bt
#0  0x0ff1d3f4 in std::ios_base::Init::Init() () from /usr/lib/libstdc++.so.6
#1  0x100d3074 in __static_initialization_and_destruction_0 (__initialize_p=1,__priority=65535) at /opt/Freescale/CodeWarrior_PA_10.0/Cross_Tools/freescale-4.4/bin/../lib/gcc/powerpc-linux-gnu/4.4.1/../../../../powerpc-linux-gnu/include/c++/4.4.1/iostream:72
#2  0x100d30d0 in global constructors keyed to outDmxData() () at ../Luminaire/Mac Source/VArtnetManager.cpp:769
#3  0x100def88 in __do_global_ctors_aux ()
#4  0x10001a58 in _init ()
#5  0x100deed8 in __libc_csu_init ()
#6  0x0fc1d684 in generic_start_main () from /lib/libc.so.6
#7  0x0fc1d8b0 in __libc_start_main () from /lib/libc.so.6
#8  0x00000000 in ?? ()

它从来没有到达main,看起来它试图分配一个全局和阻塞在初始化期间。这是一个全局变量

unsigned char outDmxData[kNumDmxBuses][513];

然后我开始剥离代码,以确保我可以让它运行。我可以编译并成功运行一个简单的hello世界与相同的编译器设置没有问题。然后我开始慢慢地添加对象,直到我遇到这个。

Program received signal SIGILL, Illegal instruction.
0x0ff6b680 in std::string::assign(std::string const&) ()
from /usr/lib/libstdc++.so.6
(gdb) bt
#0  0x0ff6b680 in std::string::assign(std::string const&) () from /usr/lib/libstdc++.so.6
#1  0x0ff6b6e4 in std::string::operator=(std::string const&) () from /usr/lib/libstdc++.so.6
#2  0x10008014 in VxQueue::InitQueue (this=0x10052038) at ../Common/SystemObjects/VxQueue.cpp:114
#3  0x10007a6c in VxQueue::VxQueue (this=0x10052038,queueName=0x1001d580 "DestoryedObjects") at ../Common/SystemObjects/VxQueue.cpp:40
#4  0x10004aa4 in VxMessageManager::CreateQueueContext (this=0x10052008,queueName=0x1001d580 "DestoryedObjects") at ../Common/SystemObjects/VxMessageManager.cpp:209
#5  0x10004750 in VxMessageManager::VxMessageManager (this=0x10052008) at ../Common/SystemObjects/VxMessageManager.cpp:187
#6  0x10003fa0 in VxMessageManager::CreateSharedMessageManager () at ../Common/SystemObjects/VxMessageManager.cpp:36
#7  0x10001714 in main () at ../Luminaire_gcc/main.cpp:68

所讨论的行是这样的。

// set default queue name
char queueName[32];
snprintf(queueName, sizeof(queueName), "queue_%04d", m_queueId);
m_queueName = std::string(queueName); // <- error in question

编辑

下面是std::ios_base::Init::Init()的反汇编。看起来。long是它有问题的指令。将std::字符串发送到几个。

   0x0ff1d3dc <+76>:    stw     r28,48(r1)
   0x0ff1d3e0 <+80>:    lwz     r24,-32768(r30)
   0x0ff1d3e4 <+84>:    stw     r31,60(r1)
   0x0ff1d3e8 <+88>:    cmpwi   cr7,r24,0
   0x0ff1d3ec <+92>:    beq-    cr7,0xff1d870 <_ZNSt8ios_base4InitC1Ev+1248>
   0x0ff1d3f0 <+96>:    lwz     r27,-32764(r30)
=> 0x0ff1d3f4 <+100>:   .long 0x7c2004ac
   0x0ff1d3f8 <+104>:   lwarx   r28,0,r27
   0x0ff1d3fc <+108>:   addi    r9,r28,1
   0x0ff1d400 <+112>:   stwcx.  r9,0,r27
   0x0ff1d404 <+116>:   bne-    0xff1d3f8 <_ZNSt8ios_base4InitC1Ev+104>

std::string问题看起来是一样的。我猜.long 0x7c2004ac的意思是它不知道指令是什么?

   0x0ff6b528 <+72>:    lwz     r0,-32760(r30)
   0x0ff6b52c <+76>:    cmpwi   cr7,r0,0
   0x0ff6b530 <+80>:    beq-    cr7,0xff6b564 <_ZNSsD1Ev+132>
   0x0ff6b534 <+84>:    addi    r10,r3,8
=> 0x0ff6b538 <+88>:    .long 0x7c2004ac
   0x0ff6b53c <+92>:    lwarx   r9,0,r10
   0x0ff6b540 <+96>:    addi    r11,r9,-1
   0x0ff6b544 <+100>:   stwcx.  r11,0,r10
   0x0ff6b548 <+104>:   bne-    0xff6b53c <_ZNSsD1Ev+92>

编辑

很抱歉这么长。更多的是为了我的利益,在我走的过程中记录这个。看起来0x7c2004ac转换为PPC_INST_LWSYNC。这让我想到了这篇文章http://gcc.gnu.org/ml/gcc-patches/2006-11/msg01238.html,这听起来正是我的问题所在(lwsync不能在e500处理器上工作)。下一个问题是,我的时间很紧,我使用的工具链是与开发工具包一起打包的。所以我不知道有什么方法可以快速修补这个问题,而不试图弄清楚如何从头开始构建工具链,我知道这不会是一个快速的任务,至少对我来说……我想我可以联系供应商,但他们过去一直没有回应,通常是我来解决他们的问题。

使用gdb命令disassemble查看第0帧中的指令是什么,然后找出该指令是否适用于您的硬件平台。

最终通过切换到不同的工具链解决了我的问题。我正在使用Codewarrior 10.0.2附带的工具链,这导致了我的问题。然后,我使用crostools -ng 1.17.0使用powerpc-e500v2-linux-gnuspe示例构建一个新的工具链。我遇到了一个问题,crosstools-ng无法使用[ERROR] configure: error: python is missing or unusable构建gdb。我确实安装了python,所以不确定为什么会出现错误。我已经交叉编译gdb自己,所以只是禁用它在菜单配置(调试设施->gdb)。我还必须在编译器升级时禁用内核上的-Werror。

另外,在编译二进制文件时,我为mpcu选项指定了e500mc。

CPPFLAGS = -MD -MP -w -g $(DEFINES) $(INCLUDES) -pthread -mcpu=e500mc
谢谢Jonathan给我指了正确的方向。