北航操作系统课件linker.loader_第1页
北航操作系统课件linker.loader_第2页
北航操作系统课件linker.loader_第3页
北航操作系统课件linker.loader_第4页
北航操作系统课件linker.loader_第5页
已阅读5页,还剩34页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

主讲教师: intread_something(void);intdo_something(int);voidwrite_something(constchar*);intsome_global_variable;staticintmain()intsome_stack_variable;some_stack_variable=read_something();write_something("Iamdone");}#include

externintintread_something(void){intres;scanf("%d",&res);returnres;}intdo_something(intvar)returnvar+}voidwrite_something(constchar*str)printf("%s:%d\n",str,}intgloballyvisiblebyallmodules(common,staticintglobal/local:visiblebyallfunctionswithinthecurrentbutnotoutsidethemodulemain()intallocatedonthestack,visibleonlywithinthe}gccprogram.cgcc-cprogram.c=>program.ogcc-cextras.c=>extras.ogccprogram.ofunctions.o-ogccversion2.96 (RedHatLinux7.32.96-110) =2- =96 GNUC_PATCHLEVEL=0- -Dunix-Dlinux- - - unix- - main.cGNUCPPversion (RedHatLinux7.32.96-110)(cpplib)(i386 "searchstarts#include<.>searchstarts/usr/lib/gcc-lib/i386-redhat-EndofsearchGNUCversion2.96 (RedHatLinux7.32.96-110)(i386-redhat-linux)compiledbyGNUCversion2.96 (RedHatLinux7.32.96-110).as-V-Qy-o Aegki.o =2 =96- GNUC_PATCHLEVEL=0- -Dunix-Dlinux - - - unix- i386- - GNUCPPversion (RedHatLinux7.32.96-110)(cpplib)(i386#include"..."searchstarts#include<...>searchstarts/usr/lib/gcc-lib/i386-redhat-Endofsearch-oGNUCversion2.96 GNUCversion2.96 (RedHatLinux7.32.96-110).as-V-Qy-o/tmp/cc2dnA1M.oexe/usr/lib/gcc-lib/i386-redhat-linux/2.96/../../../crt1.o/usr/lib/gcc-lib/i386-redhat-redhat-linux/2.96-L/usr/lib/gcc-lib/i386-redhat-linux/2.96/../../../tmp/ .string"Iam.globl

%esp,$8,$-16,$0,%eax,%esp%eax,-$12,$16,%eax,$12,

$16, .local .ident"GCC:(GNU)(RedHatLinux3.2.2-ELF程序头表(可省略节头 .data和

此节存放

ELF头描述文件组可实现对文件内容的译码与解释

/*标志本文件为目标文件,提供与机器无关的数据项的索引

/*标识目标文件类型 /*指定必需的体系结构unsignedchar unsignedchar /*指向起始虚地址的指针*/unsignedchar /*程序头表的文件偏移量*/unsignedchar /*节头表的文件偏移量*/unsignedchar unsignedchar /*ELF头的大小*/unsignedchar /*程序头表每项的大小*/ /*程序头表项的个数 /*节头表每项的大小 /*节头表项的个数 /*与节名字符串表}符号

55 GLOBAL 10NOTYPEGLOBALDEFAULTUND0NOTYPEGLOBALDEFAULTUND4OBJECTGLOBALDEFAULTCOM0NOTYPEGLOBALDEFAULTUND

33FUNC GLOBALDEFAULT 1read_something0NOTYPEGLOBALDEFAULTUNDscanf131331

0NOTYPEGLOBALDEFAULTUNDsome_global_variable0NOTYPEGLOBALDEFAULTUNDprintfgcc-Wall-olinkprogram.o(.text+0x11):Infunction:undefinedreferenceto`read_something'program.o(.text+0x1f):Infunction`main'::undefinedreferenceto`do_something'program.o(.text+0x34):Infunction:undefinedreferenceto`write_something'collect2:ldreturned1exitstatusLinker扫描文E重定UDRelocationtypedefstruct从节起始处到受重定位影响的单元的字节偏移量;对可执行文件或共享目标文件来说,它的值是受重定位影响的单元的 /*给出了与重定位修改地点有关的符号表索引和所使用的重定的类型 r_info;(symbol:24;} 94:95:96:97:98:

31 GLOBAL 124OBJECTGLOBAL 220 GLOBAL 1233 GLOBAL 120NOTYPEGLOBALDEFAULTABS 48 GLOBAL 12 99: 0NOTYPEGLOBALDEFAULTABS 61 GLOBAL 12

55 10NOTYPEGLOBALDEFAULTUND0NOTYPEGLOBALDEFAULTUND4OBJECTGLOBALDEFAULTCOMsome_global_variable0NOTYPEGLOBALDEFAULTUNDwrite_something重定位12S+*refptr-refptr=与指令- 89

r.offset=e8fcffffe8fcffff789

r.type=R_386_PC328945 83ec ff75pushle8fcffff 1783c4 89 a3000000 83ec 68000000 e8fcffff 2e83c4 89 83ec e82d000000 89c0 8945 83ec ff75 pushl e8410000 83c410 89c0 a37c9604 83ec 68388504 e83a0000 80484ac 83c4 refptr=指令-relative=-

89 83ec 83ec

ff35000000ff7568030000e8fcffff83c4

pushl0x0pushl0x8(%ebp) voidwrite_something(constchar*voidwrite_something(constchar*str)printf("%s:%d\n",str,} c O080484ac

8983ec83ec

ff357c9604ff7568458504e85cfeffff83c410

pushl0x804967cpushl0x8(%ebp)

ELF程序头节头 F CallCallCallCallCallExecve(char*filename,char*argv[],intdo_execve(char*filename,char**argv,char**envp,pt_regsasmlinkageintsys_execve(structpt_regs主要数structpt_regs在系统调用时用于保存寄存器 执行该文件的一些参数structlinux_binfmt其中定义了一些用以载入二进制文件的数structcharunsignedlongp;intstructinode*inte_uid,intargc,char* /*Nameofbinaryunsignedlongloader,int /*binfmthandlerhasputinodestructlinux_binfmtstructlinux_binfmt*next;long*use_count;int(*load_binary)(structlinux_binprm*,structpt_regs*regs);int(*load_shlib)(intint(*core_dump)(longsignr,structpt_regs*regs.ebx:指向程序文件名的指regs.ecxregs.edx:程序运行的环境的地通过这个程序的文件名,找到该程序对应的可执行文件即i结;检查对该文件的接触权限(在打开i结点的函数open_namei()实现设置程序所需的参数结构structlinux_binprm以bprm为参数,调用函数prepare_binprm(),进行一些其他检查并读入该文件的前128字节使用函数erhbnyhnlr文件载入。为它所支持的每一种格式的可执行文件都提供了一个函数(ldbir指向)以载入文件。轮流标识NOXC;在参数bprm->buf中了文件的前128字节,于是函数可以继续进行检查。如果判断结果是正确的,这个文件将被载入。然后将原进程所

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论