X86cpu运行的什么格式代码? ELF还是Bin ?

2023-11-02

ELF文件是一种格式,我们使用gcc编译出来的.o文件,和链接后生成的.out文件一般都是ELF格式的文件。

Bin文件一般指的是连接器ld -b binary链接出来的或者用objcopy -b抽出来的文件。

ELF和Bin文件都是二进制文件(binary file)。

X86对于这两种可执行文件都是可以直接运行的。
这里have some problem, the bin can't be read by the objdump, but in JOS, the boot.s and main.c can read the kernel bin according to the ELF format. why?



连接器ld使用DFS库来进行链接,ld manual中,
5.1 How It Works: An Outline of BFD
===================================

When an object file(编译器编译出来没有链接的文件叫做object file.) is opened, BFD subroutines automatically determine
the format of the input object file.  They then build a descriptor in
memory with pointers to routines that will be used to access elements of
the object file's data structures.

   As different information from the object files is required, BFD
reads from different sections of the file and processes them.  For
example, a very common operation for the linker is processing symbol
tables.  Each BFD back end provides a routine for converting between
the object file's representation of symbols and an internal canonical
format. When the linker asks for the symbol table of an object file, it
calls through a memory pointer to the routine from the relevant BFD
back end which reads and converts the table into a canonical form.  The
linker then operates upon the canonical form. When the link is finished
and the linker writes the output file's symbol table, another BFD back
end routine is called to take the newly created symbol table and
convert it into the chosen output format.

