makepkg: tell the compiler to record debugging info for debug packages

In commit 8b0d59b83a support was added for
storing the source files of binaries in debug packages. This made use of
the debugedit program which is part of the RPM package manager, which is
not very standalone.

The same effect can be achieved using -fdebug-prefix-map, an option
accepted by both the gcc and clang compilers which modifies how the
compiler itself stores the references to the source files rather than
requiring us to later edit the produced binaries. This also removes the
dependency on external programs like debugedit.

As a result of this change, source files will only be effectively added
for programs which actually use the exported CFLAGS. This is a reasonable
tradeoff as we expect our CFLAGS to be used rather than ignored. Upstream
software which do not produce useful debug packages are expected to fix
their build systems to respect the environment CFLAGS.

As a result of this change, the routine for extracting source filenames
from binaries had to be modified to derive the source file from the
final debug location, rather than the other way around.

Signed-off-by: Eli Schwartz <eschwartz@archlinux.org>
Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
Eli Schwartz 2017-10-30 14:35:23 -04:00 committed by Allan McRae
parent 259d521e37
commit 8bec63bf92
2 changed files with 6 additions and 5 deletions

View file

@ -57,15 +57,12 @@ strip_file() {
# copy source files to debug directory # copy source files to debug directory
local f t local f t
while read -r f; do while read -r t; do
t=${f/"$srcdir"/$dbgsrc} f=${t/$dbgsrc/"$srcdir"}
mkdir -p "${t%/*}" mkdir -p "${t%/*}"
cp -- "$f" "$t" cp -- "$f" "$t"
done < <(source_files "$binary") done < <(source_files "$binary")
# adjust debug symbols to point at sources
debugedit -b "${srcdir}" -d /usr/src/debug/ -i "$binary" &> /dev/null
# copy debug symbols to debug directory # copy debug symbols to debug directory
mkdir -p "$dbgdir/${binary%/*}" mkdir -p "$dbgdir/${binary%/*}"
objcopy --only-keep-debug "$binary" "$dbgdir/$binary.debug" objcopy --only-keep-debug "$binary" "$dbgdir/$binary.debug"

View file

@ -379,6 +379,10 @@ prepare_buildenv() {
fi fi
if check_option "debug" "y"; then if check_option "debug" "y"; then
if [[ -v DBGSRCDIR ]]; then
DEBUG_CFLAGS+=" -fdebug-prefix-map=$srcdir=$DBGSRCDIR"
DEBUG_CXXFLAGS+=" -fdebug-prefix-map=$srcdir=$DBGSRCDIR"
fi
CFLAGS+=" $DEBUG_CFLAGS" CFLAGS+=" $DEBUG_CFLAGS"
CXXFLAGS+=" $DEBUG_CXXFLAGS" CXXFLAGS+=" $DEBUG_CXXFLAGS"
fi fi