In mgnuc, use a temporary file to hold gcc error messages before filtering with

Branches: main, 10.04

In mgnuc, use a temporary file to hold gcc error messages before filtering with
mfiltercc, instead trying to do it directly in a pipeline.

The major problem is that the exit status of mgnuc would be that of the second
command in the pipeline (mfiltercc), and not the important command (gcc).
Fixing it without using temporary files requires horrible shell code.

scripts/mgnuc.in:
        As above.  Filtering is disabled if mktemp is not detected at configure
        time.

        Note: the deleted shell command was incorrect as fd 3 was not
        redirected back to standard output, hence if gcc wrote anything to its
        standard output (it doesn't) then it would have been lost.
This commit is contained in:
Peter Wang
2010-07-12 04:57:09 +00:00
parent 237dc9e5de
commit e7a70262a6

View File

@@ -27,6 +27,8 @@ CFLAGS_FOR_THREADS="@CFLAGS_FOR_THREADS@"
CFLAGS_FOR_NO_STRICT_ALIASING="@CFLAGS_FOR_NO_STRICT_ALIASING@"
AS="@AS@"
BYTES_PER_WORD="@BYTES_PER_WORD@"
MKTEMP=@MKTEMP@
TMPDIR=${TMPDIR=/tmp}
case "$CC" in
*gcc*)
@@ -642,7 +644,7 @@ FILTERCC=""
case $asm_labels in true)
# Check if mfiltercc is available as we may be bootstrapping with
# an older compiler which did not have it.
if mfiltercc=`which mfiltercc`
if test -n "$MKTEMP" && mfiltercc=`which mfiltercc`
then
FILTERCC=$mfiltercc
fi
@@ -687,18 +689,24 @@ ALL_CC_OPTS="$MERC_ALL_C_INCL_DIRS\
$FN_ALIGN_OPTS\
$INVISIBLE_OPTS"
case $verbose in true)
echo $CC $ALL_CC_OPTS "$@" $OVERRIDE_OPTS $ALL_LOCAL_C_INCL_DIRS;;
case $# in
0) set $CC $ALL_CC_OPTS $OVERRIDE_OPTS ;;
*) set $CC $ALL_CC_OPTS "$@" $OVERRIDE_OPTS $ALL_LOCAL_C_INCL_DIRS ;;
esac
# 3>&- closes fd 3 on both sides of the pipeline
case $#,$FILTERCC in
0,) exec $CC $ALL_CC_OPTS $OVERRIDE_OPTS ;;
0,*) exec 3>&1
exec $CC $ALL_CC_OPTS $OVERRIDE_OPTS \
2>&1 >&3 3>&- | $FILTERCC >&2 3>&- ;;
*,) exec $CC $ALL_CC_OPTS "$@" $OVERRIDE_OPTS $ALL_LOCAL_C_INCL_DIRS ;;
*,*) exec 3>&1
exec $CC $ALL_CC_OPTS "$@" $OVERRIDE_OPTS $ALL_LOCAL_C_INCL_DIRS \
2>&1 >&3 3>&- | $FILTERCC >&2 3>&- ;;
case $verbose in true)
echo "$@"
esac
if test -z "$FILTERCC"
then
exec "$@"
fi
# mktemp should give its own error message.
tmp=`$MKTEMP $TMPDIR/mgnuc.XXXXXX` || exit 1
trap 'status=$?; rm -f $tmp; exit $status' 0 1 2 3 13 15
"$@" 2> $tmp
status=$?
"$FILTERCC" < $tmp >&2
exit $status