All of lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH 0/1] Build issue related to "command -v"
@ 2021-09-28 19:55 Markus Mayer via buildroot
  2021-09-28 19:55 ` [Buildroot] [PATCH 1/1] Makefile: set HOST*_NOCCACHE variables only if unset Markus Mayer via buildroot
                   ` (2 more replies)
  0 siblings, 3 replies; 15+ messages in thread
From: Markus Mayer via buildroot @ 2021-09-28 19:55 UTC (permalink / raw)
  To: Arnout Vandecappelle, Petr Vorel; +Cc: Markus Mayer, Buildroot Mailing List

Hi all,

After commit ca6a2907c27c[1], our automated nightly builds started
experiencing build failures. It took a little while to track down what
was happening. I think I understand now what is going on.

This is a bit of a lengthy email as it was a bit of a lengthy
investigation, and I want to relay my findings and some concerns.

The Build Error
===============

The error manifests itself like this:

>>>   Buildroot 2021.08-950-ga9072df Collecting legal info
COPYING: OK (sha256: 9755181e27175cb3510b4da8629caa406fb355a19aa8e7d55f06bf8ab33323c4)
>>> toolchain-external  Executing pre-build script board/brcmstb/pre-build.sh

You must install 'gcc' on your build machine
support/dependencies/dependencies.mk:27: recipe for target 'dependencies' failed
make[3]: *** [dependencies] Error 1
Makefile:25: recipe for target '_all' failed

As you can see, this is happening for us at the "make legal-info" stage.
The error message is clearly bogus in this context. It just finished
successfully building everything without issue. Yet, when it comes to a
task that doesn't even require a compiler, it suddenly thinks host GCC
is missing and aborts.

One thing of note is that our post-build script calls "make legal-info",
and that is when the problem happens. The purpose of doing it like this
is to include the result of "make legal-info" in the image. As we will
see below, calling make from the post-build script is one crucial piece
to triggering this problem. The otheres are using ccache and the recent
switch to "command -v" from "which".

The Issue
=========

Patch ca6a2907c27c only sort-of introduced a new problem. Mostly, it
exposed a pre-existing issue. The problem existed all along, but was
hidden by "which" and the shell. With "which" being replaced by "command
-v", the issue became visible. But only under certain circumstances, and
that worries me a bit. More on that later.

The original problem is that the top-level Makefile unconditionally
defines HOSTCC_NOCCACHE and HOSTCXX_NOCCACHE. This is fine 99.9% of the
time. However, if one is
   - using ccache
   - invoking make with HOSTCC/HOSTCXX already set
one ends up *with* ccache in the *_NOCCACHE variables (i.e. the exact
opposite of what should be happening)! Going forward, I'll just mention
HOSTCC_NOCCACHE, but the same applies to HOSTCXX_NOCCACHE.

How does it go astray? Because it unconditionally sets
   HOSTCC_NOCCACHE := $(HOSTCC)
HOSTCC_NOCCACHE can get overwritten in certain situations. In the
initial call to "make", all well. HOSTCC is /usr/bin/gcc, and later it
redefines
   HOSTCC = $(CCACHE) $(HOSTCC_NOCCACHE)
Now, HOSTCC references ccache and HOSTCC_NOCCACHE does not. Just as
intended.

However, when make is invoked a second time with HOSTCC already
defined to call ccache, it'll still assign
   HOSTCC_NOCCACHE := $(HOSTCC)
which now redefines HOSTCC_NOCCACHE to *INCLUDE* ccache (since HOSTCC
does, from earlier)!

How would one end up calling "make" again with HOSTCC already set to
ccache? Easy. One sets up a post-build script that calls "make
legal-info". Since the first instance of "make" is still running (it is
calling the post-build script after all), HOSTCC will already be
pointing to ccache, and it'll set HOSTCC_NOCCACHE to equal HOSTCC.
And now we have an issue. Albeit one we didn't see until patch
ca6a2907c27c. I'll explain why below.

To resolve the issue, my proposal is to set HOST*_NOCCACHE
conditionally:

ifndef HOSTCC_NOCCACHE
HOSTCC_NOCCACHE := $(HOSTCC)
endif
...
ifndef HOSTCXX_NOCCACHE
HOSTCXX_NOCCACHE := $(HOSTCXX)
endif

Doing this does indeed solve the problem, and it does seem like the
right thing to do.

Why did this work before?
=========================

There is a difference between "which" and "command -v" and how they
handle multiple arguments being passed to them. But it gets worse. There
is also a difference between "command -v" in different shells!

I am talking about dash here, Debian's and Ubuntu's /bin/sh
implementation, which is what support/dependencies/dependencies.sh will
be using on those systems.

As explained above, we end up with HOSTCC_NOCCACHE pointing to ccache,
like so:

$ echo $HOSTCC_NOCCACHE
/local/users/mmayer/buildroot/output/arm64/host/bin/ccache /usr/bin/gcc

Here is where it gets interesting. "which" will return two lines, one
for each of the commands:

$ which $HOSTCC_NOCCACHE
/local/users/mmayer/buildroot/output/arm64/host/bin/ccache
/usr/bin/gcc

This ultimately, ends up working -- by pure chance. It's a lucky
combination of "which" and the shell behaving in just the right way.

$ `which $HOSTCC_NOCCACHE` -v 2>&1 | grep 'gcc version'
gcc version 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04) 

And that's why this issue has never before shown up. The combination
between "which" returning two lines and the shell ignoring the first and
only dealing with the second, made things work.

However, dash's "command -v" will ignore the second argument:

