Feature request: replace __FILE__ with file's basename instead its full name

Bug #1716347 reported by Franz Hollerer
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
GNU Arm Embedded Toolchain
New
Undecided
Unassigned

Bug Description

Actually, this is a feature request, not a bug report.

It would be great to have a command line option to tell the preprocessor to replace __FILE__ with the basename of a file, not the complete name with relative or absolute path components as passed to the preprocessor / compiler when invoked.

Reason is to minimise the amount of FLASH / code memory required for the strings.

Explanation:

 I am using arm-none-eabi-gcc version 6.3.1 downloaded from https://developer.arm.com/ to build fora Cortex-M4 with 32 kB code memory. Unfortunately, the cmake Build system I am using always passes the absolute file path to the compiler, furthermore the driver code provided by the chip vendor uses allot of assert()s.

I don't want to turn off assert()s completely, but with __FILE__ being replaced with the full file name blows up my firmware image. Restricting it to the file's basename would bring the image back to reasonable size, by still providing good error messages.

I think this feature would be valuable for other developers too.

Thanks & Best regards,

Franz Hollerer

Revision history for this message
Thomas Preud'homme (thomas-preudhomme) wrote :

Hi Franz,

This is a general improvement to GCC (not ARM specific) hence I would suggest you to report it on the project's bugzilla: http://gcc.gnu.org/bugzilla.

Best regards,

Tom

Revision history for this message
Leo Havmøller (leh-p) wrote :

Gcc has a __BASE_FILE__ macro for this: https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html.
However, this stackoverflow post (https://stackoverflow.com/questions/8487986/file-macro-shows-full-path) claims that it just gives the same result as __FILE__.

Revision history for this message
Franz Hollerer (f-hollerer) wrote :

> However, this stackoverflow post (https://stackoverflow.com/questions/8487986/file-macro-shows-full-path) claims that it just gives the same result as __FILE__.

I can confirm this claim, at least for

- gcc (Debian 6.3.0-18) 6.3.0 20170516
- arm-none-eabi-gcc (GNU Tools for ARM Embedded Processors 6-2017-q2-update) 6.3.1 20170620 (release) [ARM/embedded-6-branch revision 249437]

For both compilers __BASE_FILE__ gives the same result as __FILE__, which is the name of the file as specfied on the command line when invoking the compiler.

Furthermore, I use __FILE__ indirectly via assert(), which is scattered through driver code provided by the chip vendor. Therefore, __BASE_FILE__ is no option.

Revision history for this message
Christophe Lyon (christophe-lyon) wrote :

Hello,

I think this is similar to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=42579, which I fixed recently by adding support for __FILE_NAME__ in GCC. This will be available with gcc-12.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.