Bug 1697929 - Create a breakpad injector toolchain build. r=glandium
authorSteve Fink <sfink@mozilla.com>
Mon, 19 Apr 2021 14:21:42 +0000
changeset 576548 da7d7390ef5d0e00f81a6522a2a345c952de8abc
parent 576547 abe51227f6a28f620f71da8e58c8a0ddc5a5829e
child 576549 1526c8b3fb4ef8977c0d2fcfb0bba3d258c0e75d
push id38389
push userdluca@mozilla.com
push dateMon, 19 Apr 2021 22:16:26 +0000
treeherdermozilla-central@e2fb29057e4c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersglandium
bugs1697929
milestone89.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1697929 - Create a breakpad injector toolchain build. r=glandium Differential Revision: https://phabricator.services.mozilla.com/D109504
js/src/devtools/automation/autospider.py
old-configure.in
taskcluster/ci/toolchain/minidump_stackwalk.yml
taskcluster/scripts/misc/build-breakpad-injector.sh
toolkit/crashreporter/breakpad-client/linux/handler/exception_handler.cc
tools/crashreporter/injector/app.mozbuild
tools/crashreporter/injector/injector.cc
tools/crashreporter/injector/moz.build
tools/crashreporter/injector/moz.configure
--- a/js/src/devtools/automation/autospider.py
+++ b/js/src/devtools/automation/autospider.py
@@ -450,31 +450,31 @@ if AUTOMATION:
         use_minidump = variant.get("use_minidump", True)
     else:
         use_minidump = False
 else:
     use_minidump = False
 
 if use_minidump:
     env.setdefault("MINIDUMP_SAVE_PATH", env["MOZ_UPLOAD_DIR"])
-    env.setdefault("DUMP_SYMS", os.path.join(DIR.fetches, "dump_syms", "dump_syms"))
-    injector_lib = None
-    if platform.system() == "Linux":
-        injector_lib = os.path.join(
-            DIR.tooltool, "breakpad-tools", "libbreakpadinjector.so"
-        )
-        env.setdefault(
-            "MINIDUMP_STACKWALK",
-            os.path.join(DIR.tooltool, "breakpad-tools", "minidump_stackwalk"),
-        )
-    elif platform.system() == "Darwin":
-        injector_lib = os.path.join(
-            DIR.tooltool, "breakpad-tools", "breakpadinjector.dylib"
-        )
-    if not injector_lib or not os.path.exists(injector_lib):
+
+    injector_basename = {
+        "Linux": "libbreakpadinjector.so",
+        "Darwin": "breakpadinjector.dylib",
+    }.get(platform.system())
+
+    injector_lib = resolve_path((DIR.fetches,), "injector", injector_basename)
+    stackwalk = resolve_path((DIR.fetches,), "minidump_stackwalk", "minidump_stackwalk")
+    if stackwalk is not None:
+        env.setdefault("MINIDUMP_STACKWALK", stackwalk)
+    dump_syms = resolve_path((DIR.fetches,), "dump_syms", "dump_syms")
+    if dump_syms is not None:
+        env.setdefault("DUMP_SYMS", dump_syms)
+
+    if injector_lib is None:
         use_minidump = False
 
     info("use_minidump is {}".format(use_minidump))
     info("  MINIDUMP_SAVE_PATH={}".format(env["MINIDUMP_SAVE_PATH"]))
     info("  injector lib is {}".format(injector_lib))
     info("  MINIDUMP_STACKWALK={}".format(env.get("MINIDUMP_STACKWALK")))
 
 
--- a/old-configure.in
+++ b/old-configure.in
@@ -885,16 +885,19 @@ Darwin)
   STL_FLAGS="-I${DIST}/stl_wrappers"
   WRAP_STL_INCLUDES=1
   ;;
 esac
 
 if test "$MOZ_BUILD_APP" = "tools/crashreporter"; then
     WRAP_STL_INCLUDES=
 fi
+if test "$MOZ_BUILD_APP" = "tools/crashreporter/injector"; then
+    WRAP_STL_INCLUDES=
+fi
 
 dnl Checks for header files.
 dnl ========================================================
 AC_HEADER_DIRENT
 case "$target_os" in
 bitrig*|dragonfly*|freebsd*|openbsd*)
 # for stuff like -lXshm
     CPPFLAGS="${CPPFLAGS} ${X_CFLAGS}"