$ command -v $HOSTCC_NOCCACHE 
/local/users/mmayer/buildroot/output/arm64/host/bin/ccache

And there's our problem. dependencies.sh now learns that $COMPILER is
apparently ccache. It runs "ccache -v", can't find "gcc" in ccache's
output and aborts the build concluding that gcc must not be installed.

$ `command -v $HOSTCC_NOCCACHE` -v
.../output/arm64/host/bin/ccache: invalid option -- 'v'
Usage:
    ccache [options]
    ccache compiler [compiler options]
    compiler [compiler options]          (via symbolic link)
[...]

Please note that "command -v" in bash does *NOT* do this! Bash's
"command -v" seems to behave just like "which" used to. Yikes!

bash$ command -v $HOSTCC_NOCCACHE
/local/users/mmayer/buildroot/output/arm64/host/bin/ccache
/usr/bin/gcc

bash$ `command -v $HOSTCC_NOCCACHE` -v 2>&1 | grep 'gcc version'
gcc version 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04) 

I can't stress this enough. "command -v" behaves differently for bash
and dash! This does not give me the warm and fuzzies.

The Use of "command -v"
=======================

The command "command -v" may be mandated by POSIX, but it is clearly
implemented differently across different shells. Even shells that are
generally considered to be fairly compatible (bash and dash) do vastly
different things.

As such, relying on "command -v" seems a little risky in that it opens
up the possibility for strange build errors that others cannot reproduce
and that nobody would ever think to investigate as being related to the
"command -v" implementation of a specific shell.

There is also the issue of some developers working with different
distributions. Somebody developing a feature on distro 1 might create
build problems for others using distro 2 and vice versa. Neither would
have a way of knowing ahead of time that there will be an issue.

I am wondering if it might be prudent to provide a host-which package,
such that Buildroot can build its own "which" command if the system
doesn't have one and stick to using "which" despite it being deprecated.
At least for the time being and until "command -v" can be explored and
evaluated a bit more.

"which" has been around for a long time, and it is a known entity. To me
personally, and after what I learned here, relying on "command -v" seems
to be a bit like opening a can of worms. Who knows what else will happen
some time down the road when nobody is even thinking about the "which"
-> "command -v" change anymore?

With all of that explained, I'll defer to you on the final call on the
matter of using or not using "command -v".

However, please accept my Makefile change irrespective of the "command
-v" situation.

Regards,
-Markus

[1] https://git.buildroot.net/buildroot/commit/?id=ca6a2907c27c

Markus Mayer (1):
  Makefile: set HOST*_NOCCACHE variables only if unset

 Makefile | 4 ++++
 1 file changed, 4 insertions(+)

-- 
2.25.1

_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Buildroot] [PATCH 1/1] Makefile: set HOST*_NOCCACHE variables only if unset
  2021-09-28 19:55 [Buildroot] [PATCH 0/1] Build issue related to "command -v" Markus Mayer via buildroot
@ 2021-09-28 19:55 ` Markus Mayer via buildroot
  2021-09-29 19:27   ` Petr Vorel
                     ` (2 more replies)
  2021-09-29  8:24 ` [Buildroot] [PATCH 0/1] Build issue related to "command -v" Nicolas Cavallari
  2021-09-29 19:59 ` Arnout Vandecappelle
  2 siblings, 3 replies; 15+ messages in thread
From: Markus Mayer via buildroot @ 2021-09-28 19:55 UTC (permalink / raw)
  To: Arnout Vandecappelle, Petr Vorel; +Cc: Markus Mayer, Buildroot Mailing List

Set HOSTCC_NOCCACHE and HOSTCXX_NOCCACHE only if they are not set. This
allows recursive calls to "make" to work as intended in the presence of
ccache.

Without guarding these variables, a recursive invocation of make would
re-define
    HOSTCC_NOCCACHE := $(HOSTCC)
and
    HOSTCXX_NOCCACHE := $(HOSTCXX)
at a point in time when HOSTCC and HOSTCXX already point to ccache.

Signed-off-by: Markus Mayer <mmayer@broadcom.com>
---
 Makefile | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/Makefile b/Makefile
index d248bd76b2..71c0577030 100644
--- a/Makefile
+++ b/Makefile
@@ -286,12 +286,16 @@ ifndef HOSTCC
 HOSTCC := gcc
 HOSTCC := $(shell command -v $(HOSTCC) || type -p $(HOSTCC) || echo gcc)
 endif
+ifndef HOSTCC_NOCCACHE
 HOSTCC_NOCCACHE := $(HOSTCC)
+endif
 ifndef HOSTCXX
 HOSTCXX := g++
 HOSTCXX := $(shell command -v $(HOSTCXX) || type -p $(HOSTCXX) || echo g++)
 endif
+ifndef HOSTCXX_NOCCACHE
 HOSTCXX_NOCCACHE := $(HOSTCXX)
+endif
 ifndef HOSTCPP
 HOSTCPP := cpp
 endif
-- 
2.25.1

_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: [Buildroot] [PATCH 0/1] Build issue related to "command -v"
  2021-09-28 19:55 [Buildroot] [PATCH 0/1] Build issue related to "command -v" Markus Mayer via buildroot
  2021-09-28 19:55 ` [Buildroot] [PATCH 1/1] Makefile: set HOST*_NOCCACHE variables only if unset Markus Mayer via buildroot
