Question

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?

Was it helpful?

Solution

#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 )

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top