About Gnu Linker1

1 OverView

  • ld combines a number of object and archive files, relocates their data and ties up symbol references.
  • This version of ld uses the general purpose BFD libraries to operate on object files. This allows ld to read, combine, and write object files in many different formats.
  • the gnu linker is more helpful in providing diagnostic information. ld continues executing, allowing you to identify other errors.

 

2 Linker Command

 

3 Linker Scripts

3.1  Basic Linker Script Concepts

  • object file: 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.
  • input section : a section in an input file as an input section.
  • output section : a section in the output file is an output section.
  • contents : Most sections have an associated block of data, known as the section contents.
  • loadable : mean that the contents should be loaded into memory when the output file is run.
  • allocatable : 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.
  • neither loadable nor allocatable section: contains some sort of debugging information.
  • VMA: 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.
  • LMA: The second is the LMA, or load memory address. This is the address at which the section will be loaded.

 

3.2 Linker Scripts Formate

Linker scripts are text files. You write a linker script as a series of commands. Each command is either a keyword, possibly followed by arguments, or an assignment to a symbol.

 

3.3 Simple Linker Script Example

3.3.1 SECTIONS command

describe the memory layout of the output file. Example as below:

SECTIONS

{

. = 0x10000;

.text : { *(.text) }

. = 0x8000000;

.data : { *(.data) }

.bss : { *(.bss) }

}

  • The first line sets the value of the special symbol ‘.’, which is the location counter. If you do not specify the address of an output section in some other way, the address is set from the current value of the location counter. The location counter is then incremented by the size of the output section. At the start of the ‘SECTIONS’ command, the location counter has the value ‘0’.
  •  The second line defines an output section, ‘.text’. Within the curly braces after the output section name, you list the names of the input sections which should be placed into this output section.
  • The ‘*’ is a wildcard which matches any file name. The expression ‘*(.text)’ means all ‘.text’ input sections in all input files.

 

3.4 Simple Linker Script Commands

3.4.1 Setting the Entry Point

The first instruction to execute in a program is called the entry point.

ENTRY(symbol)

There are several ways to set the entry point.

_ the ‘-e’ entry command-line option;

_ the ENTRY(symbol) command in a linker script;

_ the value of the symbol start, if defined;

_ the address of the first byte of the ‘.text’ section, if present;

_ The address 0.

 

3.4.2 Commands Dealing with Files

INCLUDE filename - Include the linker script filename at this point.

INPUT(file, file, ...) - directs the linker to include the named files in the link, as though they were named on the command line.

GROUP(file, file, ...) - like INPUT, except that the named files should all be archives, and they are searched repeatedly until no new undefined references are created.

 

3.4.3 Assign alias names to memory regions

REGION_ALIAS(alias, region)

The REGION_ALIAS function creates an alias name alias for the memory region region.

 

3.5 Assigning Values to Symbols

 

转载于:https://www.cnblogs.com/zhizhi25/p/9683633.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值