c - binutils - kernel - "_binary"是什么意思?

标签 c assembly linker kernel binutils

我正在阅读 xv6 讲座。 我有一个名为 initcode.S 的文件,它将被链接到内核中。

现在以这种方式创建了两个符号:

    extern char _binary_initcode_start[], _binary_initcode_size[];

在一个函数中。

讲座说:

as part of the kernel build process, the linker embeds that binary that defines two special symbols, _binary_initcode_starcode_size, indicating the location and size of the binary.

我知道 binutils 正在获取此汇编代码的地址和大小。

我想知道符号:它是默认的吗?我的搜索并没有清楚地证明这一点。

  • _binary -> 原来是汇编代码

  • _initcode -> 我的文件名

  • _start -> 我感兴趣的参数。

这意味着任何编译的汇编代码也会有这些变量。

不过,我没有证据证明这一点。


问题是:

_binary_myAsmFileHere_myParameterhere 是 binutils 提供给程序集文件以导出其地址、大小等的默认变量结构吗?

有人能告诉我我的假设是否正确,是否比那个更好:规则

谢谢

最佳答案

奇怪的是,ld 手册中似乎没有记载。然而,man objcopy确实是这样说的:

You can access this binary data inside a program by referencing the special symbols that are created by the conversion process. These symbols are called _binary_objfile_start, _binary_objfile_end and _binary_objfile_size. e.g. you can transform a picture file into an object file and then access it in your code using these symbols.

显然 ld 在嵌入二进制文件时使用相同的逻辑。 请注意 Makefile xv6 包含用于链接内核的这一行:

$(LD) $(LDFLAGS) -T kernel.ld -o kernel entry.o $(OBJS) -b binary initcode entryother

如你所见,它使用-b binary嵌入文件initcodeentryother,所以上面的符号将在这个过程。

关于c - binutils - kernel - "_binary"是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29034840/

相关文章:

在 GCC 中调试 vtable 链接器错误

C - 尝试在 charArray[n][] 中查找 char[] 并记录 n 的值

c - 我的C代码有什么问题?循环中有东西吗?

c++ - objdump 和 objcopy 作为 c/c++ 库

visual-studio - 当不需要清理时避免 "push ebp, mov esp, ebp"序言

c++ - dlopen 找不到分解的符号

C 编译器可以在结构中的第一个元素之前添加填充吗?

linux - 程序集——系统调用写入返回 -38,无输出

linux - 在 nasm 汇编 intel x86 中获取数字而不是 Ascii

linker - CATiledLayer 无法处理我的 iOS5 项目