gpt4 book ai didi

linux - ELF 可执行文件的起点?

转载 作者:太空狗 更新时间:2023-10-29 11:05:09 30 4
gpt4 key购买 nike

我在 lubuntu 12.10 上用 anjuta 编译了以下 C 程序

int main()
{
return 0;
}

文件名为foobar

然后我打开终端并写命令

ndisasm foobar -b 32 1>asm.txt

(使用32位指令选项反汇编foobar并将反汇编结果保存到asm.txt)

我打开 asm.txt有很多 0x0000 和难以理解的代码。

指令 jg 0x47(0x7F45) on 0x00000000 and dec esp(0x4C) on 0x00000002 好像是ELF文件格式的签名。(因为十六进制代码 0x454c46 在 ascii 中是 'ELF')

Linux 可能会将此代码加载到内存并且不会跳转到 0x00000000,因为没有可执行代码。

我在这里有问题。

  1. 我怎么知道起始地址的地址?
  2. 哪些代码可以忽略?(也许许多 0x0000 可以忽略,但还有什么?)

最佳答案

即使是像您这样最简单的程序,gcc 也会链接一些库和一些目标文件(特别是 crt0.o,它调用您的 main并包含 _start,ELF 起点)。并且您的二进制文件可能动态链接到某些 libc.so.6,因此需要动态链接器(使用 ldd foobar 来查找)。使用 gcc -v 了解 gcc 正在做什么。和 objdump有很多有趣的标志或选项。

您可能还想阅读 Assembly Howto , X86 calling conventions , this question , the X86-64 ABI , these notes on X86-64 programming

关于linux - ELF 可执行文件的起点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14002502/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com