在编写一些 x64 程序集时,我偶然发现了一些奇怪的东西。函数调用在主线程上执行时工作正常,但在作为 pthread 执行时会导致分段错误。起初我以为我使堆栈无效,因为它只在第二次调用时出现段错误,但这与它在主线程上正常工作但在新生成的线程上崩溃的事实不匹配。
来自 gdb:
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Value: 1337
Value: 1337
[New Thread 0x7ffff77f6700 (LWP 8717)]
Return value: 0
Value: 1337
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7ffff77f6700 (LWP 8717)]
__printf (format=0x600570 <fmt> "Value: %d\n") at printf.c:28
28 printf.c: No such file or directory.
Run Code Online (Sandbox Code Playgroud)
有没有人知道这里会发生什么?
extern printf
extern pthread_create
extern pthread_join
extern pthread_exit
section .data
align 4
fmt db "Value: %d", 0x0A, 0
fmt_rval db "Return value: …Run Code Online (Sandbox Code Playgroud)