当前位置:网站首页>3. compilation and linking principle
3. compilation and linking principle
2022-06-23 01:40:00 【For financial freedom!】



precompile ( Preprocessing ):# The first command handles
compile :gcc -O1(O2 O3) Optimization level
assembly : Generate .o Relocatable binaries ( Platform specific machine code 0101 such )
.a :Linux Static library files .lib :Windows Static library file under
link : all .o file + Static library files .lib Join the link
- Step one : all .o Merging of file segments , After the symbol table is merged , Perform symbol parsing
- Step two : Relocation of symbols ( relocation ), This is the core of the link

main In file gdata、sum It refers to external variables 、 function , stay main.o Will symbols be generated in the ?
objdump -t command : Look at the symbol table :
l:local
g:global
stay main.o In the segment information of ,gdata 、_z3sumii stay main They are used in the document , But I don't know how to define it , So the symbol can only be given to them for the time being UND(undefined). And in the sum It is known in the document that sum function gdata Know how to define , So there's a sign !
During the compilation process , Symbols are not assigned virtual addresses ! You can see that after compilation ,main.o These places are located at 0:
readelf -S main.o: View segment information
link :
main.o sum.o
The segments will be merged ,.text .data .bss And so on ,UND When merging , You will find this variable in other files , Find the place where the symbol is defined (text data perhaps bss etc. ) After successful symbol parsing , Assign virtual addresses to all symbols ,data gdata sum These must have addresses , All those places were 0000, Now you need to write down the specific address , This is called symbol redirection !
Manual link : The entry function is specified as main, You can see all the variables 、 Functions have specific addresses ,*UND* It's gone !


a.out On the disk ,elf header Contains the entry address of the program ,program headers Tell the system to load text data paragraph , Load into memory ! hold text,data bss Segments are mapped to the virtual address space of the process ( Several blogs have talked about the virtual space of processes ), Execute the address mapping page exception handler to allocate physical memory !
边栏推荐
- On AI and its future trend | community essay solicitation
- Get the start and end dates of the current week
- Pat a - 1010 radical (thinking + two points)
- MySQL - SQL execution process
- Flink synchronizes MySQL data to es
- 3D printing microstructure
- Sfod: passive domain adaptation and upgrade optimization, making the detection model easier to adapt to new data
- Wallys/DR7915-wifi6-MT7915-MT7975-2T2R-support-OpenWRT-802.11AX-supporting-MiniPCIe
- Add / get and delete cookies
- Wechat mobile terminal development - account login authorization
猜你喜欢

Xiaobai operates win10 to expand Disk C (allocate disk D memory to Disk C) and the test is valid for many times

office2016+visio2016

Sélecteur de hiérarchie

Huawei cloud recruits partners in the field of industrial intelligence to provide strong support + commercial realization

Explain the startup process of opengauss multithreading architecture in detail

Debian10 LVM logical volumes

SQL programming task02 job - basic query and sorting
![[launch] redis Series 2: data persistence to improve availability](/img/f4/5bc7ca3e17c6656e71df515182842e.png)
[launch] redis Series 2: data persistence to improve availability

Autumn move script C

Do you know the memory components of MySQL InnoDB?
随机推荐
Debian10 LVM logical volumes
ERROR { err: YAMLException: end of the stream or a document separator is expected at line 6, colum
A hundred lines of code to realize reliable delay queue based on redis
What aspects of language and database knowledge are needed to build a web Kanban!
LeetCode 206. Reverse linked list (iteration + recursion)
Philosopher's walk gym divide and conquer + fractal
A blog allows you to understand the use of material design
Autumn move script C
C#. Net universal database access encapsulation classes (access, sqlserver, Oracle)
人民币的单位的大写
278. digital combination
Js--- SVG to png
Uint8 serializing and deserializing pits using stringstream
Network module packaging
Day260: the number III that appears only once
Phantomjs Usage Summary
3D打印微组织
Similar to attention NLP
Lexical Sign Sequence
Unit of RMB in words