@ 2021-09-29  8:24 ` Nicolas Cavallari
  2021-09-29 16:14   ` David Laight
  2021-09-29 19:59 ` Arnout Vandecappelle
  2 siblings, 1 reply; 15+ messages in thread
From: Nicolas Cavallari @ 2021-09-29  8:24 UTC (permalink / raw)
  To: Markus Mayer, Arnout Vandecappelle, Petr Vorel; +Cc: Buildroot Mailing List

On 28/09/2021 21:55, Markus Mayer via buildroot wrote:
> Please note that "command -v" in bash does*NOT*  do this! Bash's
> "command -v" seems to behave just like "which" used to. Yikes!
> 
> bash$ command -v $HOSTCC_NOCCACHE
> /local/users/mmayer/buildroot/output/arm64/host/bin/ccache
> /usr/bin/gcc
> 
> bash$ `command -v $HOSTCC_NOCCACHE` -v 2>&1 | grep 'gcc version'
> gcc version 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04)
> 
> I can't stress this enough. "command -v" behaves differently for bash
> and dash! This does not give me the warm and fuzzies.

POSIX 2008 is very clear on this: additional parameters to command -v 
must be ignored, so bash is non-conformant.

Additionally, the dependencies.sh script should probably quote the shell 
variables that it uses. This would have caught the problem much earlier.
Unless HOSTCC is allowed to contain multiple parameters, but i'm not 
sure if buildroot maintainers consider this to be allowed.

> As such, relying on "command -v" seems a little risky in that it opens
> up the possibility for strange build errors that others cannot reproduce
> and that nobody would ever think to investigate as being related to the
> "command -v" implementation of a specific shell.
 >
> There is also the issue of some developers working with different
> distributions. Somebody developing a feature on distro 1 might create
> build problems for others using distro 2 and vice versa. Neither would
> have a way of knowing ahead of time that there will be an issue.

This is why there are standards and why respecting them is important, 
otherwise it would be impossible to get anything done.

command -v is defined since 2008 and any shell that misbehave has a bug 
that need to be fixed. Of course there can be workaround here and here. 
For example, there are 'command -v CMD || type -p CMD' patterns in the 
main Makefile already.

Meanwhile, 'which' is not standard, and right now, it misbehaves on 
Debian by filling the screen with warnings.

> I am wondering if it might be prudent to provide a host-which package,
> such that Buildroot can build its own "which" command if the system
> doesn't have one and stick to using "which" despite it being deprecated.
> At least for the time being and until "command -v" can be explored and
> evaluated a bit more.

This is a chicken-and-egg problem. How do you compile host-which without 
being able to test if gcc or make are available ?
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Buildroot] [PATCH 0/1] Build issue related to "command -v"
  2021-09-29  8:24 ` [Buildroot] [PATCH 0/1] Build issue related to "command -v" Nicolas Cavallari
@ 2021-09-29 16:14   ` David Laight
  2021-09-29 17:30     ` Petr Vorel
  0 siblings, 1 reply; 15+ messages in thread
From: David Laight @ 2021-09-29 16:14 UTC (permalink / raw)
  To: 'Nicolas Cavallari',
	Markus Mayer, Arnout Vandecappelle, Petr Vorel
  Cc: Buildroot Mailing List

...
> Meanwhile, 'which' is not standard, and right now, it misbehaves on
> Debian by filling the screen with warnings.

'which' is a shell script that is trying to emulate a csh builtin.
I've NFI why people keep using it :-)

The equivalent bourne shell command is 'type'.

As for 'command -v' no idea what the POSIX committee had
for lunch that day :-)
It was probably they same day they added 'fc' (from ksh??)

	David


	

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)

_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Buildroot] [PATCH 0/1] Build issue related to "command -v"
  2021-09-29 16:14   ` David Laight
@ 2021-09-29 17:30     ` Petr Vorel
  0 siblings, 0 replies; 15+ messages in thread
From: Petr Vorel @ 2021-09-29 17:30 UTC (permalink / raw)
  To: David Laight; +Cc: Markus Mayer, Buildroot Mailing List

Hi all,

> ...
> > Meanwhile, 'which' is not standard, and right now, it misbehaves on
> > Debian by filling the screen with warnings.

> 'which' is a shell script that is trying to emulate a csh builtin.
> I've NFI why people keep using it :-)
FYI Yes, version from the Debian's debianutils package was a shell script, but
other distros had GNU which [2], which is C code.

> The equivalent bourne shell command is 'type'.
I also knew 'type' and was suspicious about 'command -v' support across
implemented shell, until I asked [3], because checkbashisms.pl [4] complains
about 'type' and it's ok with 'command -v'.

'type' is part of POSIX, but as part of the X/Open Systems Interfaces option
(XSI) [5] thus it might not be implemented on very small systems.
'command -v' is POSIX but not extension [6] thus it should be everywhere.

I tested 'command -v' is supported by commonly used shells (bash, dash, busybox
ash, zsh). Although so does 'type' thus I prefer to use 'command -v' instead of
'type' in shell scripts thus I can check them with checkbashisms.pl.

> As for 'command -v' no idea what the POSIX committee had
> for lunch that day :-)
> It was probably they same day they added 'fc' (from ksh??)
I cannot comment that, but if you read their definition [5] and [6] has slightly
different purpose.

Kind regards,
Petr

[1] https://salsa.debian.org/debian/debianutils/-/commit/3a8dd10b4502f7bae8fc6973c13ce23fc9da7efb
[2] https://ftp.gnu.org/gnu/which/which-2.21.tar.gz
[3] https://unix.stackexchange.com/a/667293
[4] https://salsa.debian.org/debian/devscripts/-/blob/master/scripts/checkbashisms.pl
[5] https://pubs.opengroup.org/onlinepubs/9699919799/utilities/type.html
[6] https://pubs.opengroup.org/onlinepubs/9699919799/utilities/command.html

