未找到 GRUB 多重引导标头 [英] GRUB Multiboot header not found

查看:37
本文介绍了未找到 GRUB 多重引导标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

阅读完这个这个问题后,这是主要的答案,我在内核上运行 readelf,并注意到我的 .text 部分位于 0x00101000 而不是 0x00100000.我还注意到上面的一个部分读取了 .not.gnu.build-i ,它位于 .text 部分应该在的位置.有没有办法让我的 .text 部分位于正确的位置?我已经用align 4设置为1M.

After reading this this question and it's primary answer, I ran readelf on my kernel, and noticed my .text section was at 0x00101000 and not 0x00100000. I also noticed a section above that read .not.gnu.build-i that was in the place the .text section is supposed to be. Is there a way I could make my .text section be in the correct place? I have already used align 4 to set it to 1M.

推荐答案

问题在于 LD(或 LD via GCC)是在第一个 4k 中自动放置注释部分(如果生成了).如果使用 GCC 链接最终内核,则传递 -Wl,--build-id=none 选项.如果你直接使用 LD 来链接最终的二进制文件,那么你可以传递它 --build-id=none .

The issue is that LD (or LD via GCC) is automatically placing a notes section (if one was generated) in the first 4k. If linking the final kernel with GCC pass it the -Wl,--build-id=none option. If you are using LD directly to link the final binary then you can pass it --build-id=none .

如果编写多引导 ELF 对象,此额外部分的存在会强制多引导头超出文件中的 8k 位置.这是因为 ELF 标头通常最少占用文件的前 4k.为 .note.gnu.build-id.multiboot 部分添加 4k 现在超出了物理文件的 8k 标记.这将导致像 GRUB 这样的多重引导加载程序认为您的 ELF 可执行文件没有多重引导头,因为它只查看文件的前 8k.

If writing a multiboot ELF object the existence of this extra section can force the mulitboot header beyond the 8k position in the file. This is accounting for the fact that ELF headers usually take a minimum of the first 4k of the file. Add in the 4k for .note.gnu.build-id and .multiboot section is now beyond 8k mark of the physical file. This will cause a multiboot loader like GRUB to think your ELF executable doesn't have a multiboot header since it only looks through the first 8k of the file.

这篇关于未找到 GRUB 多重引导标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