문제

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?

도움이 되었습니까?

해결책

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

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top