解释一个ldscript资料.docx

上传人:b****1 文档编号:13693171 上传时间:2023-06-16 格式:DOCX 页数:22 大小:22.15KB
下载 相关 举报
解释一个ldscript资料.docx_第1页
第1页 / 共22页
解释一个ldscript资料.docx_第2页
第2页 / 共22页
解释一个ldscript资料.docx_第3页
第3页 / 共22页
解释一个ldscript资料.docx_第4页
第4页 / 共22页
解释一个ldscript资料.docx_第5页
第5页 / 共22页
解释一个ldscript资料.docx_第6页
第6页 / 共22页
解释一个ldscript资料.docx_第7页
第7页 / 共22页
解释一个ldscript资料.docx_第8页
第8页 / 共22页
解释一个ldscript资料.docx_第9页
第9页 / 共22页
解释一个ldscript资料.docx_第10页
第10页 / 共22页
解释一个ldscript资料.docx_第11页
第11页 / 共22页
解释一个ldscript资料.docx_第12页
第12页 / 共22页
解释一个ldscript资料.docx_第13页
第13页 / 共22页
解释一个ldscript资料.docx_第14页
第14页 / 共22页
解释一个ldscript资料.docx_第15页
第15页 / 共22页
解释一个ldscript资料.docx_第16页
第16页 / 共22页
解释一个ldscript资料.docx_第17页
第17页 / 共22页
解释一个ldscript资料.docx_第18页
第18页 / 共22页
解释一个ldscript资料.docx_第19页
第19页 / 共22页
解释一个ldscript资料.docx_第20页
第20页 / 共22页
亲,该文档总共22页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

解释一个ldscript资料.docx

《解释一个ldscript资料.docx》由会员分享,可在线阅读,更多相关《解释一个ldscript资料.docx(22页珍藏版)》请在冰点文库上搜索。

解释一个ldscript资料.docx

解释一个ldscript资料

解释一个ld.script资料

GNUld(GNUBinutilsforUbuntu)2.20.1-system.20100303

Supportedemulations:

elf_i386

i386linux

elf_x86_64

elf_l1om

usinginternallinkerscript:

==================================================

/*Scriptfor-zcombreloc:

combineandsortrelocsections*/

OUTPUT_FORMAT("elf32-i386","elf32-i386",

"elf32-i386")

OUTPUT_ARCH(i386)

ENTRY(_start)

SEARCH_DIR("/usr/i486-linux-gnu/lib32");SEARCH_DIR("/usr/local/lib32");

SEARCH_DIR("/lib32");SEARCH_DIR("/usr/lib32");SEARCH_DIR("/usr/i486-linux-gnu/lib");

SEARCH_DIR("/usr/local/lib");SEARCH_DIR("/lib");SEARCH_DIR("/usr/lib");

SECTIONS

{

/*Read-onlysections,mergedintotextsegment:

*/

PROVIDE(__executable_start=SEGMENT_START("text-segment",0x08048000));

.=SEGMENT_START("text-segment",0x08048000)+SIZEOF_HEADERS;

.interp:

{*(.interp)}

.note.gnu.build-id:

{*(.note.gnu.build-id)}

.hash:

{*(.hash)}

.gnu.hash:

{*(.gnu.hash)}

.dynsym:

{*(.dynsym)}

.dynstr:

{*(.dynstr)}

.gnu.version:

{*(.gnu.version)}

.gnu.version_d:

{*(.gnu.version_d)}

.gnu.version_r:

{*(.gnu.version_r)}

.rel.dyn:

{

*(.rel.init)

*(.rel.text.rel.text.*.rel.gnu.linkonce.t.*)

*(.rel.fini)

*(.rel.rodata.rel.rodata.*.rel.gnu.linkonce.r.*)

*(.rel.data.rel.ro*.rel.gnu.linkonce.d.rel.ro.*)

*(.rel.data.rel.data.*.rel.gnu.linkonce.d.*)

*(.rel.tdata.rel.tdata.*.rel.gnu.linkonce.td.*)

*(.rel.tbss.rel.tbss.*.rel.gnu.linkonce.tb.*)

*(.rel.ctors)

*(.rel.dtors)

*(.rel.got)

*(.rel.bss.rel.bss.*.rel.gnu.linkonce.b.*)

*(.rel.ifunc)

}

.rel.plt:

{

*(.rel.plt)

PROVIDE_HIDDEN(__rel_iplt_start=.);

*(.rel.iplt)

PROVIDE_HIDDEN(__rel_iplt_end=.);

}

.init:

{

KEEP(*(.init))

}=0x90909090

.plt:

{*(.plt)*(.iplt)}

.text:

{

*(.text.unlikely.text.*_unlikely)

*(.text.stub.text.*.gnu.linkonce.t.*)

/*.gnu.warningsectionsarehandledspeciallybyelf32.em.*/

*(.gnu.warning)

}=0x90909090

.fini:

{

KEEP(*(.fini))

}=0x90909090

PROVIDE(__etext=.);

PROVIDE(_etext=.);

PROVIDE(etext=.);

.rodata:

{*(.rodata.rodata.*.gnu.linkonce.r.*)}

.rodata1:

{*(.rodata1)}

.eh_frame_hdr:

{*(.eh_frame_hdr)}

.eh_frame:

ONLY_IF_RO{KEEP(*(.eh_frame))}

.gcc_except_table:

ONLY_IF_RO{*(.gcc_except_table.gcc_except_table.*)}

/*Adjusttheaddressforthedatasegment.Wewanttoadjustupto

thesameaddresswithinthepageonthenextpageup.*/

.=ALIGN(CONSTANT(MAXPAGESIZE))-((CONSTANT(MAXPAGESIZE)-.)&(CONSTANT(MAXPAGESIZE)-1));.=DATA_SEGMENT_ALIGN(CONSTANT(MAXPAGESIZE),CONSTANT(COMMONPAGESIZE));

/*Exceptionhandling*/

.eh_frame:

ONLY_IF_RW{KEEP(*(.eh_frame))}

.gcc_except_table:

ONLY_IF_RW{*(.gcc_except_table.gcc_except_table.*)}

/*ThreadLocalStoragesections*/

.tdata:

{*(.tdata.tdata.*.gnu.linkonce.td.*)}

.tbss:

{*(.tbss.tbss.*.gnu.linkonce.tb.*)*(.tcommon)}

.preinit_array:

{

PROVIDE_HIDDEN(__preinit_array_start=.);

KEEP(*(.preinit_array))

PROVIDE_HIDDEN(__preinit_array_end=.);

}

.init_array:

{

PROVIDE_HIDDEN(__init_array_start=.);

KEEP(*(SORT(.init_array.*)))

KEEP(*(.init_array))

PROVIDE_HIDDEN(__init_array_end=.);

}

.fini_array:

{

PROVIDE_HIDDEN(__fini_array_start=.);

KEEP(*(.fini_array))

KEEP(*(SORT(.fini_array.*)))

PROVIDE_HIDDEN(__fini_array_end=.);

}

.ctors:

{

/*gccusescrtbegin.otofindthestartof

theconstructors,sowemakesureitis

first.Becausethisisawildcard,it

doesn'tmatteriftheuserdoesnot

actuallylinkagainstcrtbegin.o;the

linkerwon'tlookforafiletomatcha

wildcard.Thewildcardalsomeansthatit

doesn'tmatterwhichdirectorycrtbegin.o

isin.*/

KEEP(*crtbegin.o(.ctors))

KEEP(*crtbegin?

.o(.ctors))

/*Wedon'twanttoincludethe.ctorsectionfrom

thecrtend.ofileuntilafterthesortedctors.

The.ctorsectionfromthecrtendfilecontainsthe

endofctorsmarkeranditmustbelast*/

KEEP(*(EXCLUDE_FILE(*crtend.o*crtend?

.o).ctors))

KEEP(*(SORT(.ctors.*)))

KEEP(*(.ctors))

}

.dtors:

{

KEEP(*crtbegin.o(.dtors))

KEEP(*crtbegin?

.o(.dtors))

KEEP(*(EXCLUDE_FILE(*crtend.o*crtend?

.o).dtors))

KEEP(*(SORT(.dtors.*)))

KEEP(*(.dtors))

}

.jcr:

{KEEP(*(.jcr))}

.data.rel.ro:

{*(.data.rel.ro.local*.gnu.linkonce.d.rel.ro.local.*)*(.data.rel.ro*.gnu.linkonce.d.rel.ro.*)}

.dynamic:

{*(.dynamic)}

.got:

{*(.got)*(.igot)}

.=DATA_SEGMENT_RELRO_END(12,.);

.got.plt:

{*(.got.plt)*(.igot.plt)}

.data:

{

*(.data.data.*.gnu.linkonce.d.*)

SORT(CONSTRUCTORS)

}

.data1:

{*(.data1)}

_edata=.;PROVIDE(edata=.);

__bss_start=.;

.bss:

{

*(.dynbss)

*(.bss.bss.*.gnu.linkonce.b.*)

*(COMMON)

/*Alignheretoensurethatthe.bsssectionoccupiesspaceupto

_end.Alignafter.bsstoensurecorrectalignmentevenifthe

.bsssectiondisappearsbecausetherearenoinputsections.

FIXME:

Whydoweneedit?

Whenthereisno.bsssection,wedon't

padthe.datasection.*/

.=ALIGN(.!

=0?

32/8:

1);

}

.=ALIGN(32/8);

.=ALIGN(32/8);

_end=.;PROVIDE(end=.);

.=DATA_SEGMENT_END(.);

/*Stabsdebuggingsections.*/

.stab0:

{*(.stab)}

.stabstr0:

{*(.stabstr)}

.stab.excl0:

{*(.stab.excl)}

.stab.exclstr0:

{*(.stab.exclstr)}

.stab.index0:

{*(.stab.index)}

.stab.indexstr0:

{*(.stab.indexstr)}

.comment0:

{*(.comment)}

/*DWARFdebugsections.

SymbolsintheDWARFdebuggingsectionsarerelativetothebeginning

ofthesectionsowebeginthemat0.*/

/*DWARF1*/

.debug0:

{*(.debug)}

.line0:

{*(.line)}

/*GNUDWARF1extensions*/

.debug_srcinfo0:

{*(.debug_srcinfo)}

.debug_sfnames0:

{*(.debug_sfnames)}

/*DWARF1.1andDWARF2*/

.debug_aranges0:

{*(.debug_aranges)}

.debug_pubnames0:

{*(.debug_pubnames)}

/*DWARF2*/

.debug_info0:

{*(.debug_info.gnu.linkonce.wi.*)}

.debug_abbrev0:

{*(.debug_abbrev)}

.debug_line0:

{*(.debug_line)}

.debug_frame0:

{*(.debug_frame)}

.debug_str0:

{*(.debug_str)}

.debug_loc0:

{*(.debug_loc)}

.debug_macinfo0:

{*(.debug_macinfo)}

/*SGI/MIPSDWARF2extensions*/

.debug_weaknames0:

{*(.debug_weaknames)}

.debug_funcnames0:

{*(.debug_funcnames)}

.debug_typenames0:

{*(.debug_typenames)}

.debug_varnames0:

{*(.debug_varnames)}

/*DWARF3*/

.debug_pubtypes0:

{*(.debug_pubtypes)}

.debug_ranges0:

{*(.debug_ranges)}

.gnu.attributes0:

{KEEP(*(.gnu.attributes))}

/DISCARD/:

{*(.note.GNU-stack)*(.gnu_debuglink)*(.gnu.lto_*)}

}

==================================================下面逐句解释。

OUTPUT_FORMAT("elf32-i386","elf32-i386",

"elf32-i386")

OUTPUT_ARCH(i386)OUTPUT_FORMAT和OUTPUT_ARCH都是ld脚本的保留字命令。

OUTPUT_FORMAT说明输出二进制文件的格式。

OUTPUT_ARCH说明输出文件系统平台。

ENTRY(_start)ENTRY命令的作用是,将后面括号中的符号值设置成入口地址。

入口地址(entrypoint)的定义是这样的──进程执行的第一条用户空间的指令在进程地址空间中的地址。

ld有多种方法设置进程入口地址,通常它按以下顺序:

(编号越前,优先级越高)

1,ld命令行的-e选项

2,连接脚本的ENTRY(SYMBOL)命令

3,如果定义了start符号,使用start符号值

4,如果存在.textsection,使用.textsection的第一字节的位置值

5,使用值0

SEARCH_DIR("/usr/i486-linux-gnu/lib32");

 

设置链接时搜寻库文件目录.

SECTIONS

{然后,接下来是一大段的SECTIONS,对应的右大括号直到脚本的末尾。

SECTIONS命令告诉ld如何把输入文件的sections映射到输出文件的各个section:

即是如何将输入section

合为输出section;如何把输出section放入程序地址空间(VMA)和进程地址空间(LMA)。

该命令格式如下:

SECTIONS

{

….

}/*Read-onlysections,mergedintotextsegment:

*/

PROVIDE(__executable_start=SEGMENT_START("text-segment",0x08048000));PROVIDE定义的变量如果源文件中已经定义值那么用源文件中的,如果没有定义则用脚本中定义的。

并设定该变量的值为0x08048000.=SEGMENT_START("text-segment",0x08048000)+SIZEOF_HEADERS;

 

这句把定位器符号置为0x08048000+SIZE_HEADERS(若不指定,则该符号的初始值为0)。

SIZE_HEADERS为输出文件的文件头.

.是一个特殊的符号,它是定位器,一个位置指针,指向程序地址空间内的某位置(或某section内的偏移,如果它在SECTIONS命令内的某section描述内),该符号只能在SECTIONS命令内使用。

.rel.dyn:

{

*(.rel.init)

*(.rel.text.rel.text.*.rel.gnu.linkonce.t.*)

*(.rel.fini)

*(.rel.rodata.rel.rodata.*.rel.gnu.linkonce.r.*)

*(.rel.data.rel.ro*.rel.gnu.linkonce.d.rel.ro.*)

*(.rel.data.rel.data.*.rel.gnu.linkonce.d.*)

*(.rel.tdata.rel.tdata.*.rel.gnu.linkonce.td.*)

*(.rel.tbss.rel.tbss.*.rel.gnu.linkonce.tb.*)

*(.rel.ctors)

*(.rel.dtors)

*(.rel.got)

*(.rel.bss.rel.bss.*.rel.gnu.linkonce.b.*)

*(.rel.ifunc)

}

.rel.plt:

{

*(.rel.plt)

PROVIDE_HIDDEN(__rel_iplt_start=.);

*(.rel.iplt)

PROVIDE_HIDDEN(__rel_iplt_end=.);

}

以上这些段主要用于重定位.具体的内容还需进一步学习.先不做介绍..init:

{

KEEP(*(.init))

}=0x90909090

.plt:

{*(.plt)*(.iplt)}

.text:

{

*(.text.unlikely.text.*_unlikely)

*(.text.stub.text.*.gnu.linkonce.t.*)

/*.gnu.warningsectionsarehandledspeciallybyelf32.em.*/

*(.gnu.warning)

}=0x90909090.init将在下文与.fini一起介绍..text:

表示text段开始.

*(.text)将所有(*符号代表任意输入文件)输入文件的.textsection合并成一个.textsection,该section的地址由定位器符号的值指定,即0x08048000.

*(.text.unlikely.text.*_unlikely)

*(.text.stub.text.*.gnu.linkonce.t.*)

/*.gnu.warningsectionsarehandledspeciallybyelf32.em.*/

*(.gnu.warning).fini:

{

KEEP(*(.fini))#

KEEP()强制连接器保留一些特定的section

}=0x90909090ELF文件中定义了.init和.fini两个特殊的段,其中.init段中的代码会在main之前被执行,.fini段中的代码会在main退出之后被执行.默认用NOP(0x90)字段进行填充.PROVIDE(__etext=.);

PROVIDE(_etext=.);

PROVIDE(etext=.);__etext=._etext=.etext=.;我们看到,很多变量都定义成等于这个.符,实际上这个符号所代表的值是在变化的,随着越往后走,值越增加,根据前面填充的多少自动往后加。

即指定当前地址值为代码段结束位置.

这里就定义了一个etext符号,当目标文件内引用了etext符号,却没有定义它时,etext符号对应的地址被定义为.textsection之后的第一个字节的地址。

 

.rodata:

{*(.rodata.rodata.*.gnu.linkonce.r.*)}

.rodata1:

{*(.rodata1)}

数据段终于来到了,意思很容易理解的了(用于只读数据段)。

/*Adjusttheaddressforthedatasegment.Wewanttoadjustupto

thesameaddresswithinthepageonthenextpageup.*/

.=ALIGN(CONSTANT(MAXPAGESIZE))-((CONSTANT(MAXPAGESIZE)-.)&

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 自然科学 > 物理

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2