Adjust build-debug-info (used to create debug packages):

- Use llvm-objcopy instead of (binutils) objcopy when creating detached
debug symbols and adding the gnu-debuglink section.

- For llvm-objcopy and strip, output to a temporary file and copy it
back to the original file. The LLVM tools create a new file, so hard links
are not normally maintained, but this method keeps them.

https://github.com/llvm/llvm-project/issues/59848#issuecomment-1374070557

ok naddy@.

This should allow us to move back to llvm-strip in base on archs where
we use ld.lld, which (alongside the change to llvm-objcopy) avoids problems
that have been seen during mimmutable(2) development with GNU_RELRO with
the version of binutils that we have.
This commit is contained in:
sthen 2023-01-22 20:48:00 +00:00
parent baaba3378d
commit 9a855887d9

View File

@ -1,5 +1,5 @@
#! /usr/bin/perl
# $OpenBSD: build-debug-info,v 1.46 2022/09/11 08:40:40 espie Exp $
# $OpenBSD: build-debug-info,v 1.47 2023/01/22 20:48:00 sthen Exp $
# Copyright (c) 2019 Marc Espie <espie@openbsd.org>
#
# Permission to use, copy, modify, and distribute this software for any
@ -236,7 +236,7 @@ my $base = PlistFactory->parse_args($self);
use File::Basename;
$self->{mk} = $state->openfile($state->{pkgdir}."/Makefile.new");
print {$self->{mk}} << 'EOPREAMBLE';
# Makefile generated by build-debug-info $OpenBSD: build-debug-info,v 1.46 2022/09/11 08:40:40 espie Exp $
# Makefile generated by build-debug-info $OpenBSD: build-debug-info,v 1.47 2023/01/22 20:48:00 sthen Exp $
# No serviceable parts
# Intended to run under the stage area after cd ${WRKINST}
@ -246,10 +246,10 @@ OBJCOPY_RULE = ${INSTALL_DATA_DIR} ${@D} && \
if readelf 2>/dev/null -wi $?|cmp -s /dev/null -; then \
echo "Warning: no debug-info in $?"; \
fi && \
objcopy --only-keep-debug $? $@ && \
llvm-objcopy --only-keep-debug $? $@ && \
${DWZ} $@ && \
strip -d $? && \
objcopy --add-gnu-debuglink=$@ $? && \
strip -d -o $?.stripped $? && cp $?.stripped $? && rm $?.stripped && \
llvm-objcopy --add-gnu-debuglink=$@ $? $?.debuglink && cp $?.debuglink $? && rm $?.debuglink && \
chmod $$perm $? && \
touch $@