From: Mike Gilbert <floppym@gentoo.org>
To: gentoo-portage-dev@lists.gentoo.org
Cc: Mike Gilbert <floppym@gentoo.org>
Subject: [gentoo-portage-dev] [PATCH] estrip: rework hard link logic in save_elf_debug
Date: Mon, 25 Oct 2021 13:09:49 -0400 [thread overview]
Message-ID: <20211025170949.3653760-1-floppym@gentoo.org> (raw)
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 <floppym@gentoo.org>
---
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
next reply other threads:[~2021-10-25 17:09 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-25 17:09 Mike Gilbert [this message]
2021-10-27 14:51 ` [gentoo-portage-dev] [PATCH] estrip: rework hard link logic in save_elf_debug Alec Warner
2021-10-28 15:11 ` Mike Gilbert
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211025170949.3653760-1-floppym@gentoo.org \
--to=floppym@gentoo.org \
--cc=gentoo-portage-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox