Bug 13701 - Long-standing build output gcc-version spam on Cygwin host
Summary: Long-standing build output gcc-version spam on Cygwin host
Status: RESOLVED FIXED
Alias: None
Product: Busybox
Classification: Unclassified
Component: Other (show other bugs)
Version: unspecified
Hardware: PC Windows
: P5 trivial
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-03-31 23:40 UTC by Chris Renshaw
Modified: 2021-04-22 07:22 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:


Attachments
gcc-version.sh patch for the reported issue (601 bytes, patch)
2021-03-31 23:40 UTC, Chris Renshaw
Details
New gcc-version.sh patch for the issue. (647 bytes, patch)
2021-04-18 14:43 UTC, Chris Renshaw
Details
Final patch for the gcc-version.sh (914 bytes, patch)
2021-04-21 17:48 UTC, Chris Renshaw
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Renshaw 2021-03-31 23:40:55 UTC
Created attachment 8861 [details]
gcc-version.sh patch for the reported issue

This shows up multiple times during build with Cygwin host

: invalid numberbox-1.32.1/scripts/gcc-version.sh: line 12: printf: 9

Appears to be some slight difference in gcc output causing it, but doesn't actually then seem to have any effect on the build as far as I can tell.

Regardless, here's a minor patch to resolve it.
Comment 1 Denys Vlasenko 2021-04-14 17:06:57 UTC
NAK. Investigate what happens when

echo __GNUC__ __GNUC_MINOR__ | gcc -E -xc -

is run.
Comment 2 Chris Renshaw 2021-04-14 19:23:45 UTC
Chris@Homebase ~
$ echo __GNUC__ __GNUC_MINOR__ | gcc -E -xc -
# 1 "<stdin>"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "<stdin>"
9 3

Chris@Homebase ~
$
Comment 3 Bernhard Reutner-Fischer 2021-04-15 18:07:13 UTC
So would echo -n or printf work, to omit the trailing newline?

echo -n __GNUC__ __GNUC_MINOR__ | cc -E -xc - | tail -n 1
printf "__GNUC__ __GNUC_MINOR__" | cc -E -xc - | tail -n 1
Comment 4 Denys Vlasenko 2021-04-16 11:54:45 UTC
Just adding
    | grep .
to that pipe to filter out empty lines should fix it. Can you confirm?
Comment 5 Chris Renshaw 2021-04-16 14:32:01 UTC
Chris@Homebase ~
$ echo -n __GNUC__ __GNUC_MINOR__ | gcc -E -xc - | tail -n 1
9 3

Chris@Homebase ~
$ printf "__GNUC__ __GNUC_MINOR__" | gcc -E -xc - | tail -n 1
9 3

Chris@Homebase ~
$ echo __GNUC__ __GNUC_MINOR__ | gcc -E -xc - | grep .
# 1 "<stdin>"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "<stdin>"
9 3

Chris@Homebase ~
$
Comment 6 Denys Vlasenko 2021-04-18 11:24:30 UTC
I meant this:

--- a/scripts/gcc-version.sh
+++ b/scripts/gcc-version.sh
@@ -8,5 +8,5 @@

 compiler="$*"

-MAJ_MIN=$(echo __GNUC__ __GNUC_MINOR__ | $compiler -E -xc - | tail -n 1)
+MAJ_MIN=$(echo __GNUC__ __GNUC_MINOR__ | $compiler -E -xc - | grep . | tail -n 1)
 printf '%02d%02d\n' $MAJ_MIN
Comment 7 Chris Renshaw 2021-04-18 13:49:14 UTC
Hmm, looks the same output from command-line.. I'll try actually patching the file and running a compile.


Chris@Homebase ~
$ compiler=gcc

Chris@Homebase ~
$ MAJ_MIN=$(echo __GNUC__ __GNUC_MINOR__ | $compiler -E -xc - | tail -n 1)

Chris@Homebase ~
$ printf '%02d%02d\n' $MAJ_MIN
0903

Chris@Homebase ~
$ MAJ_MIN=$(echo __GNUC__ __GNUC_MINOR__ | $compiler -E -xc - | grep . | tail -n 1)

Chris@Homebase ~
$ printf '%02d%02d\n' $MAJ_MIN
0903

Chris@Homebase ~
$
Comment 8 Chris Renshaw 2021-04-18 14:02:43 UTC
Unfortunately still broken with your committed patch, so I'm reopening:

