Arm Linux Kernel Hacks

rousalome.egloos.com

포토로그 Kernel Crash


통계 위젯 (화이트)

693
557
422265


[리눅스커널] '-Werror' 옵션 제거: WARNING 메시지 Error 제외 Kernel_Contribution_Tips

최근 커널 코드를 빌드하면 다음과 같이 WARNING이 떠도 에러로 처리합니다.

linux-next/drivers/firmware/arm_ffa/driver.c:180:6: error: unused variable ‘compat_version’ [-Werror=unused-variable]
  u32 compat_version;
      ^
  AR      init/built-in.a
  CC      drivers/crypto/cavium/zip/zip_device.o
cc1: all warnings being treated as errors

그 이유는 다음 커밋이 유입됐기 때문입니다.

Author: Linus Torvalds 
Date:   Sun Sep 5 11:24:05 2021 -0700

    Enable '-Werror' by default for all kernel builds

    ... but make it a config option so that broken environments can disable
    it when required.

    We really should always have a clean build, and will disable specific
    over-eager warnings as required, if we can't fix them.  But while I
    fairly religiously enforce that in my own tree, it doesn't get enforced
    by various build robots that don't necessarily report warnings.

    So this just makes '-Werror' a default compiler flag, but allows people
    to disable it for their configuration if they have some particular
    issues.

    Occasionally, new compiler versions end up enabling new warnings, and it
    can take a while before we have them fixed (or the warnings disabled if
    that is what it takes), so the config option allows for that situation.

    Hopefully this will mean that I get fewer pull requests that have new
    warnings that were not noticed by various automation we have in place.

    Knock wood.
diff --git a/Makefile b/Makefile
index 6bc1c5b..d45fc2e 100644
--- a/Makefile
+++ b/Makefile
@@ -785,6 +785,9 @@ stackp-flags-$(CONFIG_STACKPROTECTOR_STRONG)      := -fstack-protector-strong

 KBUILD_CFLAGS += $(stackp-flags-y)

+KBUILD_CFLAGS-$(CONFIG_WERROR) += -Werror
+KBUILD_CFLAGS += $(KBUILD_CFLAGS-y)
+
 ifdef CONFIG_CC_IS_CLANG
 KBUILD_CPPFLAGS += -Qunused-arguments
 # The kernel builds with '-std=gnu89' so use of GNU extensions is acceptable.
diff --git a/init/Kconfig b/init/Kconfig
index e708180..8cb97f1 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -137,6 +137,20 @@ config COMPILE_TEST
          here. If you are a user/distributor, say N here to exclude useless
          drivers to be distributed.

+config WERROR
+       bool "Compile the kernel with warnings as errors"
+       default y
+       help
+         A kernel build should not cause any compiler warnings, and this
+         enables the '-Werror' flag to enforce that rule by default.
+
+         However, if you have a new (or very old) compiler with odd and
+         unusual warnings, or you have some architecture with problems,
+         you may need to disable this config option in order to
+         successfully build the kernel.
+
+         If in doubt, say Y.
+
 config UAPI_HEADER_TEST
        bool "Compile test UAPI headers"
        depends on HEADERS_INSTALL && CC_CAN_LINK

<출처> 
https://lkml.org/lkml/2021/9/6/452

다음과 같은 패치를 적용하면 WARNING이 발생해도 Error 메시지를 출력하지 않습니다.

diff --git a/Makefile b/Makefile
index c1e954c..f2f69ca 100644
--- a/Makefile
+++ b/Makefile
@@ -858,9 +858,6 @@ stackp-flags-$(CONFIG_STACKPROTECTOR_STRONG)      := -fstack-protector-strong

 KBUILD_CFLAGS += $(stackp-flags-y)

-KBUILD_CFLAGS-$(CONFIG_WERROR) += -Werror
-KBUILD_CFLAGS += $(KBUILD_CFLAGS-y)
-
 KBUILD_RUSTFLAGS-$(CONFIG_WERROR) += -Dwarnings
 KBUILD_RUSTFLAGS += $(KBUILD_RUSTFLAGS-y)


덧글

댓글 입력 영역