操作系统_有关一个hello world程序诞生到消亡的几个开放性问题

本文探讨了操作系统中hello world程序从诞生到消亡的过程,涉及ELF文件格式、编译链接、可执行文件加载、内存映像、程序启动与执行、内存管理和程序卸载等关键环节。通过解析程序的生命周期,阐述了操作系统如何管理和控制程序的执行。
摘要由CSDN通过智能技术生成

操作系统中hello world程序从诞生到消亡的开放性问题

关键词: ELF格式; 编译链接过程; 可执行文件的格式; 可执行程序的加载; 可执行程序的开始执行; hello world在内存中的镜像; 寻址; 调度程序; 内存管理; 系统调用; hello world程序卸载;

预备问题

什么是ELF格式(编译器)

开放性问题1

hello world的编译链接过程和hello world上可执行文件的格式、hello world可执行程序的加载以及如何开始执行

开放性问题2

hello world在内存中的镜像

补充问题

  • 寻址

  • 调度程序

  • 内存管理

  • 系统调用

  • hello world程序卸载



预备问题

以下是百度百科中对什么是ELF文件的定义

ELF(Executable and Linking Format)是一种对象文件的格式,是Linux的主要可执行文件格式。

ELF文件由4部分组成,分别是ELF头(ELF header)、程序头表(Program header table)、节(Section)和节头表(Section header table)。实际上,一个文件中不一定包含全部内容,而且他们的位置也未必如同所示这样安排,只有ELF头的位置是固定的,其余各部分的位置、大小等信息由ELF头中的各项值来决定。

当然这只是百度百科,娱乐一下就够了。那么具体什么是ELF格式我会在后文中引出。(Copyright © http://blog.csdn.net/s_gy_zetrov. All Rights Reserved)

我们都知道,以C语言为例,一段完整的程序,要经过预处理-编译-汇编-链接后才能称为可让cpu执行的文件,这个过程中用到的“工具”分别叫做preprocessor, compiler, assembler, linker。这里我并没有使用他们的中文译名,我也不打算用,使用英文原文是最准确的。当然后面我有可能会用到类似“编译器”这种中文说法,对应的英文自行脑补。

编译过程.png

使用gcc编译链的话,我们会在整个编译过程中看到很多不同后缀名的文件,下表1是一个概览:

                        表1 编译过程中不同后缀名文件含义概览

suffix(file extension) description
hello.c 需要被预处理的C源码
hello.i 不应被预处理的C源码
hello.ii 不应被预处理的C++源码
hello.h 头文件,不应被编译或链接
hello.cc
hello.cp
hello.cxx
hello.cpp
hello.c++
hello.C
需要被预处理的C++源码
hello.s 汇编码
hello.S 需要被预处理的汇编码
hello.o 默认为对象文件,文件名为将 .c, .i, .s etc替换为.o后得到

在源码被汇编后会生成一个目标文件【Object files (e.g. .o, .obj)】,接着linker会为obj文件链接动态库,最终生成可执行文件。

obj文件和可执行文件有很多种形式,这里就包括COFF (Common Object-File Format) 和我要说的ELF文件 (Executable and Linking Format) ,最直观的区别就是ELF通常应用于Linux中而COFF则通常应用于Windows中。

下面列举一些常见的object file format(见表2)

                        表2 常见的object file format简述「摘自ref. [1]」

Object File Format description
xxxx.out The ‘.out’ format is the original file format for Unix. It consists of three sections: text, data, and bss, which are for program code, initialized data, and uninitialized data, respectively. This format is so simple that it doesn’t have any reserved place for debugging information. The only debugging format for a.out is stabs, which is encoded as a set of normal symbols with distinctive attributes.
COFF The COFF (Common Object File Format) format was introduced with System V Release 3 (SVR3) Unix. COFF files may have multiple sections, each prefixed by a header. The number of sections is limited. The COFF specification includes support for debugging but the debugging information was limited. There is no file extension for this format.
ECOFF A variant of COFF. ECOFF is an Extended COFF originally introduced for Mips and Alpha workstations.
XCOFF The IBM RS/6000 running AIX uses an object file format called XCOFF (eXtended COFF). The COFF sections, symbols, and line numbers are used, but debugging symbols are dbx-style stabs whose strings are located in the .debug section (rather than the string table). The default name for an XCOFF executable file is a.out.
PE Windows 9x and NT use the PE (Portable Executable) format for their executables. PE is basically COFF with additional headers. The extension normally .exe.
ELF The ELF (Executable and Linking Format) format came with System V Release 4 (SVR4) Unix. ELF
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值