> 	David
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Buildroot] [PATCH 1/1] Makefile: set HOST*_NOCCACHE variables only if unset
  2021-09-28 19:55 ` [Buildroot] [PATCH 1/1] Makefile: set HOST*_NOCCACHE variables only if unset Markus Mayer via buildroot
@ 2021-09-29 19:27   ` Petr Vorel
  2021-12-28 21:18   ` Thomas Petazzoni
  2021-12-29  9:12   ` Thomas Petazzoni
  2 siblings, 0 replies; 15+ messages in thread
From: Petr Vorel @ 2021-09-29 19:27 UTC (permalink / raw)
  To: Markus Mayer; +Cc: Buildroot Mailing List

Reviewed-by: Petr Vorel <petr.vorel@gmail.com>

Kind regards,
Petr
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Buildroot] [PATCH 0/1] Build issue related to "command -v"
  2021-09-28 19:55 [Buildroot] [PATCH 0/1] Build issue related to "command -v" Markus Mayer via buildroot
  2021-09-28 19:55 ` [Buildroot] [PATCH 1/1] Makefile: set HOST*_NOCCACHE variables only if unset Markus Mayer via buildroot
  2021-09-29  8:24 ` [Buildroot] [PATCH 0/1] Build issue related to "command -v" Nicolas Cavallari
@ 2021-09-29 19:59 ` Arnout Vandecappelle
  2021-09-29 20:11   ` Petr Vorel
  2 siblings, 1 reply; 15+ messages in thread
From: Arnout Vandecappelle @ 2021-09-29 19:59 UTC (permalink / raw)
  To: Markus Mayer, Petr Vorel
  Cc: David Laight, Yann E. MORIN, Buildroot Mailing List

  Hi Markus,

  Thank you for this extensive investigation!

On 28/09/2021 21:55, Markus Mayer wrote:
> Hi all,
> 
> After commit ca6a2907c27c[1], our automated nightly builds started
> experiencing build failures. It took a little while to track down what
> was happening. I think I understand now what is going on.
> 
> This is a bit of a lengthy email as it was a bit of a lengthy
> investigation, and I want to relay my findings and some concerns.

[snip]

> One thing of note is that our post-build script calls "make legal-info",
> and that is when the problem happens. The purpose of doing it like this
> is to include the result of "make legal-info" in the image.

  Calling into Buildroot's Makefile recursively from within a post-build script 
(or a package or whatever) is not something that is supported, in the sense that 
it's not something that anybody ever tests. The use case definitely makes sense 
though. I even heard of people starting the build of a different configuration 
in a post-build script (e.g. for an initramfs).

  So maybe we should add a test in support/testing that validates this scenario.


> However, when make is invoked a second time with HOSTCC already
> defined to call ccache, it'll still assign
>     HOSTCC_NOCCACHE := $(HOSTCC)
> which now redefines HOSTCC_NOCCACHE to *INCLUDE* ccache (since HOSTCC
> does, from earlier)!

  This is clearly wrong. Your patch helps, but we still have a similar situation 
with HOSTCC which will be .../ccache .../ccache /usr/bin/gcc in the recursive 
invocation (i.e. with two times ccache). Although maybe that's not really an 
issue - "ccache ccache gcc -v" at least gives the expected results.

  I'm thinking that maybe we should detect recursive invocation in the top-level 
Makefile and behave differently. For example, everything that is exported 
doesn't need to be exported again, and stuff like that. Or at least we could 
protect the entire HOSTCC etc. block against recursive override.

  Also, the entire handling of HOSTCC is a bit flaky. It is still from 
prehistoric commit 8027784 with no clear requirements (e.g. is HOSTCC allowed to 
be a command with arguments? Is it allowed to be a relative path?). It has been 
documented after-the-fact in docs/manual/common-usage.txt, but I wonder if we 
really still need it? I guess it's a way for people to use a host compiler that 
is more recent that the distro-provided one, but it could just as well be added 
to $PATH and be done with it...

[snip]

> Here is where it gets interesting. "which" will return two lines, one
> for each of the commands:
> 
> $ which $HOSTCC_NOCCACHE
> /local/users/mmayer/buildroot/output/arm64/host/bin/ccache
> /usr/bin/gcc

  As mentioned by Nicolas, we really should quote the argument to "command -v", 
or apply $(firstword ...) to avoid this issue. Indepedent of which or command -v.

[snip]

> As such, relying on "command -v" seems a little risky in that it opens
> up the possibility for strange build errors that others cannot reproduce
> and that nobody would ever think to investigate as being related to the
> "command -v" implementation of a specific shell.

  It is solving an actual problem (i.e. that "which" is deprecated in some 
distros), so the best we can do is make the change early enough before a release 
so people can discover problems with it.


> There is also the issue of some developers working with different
> distributions. Somebody developing a feature on distro 1 might create
> build problems for others using distro 2 and vice versa. Neither would
> have a way of knowing ahead of time that there will be an issue.

  That issue exists regardless of "which" (which BTW has different 
implementations on different distros anyway, so it can also cause problems). We 
try to minimise the external dependencies of Buildroot, and removing "which" 
from the external dependencies is a good thing IMHO.


  Bottom line: I think we need to take four actions here.

1. Apply your patch.
2. Improve on it by detecting that the Buildroot overrides have already been 
exported and don't need to be exported again.
3. Verify all calls to "command -v" and make sure the argument is either quoted 
or uses $(firstword).
4. Consider the removal of HOSTCC and friends as user-settable variables.


  Regards,
  Arnout


