Bug 1429056 - Wrap llvm-dsymutil calls on automation. r?build draft
authorMike Hommey <mh+mozilla@glandium.org>
Fri, 19 Jan 2018 10:20:41 +0900
changeset 722592 18b65f9c144fa74ed3960044555b0d79e962e89b
parent 722591 52b94751859332f043eb5d4f8a0565561df7a644
child 722594 6a2531af2027aa127ea217876ee671e36c0c5ebe
push id96180
push userbmo:mh+mozilla@glandium.org
push dateFri, 19 Jan 2018 10:06:50 +0000
reviewersbuild
bugs1429056
milestone59.0a1
Bug 1429056 - Wrap llvm-dsymutil calls on automation. r?build We add a wrapper for llvm-dsymutil for macosx CI builds such that when it crashes, we attempt to get a reduced test case and upload it as a build artifact. This will allow to more easily report such crashes upstream.
build/macosx/cross-mozconfig.common
build/macosx/llvm-dsymutil
--- a/build/macosx/cross-mozconfig.common
+++ b/build/macosx/cross-mozconfig.common
@@ -26,17 +26,18 @@ FLAGS="-target x86_64-apple-darwin11 -B 
 
 export CC="$topsrcdir/clang/bin/clang $FLAGS"
 export CXX="$topsrcdir/clang/bin/clang++ $FLAGS"
 export CPP="$topsrcdir/clang/bin/clang $FLAGS -E"
 export LLVMCONFIG=$topsrcdir/clang/bin/llvm-config
 export LDFLAGS="-Wl,-syslibroot,$CROSS_SYSROOT -Wl,-dead_strip"
 export BINDGEN_CFLAGS="$FLAGS"
 export TOOLCHAIN_PREFIX=$CROSS_CCTOOLS_PATH/bin/x86_64-apple-darwin11-
-export DSYMUTIL=$topsrcdir/llvm-dsymutil/bin/llvm-dsymutil
+export DSYMUTIL=$topsrcdir/build/macosx/llvm-dsymutil
+mk_add_options "export REAL_DSYMUTIL=$topsrcdir/llvm-dsymutil/bin/llvm-dsymutil"
 export MKFSHFS=$topsrcdir/hfsplus-tools/newfs_hfs
 export DMG_TOOL=$topsrcdir/dmg/dmg
 export HFS_TOOL=$topsrcdir/dmg/hfsplus
 
 export HOST_CC="$topsrcdir/clang/bin/clang"
 export HOST_CXX="$topsrcdir/clang/bin/clang++"
 export HOST_CPP="$topsrcdir/clang/bin/clang -E"
 export HOST_CFLAGS="-g"
new file mode 100755
--- /dev/null
+++ b/build/macosx/llvm-dsymutil
@@ -0,0 +1,75 @@
+#!/bin/sh
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+"$REAL_DSYMUTIL" "$@"
+ret=$?
+if [ $ret -ne 139 ]; then
+  exit $ret
+fi
+
+echo "$REAL_DSYMUTIL crashed. Trying to get a reduced testcase." >&2
+tmpdir=$(mktemp -d)
+trap "rm -rf $tmpdir" EXIT
+
+# Get the library file name from the command line arguments. We assume
+# it's the last argument that doesn't start with a dash.
+for arg in "$@"; do
+  case "$arg" in
+  -*)
+    ;;
+  *)
+    lib="$arg"
+    ;;
+  esac
+done
+
+last_obj=$("$REAL_DSYMUTIL" --verbose "$@" 2> /dev/null | sed -n "/trying to open/s/trying to open '\(.*\)'/\1/p" | tail -1)
+
+case "$last_obj" in
+"")
+  echo "Could not produce a reduced testcase. Aborting." >&2
+  # Ideally, we'd produce an archive with every .o and .a involved, but so
+  # far, this case has never happened, so, meh.
+  exit 139
+  ;;
+*.a\(*.o\))
+  # The crash likely happened while reading one particular object in a library.
+  # Create a new library with just that one object.
+  archive=$(readlink -f "${last_obj%(*}")
+  obj="${last_obj#*.a(}"
+  obj="${obj%)}"
+  (cd "$tmpdir"; ar x "$archive" "$obj")
+  mkdir -p $tmpdir/crasher/$(dirname "$archive")
+  (cd "$tmpdir"; ar cr "$tmpdir/crasher/$archive" "$obj")
+  rm "$tmpdir/$obj"
+  ;;
+*)
+  # The crash likely happened while reading one particular object.
+  obj=$(readlink -f "$last_obj")
+  mkdir -p "$tmpdir/crasher/$(dirname "$obj")"
+  cp "$obj" "$tmpdir/crasher/$obj"
+  ;;
+esac
+cp "$lib" "$tmpdir/crasher"
+cat > "$tmpdir/crasher/run-me.sh" <<EOF
+#!/bin/sh
+DSYMUTIL="\${DSYMUTIL:-llvm-dsymutil}"
+dir="\$(dirname \$0)"
+\$DSYMUTIL -oso-prepend-path="\$dir" "\$dir/$(basename "$lib")"
+exit \$?
+EOF
+chmod +x "$tmpdir/crasher/run-me.sh"
+(cd "$tmpdir"/crasher; DSYMUTIL=/builds/worker/workspace/build/src/llvm-dsymutil/bin/llvm-dsymutil ./run-me.sh > /dev/null 2>&1)
+if [ $? -eq 139 ]; then
+  echo "Could reproduce with a reduced testcase. Creating an artifact." >&2
+  mkdir -p "$HOME/artifacts"
+  artifact=dsymutil-crasher.tar.xz
+  tar -Jcf "$HOME/artifacts/$artifact" -C "$tmpdir" crasher/
+  echo "Check the $artifact artifact." >&2
+else
+  echo "Could not reproduce with a reduced testcase. Sorry." >&2
+fi
+
+exit 139