Linker scripts之Intro

1  Intro

  Every link is controlled by a linker script.

  The main purpose of the linker script is to describe how the sections in the input files should be mapped into the output file, and to control the memory layout of the output file.

  The linker always uses a linker script. If you do not supply one yourself, the linker will use a default script that is compiled into the linker executable. You can use the `--verbose‘ command line option to display the default linker script. Certain command line options, such as `-r‘ or `-N‘, will affect the default linker script.

  You may supply your own linker script by using the `-T‘ command line option. When you do this, your linker script will replace the default linker script.

2  Basic concepts

  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.

  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 as loadable, which mean 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.

  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.

  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.

时间: 2024-10-29 19:08:22

Linker scripts之Intro的相关文章

Linux内核Makefile文件(翻译自内核手册)

转载自:http://www.cnblogs.com/jason-lu/p/3728198.html --译自Linux3.9.5 Kernel Makefiles(内核目录documention/kbuild/makefiles.txt) kbuild(kernel build) 内核编译器 This document describes the Linux kernel Makefiles 本文当介绍了Linux内核的Makefile === Table of Contents=== 目录

kbuild-(directory)

00-INDEX - this file: info on the kernel build process kbuild.txt - developer information on kbuild kconfig.txt - usage help for make *config kconfig-language.txt - specification of Config Language, the language in Kconfig files makefiles.txt - devel

Linux Kernel的Makefile与Kconfig文件的语法

https://www.kernel.org/doc/Documentation/kbuild/kconfig-language.txt Introduction ------------ The configuration database is a collection of configuration options organized in a tree structure: +- Code maturity level options | +- Prompt for developme

Autotools Mythbuster

Preface Diego Elio?"Flameeyes"?Pettenò Author and Publisher?<[email protected]> SRC=https://autotools.io/index.html David J.?"user99"?Cozatt Miscellaneous Editing?<[email protected]> Copyright ? 2009-2013 Diego Elio Pettenò

LPC18xx LPC43xx LPC4370 Bootrom USB DFU FPB - Flash Patch and Breakpoint Unit

What is the difference between a Bootrom vs bootloader on ARM systems Bootrom Bootrom (or Boot ROM) is a small piece of mask ROM or write-protected flash embedded inside the processor chip. It contains the very first code which is executed by the pro

GCC 4.9.0 发布,提升 C++11 和 C++14 特性

from :http://www.oschina.net/news/51084/gcc-4-9-0 GCC 4.9.0 发布,此版本是个主要版本更新,包括了 GCC 4.8.x 系列和之前的 GCC 版本都没有的新特性,新特性非常之多.下载地址:http://gcc.gnu.org/mirrors.html 警告 移除 mudflap 运行时检查器,mudflap 选项保留,但没有任何效果. 对一些很多老的系统和一些不维护的平台的支持在 4.9 版本中声明为过世的,下一个版本将永久删除,例如 S

GCC 4.9.0 公布,提升 C++11 和 C++14 特性

from :http://www.oschina.net/news/51084/gcc-4-9-0 GCC 4.9.0 公布,此版本号是个主要版本号更新,包含了 GCC 4.8.x 系列和之前的 GCC 版本号都没有的新特性,新特性很之多.下载地址:http://gcc.gnu.org/mirrors.html 警告 移除 mudflap 执行时检查器,mudflap 选项保留,但没有不论什么效果. 对一些非常多老的系统和一些不维护的平台的支持在 4.9 版本号中声明为过世的,下一个版本号将永久

HOWTO Install the MinGW (GCC) Compiler Suite

Posted July 25th, 2008 by mingwadmin getting started install mingw Automated Installer If you are new to MinGW, see the MinGW Getting Started instructions to use the automated GUI or manual CLI (Command Line Interface) installers. What follows below

Keil5配置GCC编译器编译STM32工程

Keil一般使用ARMCC编译MCU工程代码.偶然听说Keil也是支持内嵌GCC编译器的.于是尝试了网上博客所述的一些方法,最终找到了一篇博客 http://blog.csdn.net/lan120576664/article/details/46806991 按照文中所述,发现仍存在一些其他错误,后来又查找了其他相关资料,在这作以总结 一.下载GCC编译器https://launchpad.net/gcc-arm-embedded/ 二.安装GCCGCC解压到keil的安装目录下面.如下图 三