3.5.1 Simple Assignments

  • symbol = expression ;
  • symbol += expression ;
  • The first case will define symbol to the value of expression. In the other cases, symbol must already be defined.
  • The special symbol name ‘.’ indicates the location counter. You may only use this within a SECTIONS command.
  • The semicolon after expression is required.

3.6 SECTIONS Command

The SECTIONS command tells the linker how to map input sections into output sections,and how to place the output sections in memory.

SECTIONS

{

  sections-command

  sections-command

  ...

}

Each sections-command may of be one of the following:

_ an ENTRY command

_ a symbol assignment

_ an output section description

_ an overlay description

3.6.1 Output Section Description

section [address] [(type)] :

[AT(lma)]

[ALIGN(section_align)]

[SUBALIGN(subsection_align)]

[constraint]

{

  output-section-command

  output-section-command

  ...

} [>region] [AT>lma_region] [:phdr :phdr ...] [=fillexp]

Each output-section-command may be one of the following:

_ a symbol assignment

_ an input section description

_ data values to include directly

_ a special output section keyword

3.6.2 Output Section Name

The name of the output section is section.

3.6.3 Output Section Address

  • The address is an expression for the VMA of the output section.
  • If you do not provide address, the linker will set it based on region if present, or otherwise based on the current value of the location counter.
  • If you provide address, the address of the output section will be set to precisely that.
  • If you provide neither address nor region, then the address of the output section will be set to the current value of the location counter aligned to the alignment requirements of the output section.

3.6.4 Input Section Description

  • The input section description is the most basic linker script operation. You use output
  • sections to tell the linker how to lay out your program in memory. You use input section
  • descriptions to tell the linker how to map the input files into your memory layout.

3.6.4.2 Input Section Wildcard Patterns

  1. ‘*’ matches any number of characters
  2. ‘?’ matches any single character
  3. ‘[chars]’ matches a single instance of any of the chars;
  4. ‘-’ be used to specify a range of characters, as in ‘[a-z]’ to match any lower case letter.
  5. ‘\’ quotes the following character

3.6.4.3 Input Section for Common Symbols

  • in many object file formats common symbols do not have a particular input section. The linker treats common symbols as though they are in an input section named ‘COMMON’.
  • .bss { *(.bss) *(COMMON) }

