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.

About Gnu Linker2的更多相关文章

  1. 感悟 GNU C 以及将 Vim 打造成 C/C++ 的半自动化 IDE

    C 语言在 Linux 系统中的重要性自然是无与伦比.不可替代,所以我写 Linux 江湖系列不可能不提 C 语言.C 语言是我的启蒙语言,感谢 C 语言带领我进入了程序世界.虽然现在不靠它吃饭,但是 ...

  2. 使用 GCC 和 GNU Binutils 编写能在 x86 实模式运行的 16 位代码

    不可否认,这次的标题有点长.之所以把标题写得这么详细,主要是为了搜索引擎能够准确地把确实需要了解 GCC 生成 16 位实模式代码方法的朋友带到我的博客.先说一下背景,编写能在 x86 实模式下运行的 ...

  3. 在 Linux 中使用 Eclipse 和 Gnu Autotools 管理 C/C++ 项目

    在我该系列的之前的所有随笔中,都是采用 Linux 发行版自带的包管理工具(如 apt-get.yum 等)进行软件的安装和卸载,从来没有向大家展示使用源代码自行编译安装软件的方法.但是长期混迹于 U ...

  4. GNU Readline 库及编程简介

    用过 Bash 命令行的一定知道,Bash 有几个特性: TAB 键可以用来命令补全 ↑ 或 ↓ 键可以用来快速输入历史命令 还有一些交互式行编辑快捷键: C-A / C-E 将光标移到行首/行尾 C ...

  5. GNU Radio Radar Toolbox

    GNU Radio Radar Toolbox Install guide Change to any folder in your home directory and enter followin ...

  6. gnu coreutils-8.25 for win32 static - Beta

    gnu.win32-coreutils-8.25.7z 2.7 Mb bc-1.06.tar.gz coreutils-8.25.tar.xz diffutils-3.5.tar.xz gawk-4. ...

  7. window下搭建c开发环境(GNU环境的安装)

    一.在windows平台上安装GNU环境 windows操作系统不自带GNU环境,如果需要开发跨平台的C语言程序,那么需要给windows安装GNU环境 windows下的两款GNU环境:MinGW和 ...

  8. GNU make使用变量⑤变量的引用、定义等

    在 Makefile 中,变量是一个名字(像是 C 语言中的宏),代表一个文本字符串(变量的值).在 Makefile 的目标.依赖.命令中引用变量的地方,变量会被它的值所取代(与 C 语言中宏引用的 ...

  9. (转)完全用GNU/Linux工作 by 王珢

    完全用GNU/Linux工作 王珢      (看完这篇博文,非常喜欢王珢的这篇博客,也我坚定了学gnu/linux的决心,并努力去按照国外的计算机思维模式去学习编程提高自己.看完这篇文章令我热血沸腾 ...

随机推荐

  1. zabbix AGENTS 在WINDOWS的安装

    1.下载 https://assets.zabbix.com/downloads/3.4.0/zabbix_agents_3.4.0.win.zip 解压 zabbix_agents_3.4.0.wi ...

  2. call,apply,bind 方法的学习

    这是三个常用的操作函数的方法,在js中函数就是一等公民,所以说掌握这三个方法还是有必要的 call 和 apply,都会绑定函数的上下文(context)并立即执行调用该方法函数,两者区别在于,接受的 ...

  3. POJ1064 Cable master(二分 浮点误差)

    题目链接:传送门 题目大意: 给出n根长度为1-1e5的电线,想要从中切割出k段等长的部分(不可拼接),问这个k段等长的电线最长可以是多长(保留两位小数向下取整). 思路: 很裸的题意,二分答案即可. ...

  4. postman Could not get any response。

    浏览器输入地址可以返回结果,但是由于返回的json没有格式,看起来比较麻烦,用postman却报错Could not get any response. 可以注意到下面写了可能的情况:比如服务器无响应 ...

  5. Springboot 使用过滤器进行加密解密(二)

    之前写过一篇关于过滤器实现加密解密功能的文章,但是在实际开发业务中发现,还是有一些问题的,在此特地说明. 第一:过滤器走两遍的问题: 1.过滤器上,添加了两个注解 第一个:@Compent   将此F ...

  6. 第七次实验:CC2530平台上多跳通信的TinyOS编程

    module  P2MM { uses interface Boot; uses interface Timer<TMilli> as Timer0; uses interface Spl ...

  7. Java中如何拆分字符串为字符数组

    题目:输入一串字符,由(){}[]组成,判断是否所有的括号都是闭括号,是的返回TRUE,不是返回FALSE. /*输入字符串,拆解为字符数组 * 用函数s.charAt(i)来完成 * * */imp ...

  8. Spring mvc后台重定向页面,实际前端不跳转

    1.ajax不支持重定向 ajax是不支持重定向的,因为ajax本身就是局部刷新,不重新加载页面的. 2.若后台出现需要重定向页面,可以设置唯一错误码 前端ajax公共调用后,凡是遇到这一类错误码,则 ...

  9. ubuntu typora使用学习

    typora使用方法 标题: 对于标题,直接用ctrl+对应数字就是第几级标题 文字格式: ctrl+B/I/U 进入加粗/倾斜/下划模式,不需要符号键入 居中的话 用 CENTER 列表引用: 可直 ...

  10. java删除文件支持通配符

    原文:https://blog.csdn.net/wdzayyt/article/details/7209530 感谢原作者 package com.covics.zfh; import java.i ...