Skip to content

Commit

Permalink
crashpad: strip handler binary
Browse files Browse the repository at this point in the history
  • Loading branch information
Chilledheart committed Aug 30, 2024
1 parent 4466f1b commit 6c0a054
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/releases-android-binary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ jobs:
with:
path: |
third_party/crashpad
key: ${{ runner.os }}-android-${{ matrix.arch }}-crashpad-${{ hashFiles('CRASHPAD_COMMIT') }}-v${{ env.CACHE_EPOCH }}
key: ${{ runner.os }}-android-${{ matrix.arch }}-crashpad-${{ hashFiles('CRASHPAD_COMMIT') }}-v${{ env.CACHE_EPOCH }}-stripped
- name: Cache cargo build stage
id: cargo-cache
uses: actions/cache@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/releases-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ jobs:
with:
path: |
third_party/crashpad
key: ${{ runner.os }}-mac-${{ matrix.arch }}-crashpad-${{ hashFiles('CRASHPAD_COMMIT') }}-v${{ env.CACHE_EPOCH }}
key: ${{ runner.os }}-mac-${{ matrix.arch }}-crashpad-${{ hashFiles('CRASHPAD_COMMIT') }}-v${{ env.CACHE_EPOCH }}-stripped
- name: Build build tool
run: |
cd tools
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/releases-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ jobs:
with:
path: |
third_party/crashpad
key: ${{ runner.os }}-msvc-dynamic-${{ matrix.arch }}-crashpad-${{ hashFiles('CRASHPAD_COMMIT') }}-v${{ env.CACHE_EPOCH }}
key: ${{ runner.os }}-msvc-dynamic-${{ matrix.arch }}-crashpad-${{ hashFiles('CRASHPAD_COMMIT') }}-v${{ env.CACHE_EPOCH }}-stripped
- uses: actions/setup-go@v5
with:
go-version: '>=1.20.0'
Expand Down
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2761,6 +2761,7 @@ if (MSVC AND MSVC_CRT_LINKAGE STREQUAL "dynamic" AND NOT ALLOW_XP AND ${CMAKE_BU
set(USE_CRASHPAD ON)

file(COPY "${_CRASHPAD_BINARY_PREFIX}/crashpad_handler.exe" DESTINATION ${CMAKE_BINARY_DIR})
file(COPY "${_CRASHPAD_BINARY_PREFIX}/crashpad_handler.pdb" DESTINATION ${CMAKE_BINARY_DIR})

install(FILES "${_CRASHPAD_BINARY_PREFIX}/crashpad_handler.exe" DESTINATION "${CMAKE_INSTALL_BINDIR}")
endif()
Expand Down Expand Up @@ -2873,6 +2874,7 @@ if (UNIX AND (${CMAKE_BUILD_TYPE} MATCHES MinSizeRel OR ${CMAKE_BUILD_TYPE} MATC

if (NOT IOS)
file(COPY "${_CRASHPAD_BINARY_PREFIX}/crashpad_handler" DESTINATION ${CMAKE_BINARY_DIR})
file(COPY "${_CRASHPAD_BINARY_PREFIX}/crashpad_handler.dbg" DESTINATION ${CMAKE_BINARY_DIR})
set(_CRASHPAD_BINARY "${CMAKE_BINARY_DIR}/crashpad_handler")
endif()
endif()
Expand Down
21 changes: 21 additions & 0 deletions scripts/build-crashpad.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,36 @@ fi
case "$ARCH" in
Darwin)
WITH_OS_DEFAULT="mac"
BIN_SUFFIX=""
;;
Linux)
WITH_OS_DEFAULT="linux"
BIN_SUFFIX=""
;;
Windows)
WITH_OS_DEFAULT="win"
BIN_SUFFIX=".exe"
;;
esac

WITH_OS=${WITH_OS:-${WITH_OS_DEFAULT}}
OBJCOPY="$PWD/llvm-build/Release+Asserts/bin/llvm-objcopy"

# strip debug symbols (ignore msvc build which generating pdbs already)
function strip_binary {
if [ "$WITH_OS" = "win" ]; then
echo 'omit calling llvm-objcopy on msvc binary'
return
fi

local bin_dir="$(dirname $1)"
local bin_name="$(basename $1)"
pushd "$bin_dir"
"$OBJCOPY" --only-keep-debug "${bin_name}" "${bin_name}.dbg"
"$OBJCOPY" --strip-debug "${bin_name}"
"$OBJCOPY" --add-gnu-debuglink="${bin_name}.dbg" "${bin_name}"
popd
}

if [ "$WITH_OS" ]; then
flags="$flags
Expand Down Expand Up @@ -201,3 +221,4 @@ mkdir -p "$bin_out"
echo "$bin_flags" > "$bin_out/args.gn"
gn gen "$bin_out" --script-executable="$PYTHON" --export-compile-comman
ninja -C "$bin_out" crashpad_handler
strip_binary "${bin_out}/crashpad_handler${BIN_SUFFIX}"
62 changes: 32 additions & 30 deletions tools/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -1620,30 +1620,10 @@ func postStateStripBinaries() {
cmdRun([]string{objcopy, "--strip-debug", getAppName()}, false)
// to add a link to the debugging info into the stripped executable.
cmdRun([]string{objcopy, "--add-gnu-debuglink=" + getAppName() + ".dbg", getAppName()}, false)

// strip crashpad_handler as well if any
hasCrashpad := true
crashpadPath := "crashpad_handler"
if _, err := os.Stat(crashpadPath); errors.Is(err, os.ErrNotExist) {
hasCrashpad = false
}
if hasCrashpad {
cmdRun([]string{objcopy, "--strip-debug", crashpadPath}, false)
}
} else if systemNameFlag == "darwin" {
cmdRun([]string{"dsymutil", filepath.Join(getAppName(), "Contents", "MacOS", APPNAME),
"--statistics", "--papertrail", "-o", getAppName() + ".dSYM"}, false)
cmdRun([]string{"strip", "-S", "-x", "-v", filepath.Join(getAppName(), "Contents", "MacOS", APPNAME)}, false)

// strip crashpad_handler as well if any
hasCrashpad := true
crashpadPath := filepath.Join(getAppName(), "Contents", "Resources", "crashpad_handler")
if _, err := os.Stat(crashpadPath); errors.Is(err, os.ErrNotExist) {
hasCrashpad = false
}
if hasCrashpad {
cmdRun([]string{"strip", "-S", "-x", "-v", crashpadPath}, false)
}
} else if systemNameFlag == "ios" {
cmdRun([]string{"dsymutil", filepath.Join(getAppName(), APPNAME),
"--statistics", "--papertrail", "-o", getAppName() + ".dSYM"}, false)
Expand Down Expand Up @@ -2236,9 +2216,18 @@ func postStateArchives() map[string][]string {
if systemNameFlag == "ios" {
archive = fmt.Sprintf(archiveFormat, APPNAME, "", ".ipa")
}
hasCrashpad := true
hasCrashpadExe := true
if _, err := os.Stat("crashpad_handler.exe"); errors.Is(err, os.ErrNotExist) {
hasCrashpad = false
hasCrashpadExe = false
}
hasCrashpadPdb := true
if _, err := os.Stat("crashpad_handler.pdb"); errors.Is(err, os.ErrNotExist) {
hasCrashpadPdb = false
}

hasCrashpadDbg := true
if _, err := os.Stat("crashpad_handler.dbg"); errors.Is(err, os.ErrNotExist) {
hasCrashpadDbg = false
}

msiArchive := fmt.Sprintf(archiveFormat, APPNAME, "", ".msi")
Expand Down Expand Up @@ -2274,7 +2263,7 @@ func postStateArchives() map[string][]string {
paths = append(paths, fmt.Sprintf("../doc/%s.1", APPNAME))
}
// copying dependent crashpad handler if any
if hasCrashpad {
if hasCrashpadExe {
paths = append(paths, "crashpad_handler.exe")
}

Expand All @@ -2292,7 +2281,7 @@ func postStateArchives() map[string][]string {
// error CNDL0265 : The Platform attribute has an invalid value arm64.
// Possible values are x86, x64, or ia64.
if systemNameFlag == "windows" && msvcTargetArchFlag != "arm64" {
generateMsi(msiArchive, dllPaths, licensePaths, hasCrashpad)
generateMsi(msiArchive, dllPaths, licensePaths, hasCrashpadExe)
archives[msiArchive] = []string{msiArchive}
}
// nsis installer
Expand All @@ -2304,16 +2293,29 @@ func postStateArchives() map[string][]string {
}
// debuginfo file
if systemNameFlag == "windows" {
archiveFiles(debugArchive, archivePrefix, []string{APPNAME + ".pdb"})
dbgPaths = append(dbgPaths, APPNAME+".pdb")
if hasCrashpadPdb {
dbgPaths = append(dbgPaths, "crashpad_handler.pdb")
}
archiveFiles(debugArchive, archivePrefix, dbgPaths)
} else if systemNameFlag == "mingw" || systemNameFlag == "harmony" || systemNameFlag == "linux" || systemNameFlag == "freebsd" {
archiveFiles(debugArchive, archivePrefix, []string{getAppName() + ".dbg"})
dbgPaths = append(dbgPaths, APPNAME+".dbg")
dbgPaths = append(dbgPaths, getAppName() + ".dbg")
if hasCrashpadDbg {
dbgPaths = append(dbgPaths, "crashpad_handler.dbg")
}
archiveFiles(debugArchive, archivePrefix, dbgPaths)
} else if systemNameFlag == "android" {
archiveFiles(debugArchive, archivePrefix, []string{getAppName() + ".dbg"})
dbgPaths = append(dbgPaths, APPNAME+".dbg")
dbgPaths = append(dbgPaths, getAppName() + ".dbg")
if hasCrashpadDbg {
dbgPaths = append(dbgPaths, "crashpad_handler.dbg")
}
archiveFiles(debugArchive, archivePrefix, dbgPaths)
} else if systemNameFlag == "darwin" {
archiveFiles(debugArchive, archivePrefix, []string{getAppName() + ".dSYM"})
dbgPaths = append(dbgPaths, getAppName() + ".dSYM")
if hasCrashpadDbg {
dbgPaths = append(dbgPaths, "crashpad_handler.dbg")
}
archiveFiles(debugArchive, archivePrefix, dbgPaths)
} else if systemNameFlag == "ios" {
cmdRun([]string{"rm", "-rf", getAppName() + ".dSYM"}, true)
buildSubdir := cmakeBuildTypeFlag + "-iphoneos"
Expand Down

0 comments on commit 6c0a054

Please sign in to comment.