> I am wondering if it might be prudent to provide a host-which package,
> such that Buildroot can build its own "which" command if the system
> doesn't have one and stick to using "which" despite it being deprecated.
> At least for the time being and until "command -v" can be explored and
> evaluated a bit more.
> 
> "which" has been around for a long time, and it is a known entity. To me
> personally, and after what I learned here, relying on "command -v" seems
> to be a bit like opening a can of worms. Who knows what else will happen
> some time down the road when nobody is even thinking about the "which"
> -> "command -v" change anymore?
> 
> With all of that explained, I'll defer to you on the final call on the
> matter of using or not using "command -v".
> 
> However, please accept my Makefile change irrespective of the "command
> -v" situation.
> 
> Regards,
> -Markus
> 
> [1] https://git.buildroot.net/buildroot/commit/?id=ca6a2907c27c
> 
> Markus Mayer (1):
>    Makefile: set HOST*_NOCCACHE variables only if unset
> 
>   Makefile | 4 ++++
>   1 file changed, 4 insertions(+)
> 
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Buildroot] [PATCH 0/1] Build issue related to "command -v"
  2021-09-29 19:59 ` Arnout Vandecappelle
@ 2021-09-29 20:11   ` Petr Vorel
  2021-10-01 17:53     ` Markus Mayer via buildroot
  0 siblings, 1 reply; 15+ messages in thread
From: Petr Vorel @ 2021-09-29 20:11 UTC (permalink / raw)
  To: Arnout Vandecappelle
  Cc: Yann E. MORIN, David Laight, Markus Mayer, Buildroot Mailing List

Hi Markus, Arnout, all,

>  Hi Markus,

>  Thank you for this extensive investigation!

> On 28/09/2021 21:55, Markus Mayer wrote:
> > Hi all,

> > After commit ca6a2907c27c[1], our automated nightly builds started
> > experiencing build failures. It took a little while to track down what
> > was happening. I think I understand now what is going on.

> > This is a bit of a lengthy email as it was a bit of a lengthy
> > investigation, and I want to relay my findings and some concerns.

> [snip]

> > One thing of note is that our post-build script calls "make legal-info",
> > and that is when the problem happens. The purpose of doing it like this
> > is to include the result of "make legal-info" in the image.

>  Calling into Buildroot's Makefile recursively from within a post-build
> script (or a package or whatever) is not something that is supported, in the
> sense that it's not something that anybody ever tests. The use case
> definitely makes sense though. I even heard of people starting the build of
> a different configuration in a post-build script (e.g. for an initramfs).

>  So maybe we should add a test in support/testing that validates this scenario.
+1


> > However, when make is invoked a second time with HOSTCC already
> > defined to call ccache, it'll still assign
> >     HOSTCC_NOCCACHE := $(HOSTCC)
> > which now redefines HOSTCC_NOCCACHE to *INCLUDE* ccache (since HOSTCC
> > does, from earlier)!

>  This is clearly wrong. Your patch helps, but we still have a similar
> situation with HOSTCC which will be .../ccache .../ccache /usr/bin/gcc in
> the recursive invocation (i.e. with two times ccache). Although maybe that's
> not really an issue - "ccache ccache gcc -v" at least gives the expected
> results.
Ah, sorry for not catching this.

>  I'm thinking that maybe we should detect recursive invocation in the
> top-level Makefile and behave differently. For example, everything that is
> exported doesn't need to be exported again, and stuff like that. Or at least
> we could protect the entire HOSTCC etc. block against recursive override.
+1

>  Also, the entire handling of HOSTCC is a bit flaky. It is still from
> prehistoric commit 8027784 with no clear requirements (e.g. is HOSTCC
> allowed to be a command with arguments? Is it allowed to be a relative
> path?). It has been documented after-the-fact in
> docs/manual/common-usage.txt, but I wonder if we really still need it? I
> guess it's a way for people to use a host compiler that is more recent that
> the distro-provided one, but it could just as well be added to $PATH and be
> done with it...

> [snip]

> > Here is where it gets interesting. "which" will return two lines, one
> > for each of the commands:

> > $ which $HOSTCC_NOCCACHE
> > /local/users/mmayer/buildroot/output/arm64/host/bin/ccache
> > /usr/bin/gcc

>  As mentioned by Nicolas, we really should quote the argument to "command
> -v", or apply $(firstword ...) to avoid this issue. Indepedent of which or
> command -v.
+1 
IMHO quoting would require fixing unwanted redefinition
HOSTCC_NOCCACHE, ($(firstword ...) would not but hide the issue, thus I'd prefer
fixing the redefinition.

> [snip]

> > As such, relying on "command -v" seems a little risky in that it opens
> > up the possibility for strange build errors that others cannot reproduce
> > and that nobody would ever think to investigate as being related to the
> > "command -v" implementation of a specific shell.

>  It is solving an actual problem (i.e. that "which" is deprecated in some
> distros), so the best we can do is make the change early enough before a
> release so people can discover problems with it.


> > There is also the issue of some developers working with different
> > distributions. Somebody developing a feature on distro 1 might create
> > build problems for others using distro 2 and vice versa. Neither would
> > have a way of knowing ahead of time that there will be an issue.

>  That issue exists regardless of "which" (which BTW has different
> implementations on different distros anyway, so it can also cause problems).
+1 FYI there is LTP script to cover some which functionality [1]. IMHO type or
command -v are more tested in shell implementation than this simple test.
> We try to minimise the external dependencies of Buildroot, and removing
> "which" from the external dependencies is a good thing IMHO.


>  Bottom line: I think we need to take four actions here.

> 1. Apply your patch.
> 2. Improve on it by detecting that the Buildroot overrides have already been
> exported and don't need to be exported again.
> 3. Verify all calls to "command -v" and make sure the argument is either
> quoted or uses $(firstword).
> 4. Consider the removal of HOSTCC and friends as user-settable variables.

Thanks for further investigation.

Kind regards,
Petr

>  Regards,
>  Arnout

[1] https://github.com/linux-test-project/ltp/blob/master/testcases/commands/which/which01.sh
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Buildroot] [PATCH 0/1] Build issue related to "command -v"
  2021-09-29 20:11   ` Petr Vorel
