【问题标题】:Trying to use an asm function in an other, while compiling a lib.so using nasm尝试在另一个中使用 asm 函数,同时使用 nasm 编译 lib.so
【发布时间】:2018-04-15 15:05:09
【问题描述】:

如前所述,我试图在另一个中重用 asm 函数,同时在 libasm.so 中编译它们。 基本上,这就是我正在做的事情:

    strpbrk:

    init:  
    push rbp
    mov rbp, rsp
    mov r9, rdi
    mov r10, rsi
    mov rdx, -1
    loop:
    mov rbx, r9
    inc rdx
    add rbx, rdx
    movzx ebx, BYTE[rbx]

    mov [buf], ebx
    movzx rsi, WORD[buf]
    mov rdi, r10
    call strstr
    cmp rax, 0
    jne end

    cmp bl, 0
    jne loop

    end:
    leave
    ret

    SECTION .data

    buf db 0, 0

这是错误:

    nasm -f elf64 src/strstr.asm -o src/strstr.o
    nasm -f elf64 src/strpbrk.asm -o src/strpbrk.o
    src/strpbrk.asm:23: error: symbol `strstr' undefined
    make: *** [Makefile:28: src/strpbrk.o] Error 1

考虑到我试图调用的 strstr 函数是在同一个 makefile 上创建的。

一个想法如何编译使用它们的机器人?

【问题讨论】:

    标签: assembly 64-bit nasm


    【解决方案1】:

    使用 nasm,您需要将来自其他翻译单元的符号声明为 extern,否则汇编程序会报错。阅读documentation了解详情。

    对于你的问题,写

    extern strstr
    

    strpbrk.asm 中告诉nasm strstr 是一个外部提供的符号。

    【讨论】:

      猜你喜欢
      • 2023-01-19
      • 2017-10-13
      • 1970-01-01
      • 2017-12-12
      • 2015-04-12
      • 2016-10-27
      • 2015-12-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多