public inbox for llvm@lists.linux.dev
 help / color / mirror / Atom feed
From: Masahiro Yamada <masahiroy@kernel.org>
To: linux-kbuild@vger.kernel.org
Cc: linux-kernel@vger.kernel.org,
	Peter Zijlstra <peterz@infradead.org>,
	Josh Poimboeuf <jpoimboe@redhat.com>,
	llvm@lists.linux.dev, Helge Deller <deller@gmx.de>,
	linux-parisc@vger.kernel.org,
	Masahiro Yamada <masahiroy@kernel.org>,
	"James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>
Subject: [PATCH v7 3/8] parisc: fix the exit status of arch/parisc/nm
Date: Fri, 27 May 2022 19:01:50 +0900	[thread overview]
Message-ID: <20220527100155.1996314-4-masahiroy@kernel.org> (raw)
In-Reply-To: <20220527100155.1996314-1-masahiroy@kernel.org>

parisc overrides 'nm' with a shell script. I do not know the reason,
but anyway it is how it has worked since 2003. [1]

A problem is that this script returns the exit code of grep instead of
${CROSS_COMPILE}nm.

grep(1) says:
    Normally the exit status is 0 if a line is selected, 1 if no lines
    were selected, and 2 if an error occurred. However, if the -q or
    --quiet or --silent is used and a line is selected, the exit status
    is 0 even if an error occurred.

When the given object has no symbol, grep returns 1, while the true nm
returns 0. Hence, build rules using ${NM} fail on ARCH=parisc even if
the given object is valid.

This commit corrects the exit status of the script.

 - A pipeline returns the exit status of the last command (here, grep).
   The exit status of ${CROSS_COMPILE}nm is just ignored. Use bash's
   pipefail flag to catch errors of ${CROSS_COMPILE}nm.

 - If grep returns 1, this script should return 0 in order to mimic
   true nm. If grep returns 2, it is a real and fatal error. Return
   it as is.

[1]: https://git.kernel.org/pub/scm/linux/kernel/git/history/history.git/commit/?id=36eaa6e4c0e0b6950136b956b72fd08155b92ca3

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

Changes in v7:
  - New patch

 arch/parisc/Makefile |  2 +-
 arch/parisc/nm       | 12 ++++++++++--
 2 files changed, 11 insertions(+), 3 deletions(-)
 mode change 100644 => 100755 arch/parisc/nm

diff --git a/arch/parisc/Makefile b/arch/parisc/Makefile
index aca1710fd658..e7139955367d 100644
--- a/arch/parisc/Makefile
+++ b/arch/parisc/Makefile
@@ -18,7 +18,7 @@
 boot := arch/parisc/boot
 KBUILD_IMAGE := $(boot)/bzImage
 
-NM		= sh $(srctree)/arch/parisc/nm
+NM		= $(srctree)/arch/parisc/nm
 CHECKFLAGS	+= -D__hppa__=1
 
 ifdef CONFIG_64BIT
diff --git a/arch/parisc/nm b/arch/parisc/nm
old mode 100644
new mode 100755
index c788308de33f..3e72238a91f3
--- a/arch/parisc/nm
+++ b/arch/parisc/nm
@@ -1,6 +1,14 @@
-#!/bin/sh
+#!/bin/bash
 ##
 # Hack to have an nm which removes the local symbols.  We also rely
 # on this nm being hidden out of the ordinarily executable path
 ##
-${CROSS_COMPILE}nm $* | grep -v '.LC*[0-9]*$'
+
+# use pipefail to catch error of ${CROSS_COMPILE}nm
+set -o pipefail
+
+# grep exits with 1 if no lines were selected.
+# If the given object has no symbol, grep returns 1, but it is not an error.
+
+${CROSS_COMPILE}nm "$@" |
+{ grep -v '.LC*[0-9]*$' || { exit_code=$?; test $exit_code -eq 1 || exit $exit_code; } }
-- 
2.32.0


  parent reply	other threads:[~2022-05-27 10:09 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-27 10:01 [PATCH v7 0/8] kbuild: yet another series of cleanups Masahiro Yamada
2022-05-27 10:01 ` [PATCH v7 1/8] kbuild: replace $(linked-object) with CONFIG options Masahiro Yamada
2022-05-27 15:00   ` Josh Poimboeuf
2022-05-27 17:32   ` Nick Desaulniers
2022-05-28  2:32   ` Sedat Dilek
2022-05-28  7:10     ` Masahiro Yamada
2022-05-27 10:01 ` [PATCH v7 2/8] kbuild: do not create *.prelink.o for Clang LTO or IBT Masahiro Yamada
2022-05-27 15:31   ` Josh Poimboeuf
2022-05-27 10:01 ` Masahiro Yamada [this message]
2022-05-27 13:57   ` [PATCH v7 3/8] parisc: fix the exit status of arch/parisc/nm Helge Deller
2022-05-27 14:21     ` Masahiro Yamada
2022-05-27 10:01 ` [PATCH v7 4/8] kbuild: check static EXPORT_SYMBOL* by script instead of modpost Masahiro Yamada
2022-05-27 10:01 ` [PATCH v7 5/8] kbuild: make built-in.a rule robust against too long argument error Masahiro Yamada
2022-05-27 10:01 ` [PATCH v7 6/8] kbuild: make *.mod " Masahiro Yamada
2022-05-27 10:01 ` [PATCH v7 7/8] kbuild: add cmd_and_savecmd macro Masahiro Yamada
2022-05-27 10:01 ` [PATCH v7 8/8] kbuild: rebuild multi-object modules when objtool is updated Masahiro Yamada
2022-05-27 15:50   ` Josh Poimboeuf
2022-05-27 17:41     ` Masahiro Yamada

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220527100155.1996314-4-masahiroy@kernel.org \
    --to=masahiroy@kernel.org \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=deller@gmx.de \
    --cc=jpoimboe@redhat.com \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-parisc@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox