From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 7231F158086 for ; Mon, 25 Oct 2021 17:09:59 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id A9976E07DB; Mon, 25 Oct 2021 17:09:58 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 44102E07DB for ; Mon, 25 Oct 2021 17:09:58 +0000 (UTC) From: Mike Gilbert To: gentoo-portage-dev@lists.gentoo.org Cc: Mike Gilbert Subject: [gentoo-portage-dev] [PATCH] estrip: rework hard link logic in save_elf_debug Date: Mon, 25 Oct 2021 13:09:49 -0400 Message-Id: <20211025170949.3653760-1-floppym@gentoo.org> X-Mailer: git-send-email 2.33.1 Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-portage-dev@lists.gentoo.org Reply-to: gentoo-portage-dev@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Archives-Salt: 75241d1d-ad25-4aa7-b743-97036f9f008e X-Archives-Hash: 518f785cd7ae7b8b2e8eb22b8051e868 GDB loads debug files based on the file name given in the .gnu_debuglink section, prepended with /usr/lib/debug/${dirname}, where dirname is the absolute path to the parent directory of the binary being executed. For each unique inode as input, we need a link to the debug file with the GNU debuglink as its basename. A link to the debug file should exist for each directory in which the input inode exists. The debug link names should be based on the .gnu_debuglink value instead of the name of the file we are processing as input. The .gnu_debuglink value is based on the name of the first link processed for each inode. We save this value as a symlink, and then read it back as we process subsequent links. For example, given the following input: INODE PATH 1 /usr/bin/git 1 /usr/libexec/git-core/git-add 2 /usr/bin/git-shell 2 /usr/libexec/git-core/git-shell We generate the following inodes for the debug files: INODE DEBUGLINK 3 git.debug 4 git-shell.debug We should generate the following links: INODE PATH 3 /usr/lib/debug/usr/bin/git.debug 3 /usr/lib/debug/usr/libexec/git-core/git.debug 4 /usr/bin/debug/usr/bin/git-shell.debug 4 /usr/bin/debug/usr/libexec/git-core/git-shell.debug The previous code would have generated this broken output: INODE PATH 3 /usr/lib/debug/usr/bin/git.debug 3 /usr/lib/debug/usr/libexec/git-core/git-add.debug (*) 4 /usr/bin/debug/usr/bin/git-shell.debug 4 /usr/bin/debug/usr/libexec/git-core/git-shell.debug (*) This link has the wrong name. Bug: https://bugs.gentoo.org/820107 Signed-off-by: Mike Gilbert --- bin/estrip | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/bin/estrip b/bin/estrip index abe523fff..8134020fd 100755 --- a/bin/estrip +++ b/bin/estrip @@ -201,17 +201,29 @@ save_elf_debug() { local x=$1 local inode_debug=$2 local splitdebug=$3 - local d_noslash=${D%/} - local y=${ED%/}/usr/lib/debug/${x:${#d_noslash}}.debug + + local x_basename=${x##*/} + local x_dirname=${x%/*} + local y_dirname=${ED%/}/usr/lib/debug/${x_dirname#${D%/}/} + local y_basename y # dont save debug info twice [[ ${x} == *".debug" ]] && return 0 - mkdir -p "${y%/*}" + mkdir -p "${y_dirname}" || die + + if [[ -L ${inode_debug} ]] ; then + y_basename=$(readlink "${inode_debug}") || die + y_basename=${y_basename##*/} + y=${y_dirname}/${y_basename} - if [ -f "${inode_debug}" ] ; then - ln "${inode_debug}" "${y}" || die "ln failed unexpectedly" + if [[ ! -e ${y} ]]; then + ln -L "${inode_debug}" "${y}" || die + fi else + y_basename=${x_basename}.debug + y=${y_dirname}/${y_basename} + if [[ -n ${splitdebug} ]] ; then mv "${splitdebug}" "${y}" else @@ -222,11 +234,12 @@ save_elf_debug() { fi # Only do the following if the debug file was # successfully created (see bug #446774). - if [ $? -eq 0 ] ; then + if [[ $? -eq 0 ]] ; then local args="a-x,o-w" [[ -g ${x} || -u ${x} ]] && args+=",go-r" chmod ${args} "${y}" - ln "${y}" "${inode_debug}" || die "ln failed unexpectedly" + # symlink so we can read the name back. + ln -s "${y}" "${inode_debug}" || die fi fi @@ -239,8 +252,8 @@ save_elf_debug() { local buildid_dir="${ED%/}/usr/lib/debug/.build-id/${buildid:0:2}" local buildid_file="${buildid_dir}/${buildid:2}" mkdir -p "${buildid_dir}" - [ -L "${buildid_file}".debug ] || ln -s "../../${x:$((${#d_noslash} + 1))}.debug" "${buildid_file}.debug" - [ -L "${buildid_file}" ] || ln -s "/${x:$((${#d_noslash} + 1))}" "${buildid_file}" + [[ -L "${buildid_file}".debug ]] || ln -s "../../${x#${D%/}/}.debug" "${buildid_file}.debug" + [[ -L "${buildid_file}" ]] || ln -s "../../../../../${x#${D%/}/}" "${buildid_file}" fi } -- 2.33.1