URN Logo
UNIX Resources » Linux » China Linux Forum » CPU 与 编译器 » 8 » <<A guide to the internals of the GNU linker>>摘录
announcement 声明: 本页内容为中国Linux论坛的内容镜像,文章的版权以及其他所有的相关权利属于中国Linux论坛和相应文章的作者,如果转载,请注明文章来源及相关版权信息。
Resources
China Linux Forum(finished)
Linux Forum(finished)
FreeBSD China(finished)
linuxforum.net
  业界新闻与评论
  自由软件杂谈
  IT 人生
  Linux软件快递
  翻译作坊
  Linux图书与评论
  GNU Emacs/XEmacs
  Linux 中文环境和中文化
  Linux桌面与办公软件
  Linux 多媒体与娱乐版
  自由之窗Mozilla
  笔记本电脑上的Linux
  Gentoo
  Debian 一族
  网络管理技术
  Linux 安装与入门
  WEB服务器和FTP服务器
  域名服务器和邮件服务器
  Linux防火墙和代理服务器应用
  文件及打印服务器
  技术培训与认证
  Linux内核技术
  Linux 嵌入技术
  Linux设备驱动程序
  Linux 集群技术
  LINUX平台数据库
  系统和网络安全
  CPU 与 编译器
  系统计算研究所专栏
  Linux下的GUI软件开发
  C/C++编程版
  PHP 技 术
  Java&jsp技术
  Shell编程技术
  Perl 编 程
  Python 编 程
  XML/Web Service 技术
  永远的Unix
  FreeBSD世界
   
<<A guide to the internals of the GNU linker>>摘录
Author: gillionaire    Posted: 2005-07-10 22:59    Length: 4,762 byte(s)
[Original] [Print] [Top]
前几天看的,把其中的重点摘录了一下翻译过来,在移植ld的时候用的上。
附件里是全文。

每个target都若干个emulations,其中包含默认的linker script。
emulation在build过程中由shell脚本genscripts.sh产生。genscripts.sh首先读入emulparams目录的一个文件来,这个文件用来设置在genscripts.sh中使用到的一些shell变量和其他要被调用的shell脚本;然后调用scripttempl目录下的一个shell脚本,由此生成默认的linker scripts(该shell会被调用5、6次,对应生成5、6个linker scripts,链接时由命令行参数选择);之后调用emultempl目录下个shell脚本,该脚本生成emulation的源文件,绝大多数的target都是用generic.em来生成。

ld的命令行中用-m可以指定emulation,用-V可以显示target支持的所有emulations。

emulparams目录下的shell脚本由在configure.tgt中设置的名为targ_emul的shell变量指定。targ_emul=emul ---> 脚本就是emulparams/emul.sh。emul.sh中主要设置脚本变量供genscripts.sh和scripttempl、emultempl目录下的脚本使用。SCRIPT_NAME=script(指定scripttempl目录下的脚本为script.sc)、TEMPLATE_NAME=template(指定emultempl目录下的脚本为template.em,缺省值为generic)、GENERATE_SHLIB_SCRIPT、OUTPUT_FORMAT、ARCH、ENTRY、TEXT_START_ADDR、NONPAGED_TEXT_START_ADDR、SEGMENT_SIZE、TARGET_PAGE_SIZE、ALIGNMENT。

scripttempl/script.sc就是输出一个链接脚本到标准输出,如果emulparams目录下的脚本文件是emul.sh,那么输出的链接脚本就是build目录下的ldscripts/emul.extension。extension由genscripts.sh中的shell变量LD_FLAG指定,genscripts.sh调用scripttempl/script.sc脚本5到8次,每次生成一个不同的链接脚本,对应的后缀extension不同。
-----------------------------------------------------
|LD_FLAG |链接脚本后缀名 | ld调用参数 |
-----------------------------------------------------
|empty | .x |without followings(默认)|
-----------------------------------------------------
|n | .xn | -n |
-----------------------------------------------------
|N | .xbn | -N |
-----------------------------------------------------
|r | .xr | -r |
-----------------------------------------------------
|u | .xu | -u |
-----------------------------------------------------
|shared | .xs | -shared |
-----------------------------------------------------
|c | .xc | -c |
-----------------------------------------------------
|cshared | .xsc | -cshared |
-----------------------------------------------------
除此,在script.sc中还会定义如下几个shell变量:RELOCATING、CONSTRUCTING、DATA_ALIGNMENT、CREATE_SHLIB、COMBRELOC。链接脚本的主要作用是把各个sections按顺序排放在正确的内存地址上。在一些特殊targets中链接脚本还有其他的作用。在MIPS平台上,链接脚本要定义符号_gp来初始化$gp reg。嵌入式系统的链接脚本中要定义符号__stack来初始化栈指针。

emultempl/template.em中的变量和函数都是static的。唯一全局可见的数据对象名为ld_
EMULATION_NAME_emulation,该变量是一个struct ld_emulation_xfer_struct结构类型,定义在ldemul.h中。这个结构中的域主要都是些函数指针,会被linker使用到。在build后,emultempl/下的脚本由template.em生成etemplate.c的源文件,再用ldemul.h和ldemul.c把指定的emulation赋值给变量ld_emulation。

ld的整个流程:
? main() in ‘ldmain.c’
? ‘emultempl/EMULATION.em’ has your code
? ldemul_choose_target (defaults to your target_name)
? ldemul_before_parse
? Parse argv, calls ldemul_parse_args for each
? ldemul_set_symbols
? ldemul_get_script
? parse script
? may call ldemul_hll or ldemul_syslib
? may call ldemul_open_dynamic_archive
? ldemul_after_parse
? lang_process() in ‘ldlang.c’
? create output_bfd
? ldemul_set_output_arch
? ldemul_create_output_section_statements
? read objects, create input bfds - all symbols exist, but have no values
? may call ldemul_unrecognized_file
? will call ldemul_recognized_file
? ldemul_after_open
? map input sections to output sections
? may call ldemul_place_orphan for remaining sections
? ldemul_before_allocation
? gives input sections offsets into output sections, places output sections
? ldemul_after_allocation - section addresses valid
? assigns values to symbols
? ldemul_finish - symbol values valid
? output bfd is written to disk
--
Attached file: 567334-ldint.pdf
[Original] [Print] [Top]
« Previous thread
ssa与data flow比较
CPU 与 编译器
8
Next thread »
请问gcj中的class$是什么意思?
     

Copyright © 2007 UNIX Resources Network, All Rights Reserved.      About URN | Privacy & Legal | Help | Contact us
备案序号: 京ICP备05006143    webmaster: webmaster@unixresources.net
This page created on 2008-07-17 03:47:26, cost 0.034956932067871 ms.