3.6.4.4 Input Section and Garbage Collection

  • When link-time garbage collection is in use (‘--gc-sections’ to mark sections that should not be eliminated. This is accomplished by surrounding an input section’s wildcard entry with
  • KEEP(), as in KEEP(*(.init)) or KEEP(SORT_BY_NAME(*)(.ctors)).

3.6.4.5 Input Section Example

3.6.7 Output Section Discarding

  • ü  The linker will not create output sections with no contents.
  • ü  The special output section name ‘/DISCARD/’ be used to discard input sections.
  • ü  Any input sections which are assigned to an output section named ‘/DISCARD/’ are not included in the output file.

3.6.8 Output Section Attributes

section [address] [(type)] :

[AT(lma)]

[ALIGN(section_align)]

[SUBALIGN(subsection_align)]

[constraint]

{

  output-section-command

} [>region] [AT>lma_region] [:phdr :phdr ...] [=fillexp]

3.6.8.1 Output Section Type

NOLOAD The section should be marked as not loadable, so that it will not be loaded into

memory when the program is run.

DSECT COPY INFO OVERLAY type names are for backward compatibility, rarely used.

3.6.8.2 Output Section LMA

ü  if the section do not had a VMA assigned to it then the linker will use the lma region as the VMA region as well.

ü  If neither AT nor AT> is specified for an allocatable section, the linker will set the LMA such that the difference between VMA and LMA for the section is the same as the preceding output section in the same region.

ü  If there is no preceding output section or the section is not allocatable, the linker will set the LMA equal to the VMA.

3.6.8.3 Forced Output Alignment

You can increase an output section’s alignment by using ALIGN.

3.6.8.4 Forced Input Alignment

You can force input section alignment within an output section by using SUBALIGN. The value specified overrides any alignment given by input sections, whether larger or smaller.

3.6.8.5 Output Section Constraint

You can specify that an output section should only be created if all of its input sections are read-only or all of its input sections are read-write by using the keyword ONLY_IF_RO and ONLY_IF_RW respectively.

3.6.8.6 Output Section Region

You can assign a section to a previously defined region of memory by using ‘>region’.

MEMORY { rom : ORIGIN = 0x1000, LENGTH = 0x1000 }

SECTIONS { ROM : { *(.text) } >rom }

3.6.8.7 Output Section Phdr

You can assign a section to a previously defined program segment by using ‘:phdr’.

If a section is assigned to one or more segments, then all subsequent allocated sections will be assigned to those segments as well, unless they use an explicitly :phdr modifier.

use :NONE to tell the linker to not put the section in any segment at all.

Here is a simple example:

PHDRS { text PT_LOAD ; }

SECTIONS { .text : { *(.text) } :text }

3.6.8.8 Output Section Fill

You can set the fill pattern for an entire section by using ‘=fillexp’.

Any otherwise unspecified regions of memory within the output section will be filled with the value, repeated as necessary.

SECTIONS { .text : { *(.text) } =0x90909090 }

3.6.9 Overlay Description

An overlay description describe sections which are to be loaded as part of a single memory image but are to be run at the same memory address.

OVERLAY [start] : [NOCROSSREFS] [AT ( ldaddr )]

{

secname1

{

  output-section-command

  output-section-command

  ...

} [:phdr...] [=fill]

secname2

{

  output-section-command

  output-section-command

  ...

} [:phdr...] [=fill]

...

} [>region] [:phdr...] [=fill]

ü  The sections are all defined with the same starting address. The load addresses of the sections are arranged such that they are consecutive in memory starting at the load address used for the OVERLAY as a whole.

ü  __load_start_secname is defined as the starting load address of the section.

ü  __load_stop_secname is defined as the final load address of the section.

ü  At the end of the overlay, the value of the location counter is set to the start address of the overlay plus the size of the largest section.

3.7 MEMORY Command

The MEMORY command describes the location and size of blocks of memory in the target.

MEMORY

{

  name [(attr)] : ORIGIN = origin, LENGTH = len

  ...

}

The name is a name used in the linker script to refer to the region.

The attr string is an optional list of attributes that specify whether to use a particular memory region for an input section which is not explicitly mapped in the linker script.

The len is an expression for the size in bytes of the memory region.

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

About Gnu Linker2相关推荐

  1. 慢慢学Linux驱动开发,第十章,GNU C的扩展

    内核开发者使用的C语言涵盖了ISO C99标准和GNU C扩展特性.这里简单介绍一下GNU C的扩展特性. 1.内联(inline)函数 GNU的C编译器支持内联函数,也是C++的一个特性之一.就是函 ...

  2. GNU make manual 翻译( 一百四十九)

    继续翻译 5.7.4 The `--print-directory' Option ------------------------------------If you use several lev ...

  3. Linux下的ATT语法(即GNU as 汇编语法)入门

    学习这么长时间,一直在C语言这一层面上钻研和打拼,日积月累,很多关于C的疑惑在书本和资料中都难以找到答案.程序员是追求完美的一个种群,其头 脑中哪怕是存在一点点的思维黑洞都会让其坐卧不宁.不久前在it ...

  4. GNU AWK中BEGIN/END使用举例

    以下是使用gnu awk将test.cpp文件拆分成两个文件a.cpp和b.cpp,其中b.cpp仅存放test.cpp中的数据,其它内容存放在a.cpp文件中. test.cpp内容如下: #inc ...

  5. GNU/Linux平台上正则表达式的简单使用

    友情提醒:本博文涉及的内容中涉及到的系统实践操作在Centos6.5上实现,GNU/Linux简称为linux,GNU/grep简称为grep,GNU/sed简称为sed,GNU/gawk简称为awk ...

  6. GNU make 和 makefile

    GNU make 和 makefile 1.9.1?GNU make 在大型的开发项目中,通常有几十到上百个的源文件,如果每次均手工键入 gcc 命令进行编译的话,则会 非常不方便.因此,人们通常利用 ...

  7. 介绍使用 GNU Screen 的小技巧

    学习基本的 GNU Screen 终端复用技术,然后下载我们的终端命令备忘录,以便你能够熟悉常用的快捷方式. 学习基本的 GNU Screen 终端复用技术,然后下载我们的终端命令备忘录,以便你能够熟 ...

  8. 了解 GNU GPL/GNU LGPL/BSD/MIT/Apache协议

    摘自:http://blog.csdn.net/flowingflying/article/details/5746151 越来越多的开发者与设计者希望将自己的产品开源,以便其他人可以在他们的代码基础 ...

  9. 在CentOS/Debian/Ubuntu上编译安装最新版gnu make 和GNU 'binutils' (as and ld)

    先查看make版本: root@:~/clickhouse/gcc-build# make --version GNU Make 3.82 Built for x86_64-redhat-linux- ...

最新文章

  1. 一流科技完成5000万人民币A轮融资,高瓴创投独家领投
  2. 曲面屏敲代码飞起,包邮送到家!
  3. 圆桌会议 HDU - 1214(规律+模拟队列)
  4. mybatis dao实现 || 接口代理方式实现
  5. sonar 代理_Sonar
  6. “化鲲为鹏,我有话说”如何用鲲鹏弹性云服务器部署《Hadoop伪分布式》
  7. 解决:jsp 页面不全,response 内容不完整
  8. 平滑滤波器模板尺寸与平滑效果的关系_Python Opencv 图像平滑处理
  9. 【jQuery笔记Part4】01-jQuery-节点操作-添加节点-删除节点-复制节点
  10. Python与C:指针与按址传递
  11. pgMP认证,还是再看看吧!
  12. 计算机网络的硬件系统包含那些部件,计算机的硬件系统主要包括哪五大部件
  13. 鸡啄米:C++编程入门系列之前言
  14. 离散数学实验二——逻辑联结词的运算
  15. C22-利用泰勒公式求sin(x)的值
  16. html怎么设置img样式,img 元素可以用 CSS 设置样式吗?
  17. python实现文件(夹)剪切
  18. 【报错及解决】Variable w already exists, disallowed. Did you mean to set reuse=True in VarScope? Originally
  19. javaScript 阶乘尾数
  20. Windows如何找到相应的COM组件

热门文章

  1. windows下 mysql 转移data目录
  2. (3)websocket实现单聊和群聊
  3. Facebook有1万名员工在研发AR/VR设备 占员工总数近1/5
  4. 看看 JDK 8 给我们带来什么
  5. Github中Tag的使用
  6. socket编程--sockaddr_in结构体操作
  7. SPARK STREAMING之1:编程指南(翻译v1.4.1)
  8. Loader之一:基本原理
  9. python学习笔记(三)tuple(元组)
  10. Scala入门到精通——第九节 继承与组合