From patchwork Sun Jan 2 17:21:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Morten Linderud X-Patchwork-Id: 2009 Return-Path: Delivered-To: patchwork@archlinux.org Received: from mail.archlinux.org [2a01:4f9:c010:3052::1] by patchwork.archlinux.org with IMAP (fetchmail-6.4.25) for (single-drop); Sun, 02 Jan 2022 17:22:21 +0000 (UTC) Received: from mail.archlinux.org by mail.archlinux.org with LMTP id QuJIIUzf0WHiNwgAK+/4rw (envelope-from ) for ; Sun, 02 Jan 2022 17:22:20 +0000 Received: from lists.archlinux.org (lists.archlinux.org [IPv6:2a01:4f9:c010:9eb4::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.archlinux.org (Postfix) with ESMTPS id 4A8E7BDAA1E; Sun, 2 Jan 2022 17:22:19 +0000 (UTC) Received: from lists.archlinux.org (localhost [IPv6:::1]) by lists.archlinux.org (Postfix) with ESMTP id 1FF56B62925; Sun, 2 Jan 2022 17:22:19 +0000 (UTC) X-Original-To: pacman-dev@lists.archlinux.org Delivered-To: pacman-dev@lists.archlinux.org Received: from mail.archlinux.org (mail.archlinux.org [95.216.189.61]) by lists.archlinux.org (Postfix) with ESMTPS id D91DFB6291A for ; Sun, 2 Jan 2022 17:22:16 +0000 (UTC) From: Morten Linderud DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=archlinux.org; s=dkim-rsa; t=1641144136; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=ZcO6e1V2qjupu2gr6hRXPFeePyus569pTY9Pn+epTu4=; b=qA1qolzUGPRFAzTUvq/EfAsyt0f/gmHXh88MJMGdT3BH1oDU4zmQjKnSj8IDyhVnfK4o28 rL9xrPAjuxmIcPJJt3Zg211MbQ5VIerF+vCgNTCoR9NKQAV7j66JmkF5Ryikr+eOuqxswR uoS/Ig3MY436q/WpXZHxuhfMCAAEn5S5SvIJf/rWO4CSxPCOBaCyiVmjCgcg+Pw0ayyRLD MyRh95CcQQlhmFUFVYpncyNWJH32CbNeGg6nk7b/yxDkEVRK61WdUkCZ4ubIx8Rprub1l+ ZE4hjU7YvX7B8UJQdTeTnIUmH4xelC37ukiX1pzYz8STqHzuIwWCYjbVv2NBauaZ3P4wzp wgHXLb7EQubLPaIEVRbs2Fuy8yAuqmEtfOSmRwicH0d8m6tf4sG7rhuv1vMoVMJSSWX/Xz ZDWdCULBXRe/bTzkzTzc/e3CR1e6D+u9yEVS4t72YURwpdfUJN6z6xE2ZqcqssoKz98g7O P1lpQhVN24t5Q2nMNHe5a9ae/bVgDO93oGA834heCzPhyzcpQcpxSG7jSyfnRIkrzAn/r9 kZGpHLV0MRRAlQgHp07O7kOoFH1gr4ZSz4WTwp1O1RNmJ6KQLrSH6bh+3RbWHruzf96Zs0 CqaP4JsiTvgvKoOUfQPoTeytBX9fVmMSS5KbPqyYuOap7KM2uTJVs= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=archlinux.org; s=dkim-ed25519; t=1641144136; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=ZcO6e1V2qjupu2gr6hRXPFeePyus569pTY9Pn+epTu4=; b=T6/giM68DwDQdQlfldNwL0swaZrt9g0GvweYuA7zRLWTetOXU9LVpgsrHBFVzCcnI5lx0l p6Fevr9ia4cK5PAw== To: pacman-dev@lists.archlinux.org Cc: Morten Linderud Subject: [PATCH v2] strip: Use debugedit instead of AWK to parse source files Date: Sun, 2 Jan 2022 18:21:59 +0100 Message-Id: <20220102172159.2902783-1-foxboron@archlinux.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-BeenThere: pacman-dev@lists.archlinux.org X-Mailman-Version: 2.1.39 Precedence: list List-Id: Discussion list for pacman development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: pacman-dev-bounces@lists.archlinux.org Sender: "pacman-dev" Authentication-Results: mail.archlinux.org; dkim=pass header.d=archlinux.org header.s=dkim-rsa header.b=qA1qolzU; dkim=pass header.d=archlinux.org header.s=dkim-ed25519 header.b="T6/giM68"; dmarc=pass (policy=none) header.from=archlinux.org; spf=pass (mail.archlinux.org: domain of pacman-dev-bounces@lists.archlinux.org designates 2a01:4f9:c010:9eb4::1 as permitted sender) smtp.mailfrom=pacman-dev-bounces@lists.archlinux.org X-Rspamd-Queue-Id: 4A8E7BDAA1E X-Spamd-Result: default: False [-2.61 / 15.00]; DWL_DNSWL_MED(-2.00)[archlinux.org:dkim]; MID_CONTAINS_FROM(1.00)[]; RCVD_DKIM_ARC_DNSWL_MED(-0.50)[]; DMARC_POLICY_ALLOW(-0.50)[archlinux.org,none]; R_MISSING_CHARSET(0.50)[]; RCVD_IN_DNSWL_MED(-0.40)[2a01:4f9:c010:9eb4::1:from,95.216.189.61:received]; MAILLIST(-0.20)[mailman]; R_SPF_ALLOW(-0.20)[+ip6:2a01:4f9:c010:9eb4::1:c]; R_DKIM_ALLOW(-0.20)[archlinux.org:s=dkim-rsa,archlinux.org:s=dkim-ed25519]; MIME_GOOD(-0.10)[text/plain]; HAS_LIST_UNSUB(-0.01)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[pacman-dev@lists.archlinux.org]; ARC_NA(0.00)[]; RCVD_TLS_LAST(0.00)[]; ASN(0.00)[asn:24940, ipnet:2a01:4f9::/32, country:DE]; DKIM_TRACE(0.00)[archlinux.org:+]; RCVD_COUNT_THREE(0.00)[3]; FROM_NEQ_ENVFROM(0.00)[foxboron@archlinux.org,pacman-dev-bounces@lists.archlinux.org]; RCPT_COUNT_TWO(0.00)[2]; MIME_TRACE(0.00)[0:+]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; NEURAL_HAM(-0.00)[-1.000]; FORGED_SENDER_MAILLIST(0.00)[] X-Rspamd-Server: mail.archlinux.org From: Morten Linderud 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 Signed-off-by: Morten Linderud --- scripts/libmakepkg/executable/debugedit.sh.in | 38 +++++++++++++++++++ scripts/libmakepkg/tidy/strip.sh.in | 25 +++++++++--- 2 files changed, 58 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..ec0ab814 --- /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) 2011-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 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 92a6fb15..84732c6f 100644 --- a/scripts/libmakepkg/tidy/strip.sh.in +++ b/scripts/libmakepkg/tidy/strip.sh.in @@ -36,8 +36,23 @@ 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}}' + # debugedit rewrites the binary. In most cases this is handled by the gcc + # prefix-map switches which rewrites $srcdir to $dbgsrcdir. debugedit will + # not do anything in those cases. However for binaries that does not have a + # prefix-map debugedit is going to modify the binary correcting the paths. + # + # From the mailing list discussion: + # * Without -b/-d: it just lists all source files. + # * With -b, it prints all source files rooted in the specified directory, but strips the + # prefix from the output. + # * With both -b and -d, it replaces any base-dir prefixes with dest-dir + # (modifying the binary), then prints all paths rooted in the dest-dir + # (again, stripping the dest-dir prefix in the output). + 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 +73,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