ELF可执行文件的起点? [英] starting point of ELF executable file?

查看:98
本文介绍了ELF可执行文件的起点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I compile following C program on lubuntu 12.10 with anjuta

int main()
{
return 0;
}

文件名为foobar

the file name is foobar

然后我打开终端并输入命令

then I open up terminal and write command

ndisasm foobar -b 32 1>asm.txt

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

(disassemble foobar with 32 bit instruction option and save disassembled result to asm.txt)

我打开asm.txt
,其中有很多0x0000和容易理解的代码。

I open up asm.txt there are many 0x0000 and miss-understandable code.

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

the instruction jg 0x47(0x7F45) on 0x00000000 and dec esp(0x4C) on 0x00000002 seems ELF file format signature. (because the hex code 0x454c46 is 'ELF' in ascii)

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

the Linux might load this code to memory and don't jump to 0x00000000 because there is no executable code.

我在这里有问题。


  1. 我怎么知道起始地址的地址?

  2. 可以忽略哪个代码?(也许很多0x0000可以忽略,但是还有什么?)


推荐答案

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

Even for the simplest program like yours, gcc is linking some libraries and some object files (notably crt0.o which calls your main and contains _start, the ELF starting point). And your binary is probably dynamically linked to some libc.so.6 so needs the dynamic linker (use ldd foobar to find out). Use gcc -v to understand what gcc is doing. And objdump has a lot of interesting flags or options.

您可能还需要阅读组装方法 X86调用约定此问题 X86-64 ABI 这些有关X86-64编程的说明,等等

You may also want to read the Assembly Howto, the X86 calling conventions, this question, the X86-64 ABI, these notes on X86-64 programming, etc

这篇关于ELF可执行文件的起点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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