gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 23:47:40 25 4
gpt4 key购买 nike

我正在阅读 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com