Change Yocto Project Kernel Compile Optimization Level

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Change Yocto Project Kernel Compile Optimization Level

跳至解决方案
4,557 次查看
jamesburnworth
Contributor II

I'm trying to debug a kernel module and as such, need to compile it without optimizations.  I'm using the Yocto Project and can't get the module to compile with a -O0 flag despite trying several things.  So far I've tried adding the following to my local.conf.

EXTRA_IMAGE_FEATURES = "debug-tweaks tools-profile dbg-pkgs"

INHIBIT_PACKAGE_STRIP = "1"
DEBUG_BUILD = "1"

PACKAGE_DEBUG_SPLIT_STYLE = 'debug-file-directory'

I've also added the following to my kernel recipe in addition to the changes above.

DEBUG_FLAGS += "-O0"

None of this has worked.  If I run objdump -g on the .ko file in question I still find -O2 is being used.  This leads to the debugger jumping all around when I'm trying to step through source. 

Is there a way to override the kernel compile optimization level in the Yocto Project?

For kernel module debugging I'm following this guide from DS-MDK and the imx_rpmsg_tty module.

http://www2.keil.com/docs/default-source/default-document-library/gs_ds-mdk_5_27_r1.pdf?sfvrsn=2 

I'm working with this SOM.

CL-SOM-iMX7 | NXP (Freescale) i.MX 7 | System-on-Module | Computer-on-Module | CompuLab 

I've attached my local.conf, my kernel recipe, and my kernel .config.  Let me know if you need any more information.

Thanks for the help,

James

标签 (4)
1 解答
3,462 次查看
jamesburnworth
Contributor II

Hi YuriMuhin_ng,

Thanks for the response.  I tried building the kernel outside of Yocto and was able to eventually get it working. 

I made and installed two SDK's, one with debug options enable in the local.conf mentioned above and one without.  After running the environment-setup script for the debug SDK I echo'd my CFLAGS variable.  It had a -O (which goes to a -O1) in it so I appended a -O0.  I copied over my .config and ran make.  This didn't work, the kernel object was still being compiled with -O2. 

Eventually I added the following line to the Makefile in the directory with the kernel module.

CFLAGS_imx_rpmsg_tty.o := -O0

After adding that, the module compiled with -O0 and the debugging experience was fixed.  Interestingly it also worked when I used the environment-setup script for the regular SDK.

At this point I guess I still have a few questions:

  • Is this an appropriate way to modify a Makefile and was it the right Makefile to modify?
  • Could I make a similar change in Yocto so that we could trigger a system wide debug build?  This process involved quite a few manual steps that wouldn't be ideal for a development cycle.
  • And still the original question, is there a way to set the optimization level of a kernel module with Yocto variables or settings?

Thank you,

James

在原帖中查看解决方案

2 回复数
3,462 次查看
Yuri
NXP Employee
NXP Employee

Hello,

  Please try to build kernel without Yocto:

 

https://community.nxp.com/docs/DOC-334814 

Have a great day,
Yuri

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 项奖励
回复
3,463 次查看
jamesburnworth
Contributor II

Hi YuriMuhin_ng,

Thanks for the response.  I tried building the kernel outside of Yocto and was able to eventually get it working. 

I made and installed two SDK's, one with debug options enable in the local.conf mentioned above and one without.  After running the environment-setup script for the debug SDK I echo'd my CFLAGS variable.  It had a -O (which goes to a -O1) in it so I appended a -O0.  I copied over my .config and ran make.  This didn't work, the kernel object was still being compiled with -O2. 

Eventually I added the following line to the Makefile in the directory with the kernel module.

CFLAGS_imx_rpmsg_tty.o := -O0

After adding that, the module compiled with -O0 and the debugging experience was fixed.  Interestingly it also worked when I used the environment-setup script for the regular SDK.

At this point I guess I still have a few questions:

  • Is this an appropriate way to modify a Makefile and was it the right Makefile to modify?
  • Could I make a similar change in Yocto so that we could trigger a system wide debug build?  This process involved quite a few manual steps that wouldn't be ideal for a development cycle.
  • And still the original question, is there a way to set the optimization level of a kernel module with Yocto variables or settings?

Thank you,

James