: invalid numberbox-1.32.1/scripts/gcc-version.sh: line 12: printf: 9
  HOSTCC  scripts/basic/fixdep
  HOSTCC  scripts/basic/split-include
  HOSTCC  scripts/basic/docproc
  HOSTCC  scripts/kconfig/conf.o
  HOSTCC  scripts/kconfig/kxgettext.o
  HOSTCC  scripts/kconfig/mconf.o
  HOSTCC  scripts/kconfig/zconf.tab.o
  HOSTLD  scripts/kconfig/conf
scripts/kconfig/conf -s Config.in
#
# using defaults found in .config
#
: invalid numberbox-1.32.1/scripts/gcc-version.sh: line 12: printf: 9
  SPLIT   include/autoconf.h -> include/config/*
make: *** [Makefile:858: include/config/MARKER] Interrupt
Comment 9 Chris Renshaw 2021-04-18 14:26:51 UTC
I added this to gcc_version.sh to tease out the issue more, and turns out it's the NDK gcc which is being weird:

echo "$compiler:$MAJ_MIN:" >> ~/compiler.log

And from compiler.log, it is indeed a newline causing the issue:

/home/Chris/x-tools/i686-linux-android-r15c-api21-unified/bin/i686-linux-android-gcc:4 9
:

Running it directly:

$ scripts/gcc-version.sh /home/Chris/x-tools/i686-linux-android-r15c-api21-unified/bin/i686-linux-android-gcc
: invalid numberion.sh: line 12: printf: 9
0409

It doesn't look broken compared to any of the output we've looked at, but somehow the MAJ_MIN= captures a newline:

Chris@Homebase ~/busybox-1.32.1
$ echo $compiler
/home/Chris/x-tools/i686-linux-android-r15c-api21-unified/bin/i686-linux-android-gcc

Chris@Homebase ~/busybox-1.32.1
$ echo __GNUC__ __GNUC_MINOR__ | $compiler -E -xc - | tail -n 1
4 9

Even just trying to echo $MAJ_MIN on the command line gives some weird results... the trailing : should display somewhere, but doesn't:

Chris@Homebase ~/busybox-1.32.1
$ MAJ_MIN=$(echo __GNUC__ __GNUC_MINOR__ | $compiler -E -xc - | tail -n 1)

Chris@Homebase ~/busybox-1.32.1
$ echo ":${MAJ_MIN}:"
:4 9

And it gets weirder:

Chris@Homebase ~/busybox-1.32.1
$ echo ":$MAJ_MIN"
:4 9

Chris@Homebase ~/busybox-1.32.1
$ echo ":$MAJ_MIN:"
:4 9

Chris@Homebase ~/busybox-1.32.1
$ echo ":$MAJ_MIN::"
:: 9

Chris@Homebase ~/busybox-1.32.1
$ echo ":$MAJ_MIN:::"
:::9

Chris@Homebase ~/busybox-1.32.1
$ echo ":$MAJ_MIN::::"
::::

I guess gcc_version.sh still having the correct output is why I landed on 2>/dev/null as the fix back when I made the submitted patch.
Comment 10 Chris Renshaw 2021-04-18 14:42:23 UTC
Ah, I examined the output in a hex editor, it's not a LF causing the issure, it's a CR!

grep . didn't help because a CR is treated like text I guess?

Adding a new patch to resolve it properly by stripping the CR. If you use it, please maintain authorship, since I noticed you didn't for the wait3 or warning array subscript patches.
Comment 11 Chris Renshaw 2021-04-18 14:43:05 UTC
Created attachment 8906 [details]
New gcc-version.sh patch for the issue.
Comment 12 Denys Vlasenko 2021-04-20 16:01:08 UTC
So, $((echo __GNUC__ __GNUC_MINOR__ | $compiler -E -xc - | tail -n 1)) produced the string "4 9\r" ?!

My God :)

$ patch -p1 </tmp/000-gcc-version.patch --dry-run
checking file scripts/gcc-version.sh
Hunk #1 FAILED at 9.
1 out of 1 hunk FAILED

Also, please add "Signed-off-by: Chris Renshaw <osm0sis@outlook.com>" line to the patch. Our git is set up to require signoff.
Comment 13 Bernhard Reutner-Fischer 2021-04-20 17:05:16 UTC
(In reply to Denys Vlasenko from comment #12)

that's why i tried to suggest echo -n or printf in the hopes to get rid of any CRNL ;)
Comment 14 Chris Renshaw 2021-04-20 17:16:31 UTC
Yeah, crazy right? Thanks! I wasn't accounting for you adding the `grep .` to master in my updated patch. I'll rebase at HEAD and add the Signed-off line.
Comment 15 Chris Renshaw 2021-04-21 17:48:17 UTC
Created attachment 8911 [details]
Final patch for the gcc-version.sh
Comment 16 Denys Vlasenko 2021-04-22 07:22:10 UTC
Applied, thanks