- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在阅读有关 ELF 文件格式的内容,我注意到一个用 C++ 编写的小型 hello world 测试程序在 _start
符号中包含一些额外的初始化:
0000000000400770 <_start>:
...
40077f: 49 c7 c0 60 09 40 00 mov $0x400960,%r8
400786: 48 c7 c1 f0 08 40 00 mov $0x4008f0,%rcx
40078d: 48 c7 c7 5d 08 40 00 mov $0x40085d,%rdi
...
40077f
是 __libc_csu_fini
。
4008f0
是 __libc_csu_init
。
40085d
是 main
。
不应该只是 _start
到 main
吗?为什么不?如果我只是删除对 40077f
和 40008f0
的调用并替换为 nop
会发生什么情况?基本上,需要 libc 的意义是什么?
最佳答案
查看 glibc source code :
/* These functions are passed to __libc_start_main by the startup code.
These get statically linked into each program. For dynamically linked
programs, this module will come from libc_nonshared.a and differs from
the libc.a module in that it doesn't call the preinit array. */
void
__libc_csu_init (int argc, char **argv, char **envp)
{
/* For dynamically linked executables the preinit array is executed by
the dynamic linker (before initializing any shared object). */
#ifndef LIBC_NONSHARED
/* For static executables, preinit happens right before init. */
{
const size_t size = __preinit_array_end - __preinit_array_start;
size_t i;
for (i = 0; i < size; i++)
(*__preinit_array_start [i]) (argc, argv, envp);
}
#endif
#ifndef NO_INITFINI
_init ();
#endif
const size_t size = __init_array_end - __init_array_start;
for (size_t i = 0; i < size; i++)
(*__init_array_start [i]) (argc, argv, envp);
}
/* This function should not be used anymore. We run the executable's
destructor now just like any other. We cannot remove the function,
though. */
void
__libc_csu_fini (void)
{
#ifndef LIBC_NONSHARED
size_t i = __fini_array_end - __fini_array_start;
while (i-- > 0)
(*__fini_array_start [i]) ();
# ifndef NO_INITFINI
_fini ();
# endif
#endif
}
这允许库初始化代码运行。链接到程序的库可以在 gcc 中用 __attribute__((constructor))
标记函数,这种机制将在 main
之前运行这些函数,允许库自行初始化在程序开始之前。
关于linux - ELF 文件和附加符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25963628/
我们正在为大学编写一个模拟器项目,我们必须使用 ELF 文件作为输入,但我们不太确定 ELF 文件是什么样的。它应该包含我们可以执行的某些操作(所有这些都应该用二进制表示),但它是否包含其他内容?还是
我目前正在研究 ELF 格式。我想确认一下我认为正确的事情。 ELF是一种格式,它代表可执行和可链接格式。在linux中,一切都是ELF格式。 当使用gcc编译带有-c和-fPIC文件的代码时,它会将
基本上,我希望能够在 elf 二进制文件的 debug dwarf 部分中更改源文件的路径。 最佳答案 Basically I want to be able to change the path t
我想编写一个实用程序来从 ELF 二进制文件中删除程序头。例如,当我运行 readelf -l/my/elf 时,我会得到所有程序头的列表:PHDR INTERP ... GNU_STACK GNU_
考虑使用 GCC 编译的 C 标准 hello world 程序,没有任何开关。如 readelf -s说,它包含 64 个符号。它还说.symtab部分是 1024 字节长。然而,每个符号表条目有
我正在尝试为 ARM 平台编写 elf 可执行加载程序。我在这里有一些查询 1) 如何生成可重定位或位置无关的 ELF 可执行文件(编译器和链接器选项是什么) 2) 如何加载上面生成的 ELF 可执行
假设我有一个 lib xxx.so。所以我得到了所有的函数名和参数 以下命令: readelf -Ws xxx.so |c++filt 它将输出以下内容: 711: 00270209 40
我正在创建一个 ELF 可执行文件,我需要知道操作系统需要哪些部分才能加载和执行它。 Details: OS: Ubuntu 10.04 (64-bit)Kernel ve
SHT_NULL的目的是什么? ELF 中的部分? 它是由操作系统还是加载程序引用的? 这个部分的大小是多少? 它与 NULL 指针有什么关系吗? 此外,为什么此部分在部分段映射中没有条目? 来自 E
我正在学习 ELF 并且有一段时间的疑问。我试图寻找答案,但徒劳无功。如果有人能给我答案或引导我到地方寻找答案,我会很感激。 我读到的几乎所有关于 ELF 的文档都说 .text 部分包含可执行的二进
问题场景 : 简单来说,我们是否有一个 Trace32 命令来从加载到目标的 ELF 文件中读取符号(及其内容)?我们有这种特殊情况,其中 ELF 文件的应用程序特定调试符号作为 ELF 中“.nol
我试图从 Linux 程序的 elf 文件中提取特定的字符串变量(即符号),甚至从它来自的 .o 中提取。 它在 .rodata 部分,显然我知道符号名称。 是否有一系列 objdump 样式的命令和
在 Linux 上,我试图将静态链接的 ELF 文件剥离为基本要素。当我运行时: strip --strip-unneeded foo 或者 strip --strip-all foo 生成的文件仍然
我有一个 STM32,我将 ELF 文件加载到 RAM 中(使用 OpenOCD 和 JTAG)。到目前为止,我还没有真正关注我加载的 ELF 文件的大小。 通常,当我编译一个对我的板来说太大的 EL
我有一个 STM32,我将 ELF 文件加载到 RAM 中(使用 OpenOCD 和 JTAG)。到目前为止,我还没有真正关注我加载的 ELF 文件的大小。 通常,当我编译一个对我的板来说太大的 EL
我需要学习手动创建 ELF 可执行文件。到目前为止,我一直在使用在线指南,例如: Manually Creating an ELF Executable ELF reference 几次失败后,我将我
我在 readelf 实用程序的帮助下打开了我的对象 Sprite 文件: readelf -a ./my_object.o |较少的 结果我得到了很多有趣的信息。 我在部分表中看到了一个带有“GRO
ELF 文件包含两个结构来处理重定位: Elf64_Rel: typedef struct { Elf64_Addr r_offset; Uint64_t r_info; }
我一直在阅读 ELF 规范,但无法弄清楚程序入口点和 _start 地址从何而来。 看起来他们应该在一个非常一致的地方,但我做了一些琐碎的程序,_start 总是在不同的地方。 谁能澄清一下? 最佳答
这是我的测试。我有一个由源 main.c 和 misc.c 组成的 main 应用程序和一个由 lib.cname); m++; } return 0; } misc.
我是一名优秀的程序员,十分优秀!