@ 2021-10-01 17:53     ` Markus Mayer via buildroot
  2021-10-01 18:17       ` Yann E. MORIN
  0 siblings, 1 reply; 15+ messages in thread
From: Markus Mayer via buildroot @ 2021-10-01 17:53 UTC (permalink / raw)
  To: Petr Vorel; +Cc: David Laight, Yann E. MORIN, Buildroot Mailing List

Hi Petr, Arnout, all,

Thanks for all the feedback and for looking into this issue.

On Wed, Sep 29, 2021 at 10:11:46PM +0200, Petr Vorel wrote:
> Hi Markus, Arnout, all,
> 
> >  Hi Markus,
> 
> >  Thank you for this extensive investigation!

You are welcome. It was an interesting one as you can probably
imagine. :-)
 
> > On 28/09/2021 21:55, Markus Mayer wrote:
> 
> > > After commit ca6a2907c27c[1], our automated nightly builds
> > > started experiencing build failures. It took a little while to
> > > track down what was happening. I think I understand now what is
> > > going on.
> 
> > [snip]
> 
> > > One thing of note is that our post-build script calls "make
> > > legal-info", and that is when the problem happens. The purpose
> > > of doing it like this is to include the result of "make
> > > legal-info" in the image.
> 
> > Calling into Buildroot's Makefile recursively from within a
> > post-build script (or a package or whatever) is not something that
> > is supported, in the sense that it's not something that anybody
> > ever tests. The use case definitely makes sense though. I even
> > heard of people starting the build of a different configuration in
> > a post-build script (e.g. for an initramfs).
> 
> > So maybe we should add a test in support/testing that validates
> > this scenario.
> +1

Sounds good to me, as well. It does seem to be quite useful to support
this scenario.

> > > However, when make is invoked a second time with HOSTCC already
> > > defined to call ccache, it'll still assign
> > >     HOSTCC_NOCCACHE := $(HOSTCC)
> > > which now redefines HOSTCC_NOCCACHE to *INCLUDE* ccache (since
> > > HOSTCC does, from earlier)!
> 
> > This is clearly wrong. Your patch helps, but we still have a
> > similar situation with HOSTCC which will be .../ccache .../ccache
> > /usr/bin/gcc in the recursive invocation (i.e. with two times
> > ccache). Although maybe that's not really an issue - "ccache
> > ccache gcc -v" at least gives the expected results.
> Ah, sorry for not catching this.
> 
> > I'm thinking that maybe we should detect recursive invocation in
> > the top-level Makefile and behave differently. For example,
> > everything that is exported doesn't need to be exported again, and
> > stuff like that. Or at least we could protect the entire HOSTCC
> > etc. block against recursive override.
> +1

Definitely no objections from me. I'll defer to those more
knowledgeable about Makefile Magic to make the call what else might
need protection.
 
> > Also, the entire handling of HOSTCC is a bit flaky. It is still
> > from prehistoric commit 8027784 with no clear requirements (e.g. 
> > is HOSTCC allowed to be a command with arguments?  Is it allowed to
> > be a relative path?). It has been documented after-the-fact in
> > docs/manual/common-usage.txt, but I wonder if we really still need
> > it?  I guess it's a way for people to use a host compiler that is
> > more recent that the distro-provided one, but it could just as well
> > be added to $PATH and be done with it...

I think having a documented way of specifying a custom host compiler
(without "poisoning" the environment or being forced to use wrapper
scripts) is a handy thing to have.

Also, one thing you cannot do using PATH is specifying a different
compiler *name*. You can make it search different directories (such as
/opt/toolchains/gcc-x.y/bin or similar), but you can't make it look for
something other than gcc (or cc) or whatever compiler name is
hard-coded into the makefile. If you have HOSTCC, you can name the
actual compiler binary.

Somebody might just be willing to really live on the edge to try out
clang as host compiler. :-)

BTW, we are experimenting with clang as target compiler, but that is a
story for another day.
 
