How to prevent full path from appearing in binaries?

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

How to prevent full path from appearing in binaries?

跳至解决方案
8,708 次查看
dave408
Senior Contributor II

I'm using KDS 3.0 and am wondering why two binaries built from the same revision of source on identically (or so I think) installations of KDS result in different information in the binaries.

 

One thing that is very clear is that full paths are present in the binaries built using my release configuration, which is essentially the same as my debug configuration, but debug information is set to "None".

 

The only thing I have been able to come up with is that the __FILE__ macro generates a full path to the file, rather than the "short" path that takes the include folders into account.

 

Can anyone suggest a way to resolve this?

 

EDIT -- I just saw a post on StackOverflow where IAR added a --no_path_in_file_macros compiler flag to avoid this problem.  Does anyone know of an equivalent for gcc that has worked for you?  I'm currently looking that up now.  http://stackoverflow.com/questions/8487986/file-macro-shows-full-path

标签 (1)
标记 (1)
0 项奖励
回复
1 解答
7,966 次查看
guylejeune
Contributor III

Hi Dave,

I'm experiencing the same problem - looks like my post is a duplicate of yours (https://community.freescale.cohttp://m/thread/380862)

It's not only files path that are in the binary, some other printf-like text are also included.

在原帖中查看解决方案

0 项奖励
回复
12 回复数
7,789 次查看
ErichStyger
Specialist I

Hi @dave408 ,

if you want the __FILE__ macro just having the file name without the path, see assert(), __FILE__, Path and other cool GNU gcc Tricks to be aware of | MCU on Eclipse

I hope this helps,

Erich

0 项奖励
回复
7,967 次查看
guylejeune
Contributor III

Hi Dave,

I'm experiencing the same problem - looks like my post is a duplicate of yours (https://community.freescale.cohttp://m/thread/380862)

It's not only files path that are in the binary, some other printf-like text are also included.

0 项奖励
回复
7,966 次查看
dave408
Senior Contributor II

Hi Guy, thank you for letting me know!

0 项奖励
回复
7,966 次查看
trytohelp
NXP Employee
NXP Employee

Hi Dave,

Please have a look to (https://community.freescale.cohttp://m/thread/380862)

Probably you should have same problem.

Add the preprocessor compiler macro NDEBUG.


Have a great day,
Pascal
Freescale Technical Support
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

7,966 次查看
dave408
Senior Contributor II

Pascal, I have confirmed that NDEBUG does the trick here.  Thanks for helping us (guylejeune) out with this!

0 项奖励
回复
7,966 次查看
dave408
Senior Contributor II

Thanks, Pascal, I will have a look.  I thought that the release configuration I had created, where I selected No Debug information would have had the same results.  This is helpful!

0 项奖励
回复
7,966 次查看
trytohelp
NXP Employee
NXP Employee

Hi Dave,

KDS is using GCC build tool chain.

The project generates the .elf file.

The .elf includes the code and debug information.

By debug information I mean all information that the debugger needs to debug the application.

This is including the path of all source files in order to display the file associated to the executed code.

Now you can generate a Srecord file (bin, hex, ...) containing code only without debug info.

To enable the Hex/Bin Converter you need to enable the "Create flash image"  option under C/C++ build - Settings - Toolchains tab.

pastedImage_1.png

now back to Tool Settings tab, a new config is available:

    Cross ARM GNU create Flash Image

pastedImage_2.png

Is it the option/process you're looking for ?


Have a great day,
Pascal
Freescale Technical Support
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 项奖励
回复
7,966 次查看
dave408
Senior Contributor II

Hi Pascal, that's what I am already doing -- creating a binary (.bin) flash image.  It's the bin itself that has the full pathnames in it.  From what I understand, that's just how it goes, gcc will put whatever is passed to it from the command line into the binary.  So the only option is to build in a different folder.

0 项奖励
回复
7,966 次查看
trytohelp
NXP Employee
NXP Employee

Hi Dave,

do you use an external editor to open/edit the binary file ?

Which one ?

According to the gcc manual there are some options we can use on "arm-none-eabi-objcopy" tool.

By default KDS proposes -j .text and -j .data.

These options will have an impact on the bin file.


Have a great day,
Pascal
Freescale Technical Support
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 项奖励
回复
7,966 次查看
dave408
Senior Contributor II

Hi Pascal, you can use any text editor to see the paths.  Notepad works fine.

0 项奖励
回复
7,966 次查看
dave408
Senior Contributor II

For now, I'm just going to cheat and change the checkout folder on my build server to point to a shortened path.

0 项奖励
回复
7,966 次查看
dave408
Senior Contributor II

It sounds like __FILE__ just uses whatever was passed to gcc on the command line.  So it seems that I will need to figure out how to change everything to relative paths.  Has anyone here done this and know exactly what project settings need to be changed?

My initial guess was that I'll have to go into the include directories setting and change everything to relative paths.  This could affect portability across developers' machines.  In addition, the binary shows the full path to .cpp files, which would not be covered by the Includes directories.  There must be another way to deal with this...

0 项奖励
回复