mips-mti-gnu-linux,c – 关于MIPS的pthreads中的Segfault
发布日期:2021-10-23 03:55:41 浏览次数:12 分类:技术文章

本文共 2875 字,大约阅读时间需要 9 分钟。

我正在尝试在MIPS

Linux机器上运行我的代码(little-endian,没有硬件浮点数):

# cat /proc/cpuinfo | grep model

cpu model : MIPS 24Kc V5.5

我的程序在x86和ARM系统上运行良好,但在MIPS上崩溃时出现分段错误,总是在(或接近)pthreads库函数调用中.我尝试了两个工具链(here的MTI GNU / Linux工具链MIPS32R2-MIPS32R5和here的Sourcery CodeBench Lite 2016.05-8) – 细节略有不同,但总是会出现段错误.

阅读邮件列表我发现MIPS平台上出现pthreads分段错误的两个原因:

>可能在MIPS版本的uClibc中错误地实现了pthread_unlock_mutex()和pthread_wait_cond().但我使用glibc(虽然设备上的操作系统是基于uClibc的);

> pthreads中的动态库加载问题;但我的程序是静态链接的.

我写了一个非常简单的程序:

#include

#include

#include

using namespace std;

void sayHello() {

this_thread::sleep_for(chrono::seconds(2));

cout << "Hello world!" << endl;

}

int main(int argc, char* argv[]) {

thread t(sayHello);

t.join();

return 0;

}

它也在MIPS上崩溃了.在t.join()上有一个breakpoin的调试器中,我看到以下内容:

(gdb) c

Continuing.

Breakpoint 1, __start () at ../sysdeps/mips/start.S:84

84 in ../sysdeps/mips/start.S

(gdb) disassemble

Dump of assembler code for function __start:

0x004059b0 : lui gp,0x5b

0x004059b4 : addiu gp,gp,-30464

=> 0x004059b8 : move ra,zero

0x004059bc : lui a0,0x40

0x004059c0 : addiu a0,a0,21584

0x004059c4 : lw a1,0(sp)

0x004059c8 : addiu a2,sp,4

0x004059cc : li at,-8

0x004059d0 : and sp,sp,at

0x004059d4 : addiu sp,sp,-32

0x004059d8 : lui a3,0x4d

0x004059dc : addiu a3,a3,-208

0x004059e0 : lui t0,0x4d

0x004059e4 : addiu t0,t0,4

0x004059e8 : sw t0,16(sp)

0x004059ec : sw v0,20(sp)

0x004059f0 : jal 0x4cf8a0 <__libc_start_main>

0x004059f4 : sw sp,24(sp)

End of assembler dump.

… (some boring "n"-s here) …

(gdb) n

109 in ../sysdeps/mips/start.S

(gdb) disassemble

Dump of assembler code for function __start:

0x004059b0 : lui gp,0x5b

0x004059b4 : addiu gp,gp,-30464

0x004059b8 : move ra,zero

0x004059bc : lui a0,0x40

0x004059c0 : addiu a0,a0,21584

0x004059c4 : lw a1,0(sp)

0x004059c8 : addiu a2,sp,4

0x004059cc : li at,-8

0x004059d0 : and sp,sp,at

0x004059d4 : addiu sp,sp,-32

0x004059d8 : lui a3,0x4d

0x004059dc : addiu a3,a3,-208

0x004059e0 : lui t0,0x4d

0x004059e4 : addiu t0,t0,4

0x004059e8 : sw t0,16(sp)

0x004059ec : sw v0,20(sp)

=> 0x004059f0 : jal 0x4cf8a0 <__libc_start_main>

0x004059f4 : sw sp,24(sp)

End of assembler dump.

(gdb) n

[New Thread 29775]

Program received signal SIGSEGV, Segmentation fault.

0x00000000 in ?? ()

(gdb) info registers

zero at v0 v1 a0 a1 a2 a3

R0 00000000 00000000 00000016 005af490 2bc7d310 00000000 2bc7d378 00000000

t0 t1 t2 t3 t4 t5 t6 t7

R8 00000000 00000000 00000000 82ee2000 00000000 00000000 00000001 74697773

s0 s1 s2 s3 s4 s5 s6 s7

R16 7fbbf194 004450c4 00464200 004641f0 00460000 2b929478 0045742c 00000001

t8 t9 k0 k1 gp sp s8 ra

R24 00000000 00000000 2bc847a0 00000000 005a8900 7fbbf158 7f894280 0041bd54

status lo hi badvaddr cause pc

0100ff13 3b9aca00 00000000 00000000 50800008 00000000

fcsr fir hi1 lo1 hi2 lo2 hi3 lo3

00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000

dspctl restart

00000000 00000000

没有线程的示例程序运行良好.

我现在能做什么?在MIPS上有任何类似的pthreads经验吗?

转载地址:https://blog.csdn.net/weixin_30496999/article/details/117273621 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:android ontouchevent 坐标,android处理触摸事件(touchEvent)的详细流程
下一篇:c语言int mark,C语言考前冲刺题

发表评论

最新留言

路过按个爪印,很不错,赞一个!
[***.219.124.196]2024年03月24日 08时34分57秒