【发布时间】:2021-03-17 22:14:30
【问题描述】:
这里是一个很简单的汇编程序,执行后返回12即可。
$ cat a.asm
global _start
section .text
_start: mov rax, 60 ; system call for exit
mov rdi, 12 ; exit code 12
syscall
可以正确构建和执行:
$ nasm -f elf64 a.asm && ld a.o && ./a.out || echo $?
12
但是a.out的大小很大,超过4k:
$ wc -c a.out
4664 a.out
我尝试通过阅读精灵内容来理解它:
$ readelf -l a.out
Elf file type is EXEC (Executable file)
Entry point 0x401000
There are 2 program headers, starting at offset 64
Program Headers:
Type Offset VirtAddr PhysAddr
FileSiz MemSiz Flags Align
LOAD 0x0000000000000000 0x0000000000400000 0x0000000000400000
0x00000000000000b0 0x00000000000000b0 R 0x1000
LOAD 0x0000000000001000 0x0000000000401000 0x0000000000401000
0x000000000000000c 0x000000000000000c R E 0x1000
Section to Segment mapping:
Segment Sections...
00
01 .text
很奇怪,段00是按0x1000对齐的,我想这意味着这样的段至少会占用4096字节。
我的问题是这个段 00 是什么?
(nasm 版本 2.14.02,ld 版本 2.34,os 是 Ubuntu 20.04.1)
【问题讨论】:
标签: linux assembly linker ld elf