binutils - kernel - “_binary”是什么意思?

binutils - kernel - "_binary" meaning?

我正在阅读 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_myAsmFileHere_myParameterherebinutils给汇编文件的默认变量结构,用来导出它们的地址,大小等等?

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

谢谢

奇怪的是,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 在嵌入二进制文件时使用了相同的逻辑。 请注意,xv6 的 Makefile 包含用于链接内核的这一行:

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

可以看到,它使用-b binary嵌入文件initcodeentryother,所以在这个过程中会定义上面的符号。

当在汇编文件中定义 .global 变量时,要使 C 文件能够引用该变量,C 文件必须在变量名前加上“_”。这样链接器就可以 'link' C 文件中的名称与汇编文件中的名称。