> > [snip]
> 
> > > Here is where it gets interesting. "which" will return two
> > > lines, one for each of the commands:
> 
> > > $ which $HOSTCC_NOCCACHE
> > > /local/users/mmayer/buildroot/output/arm64/host/bin/ccache
> > > /usr/bin/gcc
> 
> >  As mentioned by Nicolas, we really should quote the argument to
> > "command -v", or apply $(firstword ...) to avoid this issue. 
> > Indepedent of which or command -v.
> +1 
> IMHO quoting would require fixing unwanted redefinition
> HOSTCC_NOCCACHE, ($(firstword ...) would not but hide the issue, thus
> I'd prefer fixing the redefinition.

Personally, I like the $(firstword ...) idea.
 
> > [snip]
> 
> > > As such, relying on "command -v" seems a little risky in that it
> > > opens up the possibility for strange build errors that others
> > > cannot reproduce and that nobody would ever think to investigate
> > > as being related to the "command -v" implementation of a specific
> > > shell.
> 
> > It is solving an actual problem (i.e. that "which" is deprecated
> > in some distros), so the best we can do is make the change early
> > enough before a release so people can discover problems with it.

Fair enough. And with all the suggestions in this thread, it is looking
like it can be done safely and without causing nasty surprises down the
road. I think it's fine to proceed with "command -v" in lieu of "which".
 
> > > There is also the issue of some developers working with different
> > > distributions. Somebody developing a feature on distro 1 might
> > > create build problems for others using distro 2 and vice versa. 
> > > Neither would have a way of knowing ahead of time that there will
> > > be an issue.
> 
> > That issue exists regardless of "which" (which BTW has different
> > implementations on different distros anyway, so it can also cause
> > problems).

Good point.

> +1 FYI there is LTP script to cover some which functionality [1]. 
> IMHO type or command -v are more tested in shell implementation than
> this simple test.
> > We try to minimise the external dependencies of Buildroot, and
> > removing "which" from the external dependencies is a good thing
> > IMHO.
> > Bottom line: I think we need to take four actions here.
> 
> > 1. Apply your patch.
> > 2. Improve on it by detecting that the Buildroot overrides have
> > already been exported and don't need to be exported again.
> > 3. Verify all calls to "command -v" and make sure the argument is
> > either quoted or uses $(firstword).
> > 4. Consider the removal of HOSTCC and friends as user-settable
> > variables.

Definitely +1 on points 1-3. I am a little wary about 4 as mentioned
above. While most use cases it be addressed using PATH, it does seem
to be a bit of a heavy-handed approach to tweak a system-wide variable.
And you won't be able to set the compiler name that way.

Regards,
-Markus

> [1] https://github.com/linux-test-project/ltp/blob/master/testcases/commands/which/which01.sh
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Buildroot] [PATCH 0/1] Build issue related to "command -v"
  2021-10-01 17:53     ` Markus Mayer via buildroot
@ 2021-10-01 18:17       ` Yann E. MORIN
  2021-10-02 19:23         ` Petr Vorel
  0 siblings, 1 reply; 15+ messages in thread
From: Yann E. MORIN @ 2021-10-01 18:17 UTC (permalink / raw)
  To: Markus Mayer; +Cc: David Laight, Buildroot Mailing List

Markus, All,

On 2021-10-01 10:53 -0700, Markus Mayer via buildroot spake thusly:
> On Wed, Sep 29, 2021 at 10:11:46PM +0200, Petr Vorel wrote:
> > Hi Markus, Arnout, all,
> > >  Thank you for this extensive investigation!

Yes, thanks for the investigation and the extensive feedback. 👍

> You are welcome. It was an interesting one as you can probably
> imagine. :-)

Yes, I can . ;-)

> > > On 28/09/2021 21:55, Markus Mayer wrote:
> > > > After commit ca6a2907c27c[1], our automated nightly builds
> > > > started experiencing build failures.

I've just reverted the two commits, because the change was raising a few
other issues:
    https://lore.kernel.org/buildroot/20211001180304.GV1504958@scaer/T/#m3a8f36bd76ec7d8e5038a6c8932bb6ffe23ea268

Regards,
Yann E. MORIN.

-- 
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 561 099 427 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Buildroot] [PATCH 0/1] Build issue related to "command -v"
  2021-10-01 18:17       ` Yann E. MORIN
@ 2021-10-02 19:23         ` Petr Vorel
  0 siblings, 0 replies; 15+ messages in thread
From: Petr Vorel @ 2021-10-02 19:23 UTC (permalink / raw)
  To: Yann E. MORIN; +Cc: David Laight, Markus Mayer, Buildroot Mailing List

> Markus, All,

> On 2021-10-01 10:53 -0700, Markus Mayer via buildroot spake thusly:
> > On Wed, Sep 29, 2021 at 10:11:46PM +0200, Petr Vorel wrote:
> > > Hi Markus, Arnout, all,
> > > >  Thank you for this extensive investigation!

> Yes, thanks for the investigation and the extensive feedback. 👍

> > You are welcome. It was an interesting one as you can probably
> > imagine. :-)

> Yes, I can . ;-)

> > > > On 28/09/2021 21:55, Markus Mayer wrote:
> > > > > After commit ca6a2907c27c[1], our automated nightly builds
> > > > > started experiencing build failures.

> I've just reverted the two commits, because the change was raising a few
> other issues:
>     https://lore.kernel.org/buildroot/20211001180304.GV1504958@scaer/T/#m3a8f36bd76ec7d8e5038a6c8932bb6ffe23ea268

Yann,

thanks for quick revert to fix problems!

Kind regards,
Petr

> Regards,
> Yann E. MORIN.
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Buildroot] [PATCH 1/1] Makefile: set HOST*_NOCCACHE variables only if unset
  2021-09-28 19:55 ` [Buildroot] [PATCH 1/1] Makefile: set HOST*_NOCCACHE variables only if unset Markus Mayer via buildroot
  2021-09-29 19:27   ` Petr Vorel
@ 2021-12-28 21:18   ` Thomas Petazzoni
  2021-12-28 21:26     ` Nicolas Cavallari
  2021-12-29  9:12   ` Thomas Petazzoni
  2 siblings, 1 reply; 15+ messages in thread
From: Thomas Petazzoni @ 2021-12-28 21:18 UTC (permalink / raw)
  To: Markus Mayer; +Cc: Markus Mayer via buildroot

On Tue, 28 Sep 2021 12:55:33 -0700
Markus Mayer via buildroot <buildroot@buildroot.org> wrote:

