Are*_*ski 0 c assembly gcc x86-64
我需要有关使用ASSEMBLY部件的C代码的帮助.GCC编译程序集有问题,错误:
$ make
gcc -Wall -g -std=c99 -pedantic -c -o sthread.o sthread.c
sthread.c: In function ‘sthread_create’:
sthread.c:159:57: warning: pointer of type ‘void *’ used in arithmetic [-Wpointer-arith]
t->context = __sthread_initialize_context(t->memory + DEFAULT_STACKSIZE, f, arg);
^
gcc -Wall -g -std=c99 -pedantic -c -o queue.o queue.c
as -g -o glue.o glue.s
glue.s: Assembler messages:
glue.s:32: Error: operand type mismatch for `push'
<wbudowane>: polecenia dla obiektu 'glue.o' nie powiod?y si?
make: *** [glue.o] B??d 1
Run Code Online (Sandbox Code Playgroud)
有问题的代码:
__sthread_switch:
# preserve CPU state on the stack, with exception of stack pointer, instruction pointer first, reverse order
pushq %rip #line 32
pushf
pushq %rdi
pushq %rsi
pushq %rbp
pushq %rbx
pushq %rdx
pushq %rcx
pushq %rax
# Call the high-level scheduler with the current context as an argument
movq %rsp, %rdi
movq scheduler_context, %rsp
call __sthread_scheduler
Run Code Online (Sandbox Code Playgroud)
随着X86_64你不能推%rip,实际上你根本无法直接访问它.
如果你仍然需要这样做,你可以做到
leaq 0(%rip), %rax # Or any other GPR that is free
pushq %rax
Run Code Online (Sandbox Code Playgroud)
要么
callq . + 5 # no label, hard-code instruction length
# or
callq 1f ; 1: # with a local numbered label
Run Code Online (Sandbox Code Playgroud)
虽然我不确定你为什么要隐藏它%rip,如果你从这里恢复它,执行将继续从push指令.这有什么价值吗?您需要重新考虑线程切换逻辑.