I have turned on the ld option --fatal-warning in the linux kernel. How can I generate a simple linker warning to test this feature?
Asked
Active
Viewed 725 times
0
-
1can you be more specific on what you are doing ? what problem you are facing ? – Pradheep Apr 12 '13 at 17:30
2 Answers
1
#include<stdio.h>
int main()
{
printf("Run !!");
static const char warning[] __attribute__((section(".gnu.warning.printf")))="My sweet linker warning";
return 0;
}
Save this as test.c
If you build this using:
gcc -Wl,--fatal-warnings test.c -o my_exe
You should receive your linker warning and it would not prepare "my_exe"
Now try:
gcc -Wl,--no-fatal-warnings test.c -o my_exe
In this case, warning will be reported as it is but it wont be treated as error and it will prepare "my_exe" for you.
I am not sure what exactly you meant by "turned on", but if you are seeing above behavior then I guess you are good.
If you are doing something with kernel source then you will need to replace printf with any function name you already have in source( also change .gnu.warning section name )

Icarus3
- 2,310
- 14
- 22
-
While your code won't work exactly (he is building a kernel), it has some merit given the limited information we have so far. – artless noise Apr 12 '13 at 23:07
-
Thank you all for your suggestions. I went through the makefile, and found some linker flags that were suppressing warnings. I just removed them to generate ld warnings. – Tulip Jul 29 '13 at 21:55
0
Thank you all for your suggestions. I went through the makefile, and found some linker flags that were suppressing warnings. I just removed them to generate ld warnings.

Tulip
- 183
- 2
- 8
-
If this is going to be an answer you should update it with more details. – Keith Thompson Feb 24 '15 at 19:58