From c4a21f333a7c03e63acb80dff23d16bdaf0bb58c Mon Sep 17 00:00:00 2001 From: Morten Linderud Date: Sun, 2 Jan 2022 18:21:59 +0100 Subject: [PATCH] strip: Use debugedit instead of AWK to parse source files This moves us from the fairly ugly AWK parsing line to debugedit which originally comes out of the rpm project. The original code has issues parsing anything that was not straight C/C++ and languages like Rust or Go would return invalid source code files. debugedit handles all these cases better. Fixes FS#66755 Fixes FS#66888 Fixes FS#65677 Signed-off-by: Morten Linderud Signed-off-by: Allan McRae (cherry picked from commit ae2f506ddfd11d9becda7216033fe1b159536982) --- scripts/libmakepkg/executable/debugedit.sh.in | 38 +++++++++++++++++++ scripts/libmakepkg/tidy/strip.sh.in | 22 ++++++++--- 2 files changed, 55 insertions(+), 5 deletions(-) create mode 100644 scripts/libmakepkg/executable/debugedit.sh.in diff --git a/scripts/libmakepkg/executable/debugedit.sh.in b/scripts/libmakepkg/executable/debugedit.sh.in new file mode 100644 index 00000000..55b9257a --- /dev/null +++ b/scripts/libmakepkg/executable/debugedit.sh.in @@ -0,0 +1,38 @@ +#!/usr/bin/bash +# +# debugedit.sh - Confirm presence of debugedit binary +# +# Copyright (c) 2022 Pacman Development Team +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +[[ -n "$LIBMAKEPKG_EXECUTABLE_DEBUGEDIT_SH" ]] && return +LIBMAKEPKG_EXECUTABLE_DEBUGEDIT_SH=1 + +LIBRARY=${LIBRARY:-'@libmakepkgdir@'} + +source "$LIBRARY/util/message.sh" +source "$LIBRARY/util/option.sh" + +executable_functions+=('executable_debugedit') + +executable_debugedit() { + if check_option "debug" "y"; then + if ! type -p debugedit >/dev/null; then + error "$(gettext "Cannot find the %s binary required for including source files in debug packages.")" "debugedit" + return 1 + fi + fi +} diff --git a/scripts/libmakepkg/tidy/strip.sh.in b/scripts/libmakepkg/tidy/strip.sh.in index 96602538..6955bb68 100644 --- a/scripts/libmakepkg/tidy/strip.sh.in +++ b/scripts/libmakepkg/tidy/strip.sh.in @@ -36,8 +36,20 @@ build_id() { } source_files() { - LANG=C readelf "$1" --debug-dump 2>/dev/null | \ - awk '/DW_AT_name +:/{name=$NF}/DW_AT_comp_dir +:/{{if (name == "") next}{if (name !~ /^[<\/]/) {printf "%s/", $NF}}{print name}}' + # This function does two things: + # + # 1) rewrites source file locations for packages not respecting prefix- + # map switches. This ensures all source file references in debug + # info point to $dbgsrcdir. + # + # 2) outputs a list of files from the package source files to stdout + # while stripping the $dbgsrcdir prefix + + LANG=C debugedit --no-recompute-build-id \ + --base-dir "${srcdir}" \ + --dest-dir "${dbgsrcdir}" \ + --list-file /dev/stdout "$1" \ + | sort -zu | tr '\0' '\n' } strip_file() { @@ -58,9 +70,9 @@ strip_file() { # copy source files to debug directory local file dest t while IFS= read -r t; do - file=${t/${dbgsrcdir}/"$srcdir"} - dest="${dbgsrc/"$dbgsrcdir"/}$t" - if ! [[ -f $dest ]]; then + file="${srcdir}/${t}" + dest="${dbgsrc}/${t}" + if [[ -f "$file" ]] && ! [[ -f $dest ]]; then mkdir -p "${dest%/*}" cp -- "$file" "$dest" fi