The intro of Linker scripts

Source: Internet
Author: User

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 being mapped into the out Put file, and to control the memory layout of the output file.

The linker always uses a linker script. If you don't supply one yourself, the linker would use a default script, which 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‘ , would affect the default linker script.

Supply your own linker script by using the `-T‘ command line option. When the your linker script would 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 is in a special data format known as an object file format . Each file is a called an object file. The output file is often called a executable, but for our purposes we'll also call it an object file. Each object file have, among other things, a list of sections. We sometimes refer to a, a, and a input file as an inputsection; Similarly, section A, the output file was an outputsection.

Each section in an object file has a name and a size . Most sections also has an associated block of data, known as THE&NBSP, and section contents . Section A is marked as  loadable , which mean that the contents should is loaded into memory when the OUTP UT file is run. A section with no contents may be  allocatable , which means, "an" area in memory should is set aside, but n Othing in particular should is loaded there (in some cases this memory must is zeroed out). A section which is neither loadable nor allocatable typically contains some sort of debugging information.

Every loadable or allocatable The output section have and both addresses. The first is the  VMA , or virtual memory address. The the address the section would have the if the output file is run. The second is the  LMA , or load memory address. The address at which the section would be loaded. The most cases the addresses would be the same. An example by they might be different was when a data section was loaded into ROM, and then copied to RAM when the PR Ogram starts up (this technique was often used to initialize global variables in a ROM based system). In the the ROM address would is 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 had a name, and each defined symbol had an address, among other information. If you compile a C or C + + program to an object file, you'll 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 would become an undefined symbol.

The intro of Linker scripts

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.