The role of link scripts in linkers
What is the purpose of the link script in the linker? Generally speaking, people's understanding of link scripts may stay at the conceptual level, but relatively little is known about the role of link scripts. Today I will talk to you about the function and usage of the link script.
1 the meaning of the linked script
The link script is used to describe how the linker handles target and library files
1. Merge segments in various target files
two。 Relocate the starting address of each segment
3. Relocate the final address of each symbol
The SECTIONS / / keyword, which describes the layout of each segment in memory {.text 0x08048400: / / the starting address of the code snippet {* (.text) / / merges the code fragments of all files into the executable program}. = 0x01000000; / / set the current address S1 =.; / the storage address of identifier S. + = 4; S2 =.; .data 0x0804a800: {* (.data)} .bss: {* (.bss)}}
Note:
1. The link address of each segment must conform to the specific platform specification.
two。 The identifier can be directly defined and the storage address specified in the link script
3. The storage address of the identifier in the source code can be specified in the linked specimen
4. In Linux, the legal starting address of the process code snippet (.text) is [0x08048000j0x08049000]
2 use of MEMORY
By default: the linker believes that the program should be loaded into the same storage space.
In an embedded system, if there are multiple storage spaces, MEMORY must be used to define the storage area.
The attribute definition of MEMORY:
MEMORY {RAM0 (WX): ORIGIN = 0X20000000, LENGTH = 1024KRAM1 (! X): ORIGIN = 0X04000000, LENGTH = 256K} SECTION {.text: {* (.text)} > RAM0 .data: {* (.data)} > RAM0 .bss: {* (.bss)} > RAM1} 3 ENTRY command specifies the entry point ENTRY (program) SECTIONS {.text 0x08048400: {* (.text)}
It is important to note that when the entry function is not specified, the default entry function is the _ start function, because the linker uses the default link script, and the _ start function is clearly specified internally as the entry function.
After reading the above, do you have any further understanding of the link script in the linker? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!