如何保留 Linux 内核模块构建中的 asm 输出

发布于 2024-09-02 18:38:13 字数 502 浏览 10 评论 0原文

我正在为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

z祗昰~ 2024-09-09 18:38:13

Objdump 确实支持该架构。您的可执行文件将被称为arm-none-linux-gnueabi-objdump

Objdump does support that architecture. Your executable will be called arm-none-linux-gnueabi-objdump

荒路情人 2024-09-09 18:38:13

假设 gcc 和 gnu 汇编器可以得到比 objdump 更可读的输出。告诉汇编器使用 gcc 标志保留其中间代码:

 -Wa,-alh=basename.s

并让 basename 成为您需要告诉 make: 的实际源文件名:

 -Wa,-alh=
lt;.s

这将在您的源目录中留下一堆 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:

 -Wa,-alh=basename.s

And to get basename to be the actual source filename you need to tell make:

 -Wa,-alh=
lt;.s

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.

甜宝宝 2024-09-09 18:38:13

为了获取 Linux 内核模块的汇编语言列表,我将汇编器开关添加到内核脚本/Makefile.build 中。

#cmd_cc_o_c = $(CC) $(c_flags) -c -o $(@D)/.tmp_$(@F) 
lt;
cmd_cc_o_c = $(CC) $(c_flags) -c -Wa,-alh=
lt;.lst -o $(@D)/.tmp_$(@F) 
lt;

To get an assembly language listing of my Linux kernel modules, I added the assembler switches to the kernel scripts/Makefile.build.

#cmd_cc_o_c = $(CC) $(c_flags) -c -o $(@D)/.tmp_$(@F) 
lt;
cmd_cc_o_c = $(CC) $(c_flags) -c -Wa,-alh=
lt;.lst -o $(@D)/.tmp_$(@F) 
lt;
日裸衫吸 2024-09-09 18:38:13

您可以尝试使用 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.

万劫不复 2024-09-09 18:38:13

正确的方法可能是在模块 makefile / Kbuild 文件中添加目标依赖项:(

always-m += basename.s

因为 kbuild 有正确的目标来生成 .s 文件)

如果你像我一样懒,这可能看起来像:(

MOD_NAME := some_module_name
myunits := file1 file2 file3 ... and many more... without .c extension

obj-m   := $(MOD_NAME).o
$(MOD_NAME)-y := $(addsuffix .o,$(myunits))

# Comment/uncomment to generate assembly / preprocessor output
always-m += $(addsuffix .s,$(myunits)) $(MOD_NAME).mod.s
always-m += $(addsuffix .i,$(myunits)) $(MOD_NAME).mod.i

这里有 2 个好处:程序集对于生成的模块元注册文件和预处理器输出)

The proper way is likely to add target dependencies in your module makefile / Kbuild file:

always-m += basename.s

(As kbuild has the proper targets to generate the .s files)

If you are lazy as I am, this could look like:

MOD_NAME := some_module_name
myunits := file1 file2 file3 ... and many more... without .c extension

obj-m   := $(MOD_NAME).o
$(MOD_NAME)-y := $(addsuffix .o,$(myunits))

# Comment/uncomment to generate assembly / preprocessor output
always-m += $(addsuffix .s,$(myunits)) $(MOD_NAME).mod.s
always-m += $(addsuffix .i,$(myunits)) $(MOD_NAME).mod.i

(2 bonuses here: assembly for the generated module meta-registration file, and the preprocessor output)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文