转载自http://processors.wiki.ti.com/index.php/Linker_Special_Section_Types#NOLOAD_Sections_2

Introduction

The linker allows you to create different kinds of sections called NOLOAD, DSECT, and COPY sections. How can you create these sections, and what are they good for?

Syntax

You can only create these section types in the SECTIONS directive of a linker command file. This example comes from the Assembly Language Tools User’s Guide …

SECTIONS
{
sec1: load = 0x00002000, type = DSECT {f1.obj}
sec2: load = 0x00004000, type = COPY {f2.obj}
sec3: load = 0x00006000, type = NOLOAD {f3.obj}
}

How are these sections different?

A regular section undergoes four processing steps:

  1. Allocated: Space is allocated in memory for the section.
  2. Relocated: Symbols defined in the section are relocated to their final addresses in memory. References to the section from outside are patched according to where the section is allocated. References inside the section to symbols outside the section are similarly patched to the final addresses.
  3. In Output: The section is placed in the output file.
  4. Loaded: The section is loaded to the target system.

Steps 1-3 are performed by the linker. Step 4 can be performed with a variety of methods. A section may be loaded by Code Composer Studio during a debug session, or burned into Flash memory, or any number of other methods for loading code or data to a target system.

Sections with these special types avoid one or more of these processing steps.

NOLOAD Sections

NOLOAD sections avoid steps 3 and 4. A NOLOAD section is not included in the output file. Because it is not in the output file, it is not loaded to the target system. Everything else is the same as a regular section.

COPY Sections

COPY sections avoid steps 1 and 4. Space is not allocated in memory for a COPY section. While a COPY section is in the output file, it is not loaded to the target. Everything else is the same as a regular section.

DSECT Sections

DSECT stands for Dummy Section. A DSECT only undergoes step 2, relocation. Space is not allocated in the memory map for a DSECT, nor does it appear in the output file. Thus, a DSECT is not loaded to the target. Any references to symbols in the DSECT are patched as if the section were allocated to the address given for the section. In the example above, the symbols for the DSECT are relocated starting at address 0x2000.

Summary on Section Processing

Type Allocated Relocated In Output Loaded
Regular X X X X
NOLOAD X X    
COPY   X X  
DSECT   X    

What are these sections good for?

NOLOAD Sections

NOLOAD sections are good for modeling parts of the code or data that are already present in the system. Common examples include code burned into ROM or Flash. The ROM code part of a system could be linked with a command file similar to this …

-a     /* guarantee no refs to syms outside ROM */
-r /* partial link - will link again */
rom.obj
-o rom.out MEMORY {
ROM : ...
RAM : ...
} SECTIONS {
rom_sect : { *(.text) } > ROM
}

The resulting rom.out file could be burned in ROM. The final link could use a command file similar to …

rom.out         /* code in ROM                 */
calls_rom.obj /* code that calls code in ROM */
-o calls_rom.out MEMORY { /* must be same as above */
ROM : ...
RAM : ...
} SECTIONS {
rom_sect  : type=NOLOAD > ROM
calls_rom  : { *(.text) } > RAM
}

The DSECT type could be used in place of NOLOAD. The advantage of NOLOAD is that, since space for the section is allocated in memory, allocations mistakes will be caught by the linker. Such mistakes include allocating too much code to a memory range, or allocating multiple sections to the same memory range. Because DSECT’s are not allocated space in memory, such mistakes go unchecked.

There are several other considerations when creating and linking against a ROM image. The examples above are not comprehensive. The focus is exclusively on explaining NOLOAD.

COPY Sections

COPY sections are rarely created directly by users. They are created automatically by the code generation tools to support various features.

When linking under the --ram_model (–cr) switch for RAM model initialization of global variables in C, the .cinit section is a COPY section. Linking with –-ram_model is similar to the following example

-u _c_int00
-e _c_int00 cinit = -1;
___cinit__ = cinit; SECTIONS {
.cinit {
*(.cinit)
. += 4; /* Mark end with 0 */
} fill = 0, type = COPY
}

The .cinit section is processed by a loader, such as the loader in Code Composer Studio, when loading an output file, to initialize the C global variables. This implies that the loader knows the format of the data contained in the .cinit section.

Program debug information, such as symbol records and source line number information, when organized according to the Dwarf debugging standards, is stored in COPY sections with names such as .debug_info, .debug_line, and .debug_abbrev. These sections are read by the Code Composer Studio in order to support debugging the system.

DSECT Sections

DSECT sections are rarely used. DSECT sections are not allocated to memory. Therefore, they can overlay any other section, whether DSECT or not. Thus, you need to be very careful about their use. It is easy to make a mistake that is hard to find.

Here is one example of the usage of DSECT. A source file contains four functions …

void ram1() { … }
void rom1() { … }
void ram2() { … }
void rom2() { … }

The RAM and ROM functions are separated into distinct sections with names similar to .text:_ram1. The ROM functions are burned into ROM. All of this is done with version X of the tools. After rebuilding with version X+1 of the tools, the sizes and starting addresses of all of the functions, including the ROM functions, is different. But the requirement is that the link must be done against the ROM burned from the previous build. It is possible to get the hard coded addresses of the ROM functions from the previous build. With all of that information, a link command file similar to this would work …

SECTIONS
{
.text:_rom1 : run = 0x1234, type = DSECT
.text:_rom2 : run = 0x5678, type = DSECT
}

