Basic Linker Script Concepts

本文深入探讨了链接器脚本的基本概念,解释了可加载或可分配输出段的两个地址:虚拟内存地址(VMA)和加载内存地址(LMA)。通过使用objdump程序的-h选项,展示了如何查看目标文件中的各个段,以及使用nm程序或objdump的-t选项来查看符号。文章提供了详细的段和符号列表,帮助读者理解链接器的工作原理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Basic Linker Script Concepts

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.

You can see the sections in an object file by using the objdump program with the -h option.
例如执行
objdump XX.exe –h

stage1.exec.exe:     file format pei-i386

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .text         00000200  00007c00  00007c00  000001f0  2**4
                  CONTENTS, ALLOC, LOAD, CODE
  1 .stab         000006c0  00007e00  00007e00  000003f0  2**2
                  CONTENTS, READONLY, DEBUGGING
  2 .stabstr      00000038  000084c0  000084c0  00000bf0  2**0
                  CONTENTS, READONLY, DEBUGGING

You can see the symbols in an object file by using the nm program, or by using the objdump program with the -t option.

例如执行
objdump XX.exe –t

stage1.exec.exe:     file format pei-i386

SYMBOL TABLE:
[  0](sec -2)(fl 0x00)(ty   0)(scl 103) (nx 1) 0x00000002 stage1.S
File
[  2](sec -2)(fl 0x00)(ty   0)(scl 103) (nx 1) 0x00000004 stage1.S
File
[  4](sec -2)(fl 0x00)(ty   0)(scl 103) (nx 1) 0x00000006 ./stage1.h
File
[  6](sec -2)(fl 0x00)(ty   0)(scl 103) (nx 1) 0x00000008 stage1.S
File
[  8](sec -2)(fl 0x00)(ty   0)(scl 103) (nx 1) 0x0000000a <command line>
File
[ 10](sec -2)(fl 0x00)(ty   0)(scl 103) (nx 1) 0x0000000c <built-in>
File
[ 12](sec -2)(fl 0x00)(ty   0)(scl 103) (nx 1) 0x0000000e c:\My_Code\tmp\grub4dos-0.4.4\stage1//
File
[ 14](sec -2)(fl 0x00)(ty   0)(scl 103) (nx 1) 0x0000003f stage1.S
File
[ 16](sec  1)(fl 0x00)(ty   0)(scl   6) (nx 0) 0x0000004a after_BPB
[ 17](sec  1)(fl 0x00)(ty   0)(scl   6) (nx 0) 0x00000004 mode
[ 18](sec  1)(fl 0x00)(ty   0)(scl   6) (nx 0) 0x00000005 disk_address_packet
[ 19](sec  1)(fl 0x00)(ty   0)(scl   6) (nx 0) 0x00000005 sectors
[ 20](sec  1)(fl 0x00)(ty   0)(scl   6) (nx 0) 0x00000009 heads
[ 21](sec  1)(fl 0x00)(ty   0)(scl   6) (nx 0) 0x0000000d cylinders
[ 22](sec  1)(fl 0x00)(ty   0)(scl   6) (nx 0) 0x0000000f sector_start
[ 23](sec  1)(fl 0x00)(ty   0)(scl   6) (nx 0) 0x00000010 head_start
[ 24](sec  1)(fl 0x00)(ty   0)(scl   6) (nx 0) 0x00000011 cylinder_start
[ 25](sec  1)(fl 0x00)(ty   0)(scl   6) (nx 0) 0x0000003e stage1_version
[ 26](sec  1)(fl 0x00)(ty   0)(scl   6) (nx 0) 0x00000040 boot_drive
[ 27](sec  1)(fl 0x00)(ty   0)(scl   6) (nx 0) 0x00000041 force_lba
[ 28](sec  1)(fl 0x00)(ty   0)(scl   6) (nx 0) 0x00000042 stage2_address
[ 29](sec  1)(fl 0x00)(ty   0)(scl   6) (nx 0) 0x00000044 stage2_sector
[ 30](sec  1)(fl 0x00)(ty   0)(scl   6) (nx 0) 0x00000048 stage2_segment
[ 31](sec  1)(fl 0x00)(ty   0)(scl   6) (nx 0) 0x0000004b boot_drive_check
[ 32](sec  1)(fl 0x00)(ty   0)(scl   6) (nx 0) 0x00000059 real_start
[ 33](sec  1)(fl 0x00)(ty   0)(scl   6) (nx 0) 0x0000017f notification_string
[ 34](sec  1)(fl 0x00)(ty   0)(scl   6) (nx 0) 0x000001a7 message
[ 35](sec  1)(fl 0x00)(ty   0)(scl   6) (nx 0) 0x000000cc chs_mode
[ 36](sec  1)(fl 0x00)(ty   0)(scl   6) (nx 0) 0x00000095 lba_mode
[ 37](sec  1)(fl 0x00)(ty   0)(scl   6) (nx 0) 0x00000149 copy_buffer
[ 38](sec  1)(fl 0x00)(ty   0)(scl   6) (nx 0) 0x000000dc final_init
[ 39](sec  1)(fl 0x00)(ty   0)(scl   6) (nx 0) 0x000001c3 floppy_probe
[ 40](sec  1)(fl 0x00)(ty   0)(scl   6) (nx 0) 0x00000169 hd_probe_error
[ 41](sec  1)(fl 0x00)(ty   0)(scl   6) (nx 0) 0x00000106 setup_sectors
[ 42](sec  1)(fl 0x00)(ty   0)(scl   6) (nx 0) 0x00000161 geometry_error
[ 43](sec  1)(fl 0x00)(ty   0)(scl   6) (nx 0) 0x00000171 read_error
[ 44](sec  1)(fl 0x00)(ty   0)(scl   6) (nx 0) 0x00000185 geometry_error_string
[ 45](sec  1)(fl 0x00)(ty   0)(scl   6) (nx 0) 0x00000177 general_error
[ 46](sec  1)(fl 0x00)(ty   0)(scl   6) (nx 0) 0x0000018a hd_probe_error_string
[ 47](sec  1)(fl 0x00)(ty   0)(scl   6) (nx 0) 0x00000194 read_error_string
[ 48](sec  1)(fl 0x00)(ty   0)(scl   6) (nx 0) 0x00000199 general_error_string
[ 49](sec  1)(fl 0x00)(ty   0)(scl   6) (nx 0) 0x0000017d stop
[ 50](sec  1)(fl 0x00)(ty   0)(scl   6) (nx 0) 0x000001b8 nt_magic
[ 51](sec  1)(fl 0x00)(ty   0)(scl   6) (nx 0) 0x000001be part_start
[ 52](sec  1)(fl 0x00)(ty   0)(scl   6) (nx 0) 0x000001be probe_values
[ 53](sec  1)(fl 0x00)(ty   0)(scl   6) (nx 0) 0x000001c6 probe_loop
[ 54](sec  1)(fl 0x00)(ty   0)(scl   6) (nx 0) 0x000001da fd_probe_error_string
[ 55](sec  1)(fl 0x00)(ty   0)(scl   3) (nx 1) 0x00000000 .text
AUX scnlen 0x200 nreloc 1 nlnno 0
[ 57](sec  0)(fl 0x00)(ty   0)(scl   3) (nx 1) 0x00000000 .data
AUX scnlen 0x0 nreloc 0 nlnno 0
[ 59](sec  0)(fl 0x00)(ty   0)(scl   3) (nx 1) 0x00000000 .bss
AUX scnlen 0x0 nreloc 0 nlnno 0
[ 61](sec  2)(fl 0x00)(ty   0)(scl   3) (nx 1) 0x00000000 .stab
AUX scnlen 0x6c0 nreloc 143 nlnno 0
[ 63](sec -1)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00007e00 __rdata_end__
[ 64](sec -1)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00007e00 __data_start__
[ 65](sec -1)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00001000 __size_of_stack_commit__
[ 66](sec -1)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00200000 __size_of_stack_reserve__
[ 67](sec -1)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00000004 __major_subsystem_version__
[ 68](sec -1)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00007e00 edata
[ 69](sec -1)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00007e00 __bss_start__
[ 70](sec -1)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00001000 __size_of_heap_commit__
[ 71](sec -1)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00007e00 __common_start__
[ 72](sec -1)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00000000 __dll__
[ 73](sec -1)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00000000 __minor_os_version__
[ 74](sec -1)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00400000 __image_base__
[ 75](sec -1)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00001000 __section_alignment__
[ 76](sec -1)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00007e00 end
[ 77](sec -1)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00007e00 __data_end__
[ 78](sec  1)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00000200 etext
[ 79](sec -1)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00007e00 __bss_end__
[ 80](sec  1)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00000000 _start
[ 81](sec -1)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00000200 __file_alignment__
[ 82](sec -1)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00000004 __major_os_version__
[ 83](sec -1)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00100000 __size_of_heap_reserve__
[ 84](sec -1)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00000003 __subsystem__
[ 85](sec -1)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00007e00 __rdata_start__
[ 86](sec -1)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00000001 __major_image_version__
[ 87](sec -1)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00000000 __loader_flags__
[ 88](sec -1)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00000000 __minor_subsystem_version__
[ 89](sec -1)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00000000 __minor_image_version__
[ 90](sec  1)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00000000 start

转载于:https://www.cnblogs.com/fanzi2009/archive/2009/05/21/1486366.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值