[Bug preprocessor/82176] Feature request: replace __FILE__ with file's basename instead its full name
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82176 --- Comment #7 from f.hollerer at gmx dot net --- Yes, the __FILE_NAME__ macro provided by Clang is exactly the feature I am asking for: __FILE_NAME__ Clang-specific extension that functions similar to __FILE__ but only renders the last path component (the filename) instead of an invocation dependent full path to that file.
[Bug preprocessor/82176] Feature request: replace __FILE__ with file's basename instead its full name
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82176 --- Comment #8 from f.hollerer at gmx dot net --- I have to correct me. The __FILE_NAME__ macro goes in the direction I would like to have. But this does not solve the problem with assert(). My preferred solution is to have the expansion of the __FILE__ macro controlled by a command line options. As explained in my original post I use third party code which is augmented with asserts(). I don't want to touch this code. To my understanding assert() uses __FILE__ and __LINE__. I would like to have a command line option which let __FILE__ expand to the last path component (the filename) instead of an invocation dependent full path of that file. This would: - shorten the output of assert() - minimize the image size due to shorter strings - make the build reproduceable as the output does not depend on the current working directory. To sum up. This is what the feature request is about: https://www.iar.com/support/tech-notes/general/avoiding-full-paths-in-the-output-file/ Please provide a '--no_path_in_file_macros' as provided by the IAC compiler.
[Bug preprocessor/82176] Feature request: replace __FILE__ with file's basename instead its full name
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82176 --- Comment #11 from f.hollerer at gmx dot net --- (In reply to jos...@codesourcery.com from comment #9) > On Tue, 29 Oct 2019, f.hollerer at gmx dot net wrote: > > > This would: > > > > - shorten the output of assert() > > - minimize the image size due to shorter strings > > - make the build reproduceable as the output does not depend on the current > > working directory. > > Note that we have the -ffile-prefix-map / -fmacro-prefix-map / > -fdebug-prefix-map options you can use to specify a mapping from the > actual directory names used in the build to the names you want to appear > in the output. Thank you for pointing me to this options. I have to get a more recent compiler to try them, but according the documentation they should solve my problem.
[Bug preprocessor/82176] Feature request: replace __FILE__ with file's basename instead its full name
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82176 --- Comment #12 from f.hollerer at gmx dot net --- (In reply to Gregory Fuchedzhy from comment #10) > (In reply to f.hollerer from comment #8) > > To my understanding assert() uses __FILE__ and __LINE__. I would like to > > have a command line option which let __FILE__ expand to the last path > > component (the filename) instead of an invocation dependent full path of > > that file. > > If __FILE_NAME__ is implemented would adding -D__FILE__=__FILE_NAME__ solve > your particular usecase? Yes, but then I also have to add -Wno-builtin-macro-redefined otherwise the compiler will issue a warning. I think best match is the -ffile-prefix-map option jos...@codesourcery.com pointed me to.
[Bug preprocessor/82176] New: Feature request: replace __FILE__ with file's basename instead its full name
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82176 Bug ID: 82176 Summary: Feature request: replace __FILE__ with file's basename instead its full name Product: gcc Version: 6.3.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: preprocessor Assignee: unassigned at gcc dot gnu.org Reporter: f.hollerer at gmx dot net Target Milestone: --- 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. After consutling google for a while, I found that other compiler toolchains provide this feature. E.g. IAR: https://www.iar.com/support/tech-notes/general/avoiding-full-paths-in-the-output-file/ Therefore, I think it is a feature of common interest, especially in the embedded world. Thanks & Best regards, Franz Hollerer
[Bug preprocessor/82176] Feature request: replace __FILE__ with file's basename instead its full name
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82176 --- Comment #2 from f.hollerer at gmx dot net --- > See PR 42579 which has a patch to add __FILE_BASENAME__ for this purpose. Unfortunately this does not solve the problem when __FILE__ is used indirectly via the assert() macro shipped with the compiler toolchain.