[LinkerScript.1] 基本的链接器脚本概念 - Basic Linker Script Concepts


We need to define some basic concepts and vocabulary in order to describe the linker script language.

为了描述链接器脚本语言,我们需要定义一些基本的概念和词汇.


The linker combines input files into a single output file. The output file and each input file are in a special data format known as an object file format. Each file is called an object file. The output file is often called an executable, but for our purposes we will also call it an object file. Each object file has, among other things, a list of sections. We sometimes refer to a section in an input file as an input section; similarly, a section in the output file is an output section.

链接器把一些输入文件组合到一个输出文件.输出文件和每个输入文件都是遵循一种规范数据格式中,被称为对象文件格式.每个文件被称为对象文件.输出文件经常被叫做可执行文件,但是基于我们的目的也叫它为一个对象文件.除了别的以外,每个对象文件有一组的section.我们有时候在一个输入文件中引用一个section作为输入section;类似地,输出文件中一个section是一个输出section.


Each section in an object file has a name and a size. Most sections also have an associated block of data, known as the section contents. A section may be marked asloadable, which means that the contents should be loaded into memory when the output file is run. A section with no contents may be allocatable, which means that an area in memory should be set aside, but nothing in particular should be loaded there (in some cases this memory must be zeroed out). A section which is neither loadable nor allocatable typically contains some sort of debugging information.

在一个对象文件中,每个section有一个名称和一个大小.大多数的sections也有一个相关的数据块,被称为section contents(节内容).一个section可能被标记为loadable(可加载),即意味着当输出文件被运行时,内容应该被加载到内存中.一个没有内容的section可能是allocable(可分配),即代表着在内存中会留着一块空间,但其实没有什么会被加载到这里(在有些情况中这块内存必须被设置为0).一个即不是loadable,也不是allocable的section,通常包含一些所谓的调试信息.


Every loadable or allocatable output section has two addresses. The first is the VMA, or virtual memory address. This is the address the section will have when the output file is run. The second is the LMA, or load memory address. This is the address at which the section will be loaded. In most cases the two addresses will be the same. An example of when they might be different is when a data section is loaded into ROM, and then copied into RAM when the program starts up (this technique is often used to initialize global variables in a ROM based system). In this case the ROM address would be the LMA, and the RAM address would be the VMA.

每个loadable或allocable的输出section有两个地址.第一个地址是VMA,或叫做虚拟内存地址(virtual memory address).它是输出文件被运行时,section的运行地址.第二个地址是LMA,或叫做加载内存地址(load memory address).它是section的加载地址.大多数情况下,两种地址是一样的.举一个两种地址不一样的例子,当一个数据section被加载到ROM时,但是程序在启动时却加载到RAM(这种技术经常在基于ROM的文件系统中用于初始化全局变量).在这种情况下,ROM地址是LMA,而RAM地址是VMA.


You can see the sections in an object file by using the objdump program with the ‘-h’ option.

使用objdump -h命令,你可以看到一个对象文件中的sections.


Every object file also has a list of symbols, known as the symbol table. A symbol may be defined or undefined. Each symbol has a name, and each defined symbol has an address, among other information. If you compile a C or C++ program into an object file, you will get a defined symbol for every defined function and global or static variable. Every undefined function or global variable which is referenced in the input file will become an undefined symbol.

每个对象文件也有一组的符号(symbols),被称为符号表(symobl table).一个符号可能有被定义或未定义.每个符号有一个名称,并且每个定义的符号有一个地址和其它的信息.如果你把C或C++程序编译到一个对象文件中,那么每个定义的函数和变量或静态变量都会有一个已定义的符号.在输入文件中每个未定义的函数或被引用的全局变量,都将是未定义的符号.


You can see the symbols in an object file by using the nm program, or by using the objdump program with the ‘-t’ option.

使用 nm 或 objdump -t 命令你可以看到在对象文件中的符号




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值