如何取消优化 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屋!