ld manual中ld -b选项的解释为
`-b INPUT-FORMAT'
`--format=INPUT-FORMAT'
     `ld' may be configured to support more than one kind of object
     file.  If your `ld' is configured this way, you can use the `-b'
     option to specify the binary format for input object files that
     follow this option on the command line.  Even when `ld' is
     configured to support alternative object formats, you don't
     usually need to specify this, as `ld' should be configured to
     expect as a default input format the most usual format on each
     machine.  INPUT-FORMAT is a text string, the name of a particular
     format supported by the BFD libraries.  (You can list the
     available binary formats with `objdump -i'.)  *Note BFD::.

使用objdump -i可以列出ld连接器支持的所有output格式:
BFD header file version version 2.19.51.0.14-34.fc12 20090722
elf32-i386
 (header little endian, data little endian)
  i386
a.out-i386-linux
 (header little endian, data little endian)
  i386
pei-i386
 (header little endian, data little endian)
  i386
elf64-x86-64
 (header little endian, data little endian)
  i386
elf64-little
 (header little endian, data little endian)
  i386
elf64-big
 (header big endian, data big endian)
  i386
elf32-little
 (header little endian, data little endian)
  i386
elf32-big
 (header big endian, data big endian)
  i386
srec
 (header endianness unknown, data endianness unknown)
  i386
symbolsrec
 (header endianness unknown, data endianness unknown)
  i386
verilog
 (header endianness unknown, data endianness unknown)
  i386
tekhex
 (header endianness unknown, data endianness unknown)
  i386
binary
 (header endianness unknown, data endianness unknown)
  i386
ihex
 (header endianness unknown, data endianness unknown)
  i386
trad-core
 (header endianness unknown, data endianness unknown)

               elf32-i386 a.out-i386-linux pei-i386 elf64-x86-64 elf64-little
          i386 elf32-i386 a.out-i386-linux pei-i386 elf64-x86-64 elf64-little

               elf64-big elf32-little elf32-big srec symbolsrec verilog tekhex
          i386 elf64-big elf32-little elf32-big srec symbolsrec verilog tekhex

               binary ihex trad-core
          i386 binary ihex ---------
可见ld的output格式有的是ELF格式,有的不是ELF格式,例如常见的binary,即.bin文件。ELF格式的文件可以使用readelf和objdump来分析,binary不能使用这两个工具分析。
链接后的ELF文件比binary多很多的信息,所以方便用来调试。

我们使用readelf -a 列出boot.o的信息:
ELF Header:
  Magic:   7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
  Class:                             ELF32
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              REL (Relocatable file)
  Machine:                           Intel 80386
  Version:                           0x1
  Entry point address:               0x0
  Start of program headers:          0 (bytes into file)
  Start of section headers:          672 (bytes into file)
  Flags:                             0x0
  Size of this header:               52 (bytes)
  Size of program headers:           0 (bytes)
  Number of program headers:         0
  Size of section headers:           40 (bytes)
  Number of section headers:         11
  Section header string table index: 8

Section Headers:
  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            00000000 000000 000000 00      0   0  0
  [ 1] .text             PROGBITS        00000000 000034 00006a 00  AX  0   0  4
  [ 2] .rel.text         REL             00000000 0005cc 000028 08      9   1  4
  [ 3] .data             PROGBITS        00000000 0000a0 000000 00  WA  0   0  4
  [ 4] .bss              NOBITS          00000000 0000a0 000000 00  WA  0   0  4
  [ 5] .stab             PROGBITS        00000000 0000a0 00018c 0c      7   0  4
  [ 6] .rel.stab         REL             00000000 0005f4 000100 08      9   5  4
  [ 7] .stabstr          STRTAB          00000000 00022c 00002f 00      0   0  1
  [ 8] .shstrtab         STRTAB          00000000 00025b 000043 00      0   0  1
  [ 9] .symtab           SYMTAB          00000000 000458 000110 10     10  15  4
  [10] .strtab           STRTAB          00000000 000568 000064 00      0   0  1
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings)
  I (info), L (link order), G (group), x (unknown)
  O (extra OS processing required) o (OS specific), p (processor specific)

There are no section groups in this file.

There are no program headers in this file.

Relocation section '.rel.text' at offset 0x5cc contains 5 entries:
 Offset     Info    Type            Sym.Value  Sym. Name
00000021  00000114 R_386_16          00000000   .text
0000002e  00000114 R_386_16          00000000   .text
00000041  00000f01 R_386_32          00000000   start
00000046  00001002 R_386_PC32        00000000   bootmain
00000066  00000101 R_386_32          00000000   .text

Relocation section '.rel.stab' at offset 0x5f4 contains 32 entries:
 Offset     Info    Type            Sym.Value  Sym. Name
00000014  00000101 R_386_32          00000000   .text
00000020  00000101 R_386_32          00000000   .text
0000002c  00000101 R_386_32          00000000   .text
00000038  00000101 R_386_32          00000000   .text
00000044  00000101 R_386_32          00000000   .text
00000050  00000101 R_386_32          00000000   .text
0000005c  00000101 R_386_32          00000000   .text
00000068  00000101 R_386_32          00000000   .text
00000074  00000101 R_386_32          00000000   .text
00000080  00000101 R_386_32          00000000   .text
0000008c  00000101 R_386_32          00000000   .text
00000098  00000101 R_386_32          00000000   .text
000000a4  00000101 R_386_32          00000000   .text
000000b0  00000101 R_386_32          00000000   .text
000000bc  00000101 R_386_32          00000000   .text
000000c8  00000101 R_386_32          00000000   .text
000000d4  00000101 R_386_32          00000000   .text
000000e0  00000101 R_386_32          00000000   .text
000000ec  00000101 R_386_32          00000000   .text
000000f8  00000101 R_386_32          00000000   .text
00000104  00000101 R_386_32          00000000   .text
00000110  00000101 R_386_32          00000000   .text
0000011c  00000101 R_386_32          00000000   .text
00000128  00000101 R_386_32          00000000   .text
00000134  00000101 R_386_32          00000000   .text
00000140  00000101 R_386_32          00000000   .text
0000014c  00000101 R_386_32          00000000   .text
00000158  00000101 R_386_32          00000000   .text
00000164  00000101 R_386_32          00000000   .text
00000170  00000101 R_386_32          00000000   .text
0000017c  00000101 R_386_32          00000000   .text
00000188  00000101 R_386_32          00000000   .text

There are no unwind sections in this file.

Symbol table '.symtab' contains 17 entries:
   Num:    Value  Size Type    Bind   Vis      Ndx Name
     0: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND
     1: 00000000     0 SECTION LOCAL  DEFAULT    1
     2: 00000000     0 SECTION LOCAL  DEFAULT    3
     3: 00000000     0 SECTION LOCAL  DEFAULT    4
     4: 00000008     0 NOTYPE  LOCAL  DEFAULT  ABS PROT_MODE_CSEG
     5: 00000010     0 NOTYPE  LOCAL  DEFAULT  ABS PROT_MODE_DSEG
     6: 00000001     0 NOTYPE  LOCAL  DEFAULT  ABS CR0_PE_ON
     7: 0000000a     0 NOTYPE  LOCAL  DEFAULT    1 seta20.1
     8: 00000014     0 NOTYPE  LOCAL  DEFAULT    1 seta20.2
     9: 00000064     0 NOTYPE  LOCAL  DEFAULT    1 gdtdesc
    10: 00000032     0 NOTYPE  LOCAL  DEFAULT    1 protcseg
    11: 0000004a     0 NOTYPE  LOCAL  DEFAULT    1 spin
    12: 0000004c     0 NOTYPE  LOCAL  DEFAULT    1 gdt
    13: 00000000     0 SECTION LOCAL  DEFAULT    5
    14: 00000000     0 SECTION LOCAL  DEFAULT    7
    15: 00000000     0 NOTYPE  GLOBAL DEFAULT    1 start
    16: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND bootmain


本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

X86cpu运行的什么格式代码? ELF还是Bin ? 的相关文章

  • 如何知道寄存器是否是“通用寄存器”?

    我试图了解寄存器必须具备什么标准才能被称为 通用寄存器 我相信通用寄存器是一个可以用于任何用途的寄存器 用于计算 将数据移入 移出等 并且是一个没有特殊用途的寄存器 现在我读到了ESP寄存器是通用寄存器 我猜是ESP寄存器可以用于任何事情
  • 如何将对象转换为传递给函数的类型?

    这不会编译 但我想做的只是将对象转换为传递给函数的 t public void My Func Object input Type t t object ab TypeDescriptor GetConverter t ConvertFro
  • 程序集比较标志理解

    我正在努力理解汇编程序中的以下代码片段 if EAX gt 5 EBX 1 else EBX 2 在汇编程序中 可以写如下 根据我的书 模拟jge操作说明 https www felixcloutier com x86 jcc您通常会使用
  • 序列化对于对象大小估计可靠吗?

    我使用序列化来估计对象使用的内存量 我已经读过this https stackoverflow com questions 426396 how much memory does a c net object use and this ht
  • 无关的库链接

    我有一个可能有点愚蠢的问题 因为我很确定我可能已经知道答案了 假设你有静态库A 动态共享库B和你的linux下的程序C 假设库 A 调用库 B 中的函数 并且您的程序调用库 A 中的函数 现在假设 C 在 A 中调用的所有函数都不使用 B
  • 如何动态创建新属性

    如何从对象方法内的给定参数创建属性 class Foo public function createProperty var name val here how can I create a property named var name
  • Java中如何对对象数组进行排序?

    我的数组不包含任何字符串 但它包含对象引用 每个对象引用都通过 toString 方法返回名称 id 作者和发布者 public String toString return name n id n author n publisher n
  • 设置 IRQ 映射

    我正在遵循一些教程和参考文献来尝试设置我的内核 我在教程中遇到了一些不熟悉的代码 但根本没有解释它 这是我被告知映射的代码16 IRQs 0 15 到 ISR 地点32 47 void irq remap void outportb 0x2
  • 如何在 QTableView 标题中单击鼠标右键单击上下文菜单?

    下面的示例代码 很大程度上受到here http www saltycrane com blog 2007 12 pyqt 43 qtableview qabstracttablemodel 有一个右键单击上下文菜单 当用户单击表中的单元格
  • 为什么 FMA _mm256_fmadd_pd() 内在函数有 3 个 asm 助记符:“vfmadd132pd”、“231”和“213”?

    有人可以向我解释一下为什么融合乘法累加指令有 3 种变体 vfmadd132pd vfmadd231pd and vfmadd213pd 而只有一个 C 内在函数 mm256 fmadd pd 为了简单起见 在 AT T 语法中 有什么区别
  • Ubuntu 11.10 上的 c 数学链接器问题 [重复]

    这个问题在这里已经有答案了 我从 Ubuntu 升级后出现了一些奇怪的错误 10 11 11 04 i dont know 到 11 10 我正在得到一个undefined reference to sqrt 使用 math h 时并与 l
  • C# 无法访问已释放的对象

    我正在制作一个服务器 客户端应用程序 我将服务器套接字设置为侦听 并设置 BeginAccept 方法 当我关闭服务器套接字 Socket Close 以关闭服务器时 BeginAccept 方法的异步回调方法抛出异常 我检查了异常 发现异
  • 这种没有推送寄存器的交换有多安全?

    我对汇编非常陌生 下面的代码应该通过两个不同的函数交换两个整数 首先使用swap c然后使用swap asm 但我怀疑 我是否需要push 我的意思是保存 汇编代码之前寄存器的每个值和pop稍后 就在返回之前 main 换句话说 如果我返回
  • 错误 LNK2005: xxx 已在 MSVCRT.lib(MSVCR100.dll) C:\something\LIBCMT.lib(setlocal.obj) 中定义

    我正在使用 DCMTK 库来读取 Dicom 文件 医学图像处理中使用的图像格式 我在编译此 DCMTK 源代码时遇到问题 DCMTK 使用一些额外的外部库 zlib tiff libpng libxml2 libiconv 我知道所有库都
  • 在 x86 程序集中存储大量布尔值的最佳方法是什么?

    最近我一直在处理充满布尔值的大型数组 目前 我将它们存储在 bss部分有一个 space指令 它允许我创建字节数组 但是 由于我只需要存储布尔值 因此我希望从数组中逐位读取和写入数据 目前 我能想到的最好方法是有一个 space指令所需存储
  • 在 x86 汇编中将 64 位常量移至内存

    我正在使用 Intel x64 程序集 NASM 编译器 尝试将 0x4000000000000000 常量移至内存 该常量在 ieee 754 标准双精度中应等于 2 0 我正在使用的代码是 define two 0x4000000000
  • 上游太大 - nginx + codeigniter

    我从 Nginx 收到此错误 但似乎无法弄清楚 我正在使用 codeigniter 并使用数据库进行会话 所以我想知道标题怎么会太大 有没有办法检查标题是什么 或者看看我能做些什么来修复这个错误 如果您需要我提供任何conf文件或其他文件
  • Javascript - deepEqual 比较

    问题 来自 Eloquent Javascript 第二版 第 4 章 练习 4 编写一个函数 deepEqual 它接受两个值 并且仅当它们相等时才返回 true 是相同的值或具有相同属性的对象 其值也是 与对 deepEqual 的递归
  • 如何从嵌套的对象数组中获取每个父级的值

    所以我有多个对象数组 每个对象都包含一个子对象 e g const data id 1 name parent 1 children id c1 name child 1 children id g1 name grand 1 childr
  • 可访问性不一致:参数类型的可访问性低于方法

    我试图在两个表单之间传递一个对象 基本上是对当前登录用户的引用 目前 我在登录表单中有一些类似的内容 private ACTInterface oActInterface public void button1 Click object s

随机推荐

  • u8显示服务器资源不足,系统提示“虚拟内存不足”的原因及解决方法

    马上注册 结交更多好友 享用更多功能 让你轻松玩转社区 您需要 登录 才可以下载或查看 没有帐号 注册账号 x 一 剪贴板占用了太多的内存 实际上 剪贴板是内存中的一块临时区域 当你在程序中使用了 复制 或 剪切 命令后 Windows将把
  • 电脑蓝屏显示0x000000f4怎么办的四个解决方法

    电脑蓝屏的问题是大家最常见到的电脑问题之一 大多时候蓝屏故障的出现都和软件有关 少数为硬件不兼容或者故障导致 这里粗略的分析下STOP 0x000000F4字段的问题 仅做参考 以下先来看看网友是怎么分析与解决问题的吧 蓝屏代码0x0000
  • docker-compose部署java前后端分离项目

    脚本安装 离线部署包下载 bin bash 创建docker安装目录 离线部署包找作者拿 read p 输入docker安装目录 TempDockerDir function Basic mkdir TempDockerDir cp doc
  • npm install 后序流程图记录

    随笔记录
  • 史上最全 Appium 自动化测试从入门到框架实战精华学习笔记(三)

    本文为霍格沃兹测试学院学员学习笔记 进阶学习文末加群 本系列文章汇总了从 Appium 自动化测试从基础到框架高级实战中 所涉及到的方方面面的知识点精华内容 如下所示 希望对大家快速总结和复习有所帮助 Appium 自动化测试从基础到框架实
  • elementPlus学习(持续更新)

    ElementPlus 前言 form表单 校验 以下内容不写函数字样的都是属性 prop rules show message inline message status icon require asterisk position sc
  • PHY芯片的使用(一)之基本概念讲解(MII相关)2

    今天想和大家交流一下MAC和PHY之间的接口MII MII Media Independent Interface 是介质无关接口 MII接口定义了在MAC层和物理层之间传送数据和控制状态等信息的接口 它是10M和100M兼容的接口 经过扩
  • 数字预失真技术基本原理

    功率放大器在通信系统中是一个及其重要的组件 其主要功能是将调制后的频带信号进行功率放大 使其满足发送端天线发射所需要的发射功率需求 并保证系统接收端可以采集到功率较大的信号 满足通信信道所要求的功率需求 而随着射频功率放大器发射功率的不断提
  • React - Mobx [learning......]

    import observer from mobx react Mobx安装 learning
  • 字符串中找出连续最长的数字串

    1 题目描述 读入一个字符串str 输出字符串str中的连续最长的数字串 2 输入输出示例 给一个输入abc123nj5nk88990wze这里面最长的数字串是88990 并将其输出 3 思路分析 1 首先输入是一个字符串 我们在处理的时候
  • How to Parse XML in C++

    hyperlink
  • 百度地图定位

    1 审请key 2 看demo 注意 定册定位Serveice 不同的demo使用时不一样 因为jar包不同
  • xml 模块(了解)

    本文来自 https www cnblogs com yang1333 articles 12609714 html 3177870913 1 XML文档模板
  • 蓝桥杯真题:寻找2020

    原题里边其实是一个300 300的序列 读进来之后对每一个点作为起点判断一遍四种情况就好了 代码如下所示 include
  • 缓存那些事

    前言 一般而言 现在互联网应用 网站或App 的整体流程 可以概括如图1所示 用户请求从界面 浏览器或App界面 到网络转发 应用服务再到存储 数据库或文件系统 然后返回到界面呈现内容 随着互联网的普及 内容信息越来越复杂 用户数和访问量越
  • 联想计算机游戏本,2021十大游戏本排行(最佳游戏笔记本电脑推荐)

    第五名 HP 惠普 傲慢Omen X 推荐理由 惠普的轻薄办公笔记本做得非常出色 在美国 消费者报告 中获得了非常高的评价 其机型占了CR推荐中的1 5左右 其游戏本也不遑多让 旗下的Omen X 暗影精灵系列口碑都相当不错 Omen 17
  • ARCore之路:HelloAR项目例子分析

    项目效果 通过相机扫描环境中的平面 它会生成上图中的白色网格 可通过点击白色网格来生成三维模型 下图是项目中的节点 下面将从挑选一些节点来分析 其中 Environmental Light 节点是灯光 EventSystem节点是控制输入输
  • wandb在pytorch lightning中的使用

    文章目录 使用前提 使用解析 初始化 模型超参数保存 记录其他配置参数 记录梯度 参数直方图和模型拓扑 记录metric 记录metric的最小值 最大值 记录图像 文本等 记录图像 记录文本 记录表格数据 在多GPU的情况下使用pytor
  • Unity Hub无法登陆的两种终极解决办法

    最近换了个电脑 需要重装Unity 然后unity hub 怎么都无法登陆 登陆不了就不能激活personal license 试了很多次 包括unity hub 2 5 8 和unity hub 3 3都不行 真的是很崩溃 因为是公司的电
  • X86cpu运行的什么格式代码? ELF还是Bin ?

    ELF文件是一种格式 我们使用gcc编译出来的 o文件 和链接后生成的 out文件一般都是ELF格式的文件 Bin文件一般指的是连接器ld b binary链接出来的或者用objcopy b抽出来的文件 ELF和Bin文件都是二进制文件 b