Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macros: RIOT_FILE_RELATIVE printing wrong file name for headers #4053

Closed
OlegHahm opened this issue Oct 5, 2015 · 15 comments
Closed

macros: RIOT_FILE_RELATIVE printing wrong file name for headers #4053

OlegHahm opened this issue Oct 5, 2015 · 15 comments
Assignees
Labels
Area: build system Area: Build system Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)

Comments

@OlegHahm
Copy link
Member

OlegHahm commented Oct 5, 2015

If RIOT_FILE_RELATIVE is located inside a header (e.g. inside a macro or static inline function), it will give the wrong file name, i.e. the name of the including C file instead of the header's file name.

@OlegHahm OlegHahm added the Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) label Oct 5, 2015
@kaspar030
Copy link
Contributor

Yes... Can anyone think of how to fix this?

@OlegHahm
Copy link
Member Author

Maybe @Kijewski?

@miri64
Copy link
Member

miri64 commented Oct 18, 2016

Bump

@kaspar030
Copy link
Contributor

Cantfix?

@miri64
Copy link
Member

miri64 commented Nov 18, 2016

For __FILE__ it works as expected, so there might be a way to fix it.

@Kijewski
Copy link
Contributor

Dunno if this even needs a fix. I think the current state is even better than printing the .h file, because when you look at the .c file, you can easily see that this line uses a macro, and follow its macro expansions, but it is extremely difficult to do the reverse, and trace back the expansions that led to this line in the .h file.

@miri64
Copy link
Member

miri64 commented Nov 20, 2016

Dunno if this even needs a fix. I think the current state is even better than printing the .h file, because when you look at the .c file, you can easily see that this line uses a macro, and follow its macro expansions, but it is extremely difficult to do the reverse, and trace back the expansions that led to this line in the .h file.

But if you try something like printf("%s:%d ...\n, RIOT_FILE_RELATIVE, __LINE__); the output is very confusing.

@miri64
Copy link
Member

miri64 commented Nov 20, 2016

(in inline functions I mean)

@OlegHahm
Copy link
Member Author

Dunno if this even needs a fix. I think the current state is even better than printing the .h file, because when you look at the .c file, you can easily see that this line uses a macro

Nope, because the debug message will give you the name of the .c file, but the line number from the .h file.

@Kijewski
Copy link
Contributor

the debug message will give you the name of the .c file, but the line number from the .h file.

OK, that's less than optimal :)

@OlegHahm
Copy link
Member Author

Anyone with a nice solution?

@kYc0o kYc0o added the Area: build system Area: Build system label Jul 17, 2018
@cladmi
Copy link
Contributor

cladmi commented Jul 26, 2018

I fell on a related issue because libfixmath_unittest uses __FILE__ for outputing the file name. Which makes the size of the build firmware vary with the build path. So I took some time to read about it.

From my tests, the issue mentioned here is only present for inline functions and not macros.

  • inline functions, __FILE__ and __LINE__ are evaluated as the header and RIOT_FILE_RELATIVE is set to the C file.
  • macros __FILE__ and __LINE__ are evaluated to the C file which is the same as RIOT_FILE_RELATIVE.

__FILE__ uses the path given to the compiler https://gcc.gnu.org/onlinedocs/cpp/Standard-Predefined-Macros.html

Another solution is https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70268 but only recently added for GCC 8 and as patch for llvm https://reviews.llvm.org/D49466


I tried replacing gcc $(abspath C file) by cd $(RIOTBASE) && gcc $(relative path to the C file) It makes __FILE__ have the relative value and could be used instead of RIOT_FILE_RELATIVE.
However, it makes the generated .d file have a wrong path for the c file as it is not relative to the current directory anymore.

My solution for this would be to change the way we are currently compiling and always build from $(RIOTBASE) and refer to the sources with their relative path.

make -C $(RIOTBASE) -f $(SRCDIR)/Makefile

And Makefile.base would deduce the relative SRCDIR from the Makefile location or could be specified from command line for packages.

The downside of this is that SRCS and wildcard in general should be adapted to take this into account.

core/Makefile:SRC := $(filter-out mbox.c msg.c thread_flags.c,$(wildcard *.c))

It could remove the need to do abspath all the time and only have relative path in the build.

This could also help in general to have reproducible builds when different build directories are used, even for the debug symbols and also allow spaces in the path to RIOT.


It is something I would be interested to do and would be for more than just the debug macro.
Would that be a direction you would agree to take ?

@stale
Copy link

stale bot commented Aug 10, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want me to ignore this issue, please mark it with the "State: don't stale" label. Thank you for your contributions.

@stale stale bot added the State: stale State: The issue / PR has no activity for >185 days label Aug 10, 2019
@stale stale bot closed this as completed Sep 10, 2019
@aabadie aabadie reopened this Sep 21, 2019
@stale stale bot removed the State: stale State: The issue / PR has no activity for >185 days label Sep 21, 2019
@miri64 miri64 added this to the Release 2020.07 milestone Jun 30, 2020
@MrKevinWeiss MrKevinWeiss removed this from the Release 2021.07 milestone Jul 15, 2021
@maribu
Copy link
Member

maribu commented May 17, 2023

Judging from the title only, I think @benpicco solved this some time ago

@OlegHahm
Copy link
Member Author

The macro is gone entirely and I couldn't reproduce the issue any more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: build system Area: Build system Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)
Projects
None yet
Development

No branches or pull requests

9 participants