--- a/taskcluster/ci/toolchain/minidump_stackwalk.yml
+++ b/taskcluster/ci/toolchain/minidump_stackwalk.yml
@@ -63,8 +63,21 @@ win32-minidump-stackwalk:
     worker:
         docker-image: {in-tree: mingw32-build}
     run:
         arguments: ['mingw32']
     fetches:
         toolchain:
             - linux64-clang-mingw-x86
             - mingw32-rust-1.47
+
+linux64-breakpad-injector:
+    description: "breakpad injector toolchain build"
+    run:
+        script: build-breakpad-injector.sh
+        toolchain-artifact: public/build/injector.tar.xz
+    treeherder:
+        symbol: TL(injector)
+    fetches:
+        toolchain:
+            - linux64-clang-11
+            - linux64-binutils
+            - linux64-toolchain-sysroot
new file mode 100755
--- /dev/null
+++ b/taskcluster/scripts/misc/build-breakpad-injector.sh
@@ -0,0 +1,29 @@
+#!/bin/bash
+set -x -e -v
+
+# This script is for building libbreakpadinjector.so, currently for linux only
+
+COMPRESS_EXT=xz
+
+cd $GECKO_PATH
+
+export MOZ_OBJDIR=obj-injector
+
+echo ac_add_options --enable-project=tools/crashreporter/injector > .mozconfig
+
+INJECTOR=libbreakpadinjector.so
+
+TOOLCHAINS="binutils rustc clang"
+
+for t in $TOOLCHAINS; do
+    PATH="$MOZ_FETCHES_DIR/$t/bin:$PATH"
+done
+
+./mach build -v
+
+mkdir injector
+cp $MOZ_OBJDIR/dist/bin/$INJECTOR injector/
+
+tar -acf injector.tar.$COMPRESS_EXT injector/
+mkdir -p $UPLOAD_DIR
+cp injector.tar.$COMPRESS_EXT $UPLOAD_DIR
--- a/toolkit/crashreporter/breakpad-client/linux/handler/exception_handler.cc
+++ b/toolkit/crashreporter/breakpad-client/linux/handler/exception_handler.cc
@@ -91,17 +91,16 @@
 #include "common/linux/linux_libc_support.h"
 #include "common/memory_allocator.h"
 #include "linux/log/log.h"
 #include "linux/microdump_writer/microdump_writer.h"
 #include "linux/minidump_writer/linux_dumper.h"
 #include "linux/minidump_writer/minidump_writer.h"
 #include "common/linux/eintr_wrapper.h"
 #include "third_party/lss/linux_syscall_support.h"
-#include "prenv.h"
 #if defined(MOZ_OXIDIZED_BREAKPAD)
 #include "nsString.h"
 #include "mozilla/toolkit/crashreporter/rust_minidump_writer_linux_ffi_generated.h"
 #endif
 
 #ifdef MOZ_PHC
 #include "replace_malloc_bridge.h"
 #endif
