警告:没有‘*’的间接调用 [英] Warning: indirect call without `*'

查看:44
本文介绍了警告:没有‘*’的间接调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有这个简单的组装:

.text
    .globl main
str:
    .asciz "%i\n"
add:
    push %rbp
    mov %rsp, %rbp
    movl %esi, %eax
    addl %edi, %eax
    pop %rbp
    ret

main:
    mov $1, %esi
    mov $2, %edi
    lea add(%rip), %rax
    call %rax #what is wrong here? the rax should contain first instruction of add
    mov %eax, %esi
    xor %eax, %eax
    lea str(%rip), %rdi
    call printf
    xor %eax, %eax
    ret

我收到错误:

foo.s:17: Warning: indirect call without `*'

为什么?%rax 应该包含函数的地址(如注释中所示),而不是 c,那里有带有 * 的指针,但注册包含地址.那么这里出了什么问题?

Why? The %rax should contain the address of function (as denoted in comment), and this is not c, where there are pointer with *, but register that contains an address. So what is wrong here?

推荐答案

更改

call %rax

call *%rax

这与call *(%rax) 不同.来自@interjay 的评论如下:

This is not the same as call *(%rax). From @interjay's comment below:

call *%rax 调用存储在 rax 中的地址(这是 OP 想要做的),而 call *(%rax) 调用rax

call *%rax calls the address stored in rax (which is what OP wants to do), while call *(%rax) calls the address stored in memory pointed to by rax

星号表示调用是间接调用.这意味着调用存储在 %rax

The asterisk indicates that the call is an indirect call. It means call function stored inside %rax

这篇关于警告:没有‘*’的间接调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