Browsed by
Month: March 2016

函数调用 foobar 实验

函数调用 foobar 实验

本文记录对 C 与汇编的联系, C的函数调用在汇编下的实现, 下面是实验用的C语言源码 int bar(int c, int d) { int e = c + d; return e; } int foo(int a, int b) { return bar(a, b); } int main(void) { foo(2, 3); return 0; }  

ELF 文件格式初步探索

ELF 文件格式初步探索

在Linux下编译一个汇编程序需要的工具为 as(汇编器) ld(链接器) e.g: 一个非常简单的AT&T汇编程序 .section .data .section .text .globl _start _start: movl $1, %eax movl $4, %ebx int $0x80 .section .globl 这种叫做 伪操作, .section将代码分为若干段 _start 是 symbol(符号)  符号在汇编程序中代表一个地址 .globl 表示一个符号会被链接器使用 as –32 将 汇编代码编译为 relocatable object file elf32_i386   解读ELF 文件格式 对于汇编 , 链接器来看 , elf文件是由 Section Header Table 描述的一系列Section 集合, 而执行一个ELF文件的时候, 在loader看来 它是由 Programer Header Table 描述的一系列Segment的集合 对于程序运行的时候 Program Header Table 是必须 程序链接的时候 Section Header Table 是必须的 对于一个在运行的时候动态链接的程序, Program Header Table 和 Section Header Table 都是需要的, 因为程序既要加载 也要动态链接…

Read More Read More