@@ -235,17 +234,17 @@ ExceptionHandler::ExceptionHandler(const
                                    bool install_handler,
                                    const int server_fd)
     : filter_(filter),
       callback_(callback),
       callback_context_(callback_context),
       minidump_descriptor_(descriptor),
       crash_handler_(NULL) {
 
-  g_skip_sigill_ = PR_GetEnv("MOZ_DISABLE_EXCEPTION_HANDLER_SIGILL") ? true : false;
+  g_skip_sigill_ = getenv("MOZ_DISABLE_EXCEPTION_HANDLER_SIGILL") ? true : false;
   if (server_fd >= 0)
     crash_generation_client_.reset(CrashGenerationClient::TryCreate(server_fd));
 
   if (!IsOutOfProcess() && !minidump_descriptor_.IsFD() &&
       !minidump_descriptor_.IsMicrodumpOnConsole())
     minidump_descriptor_.UpdatePath();
 
 #if defined(__ANDROID__)
new file mode 100644
--- /dev/null
+++ b/tools/crashreporter/injector/app.mozbuild
@@ -0,0 +1,14 @@
+# 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/.
+
+DIRS += [
+    '/toolkit/crashreporter/google-breakpad/src/common',
+    '/toolkit/crashreporter/google-breakpad/src/processor',
+    '/tools/crashreporter/injector',
+]
+
+if CONFIG['OS_TARGET'] in ('Linux', 'Android'):
+   DIRS += [
+       '/toolkit/crashreporter/google-breakpad/src/common/linux',
+   ]
new file mode 100644
--- /dev/null
+++ b/tools/crashreporter/injector/injector.cc
@@ -0,0 +1,38 @@
+/* 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/. */
+
+#include "linux/handler/exception_handler.h"
+
+using google_breakpad::ExceptionHandler;
+
+static ExceptionHandler* gExceptionHandler = nullptr;
+
+bool gBreakpadInjectorEnabled = true;
+
+bool TestEnabled(void* /* context */) { return gBreakpadInjectorEnabled; }
+
+bool SetGlobalExceptionHandler(
+    ExceptionHandler::FilterCallback filterCallback,
+    ExceptionHandler::MinidumpCallback minidumpCallback) {
+  const char* tempPath = getenv("TMPDIR");
+  if (!tempPath) tempPath = "/tmp";
+
+  google_breakpad::MinidumpDescriptor descriptor(tempPath);
+
+  gExceptionHandler = new ExceptionHandler(descriptor, filterCallback,
+                                           minidumpCallback, nullptr, true, -1);
+  if (!gExceptionHandler) return false;
+
+  return true;
+}
+
+// Called when loading the DLL (eg via LD_PRELOAD, or the JS shell --dll
+// option).
+void __attribute__((constructor)) SetBreakpadExceptionHandler() {
+  if (gExceptionHandler) abort();
+
+  if (!SetGlobalExceptionHandler(TestEnabled, nullptr)) abort();
+
+  if (!gExceptionHandler) abort();
+}
new file mode 100644
--- /dev/null
+++ b/tools/crashreporter/injector/moz.build
@@ -0,0 +1,36 @@
+# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# 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/.
+
+SharedLibrary("breakpadinjector")
+
+UNIFIED_SOURCES += [
+    "/toolkit/crashreporter/breakpad-client/linux/crash_generation/crash_generation_client.cc",
+    "/toolkit/crashreporter/breakpad-client/linux/dump_writer_common/thread_info.cc",
+    "/toolkit/crashreporter/breakpad-client/linux/dump_writer_common/ucontext_reader.cc",
+    "/toolkit/crashreporter/breakpad-client/linux/handler/exception_handler.cc",
+    "/toolkit/crashreporter/breakpad-client/linux/handler/guid_generator.cc",
+    "/toolkit/crashreporter/breakpad-client/linux/handler/minidump_descriptor.cc",
+    "/toolkit/crashreporter/breakpad-client/linux/log/log.cc",
+    "/toolkit/crashreporter/breakpad-client/linux/microdump_writer/microdump_writer.cc",
+    "/toolkit/crashreporter/breakpad-client/linux/minidump_writer/linux_dumper.cc",
+    "/toolkit/crashreporter/breakpad-client/linux/minidump_writer/linux_ptrace_dumper.cc",
+    "/toolkit/crashreporter/breakpad-client/linux/minidump_writer/minidump_writer.cc",
+    "/toolkit/crashreporter/breakpad-client/minidump_file_writer.cc",
+    "injector.cc",
+]
+
+USE_LIBS += [
+    "breakpad_common_s",
+    "breakpad_linux_common_s",
+]
+
+DisableStlWrapping()
+
+# On Linux we override the guid_creator.h header and use our own instead
+if CONFIG["OS_TARGET"] in ("Linux", "Android"):
+    DEFINES["COMMON_LINUX_GUID_CREATOR_H__"] = 1
+
+include("/toolkit/crashreporter/crashreporter.mozbuild")
new file mode 100644
--- /dev/null
+++ b/tools/crashreporter/injector/moz.configure
@@ -0,0 +1,3 @@
+# 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/.