如何保留 Linux 内核模块构建中的 asm 输出
我正在为 2.6.x 内核开发 Linux 内核模块,我需要查看程序集输出,尽管它目前作为临时文件完成,并已删除后记。我希望将汇编输出与我的 C 源文件混合,这样我就可以轻松地跟踪问题所在。这是针对 ARMv6 核心的,显然 objdump 不支持这种架构。我在下面包含了我的 makefile。
ETREP=/xxSourceTreexx/
GNU_BIN=$(ETREP)/arm-none-linux-gnueabi/bin
CROSS_COMPILE := $(GNU_BIN)/arm-none-linux-gnueabi-
ARCH := arm
KDIR=$(ETREP)/linux-2.6.31/
MAKE= CROSS_COMPILE=$(CROSS_COMPILE) ARCH=$(ARCH) make
obj-m += xxfile1xx.o
all:
$(MAKE) -C $(KDIR) M=$(PWD) modules
clean:
$(MAKE) -C $(KDIR) M=$(PWD) clean
I'm working on a Linux kernel module for a 2.6.x kernel and I need to view the assembly output, though it's currently being done as a temporary file an deleted afterwords. I'd like to have the assembly output mixed with my C source file so I can easily trace where my problem lies. This is for an ARMv6 core and apparently objdump doesn't support this architecture. I've included my makefile below.
ETREP=/xxSourceTreexx/
GNU_BIN=$(ETREP)/arm-none-linux-gnueabi/bin
CROSS_COMPILE := $(GNU_BIN)/arm-none-linux-gnueabi-
ARCH := arm
KDIR=$(ETREP)/linux-2.6.31/
MAKE= CROSS_COMPILE=$(CROSS_COMPILE) ARCH=$(ARCH) make
obj-m += xxfile1xx.o
all:
$(MAKE) -C $(KDIR) M=$(PWD) modules
clean:
$(MAKE) -C $(KDIR) M=$(PWD) clean
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
Objdump 确实支持该架构。您的可执行文件将被称为
arm-none-linux-gnueabi-objdump
Objdump does support that architecture. Your executable will be called
arm-none-linux-gnueabi-objdump
假设 gcc 和 gnu 汇编器可以得到比 objdump 更可读的输出。告诉汇编器使用 gcc 标志保留其中间代码:
并让
basename
成为您需要告诉 make: 的实际源文件名:这将在您的源目录中留下一堆 foo.cs 文件。这里的一个大问题是 gcc 的工作方式是在代码生成和汇编之间使用临时文件。我找不到让 gcc 保存其中间体的方法,但汇编程序很乐意为您保存一个列表。
将这个参数放入 Makefile CFLAGS 留给读者作为练习(因为我有点讨厌“make”,更讨厌“gnu info”。
Assuming gcc and the gnu assembler a more readable output than
objdump
can be had. Tell the assembler to retain its intermediate code using flags to gcc:And to get
basename
to be the actual source filename you need to tell make:which will leave piles of foo.c.s files laying around your source directory. The big problem here is that the way gcc works it uses temporary files between code generation and assembly. I can't find a way to make gcc save its intermediates but the assembler is happy to stash a listing for you.
Getting that argument into the Makefile CFLAGS is left as an exercise for the reader (because I kinda hate "make" and hate "gnu info" even more.
为了获取 Linux 内核模块的汇编语言列表,我将汇编器开关添加到内核脚本/Makefile.build 中。
To get an assembly language listing of my Linux kernel modules, I added the assembler switches to the kernel scripts/Makefile.build.
您可以尝试使用 gcc 标志“-save-temps”。
它在我的嵌入式项目中适用于我,我还没有在内核构建上尝试过。
You could try the flag "-save-temps" to gcc.
It works for me in my embedded project, I haven't tried it on kernel builds.
正确的方法可能是在模块 makefile / Kbuild 文件中添加目标依赖项:(
因为 kbuild 有正确的目标来生成 .s 文件)
如果你像我一样懒,这可能看起来像:(
这里有 2 个好处:程序集对于生成的模块元注册文件和预处理器输出)
The proper way is likely to add target dependencies in your module makefile / Kbuild file:
(As kbuild has the proper targets to generate the .s files)
If you are lazy as I am, this could look like:
(2 bonuses here: assembly for the generated module meta-registration file, and the preprocessor output)