0

I'm working on compiling a kernel and I'm having an issue in a header file. The error is nonsensical and I can't figure it out.

The offending few lines are :

#if defined(CONFIG_FRAME_POINTER) && !defined(CONFIG_ARM_UNWIND)
/*
 * return_address uses walk_stackframe to do it's work.  If both
 * CONFIG_FRAME_POINTER=y and CONFIG_ARM_UNWIND=y walk_stackframe uses 
   unwind
 * information.  For this to work in the function tracer many functions 
  would
 * have to be marked with __notrace.  So for now just depend on
 * !CONFIG_ARM_UNWIND.
 */

void *return_address(unsigned int);

#else

extern inline void *return_address(unsigned int level)
{ //<--Line 49
    return NULL;
}

#endif

#define ftrace_return_address(n) return_address(n)

The error is :

init/do_mounts_initrd.o: In function `return_address':
/home/name/rpl-enabled-kernel/./arch/arm/include/asm/ftrace.h:49: 
multiple definition of `return_address'
init/do_mounts.o:/home/name/rpl-enabled-
kernel/./arch/arm/include/asm/ftrace.h:49: first defined here

Line 49 being the open bracket. I don't really understand the error, but it seems to be suggesting that return_address can't be defined where it is because it's already defined (which has a lot of stackoverflow solutions), however the line it's pointing to to say it's already defined is where the definition takes place.

Is it somehow defining itself twice? Is it possible the header is included twice somewhere?

Edit: being declared as extern was not the issue, however it appears to have contributed to the issue. The function was multiply defined (based on some pre-processor ifs and such), and removing the extern keyword allowed the compiler to point to the actual source of the error.

Brydon Gibson
  • 1,179
  • 3
  • 11
  • 22
  • 1
    Removing the word `extern` should solve your problem. Why do you declare a function `extern` at the implementation? `extern` says the implementation is somewhere else. – mch Nov 25 '17 at 21:15
  • 1
    @mch : Good point, but that looks like an answer, not a comment. You should post an answer. – Clifford Nov 25 '17 at 21:17
  • 4
    Possible duplicate of [Effects of the extern keyword on C functions](https://stackoverflow.com/questions/856636/effects-of-the-extern-keyword-on-c-functions) – mch Nov 25 '17 at 21:18
  • That doesn't quite solve the problem. Now the error points me to the `return_address.c` file where it is defined, saying it is already defined in the header. If I remove the `{return NULL;}` in the .h, I get a ton of errors, still preceded by the redefinition one – Brydon Gibson Nov 25 '17 at 21:20
  • 1
    Function prototype `void *return_address(unsigned int);` should be in the header and function definition `void *return_address(unsigned int){return NULL;}` in the .c file. – mch Nov 25 '17 at 21:25
  • I've edited the question with more information. I still don't quite understand how what happened happened, but it's at least solved. – Brydon Gibson Nov 25 '17 at 21:26
  • If you have the function defined as `inline` in the header, that's it. You should then not *also* have it defined somewhere else, like in a .c file. You could use the `#if defined(blah_blah_blah)` in the .c file as well to conditionally defined it there, when *not* defined in the header. – Bo Persson Nov 26 '17 at 00:22
  • Is it a typo that the two paths to the file are slightly different? One is in /home/brydon and the other in /home/name – harmic Nov 26 '17 at 01:49
  • Yes that is a typo – Brydon Gibson Nov 26 '17 at 01:50

0 Answers0