Note the hard-coded addresses above are auto-generated from information in the previous build. Details of that process are beyond the scope of this article.

The result is that each ROM section is allocated exactly where it was in the previous build. NOLOAD would work for any function/section that is the same size or smaller than before. But it would not work in the case of a function which is larger. If NOLOAD were used in that case, the linker would complain about the function overlaying the starting address of a later function. Using DSECT, in effect, avoids that check

Linker Special Section Types的更多相关文章

  1. ELF Format 笔记(三)—— Section Types

    ilocker:关注 Android 安全(新入行,0基础) QQ: 2597294287 ELF 文件中会包含很多 section,所有的 section 都在 section header tab ...

  2. Android so库文件的区节section修复代码分析

    本文博客地址:http://blog.csdn.net/qq1084283172/article/details/78818917 一.Android so库文件的节表secion修复方案整理 1.简 ...

  3. Primitive Data Types

    Primitive Data Types (The Java™ Tutorials > Learning the Java Language > Language Basics) http ...

  4. [译] QUIC Wire Layout Specification - Frame Types and Formats | QUIC协议标准中文翻译(4) 帧类型和格式

    欢迎访问我的个人网站获取更好的阅读排版体验: [译] QUIC Wire Layout Specification - Frame Types and Formats | QUIC协议标准中文翻译(4 ...

  5. YASM User Manual

    This document is the user manual for the Yasm assembler. It is intended as both an introduction and ...

  6. ARM 之一 ELF文件、镜像(Image)文件、可执行文件、对象文件 详解

    [转]https://blog.csdn.net/ZCShouCSDN/article/details/100048461 ELF 文件规范   ELF(Executable and Linking ...

  7. elf.h

    1 /* This file defines standard ELF types, structures, and macros. 2 Copyright (C) 1995-2019 Free So ...

  8. 沁恒CH32V103C8T6(二): Linux RISC-V编译和烧录环境配置

    目录 沁恒CH32V103C8T6(一): 核心板焊接和Windows开发环境配置 沁恒CH32V103C8T6(二): Linux RISC-V编译和烧录环境配置 硬件准备 CH32V103 开发板 ...

  9. Spring Framework------>version4.3.5.RELAESE----->Reference Documentation学习心得----->Spring Framework中的spring web MVC模块

    spring framework中的spring web MVC模块 1.概述 spring web mvc是spring框架中的一个模块 spring web mvc实现了web的MVC架构模式,可 ...

随机推荐

  1. jenkins 重新设置 管理员密码

    由于服务器瘫痪,修好之后经常不上,就把jenkins的管理密码忘掉了. 查阅了网上所有方案之后发现没有一个 能正确修改密码的,特此列出下列网上的方法 第一.设成无需密码验证的(网上有教程,不过并不能修 ...

  2. 2016032101 - eclipse3.7+jdk1.6+maven3.0.5

    公司使用jdk1.6做开发环境,那么使用的eclipse需要下载3.7版本,因为eclipse4以上必须使用jdk1.7及其以上版本. 1.资源下载 jdk1.6需要去oracle官网去下载,可能需要 ...

  3. qt 5 界面美化

    大家都知道,用UI做起界面来非常方便,但是如果我们不熟练他的操作的话,做起来也会有不少布局的麻烦, 所以,我打算写一篇文章来记录自己参考大牛用代码写界面的文章,感谢百度,感谢各位QT大牛的帮助. 所谓 ...

  4. check whether the crystal report runtime is exists 检查crystalreport运行时是否存在

    1. Try Dim rptDoc As New CrystalDecisions.CrystalReports.Engine.ReportClass() Dim rptView As New Cry ...

  5. cf Round 601

    A.The Two Routes(BFS) 给出n个城镇,有m条铁路,铁路的补图是公路,汽车和火车同时从1出发,通过每条路的时间为1,不能同时到达除了1和n的其它点,问他们到达n点最少要用多长时间. ...

  6. Pair Project: Elevator Scheduler [电梯调度算法的实现和测试]:刘耀先-11061183,罗凡-11061174

    本次为我们两个人的第一次结对编程.从总体而言,我们对结对编程比单人编程略显不适应.但是经过一段时间的磨合,我们逐渐的习惯了这种编程方式. 1.  结对编程的优缺点 结对编程的优点: (1)       ...

  7. UIMenuController搭配UIPasteboard,执行拷贝-黏贴操作-b

    一.基本概念 UIKit框架中,可以直接执行拷贝黏贴操作的有:UITextView.UITextField和UIWebView,其他控件需要实现相关方法. 关于UIPasteboard ·黏贴板是ap ...

  8. 20 个最棒的 jQuery Tab 插件

    jQuery Tab 常用来做网页上的选项设置界面和导航,本文向你推荐最棒的 20 个 jQuery Tab 插件.Enjoy !! 1. Slider Tabs SliderTabs 是一个可定制的 ...

  9. JavaScript闭包底层解析

    1. 闭包是一个函数,这个函数有权访问另一个函数作用域中的变量,创建闭包最常见的方式,就是在函数内部创建函数.要想彻底搞清其中细节,必须从函数从创建到调用的时候都发生了什么入手 2. 函数第一次被调用 ...

  10. Win7下安装Mongodb教程

    最新Mongodb下载地址:http://www.mongodb.org/downloads 1.下载完成后,解压到任意路径,如:D:\mongodb: 2.在D:\mongodb目录下 新建data ...