【问题标题】:ld: undefined reference to 'eax'ld:未定义对“eax”的引用
【发布时间】:2012-10-06 19:46:05
【问题描述】:

我在我的旧 linux 机器(都是 intel 32bit)上从来没有遇到过这个错误,所以我很茫然。

我正在尝试汇编和链接汇编代码(这非常简单并且应该可以工作)但是ld 给出了错误

rs.o: In function `_start':
(.text+0x11): undefined reference to `eax'

有问题的行是pushl %eax 行。我只需要将 0 的单个字节推入堆栈,因此我决定使用 xor'd eax 寄存器。但是pushb 在使用代码pushb %alas 组装时给我一个“invalid suffix or operands for push”错误,如果我尝试使用pushl %eax as 组装很好但是链接器对我大喊大叫。

这里是代码。

.section .data

.section .text

.global _start

_start:

xorl %eax, %eax

#sys_socketcall(int call, __user *args)
#sys_socket(int domain, int type, int protocol)

pushl %eax          #protocol: 0
pushl $1            #type: SOCK_STREAM
pushl $2            #domain: AF_INET
movL $1, %ebx       #sys_socket
movl $102, %eax    #sys_socketcall
int $0x80

movl $eax, %ebx  #move socket fd to check echo $?
movl $1, %eax    #exit
int $0x80

感谢任何帮助。

【问题讨论】:

  • 不可能是pushl %eax_start + 0x11movl $eax, %ebx,另一方面....

标签: linux assembly x86 ld


【解决方案1】:

您的程序集中有一个错误:$eax 应该是 %eax in

movl $eax, %ebx  #move socket fd to check echo $?

【讨论】:

  • 谢谢你一个愚蠢的错误。将在 6 分钟内接受您的回答。它解决了我的链接器问题。还有一个问题。为什么'push %al'和'pushb %al'返回错误:后缀或操作数对push无效。
  • @bobmoch 您不能在 x86 程序集中推送 8 位寄存器。您必须改用push %ax/pushw %axpush %eax/pushd %eaxpush %rax/pushq %rax
  • 我明白了。谢谢(你的)信息。我还阅读了 perilbrain 的链接,现在它更有意义了。谢谢大家的帮助。
【解决方案2】:

我可以想象它是

movl $eax, %ebx  #move socket fd to check echo $?

行。

应该是

movl %eax, %ebx  #move socket fd to check echo $?

...

【讨论】:

    【解决方案3】:
    movl $eax, %ebx
    

    有问题。它尝试将名为eax 的符号的地址加载到ebx 中, 这不是您想要的。把那个错字改成

    movl %eax, %ebx
    

    告诉它做你真正想做的事。

    【讨论】:

      【解决方案4】:

      除了语法错误之外,问题是您无法将字节压入堆栈。 看看

      http://coding.derkeiler.com/Archive/Assembler/comp.lang.asm.x86/2006-03/msg00253.html

      http://www.rz.uni-karlsruhe.de/rz/docs/VTune/reference/vc266.htm

      如果可能,我会建议使用 pushw %ax。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-04-07
        • 1970-01-01
        • 2021-01-14
        • 2021-01-26
        • 2021-01-31
        相关资源
        最近更新 更多