| <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> |
| <html> |
| <!-- This file documents the GNU linker LD |
| (GNU Binutils) |
| version 2.25. |
| |
| Copyright (C) 1991-2014 Free Software Foundation, Inc. |
| |
| Permission is granted to copy, distribute and/or modify this document |
| under the terms of the GNU Free Documentation License, Version 1.3 |
| or any later version published by the Free Software Foundation; |
| with no Invariant Sections, with no Front-Cover Texts, and with no |
| Back-Cover Texts. A copy of the license is included in the |
| section entitled "GNU Free Documentation License". --> |
| <!-- Created by GNU Texinfo 5.2, http://www.gnu.org/software/texinfo/ --> |
| <head> |
| <title>LD: Basic Script Concepts</title> |
| |
| <meta name="description" content="LD: Basic Script Concepts"> |
| <meta name="keywords" content="LD: Basic Script Concepts"> |
| <meta name="resource-type" content="document"> |
| <meta name="distribution" content="global"> |
| <meta name="Generator" content="makeinfo"> |
| <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
| <link href="index.html#Top" rel="start" title="Top"> |
| <link href="LD-Index.html#LD-Index" rel="index" title="LD Index"> |
| <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents"> |
| <link href="Scripts.html#Scripts" rel="up" title="Scripts"> |
| <link href="Script-Format.html#Script-Format" rel="next" title="Script Format"> |
| <link href="Scripts.html#Scripts" rel="prev" title="Scripts"> |
| <style type="text/css"> |
| <!-- |
| a.summary-letter {text-decoration: none} |
| blockquote.smallquotation {font-size: smaller} |
| div.display {margin-left: 3.2em} |
| div.example {margin-left: 3.2em} |
| div.indentedblock {margin-left: 3.2em} |
| div.lisp {margin-left: 3.2em} |
| div.smalldisplay {margin-left: 3.2em} |
| div.smallexample {margin-left: 3.2em} |
| div.smallindentedblock {margin-left: 3.2em; font-size: smaller} |
| div.smalllisp {margin-left: 3.2em} |
| kbd {font-style:oblique} |
| pre.display {font-family: inherit} |
| pre.format {font-family: inherit} |
| pre.menu-comment {font-family: serif} |
| pre.menu-preformatted {font-family: serif} |
| pre.smalldisplay {font-family: inherit; font-size: smaller} |
| pre.smallexample {font-size: smaller} |
| pre.smallformat {font-family: inherit; font-size: smaller} |
| pre.smalllisp {font-size: smaller} |
| span.nocodebreak {white-space:nowrap} |
| span.nolinebreak {white-space:nowrap} |
| span.roman {font-family:serif; font-weight:normal} |
| span.sansserif {font-family:sans-serif; font-weight:normal} |
| ul.no-bullet {list-style: none} |
| --> |
| </style> |
| |
| |
| </head> |
| |
| <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000"> |
| <a name="Basic-Script-Concepts"></a> |
| <div class="header"> |
| <p> |
| Next: <a href="Script-Format.html#Script-Format" accesskey="n" rel="next">Script Format</a>, Up: <a href="Scripts.html#Scripts" accesskey="u" rel="up">Scripts</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="LD-Index.html#LD-Index" title="Index" rel="index">Index</a>]</p> |
| </div> |
| <hr> |
| <a name="Basic-Linker-Script-Concepts"></a> |
| <h3 class="section">3.1 Basic Linker Script Concepts</h3> |
| <a name="index-linker-script-concepts"></a> |
| <p>We need to define some basic concepts and vocabulary in order to |
| describe the linker script language. |
| </p> |
| <p>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 |
| <em>object file format</em>. Each file is called an <em>object file</em>. |
| The output file is often called an <em>executable</em>, but for our |
| purposes we will also call it an object file. Each object file has, |
| among other things, a list of <em>sections</em>. We sometimes refer to a |
| section in an input file as an <em>input section</em>; similarly, a section |
| in the output file is an <em>output section</em>. |
| </p> |
| <p>Each section in an object file has a name and a size. Most sections |
| also have an associated block of data, known as the <em>section |
| contents</em>. A section may be marked as <em>loadable</em>, which means that |
| the contents should be loaded into memory when the output file is run. |
| A section with no contents may be <em>allocatable</em>, 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. |
| </p> |
| <p>Every loadable or allocatable output section has two addresses. The |
| first is the <em>VMA</em>, or virtual memory address. This is the address |
| the section will have when the output file is run. The second is the |
| <em>LMA</em>, 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. |
| </p> |
| <p>You can see the sections in an object file by using the <code>objdump</code> |
| program with the ‘<samp>-h</samp>’ option. |
| </p> |
| <p>Every object file also has a list of <em>symbols</em>, known as the |
| <em>symbol table</em>. 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. |
| </p> |
| <p>You can see the symbols in an object file by using the <code>nm</code> |
| program, or by using the <code>objdump</code> program with the ‘<samp>-t</samp>’ |
| option. |
| </p> |
| <hr> |
| <div class="header"> |
| <p> |
| Next: <a href="Script-Format.html#Script-Format" accesskey="n" rel="next">Script Format</a>, Up: <a href="Scripts.html#Scripts" accesskey="u" rel="up">Scripts</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="LD-Index.html#LD-Index" title="Index" rel="index">Index</a>]</p> |
| </div> |
| |
| |
| |
| </body> |
| </html> |