加载警告:找不到条目符号_start [英] load warning: cannot find entry symbol _start

查看:188
本文介绍了加载警告:找不到条目符号_start的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习汇编程序设计.下面是打印"Hello,World!"的简单程序.当程序运行正常时,我在loading

I'm learning assembly programming. Below is the simple program that prints 'Hello, World!'. While the program runs perfectly, I'm getting the warning message while loading

ld:警告:找不到条目符号_start;默认为0000000008048080

ld: warning: cannot find entry symbol _start; defaulting to 0000000008048080

这是代码:

section .data
    msg db 'Hello, world!', 0xa
    len equ $ - msg

section .text
    global main

main:

    mov ebx, 1
    mov ecx, msg
    mov edx, len
    mov eax, 4
    int 0x80

    mov eax, 1
    int 0x80

任何人都可以解释此警告的含义.我正在将nasmubuntu 14一起使用.

Can anybody explain the meaning of this warning. I'm using nasm with ubuntu 14.

推荐答案

您没有说,但是从错误消息和代码中,我认为您正在使用nasm -felf32 hello32.asm && ld -melf_i386 -o hello32 hello32.o

You don't say, but from the error messages and code I assume you're building your 32bit code with nasm -felf32 hello32.asm && ld -melf_i386 -o hello32 hello32.o

(如果您实际上是在构建64位代码,则很幸运它可以正常工作,但是只要您使用esp而不是rsp进行操作,它就会立即中断.)

(If you're actually building 64bit code, you're lucky that it happens to work, but it'll break as soon as you do anything with esp instead of rsp.)

错误消息来自ld,而不是来自nasm.它在消息中说得很对.蒂姆的评论是正确的:ld在其链接的文件中查找_start符号,但如果找不到则将入口点设置为文本段的开头.

The error message is from ld, not from nasm. It says so right in the message. Tim's comment is correct: ld looks for a _start symbol in the files it links, but sets the entry point to the beginning of the text segment if it doesn't find one.

定义什么其他全局/外部符号也没有关系. main在这里完全不相关,可以指向您想要的任何位置.它仅对反汇编输出和类似内容有用.如果您删除global main/main:行,或将其更改为任何其他名称,则您的代码将完全相同.

It doesn't matter what other global/external symbols you define. main has no relevance at all here, and could point anywhere you want. It's only useful for a disassembly output and stuff like that. Your code would work exactly the same if you took out the global main / main: lines, or changed them to any other name.

标记为main是不明智的.它不是 main(),并且不接收argcargv自变量. (或者,也许32位ABI确实在进程启动时将它们放在堆栈中,以main()所需的相同顺序.64位ABI将它们放在堆栈中,但是调用main的启动代码必须将它们加载到寄存器中,因为64位使用寄存器调用ABI.)您也不能从入口点返回:堆栈上没有返回地址.

Labelling that as main is unwise, if you're building without the standard libc runtime start files. It's not main(), and doesn't receive argc and argv arguments. (Or maybe the 32bit ABI does put those on the stack at process start time, in the same order main() wants them. The 64bit ABI puts them on the stack, but the startup code that calls main has to load them into registers because 64bit uses a register-call ABI.) You also can't return from the entry point: there's no return address on the stack.

这篇关于加载警告:找不到条目符号_start的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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