> Set HOSTCC_NOCCACHE and HOSTCXX_NOCCACHE only if they are not set. This
> allows recursive calls to "make" to work as intended in the presence of
> ccache.
> 
> Without guarding these variables, a recursive invocation of make would
> re-define

What is the use-case for a recursive invocation of make, reparsing the
Buildroot Makefile?

Thomas
-- 
Thomas Petazzoni, co-owner and CEO, Bootlin
Embedded Linux and Kernel engineering and training
https://bootlin.com
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Buildroot] [PATCH 1/1] Makefile: set HOST*_NOCCACHE variables only if unset
  2021-12-28 21:18   ` Thomas Petazzoni
@ 2021-12-28 21:26     ` Nicolas Cavallari
  2021-12-29  9:00       ` Thomas Petazzoni
  0 siblings, 1 reply; 15+ messages in thread
From: Nicolas Cavallari @ 2021-12-28 21:26 UTC (permalink / raw)
  To: Thomas Petazzoni, Markus Mayer; +Cc: Markus Mayer via buildroot

On 28/12/2021 22:18, Thomas Petazzoni wrote:
> On Tue, 28 Sep 2021 12:55:33 -0700
> Markus Mayer via buildroot <buildroot@buildroot.org> wrote:
> 
>> Set HOSTCC_NOCCACHE and HOSTCXX_NOCCACHE only if they are not set. This
>> allows recursive calls to "make" to work as intended in the presence of
>> ccache.
>>
>> Without guarding these variables, a recursive invocation of make would
>> re-define
> 
> What is the use-case for a recursive invocation of make, reparsing the
> Buildroot Makefile?

The cover text mentions it: calling make legal-info inside a post-build 
script (or package, actually) to somehow include the result in the image.
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Buildroot] [PATCH 1/1] Makefile: set HOST*_NOCCACHE variables only if unset
  2021-12-28 21:26     ` Nicolas Cavallari
@ 2021-12-29  9:00       ` Thomas Petazzoni
  0 siblings, 0 replies; 15+ messages in thread
From: Thomas Petazzoni @ 2021-12-29  9:00 UTC (permalink / raw)
  To: Nicolas Cavallari; +Cc: Markus Mayer, Markus Mayer via buildroot

On Tue, 28 Dec 2021 22:26:35 +0100
Nicolas Cavallari <nicolas.cavallari@green-communications.fr> wrote:

> The cover text mentions it: calling make legal-info inside a post-build 
> script (or package, actually) to somehow include the result in the image.

Many thanks for pointing it out, because the cover letter obviously
contains all the details.

I am looking at patches through patchwork, so I tend to only see the
patches themselves and not necessarily an associated cover letter.
Especially for single patches, where a cover letter is rarely present,
and therefore I rarely tend to search for such a cover letter in the
mailing list.

Best regards,

Thomas
-- 
Thomas Petazzoni, co-owner and CEO, Bootlin
Embedded Linux and Kernel engineering and training
https://bootlin.com
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Buildroot] [PATCH 1/1] Makefile: set HOST*_NOCCACHE variables only if unset
  2021-09-28 19:55 ` [Buildroot] [PATCH 1/1] Makefile: set HOST*_NOCCACHE variables only if unset Markus Mayer via buildroot
  2021-09-29 19:27   ` Petr Vorel
  2021-12-28 21:18   ` Thomas Petazzoni
@ 2021-12-29  9:12   ` Thomas Petazzoni
  2 siblings, 0 replies; 15+ messages in thread
From: Thomas Petazzoni @ 2021-12-29  9:12 UTC (permalink / raw)
  To: Markus Mayer; +Cc: Markus Mayer via buildroot

Hello Markus,

On Tue, 28 Sep 2021 12:55:33 -0700
Markus Mayer via buildroot <buildroot@buildroot.org> wrote:

> Set HOSTCC_NOCCACHE and HOSTCXX_NOCCACHE only if they are not set. This
> allows recursive calls to "make" to work as intended in the presence of
> ccache.
> 
> Without guarding these variables, a recursive invocation of make would
> re-define
>     HOSTCC_NOCCACHE := $(HOSTCC)
> and
>     HOSTCXX_NOCCACHE := $(HOSTCXX)
> at a point in time when HOSTCC and HOSTCXX already point to ccache.
> 
> Signed-off-by: Markus Mayer <mmayer@broadcom.com>
> ---
>  Makefile | 4 ++++
>  1 file changed, 4 insertions(+)

I have extended the commit log somewhat to give more details, and
applied!

Thanks a lot,

Thomas
-- 
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2021-12-29  9:12 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-28 19:55 [Buildroot] [PATCH 0/1] Build issue related to "command -v" Markus Mayer via buildroot
2021-09-28 19:55 ` [Buildroot] [PATCH 1/1] Makefile: set HOST*_NOCCACHE variables only if unset Markus Mayer via buildroot
2021-09-29 19:27   ` Petr Vorel
2021-12-28 21:18   ` Thomas Petazzoni
2021-12-28 21:26     ` Nicolas Cavallari
2021-12-29  9:00       ` Thomas Petazzoni
2021-12-29  9:12   ` Thomas Petazzoni
2021-09-29  8:24 ` [Buildroot] [PATCH 0/1] Build issue related to "command -v" Nicolas Cavallari
2021-09-29 16:14   ` David Laight
2021-09-29 17:30     ` Petr Vorel
2021-09-29 19:59 ` Arnout Vandecappelle
2021-09-29 20:11   ` Petr Vorel
2021-10-01 17:53     ` Markus Mayer via buildroot
2021-10-01 18:17       ` Yann E. MORIN
2021-10-02 19:23         ` Petr Vorel

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.