ld: Basic Script Concepts
1
1 3.1 Basic Linker Script Concepts
1 ================================
1
1 We need to define some basic concepts and vocabulary in order to
1 describe the linker script language.
1
1 The linker combines input files into a single output file. The
1 output file and each input file are in a special data format known as an
1 "object file format". Each file is called an "object file". The output
1 file is often called an "executable", but for our purposes we will also
1 call it an object file. Each object file has, among other things, a
1 list of "sections". We sometimes refer to a section in an input file as
1 an "input section"; similarly, a section in the output file is an
1 "output section".
1
1 Each section in an object file has a name and a size. Most sections
1 also have an associated block of data, known as the "section contents".
1 A section may be marked as "loadable", which means that the contents
1 should be loaded into memory when the output file is run. A section
1 with no contents may be "allocatable", which means that an area in
1 memory should be set aside, but nothing in particular should be loaded
1 there (in some cases this memory must be zeroed out). A section which
1 is neither loadable nor allocatable typically contains some sort of
1 debugging information.
1
1 Every loadable or allocatable output section has two addresses. The
1 first is the "VMA", or virtual memory address. This is the address the
1 section will have when the output file is run. The second is the "LMA",
1 or load memory address. This is the address at which the section will
1 be loaded. In most cases the two addresses will be the same. An
1 example of when they might be different is when a data section is loaded
1 into ROM, and then copied into RAM when the program starts up (this
1 technique is often used to initialize global variables in a ROM based
1 system). In this case the ROM address would be the LMA, and the RAM
1 address would be the VMA.
1
1 You can see the sections in an object file by using the 'objdump'
1 program with the '-h' option.
1
1 Every object file also has a list of "symbols", known as the "symbol
1 table". A symbol may be defined or undefined. Each symbol has a name,
1 and each defined symbol has an address, among other information. If you
1 compile a C or C++ program into an object file, you will get a defined
1 symbol for every defined function and global or static variable. Every
1 undefined function or global variable which is referenced in the input
1 file will become an undefined symbol.
1
1 You can see the symbols in an object file by using the 'nm' program,
1 or by using the 'objdump' program with the '-t' option.
1