summaryrefslogtreecommitdiff
path: root/debian/patches/verbose-lto-linker.diff
blob: 2e5bc7438de397837cc8984bce00247dabf32969 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# DP: Emit some stderr output while doing the LTO Links

Index: b/src/gcc/lock-and-run.sh
===================================================================
--- a/src/gcc/lock-and-run.sh
+++ b/src/gcc/lock-and-run.sh
@@ -1,7 +1,8 @@
-#! /bin/sh
+#! /bin/bash
 # Shell-based mutex using mkdir.
 
 lockdir="$1" prog="$2"; shift 2 || exit 1
+cmd=$(echo $prog "$@" | sed 's,^[^ ]*/,,;s, .*\( -o [^ ]*\) .*,\1,')
 
 # Remember when we started trying to acquire the lock.
 count=0
@@ -11,24 +12,72 @@ trap 'rm -r "$lockdir" lock-stamp.$$' 0
 
 until mkdir "$lockdir" 2>/dev/null; do
     # Say something periodically so the user knows what's up.
-    if [ `expr $count % 30` = 0 ]; then
+    if [ `expr $count % 60` = 0 ]; then
 	# Reset if the lock has been renewed.
 	if [ -n "`find \"$lockdir\" -newer lock-stamp.$$`" ]; then
 	    touch lock-stamp.$$
 	    count=1
-	# Steal the lock after 5 minutes.
-	elif [ $count = 300 ]; then
-	    echo removing stale $lockdir >&2
+	# Steal the lock after 30 minutes.
+	elif [ $count = 1800 ]; then
+	    echo "removing stale $lockdir ($cmd)" >&2
 	    rm -r "$lockdir"
 	else
-	    echo waiting to acquire $lockdir >&2
+	    echo "waiting to acquire $lockdir ($cmd)" >&2
 	fi
     fi
-    sleep 1
-    count=`expr $count + 1`
+    sleep 6
+    count=`expr $count + 6`
 done
 
 echo $prog "$@"
-$prog "$@"
+$prog "$@" &
+pid=$!
+
+count=0
+# once the "stale" locks are released, everything runs in
+# parallel, so be gentle with the timeout
+max_count=$((10 * 60 * 60))
+
+while true; do
+    status=$(jobs -l | sed -n "/ $pid /s/^.* $pid //p")
+    case "x$status" in
+    xRunning*)
+	: echo >&2 "running ..."
+	;;
+    xExit*)
+	: echo >&2 "exit ..."
+	rv=$(echo $status | awk '{print $2}')
+	break
+	;;
+    xDone*)
+	rv=0
+	break
+	;;
+    x)
+	: echo >&2 "??? ..."
+	pstatus=$(ps $pid)
+	if [ "$?" -ne 0 ]; then
+	    rv=0
+	    break
+	fi
+	;;
+    *)
+	echo >&2 "$(basename $0): PID $pid ($cmd): unknown: $status"
+	rv=48
+	break
+    esac
+    sleep 2
+    count=$(($count + 6))
+    if [ "$(($count % 300))" -eq 0 ]; then
+	echo >&2 "$(basename $0): PID $pid ($cmd) running for $count seconds"
+    fi
+    if [ $count -ge $max_count ]; then
+	echo >&2 "$(basename $0): PID $pid ($cmd) timeout after $count seconds"
+	kill -1 $pid
+	rv=47
+    fi
+done
+echo >&2 "$(basename $0): PID $pid ($cmd) finished after $count seconds"
 
 # The trap runs on exit.
+exit $rv