如何对 Linux 内核进行反优化并使用 -O0 进行编译? [英] How to de-optimize the Linux kernel to and compile it with -O0?
问题描述
我想阅读和理解 Linux 内核的内存管理(尤其是碎片整理压缩迁移).
I'm wanting to read and understand the Linux kernel's Memory Management (in particular defragcompactionmigration).
所以,我关闭了 .config
中的大小优化(当然是使用 make menuconfig)并编译...这让我仍然拥有一个优化的内核.
So, I turn off optimization for size in .config
(using make menuconfig of course) and compile...This leaves me with still an optimized kernel.
注意: 当我说优化内核时,我的意思是当我使用 gdb
并告诉它 next
它会跳来跳去.我不希望这样,我希望能够像处理简单的 hello world 一样逐行执行代码.
NOTE: When I say optimized kernel, I mean that when I use gdb
and tell it next
that it'll jump around. I don't want that, I want to be able to follow the code line by line just as I would with a simple hello world.
接下来,我编辑 Makefile
并将 -O2
与 -O0
交换,这会导致事情中断.
Next, I edit the Makefile
and swap -O2
with -O0
and that causes things to break.
我发现 这个,但我不知道我想要什么文件,因为我不知道兔子洞到底有多远.
I found this, but I don't know what files I'll want because I don't know how far down the rabbit hole goes.
我可以使用更通用的选项吗?我了解内存压缩的概念;但是,我想看看一切发生在哪里以及它是如何发生的.
Is there a more generic option that I can use? I understand the concepts of memory compaction; however, I want to see where everything happens and how it exactly happens.
推荐答案
你不能去优化内核.您也许可以取消优化某些功能,如下所示:
You can't de-optimize the kernel. You might be able to de-optimize certain functions, like this:
void __attribute__((optimize("O0"))) foo(unsigned char data) {
// unmodifiable compiler code
}
但内核作为一个整体需要 -O2,因为代码本身是在假设某些函数将以某种方式优化的前提下编写的.
But the kernel as a whole requires -O2 because the code itself is written with assumptions that certain functions will be optimized in a certain way.
很抱歉,但您确实需要知道您想要进入的兔子洞的大小.
Sorry, but you really will need to know the size of the rabbit hole you want to go down.
这篇关于如何对 Linux 内核进行反优化并使用 -O0 进行编译?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!