From patchwork Sun Dec 3 09:49:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13477222 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 126A028F5 for ; Sun, 3 Dec 2023 09:49:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="MdCQBWpJ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 19F62C433C9; Sun, 3 Dec 2023 09:49:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701596995; bh=DQgligyVko6JOkpsukWsLHEde1ox5xe3QB7/zY+o3mc=; h=From:To:Cc:Subject:Date:From; b=MdCQBWpJATcuy0G8YGsVOOdYN6tVbI+HTba5TIrjOmIdUpI/IfuDMiUCCkk7sxNOq f3f/l9bHGyWii4wNCS7cbYACpBT403QtK+zJ5DgB2ui3BjGnMUuALVc3pH6EgBV+ZI bQoRQ43aqM5VVIqg4x2SgfId0j9Na0Kpei38vJLAFyQZjbZpa6FY388+nCMt+T9mz2 WCCxyX4ceHbHSwI6nMxJRsjNCwtJZZe417YofNj8Ew+3LU0mvm/YcM1BqlurDizojU D/xH2D1K9j8HnYPQ3I/ptSgdJbp5bvb3/ejDqp5Cz9+Qw3776utGljLpRllPyvimkF cOzThHeNnVlxg== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Masahiro Yamada , Nathan Chancellor , Andi Kleen , Nick Desaulniers , Nicolas Schier , Sam Ravnborg , linux-kernel@vger.kernel.org Subject: [PATCH v2 1/4] modpost: move __attribute__((format(printf, 2, 3))) to modpost.h Date: Sun, 3 Dec 2023 18:49:31 +0900 Message-Id: <20231203094934.1908270-1-masahiroy@kernel.org> X-Mailer: git-send-email 2.40.1 Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This attribute must be added to the function declaration in a header for comprehensive checking of all the callsites. Fixes: 6d9a89ea4b06 ("kbuild: declare the modpost error functions as printf like") Signed-off-by: Masahiro Yamada Reviewed-by: Nathan Chancellor --- (no changes since v1) scripts/mod/modpost.c | 3 +-- scripts/mod/modpost.h | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index cb6406f485a9..ca0a90158f85 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -60,8 +60,7 @@ static unsigned int nr_unresolved; #define MODULE_NAME_LEN (64 - sizeof(Elf_Addr)) -void __attribute__((format(printf, 2, 3))) -modpost_log(enum loglevel loglevel, const char *fmt, ...) +void modpost_log(enum loglevel loglevel, const char *fmt, ...) { va_list arglist; diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h index 69baf014da4f..9fe974dc1a52 100644 --- a/scripts/mod/modpost.h +++ b/scripts/mod/modpost.h @@ -197,7 +197,8 @@ enum loglevel { LOG_FATAL }; -void modpost_log(enum loglevel loglevel, const char *fmt, ...); +void __attribute__((format(printf, 2, 3))) +modpost_log(enum loglevel loglevel, const char *fmt, ...); /* * warn - show the given message, then let modpost continue running, still From patchwork Sun Dec 3 09:49:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13477223 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 79C3828F5 for ; Sun, 3 Dec 2023 09:49:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="krGY099a" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D41B7C433CC; Sun, 3 Dec 2023 09:49:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701596996; bh=rmsWponTX5RKX19qzp5R0zCYaOiow+z0DQeDMbnv4hs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=krGY099aw4XVTLnHqechM+QYTTiVpi77Y5Sg9sl2m20KUWYFikFGob/yeUNdPDMvv mgL2T/dyKctjBYe85UnYisBy0M2w6RF8eyks00H1v2cEq/PNLT2vbw4Mj2fKyWo8N/ JwwI/sZKc1f1xcAziikHBfx/kdu/y1JwYg4bi5F4gj+/3oRg8/alQrKu+nAZeHVaF2 PWnaplfhFxxhvlxy9pk0fAS+zw1DaDb0noGL+ok4nxxUhYPT+K9cpVzhxLcW9SX+h5 KsDXXZiroAkKy0hAhm3AZiQiFiUDB1nqv+UAPqgtImF0L2OdDi9TqeSSTXZMlM2nTW JNVr0n4xoXzPg== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Masahiro Yamada , Nathan Chancellor , Nick Desaulniers , Nicolas Schier , linux-kernel@vger.kernel.org Subject: [PATCH v2 2/4] modpost: inform compilers that fatal() never returns Date: Sun, 3 Dec 2023 18:49:32 +0900 Message-Id: <20231203094934.1908270-2-masahiroy@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231203094934.1908270-1-masahiroy@kernel.org> References: <20231203094934.1908270-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The function fatal() never returns because modpost_log() calls exit(1) when LOG_FATAL is passed. Inform compilers of this fact so that unreachable code flow can be identified at compile time. Signed-off-by: Masahiro Yamada Reviewed-by: Nathan Chancellor --- Changes in v2: - Use noreturn attribute together with alias scripts/mod/modpost.c | 3 +++ scripts/mod/modpost.h | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index ca0a90158f85..c13bc9095df3 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -90,6 +90,9 @@ void modpost_log(enum loglevel loglevel, const char *fmt, ...) error_occurred = true; } +void __attribute__((alias("modpost_log"))) +modpost_log_noret(enum loglevel loglevel, const char *fmt, ...); + static inline bool strends(const char *str, const char *postfix) { if (strlen(str) < strlen(postfix)) diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h index 9fe974dc1a52..835cababf1b0 100644 --- a/scripts/mod/modpost.h +++ b/scripts/mod/modpost.h @@ -200,6 +200,9 @@ enum loglevel { void __attribute__((format(printf, 2, 3))) modpost_log(enum loglevel loglevel, const char *fmt, ...); +void __attribute__((format(printf, 2, 3), noreturn)) +modpost_log_noret(enum loglevel loglevel, const char *fmt, ...); + /* * warn - show the given message, then let modpost continue running, still * allowing modpost to exit successfully. This should be used when @@ -215,4 +218,4 @@ modpost_log(enum loglevel loglevel, const char *fmt, ...); */ #define warn(fmt, args...) modpost_log(LOG_WARN, fmt, ##args) #define error(fmt, args...) modpost_log(LOG_ERROR, fmt, ##args) -#define fatal(fmt, args...) modpost_log(LOG_FATAL, fmt, ##args) +#define fatal(fmt, args...) modpost_log_noret(LOG_FATAL, fmt, ##args) From patchwork Sun Dec 3 09:49:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13477224 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C6CA228F5; Sun, 3 Dec 2023 09:49:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="cGbXL9/Y" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4D96FC433CA; Sun, 3 Dec 2023 09:49:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701596998; bh=2DvonXnTe7s/F9D7y3v/KBQpYELTPDsU5vhrOaqP0pU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cGbXL9/YNvdZ3anDtwiwLsyBey9CwF9Zt9CsaYDGb8EKVE3wrJB/WhDBRGjY1Uxxs Tn5B7LbKOvQkSogqXHVf/+u/ag2wpVX9EBYkBYcIh7SKaoAnySjiJN+YOVd2U9Ps58 YJRWdgzIaWA7WEVAG0xWQoEMLHmFMTVPLWjouvzxYsFX3xOctviP0fdgEJUnbfFDpM al/hCwPCuju0DP+lZOFjGzUYR65MIAj8fHRrC2gQFSlr8wdvyZnYJ8y6l0KsQ25mvc OOm9BamZlQDMJIerOt4X3z45JEQeKLjd51OACKQb610rvMHLUrXHD8l64l3XLp/7DG X54qRPJZ1vv+Q== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Masahiro Yamada , Nathan Chancellor , Nick Desaulniers , Nicolas Schier , Tom Rix , linux-kernel@vger.kernel.org, llvm@lists.linux.dev Subject: [PATCH v2 3/4] modpost: remove unneeded initializer in section_rel() Date: Sun, 3 Dec 2023 18:49:33 +0900 Message-Id: <20231203094934.1908270-3-masahiroy@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231203094934.1908270-1-masahiroy@kernel.org> References: <20231203094934.1908270-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This initializer was added to avoid -Wmaybe-uninitialized (gcc) or -Wsometimes-uninitialized (clang) warning. Now that compilers recognize fatal() never returns, it is unneeded. Signed-off-by: Masahiro Yamada --- Changes in v2: - Split into a separate patch scripts/mod/modpost.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index c13bc9095df3..3233946fa5f6 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -1421,7 +1421,7 @@ static void section_rel(struct module *mod, struct elf_info *elf, for (rel = start; rel < stop; rel++) { Elf_Sym *tsym; - Elf_Addr taddr = 0, r_offset; + Elf_Addr taddr, r_offset; unsigned int r_type, r_sym; void *loc; From patchwork Sun Dec 3 09:49:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13477225 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C0E8528F5; Sun, 3 Dec 2023 09:50:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="VNv2/I0y" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 099D3C433CB; Sun, 3 Dec 2023 09:49:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701597000; bh=3fREL+3pDb0+f3gpXJDWy/Z+fjSVV4sYVi1Ga8WtaHw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VNv2/I0y1QaQgNoItB2fCs1RK2AgJtD5NdVHjX92RWhrLjqitS+cRVeZ2kXIsGx8o QER7zjLtrPvCDVpDGyc3FQjR1VGYW3GSPNVdnBPNTd/weX/xjWmn3qQ+K1pop+vvcg GFEsnbwuHQbnxVpzlV+Nq196TtY3G02V8Ierf2Za1v9CKfTZdcZyFKZPK5izOAbYYl ZOpkXYUBx5i1XQIVUb6TT7YK1VqGX0xTOhvmbj9cb/vYAtzzh/DiO1FD7tn+eXX70Q AtM5DljHuHWcL9uKAyXzFm49NNpivgg0zf9/3DC1s2cXsmpzfMak3IwicdamK9Zc7m G3A13S5DzjkPg== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Masahiro Yamada , Nathan Chancellor , Nick Desaulniers , Nicolas Schier , Tom Rix , linux-kernel@vger.kernel.org, llvm@lists.linux.dev Subject: [PATCH v2 4/4] modpost: remove unreachable code after fatal() Date: Sun, 3 Dec 2023 18:49:34 +0900 Message-Id: <20231203094934.1908270-4-masahiroy@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231203094934.1908270-1-masahiroy@kernel.org> References: <20231203094934.1908270-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Now compilers can recognize fatal() never returns. While GCC 4.5 dropped support for -Wunreachable-code, Clang is capable of detecting the unreachable code. $ make HOSTCC=clang HOSTCFLAGS=-Wunreachable-code-return [snip] HOSTCC scripts/mod/modpost.o scripts/mod/modpost.c:520:11: warning: 'return' will never be executed [-Wunreachable-code-return] return 0; ^ scripts/mod/modpost.c:477:10: warning: 'return' will never be executed [-Wunreachable-code-return] return 0; ^ 2 warnings generated. Signed-off-by: Masahiro Yamada Reviewed-by: Nathan Chancellor --- Changes in v2: - Change the patch order - Update the commit description and add warning example. scripts/mod/modpost.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 3233946fa5f6..e2bc180cecc8 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -476,11 +476,9 @@ static int parse_elf(struct elf_info *info, const char *filename) fatal("%s: not relocatable object.", filename); /* Check if file offset is correct */ - if (hdr->e_shoff > info->size) { + if (hdr->e_shoff > info->size) fatal("section header offset=%lu in file '%s' is bigger than filesize=%zu\n", (unsigned long)hdr->e_shoff, filename, info->size); - return 0; - } if (hdr->e_shnum == SHN_UNDEF) { /* @@ -518,12 +516,11 @@ static int parse_elf(struct elf_info *info, const char *filename) const char *secname; int nobits = sechdrs[i].sh_type == SHT_NOBITS; - if (!nobits && sechdrs[i].sh_offset > info->size) { + if (!nobits && sechdrs[i].sh_offset > info->size) fatal("%s is truncated. sechdrs[i].sh_offset=%lu > sizeof(*hrd)=%zu\n", filename, (unsigned long)sechdrs[i].sh_offset, sizeof(*hdr)); - return 0; - } + secname = secstrings + sechdrs[i].sh_name; if (strcmp(secname, ".modinfo") == 0) { if (nobits)