symbols are defined in a linker script file(etext, edata, end)
2016-12-01 06:42
489 查看
##以下是man page 里面的内容,源码里面使用的三个外部变量( extern char etext, edata, end)并未定义在任何头文件里面,而是定义在了linker script file中,具体解释见最后 ## 解释
NAME
etext, edata, end - end of program segments
SYNOPSIS
extern etext;
extern edata;
extern end;
DESCRIPTION
The addresses of these symbols indicate the end of various program
segments:
etext This is the first address past the end of the text segment
(the program code).
edata This is the first address past the end of the initialized data
segment.
end This is the first address past the end of the uninitialized
data segment (also known as the BSS segment).
CONFORMING TO
Although these symbols have long been provided on most UNIX systems,
they are not standardized; use with caution.
NOTES
The program must explicitly declare these symbols; they are not
defined in any header file.
On some systems the names of these symbols are preceded by
underscores, thus: _etext, _edata, and _end. These symbols are also
defined for programs compiled on Linux.
At the start of program execution, the program break will be
somewhere near &end (perhaps at the start of the following page).
However, the break will change as memory is allocated via brk(2) or
malloc(3). Use sbrk(2) with an argument of zero to find the current
value of the program break.
EXAMPLE
When run, the program below produces output such as the following:
$ ./a.out
First address past:
program text (etext) 0x8048568
initialized data (edata) 0x804a01c
uninitialized data (end) 0x804a024
Program source
#include <stdio.h>
#include <stdlib.h>
extern char etext, edata, end; /* The symbols must have some type,
or "gcc -Wall" complains */
int
main(int argc, char *argv[])
{
printf("First address past:\n");
printf(" program text (etext) %10p\n", &etext);
printf(" initialized data (edata) %10p\n", &edata);
printf(" uninitialized data (end) %10p\n", &end);
exit(EXIT_SUCCESS);
}
##解释
Every link is controlled by a linker script. This script is written in the linker command language.
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. Most linker scripts do nothing more than this. However, when necessary, the
linker script can also direct the linker to perform many other operations, using the commands described below.
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 -verbosecommand
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.
You may also use linker scripts implicitly by naming them as input files to the linker, as though they were files to be linked. Refer to Section
4.11 Implicit Linker Scripts.
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.
You can see the sections in an object file by using the objdump program with the -h option.
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.
You can see the symbols in an object file by using the nm program, or by using the objdump program
with the -t option.
##博客仅作个人记录##
NAME
etext, edata, end - end of program segments
SYNOPSIS
extern etext;
extern edata;
extern end;
DESCRIPTION
The addresses of these symbols indicate the end of various program
segments:
etext This is the first address past the end of the text segment
(the program code).
edata This is the first address past the end of the initialized data
segment.
end This is the first address past the end of the uninitialized
data segment (also known as the BSS segment).
CONFORMING TO
Although these symbols have long been provided on most UNIX systems,
they are not standardized; use with caution.
NOTES
The program must explicitly declare these symbols; they are not
defined in any header file.
On some systems the names of these symbols are preceded by
underscores, thus: _etext, _edata, and _end. These symbols are also
defined for programs compiled on Linux.
At the start of program execution, the program break will be
somewhere near &end (perhaps at the start of the following page).
However, the break will change as memory is allocated via brk(2) or
malloc(3). Use sbrk(2) with an argument of zero to find the current
value of the program break.
EXAMPLE
When run, the program below produces output such as the following:
$ ./a.out
First address past:
program text (etext) 0x8048568
initialized data (edata) 0x804a01c
uninitialized data (end) 0x804a024
Program source
#include <stdio.h>
#include <stdlib.h>
extern char etext, edata, end; /* The symbols must have some type,
or "gcc -Wall" complains */
int
main(int argc, char *argv[])
{
printf("First address past:\n");
printf(" program text (etext) %10p\n", &etext);
printf(" initialized data (edata) %10p\n", &edata);
printf(" uninitialized data (end) %10p\n", &end);
exit(EXIT_SUCCESS);
}
##解释
Chapter 4. Linker Scripts
Every link is controlled by a linker script. This script is written in the linker command language.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. Most linker scripts do nothing more than this. However, when necessary, the
linker script can also direct the linker to perform many other operations, using the commands described below.
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 -verbosecommand
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.
You may also use linker scripts implicitly by naming them as input files to the linker, as though they were files to be linked. Refer to Section
4.11 Implicit Linker Scripts.
4.1. Basic Linker Script Concepts
We need to define some basic concepts and vocabulary in order to describe the linker script language.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.
You can see the sections in an object file by using the objdump program with the -h option.
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.
You can see the symbols in an object file by using the nm program, or by using the objdump program
with the -t option.
##博客仅作个人记录##
相关文章推荐
- C++Builder 6 [BCB6] 共享数据段 错误 测试 (bug 、[Linker Error] Section SHSEG defined in .def file is empty)
- How to pass SOAP headers into python SUDS that are not defined in WSDL file
- Unity3d 提示 "The scripts file name does not match the name of the class defined in the script!"的解决办法
- centos 16安装PHP7.0 异常 No pool defined. at least one pool section must be specified in config file
- VS2012 error C1071: unexpected end of file found in comment
- java错误提示------ The public type must be defined in its own file
- error C2601: ' ": local function definitions are illegal;fatal error C1075: end of file found before
- “The public type XYZ must be defined in its own file”解决方法
- 【Tomcat错误系列】Tomcat9.0版本出现The valid characters are defined in RFC 7230 and RFC 3986问题
- ionic创建项目报错:Couldn't find ionic.config.json file. Are you in an Ionic project?
- Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986
- PHP关于syntax error语法错误的问题(Parse error: syntax error, unexpected end of file in xxxxxxxx)
- 转:Code-blocks are not allowed in this file: Using Server-Side Code with SharePoint
- 调试记录:The public type <<classname>> must be defined in its own file
- 安装rvds2.2,出现Error: %variable HOSTPLAT is not defined in File RDI\armsd\1.3.1\66\install.xml
- 待解决问题:“gcc编译:file format not recognized; treating as linker script”
- c++ linker warning: defined in discarded section
- 异常:Invalid character found in the request target. The valid characters are defined in RFC 3986
- 解决Invalid character found in the request target. The valid characters are defined in RFC 7230 and RF
- Kconfig 语法错误:'endchoice' in different file than 'choice'和location of the 'choice'